diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 9bc1e3a7..8448bfed 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -744,13 +744,75 @@ void lcMainWindow::CreateToolBars() mPartsToolBar->raise(); } +class lcElidedLabel : public QFrame +{ +public: + explicit lcElidedLabel(QWidget* Parent = nullptr) + : QFrame(Parent) + { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + } + + void setText(const QString& Text) + { + mText = Text; + update(); + } + +protected: + void paintEvent(QPaintEvent* event) override; + + QString mText; +}; + +void lcElidedLabel::paintEvent(QPaintEvent* event) +{ + QFrame::paintEvent(event); + + QPainter Painter(this); + QFontMetrics FontMetrics = Painter.fontMetrics(); + + int LineSpacing = FontMetrics.lineSpacing(); + int y = 0; + + QTextLayout TextLayout(mText, Painter.font()); + TextLayout.beginLayout(); + + for (;;) + { + QTextLine Line = TextLayout.createLine(); + + if (!Line.isValid()) + break; + + Line.setLineWidth(width()); + int NextLineY = y + LineSpacing; + + if (height() >= NextLineY + LineSpacing) + { + Line.draw(&Painter, QPoint(0, y)); + y = NextLineY; + } + else + { + QString LastLine = mText.mid(Line.textStart()); + QString ElidedLastLine = FontMetrics.elidedText(LastLine, Qt::ElideRight, width()); + Painter.drawText(QPoint(0, y + FontMetrics.ascent()), ElidedLastLine); + Line = TextLayout.createLine(); + break; + } + } + + TextLayout.endLayout(); +} + void lcMainWindow::CreateStatusBar() { QStatusBar* StatusBar = new QStatusBar(this); setStatusBar(StatusBar); - mStatusBarLabel = new QLabel(); - StatusBar->addWidget(mStatusBarLabel); + mStatusBarLabel = new lcElidedLabel(); + StatusBar->addWidget(mStatusBarLabel, 1); mStatusPositionLabel = new QLabel(); StatusBar->addPermanentWidget(mStatusPositionLabel); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 6b57dcea..355f6313 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -13,6 +13,7 @@ class lcQPartsTree; class lcQColorList; class lcQPropertiesTree; class lcTimelineWidget; +class lcElidedLabel; #ifdef QT_NO_PRINTER class QPrinter; #endif @@ -420,7 +421,7 @@ protected: QLineEdit* mTransformYEdit; QLineEdit* mTransformZEdit; - QLabel* mStatusBarLabel; + lcElidedLabel* mStatusBarLabel; QLabel* mStatusPositionLabel; QLabel* mStatusSnapLabel; QLabel* mStatusTimeLabel;