ui: Fixed code file title buttons might shrink to zero content when elided
This commit is contained in:
@@ -15,8 +15,10 @@ QtSelfRefreshIconButton::QtSelfRefreshIconButton(
|
|||||||
setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
m_timer.setSingleShot(true);
|
m_updateTimer.setSingleShot(true);
|
||||||
connect(&m_timer, &QTimer::timeout, [this](){ updateText(width()); });
|
m_blockTimer.setSingleShot(true);
|
||||||
|
connect(&m_updateTimer, &QTimer::timeout, [this](){ updateText(width()); });
|
||||||
|
connect(&m_blockTimer, &QTimer::timeout, [this](){ m_blockUpdate = false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtSelfRefreshIconButton::setText(const QString& text)
|
void QtSelfRefreshIconButton::setText(const QString& text)
|
||||||
@@ -26,7 +28,7 @@ void QtSelfRefreshIconButton::setText(const QString& text)
|
|||||||
|
|
||||||
if (m_autoElide)
|
if (m_autoElide)
|
||||||
{
|
{
|
||||||
m_timer.start(25);
|
m_updateTimer.start(25);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ void QtSelfRefreshIconButton::resizeEvent(QResizeEvent *event)
|
|||||||
{
|
{
|
||||||
if (m_autoElide)
|
if (m_autoElide)
|
||||||
{
|
{
|
||||||
m_timer.stop();
|
m_updateTimer.stop();
|
||||||
updateText(event->size().width());
|
updateText(event->size().width());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +75,11 @@ void QtSelfRefreshIconButton::resizeEvent(QResizeEvent *event)
|
|||||||
|
|
||||||
void QtSelfRefreshIconButton::updateText(int width)
|
void QtSelfRefreshIconButton::updateText(int width)
|
||||||
{
|
{
|
||||||
QPushButton::setText(
|
if (!m_blockUpdate)
|
||||||
fontMetrics().elidedText(m_text, Qt::ElideLeft, width - iconSize().width() - 22));
|
{
|
||||||
|
m_blockUpdate = true;
|
||||||
|
QPushButton::setText(
|
||||||
|
fontMetrics().elidedText(m_text, Qt::ElideLeft, width - iconSize().width() - 22));
|
||||||
|
m_blockTimer.start(50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ private:
|
|||||||
const std::string m_buttonKey;
|
const std::string m_buttonKey;
|
||||||
|
|
||||||
bool m_autoElide = false;
|
bool m_autoElide = false;
|
||||||
QTimer m_timer;
|
bool m_blockUpdate = false;
|
||||||
|
QTimer m_updateTimer;
|
||||||
|
QTimer m_blockTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QT_SELF_REFRESH_ICON_BUTTON_H
|
#endif // QT_SELF_REFRESH_ICON_BUTTON_H
|
||||||
|
|||||||
Reference in New Issue
Block a user