mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Elide status bar text. Fixes #417.
This commit is contained in:
parent
3044bf3972
commit
6891c59d38
2 changed files with 66 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue