| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "gui/reusable/squeezelabel.h" |
| 4 | |
| 5 | SqueezeLabel::SqueezeLabel(QWidget* parent) : QLabel(parent) {} |
| 6 | |
| 7 | void SqueezeLabel::paintEvent(QPaintEvent* event) { |
| 8 | if (m_squeezedTextCache != text()) { |
| 9 | m_squeezedTextCache = text(); |
| 10 | QFontMetrics fm = fontMetrics(); |
| 11 | |
| 12 | if (fm.horizontalAdvance(m_squeezedTextCache) > contentsRect().width()) { |
| 13 | setText(fm.elidedText(text(), Qt::TextElideMode::ElideRight, width())); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | QLabel::paintEvent(event); |
| 18 | } |