Use empty list label code for welcome screen
Signed-off-by: crpz1 <8588315+crpz1@users.noreply.github.com>
This commit is contained in:
parent
99cbb5d0b2
commit
9aa81cf005
@ -482,32 +482,42 @@ void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event)
|
|||||||
|
|
||||||
if (model()->rowCount() == 0) {
|
if (model()->rowCount() == 0) {
|
||||||
painter.save();
|
painter.save();
|
||||||
const QString line1 = tr("Welcome!");
|
QString emptyString = tr("Welcome!") + "\n" + tr("Click \"Add Instance\" to get started.");
|
||||||
const QString line2 = tr("Click \"Add Instance\" to get started.");
|
|
||||||
auto rect = this->viewport()->rect();
|
|
||||||
auto font = option.font;
|
|
||||||
font.setPointSize(37);
|
|
||||||
painter.setFont(font);
|
|
||||||
auto fm = painter.fontMetrics();
|
|
||||||
|
|
||||||
if (rect.height() <= (fm.height() * 5) || rect.width() <= fm.horizontalAdvance(line2)) {
|
// calculate the rect for the overlay
|
||||||
auto s = rect.height() / (5. * fm.height());
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
auto sx = rect.width() * 1. / fm.horizontalAdvance(line2);
|
QFont font("sans", 20);
|
||||||
if (s >= sx)
|
font.setBold(true);
|
||||||
s = sx;
|
|
||||||
auto ps = font.pointSize() * s;
|
QRect bounds = viewport()->geometry();
|
||||||
if (ps <= 0)
|
bounds.moveTop(0);
|
||||||
ps = 1;
|
auto innerBounds = bounds;
|
||||||
font.setPointSize(ps);
|
innerBounds.adjust(10, 10, -10, -10);
|
||||||
painter.setFont(font);
|
|
||||||
fm = painter.fontMetrics();
|
QColor background = QApplication::palette().color(QPalette::WindowText);
|
||||||
|
QColor foreground = QApplication::palette().color(QPalette::Base);
|
||||||
|
foreground.setAlpha(190);
|
||||||
|
painter.setFont(font);
|
||||||
|
auto fontMetrics = painter.fontMetrics();
|
||||||
|
auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
|
||||||
|
textRect.moveCenter(bounds.center());
|
||||||
|
|
||||||
|
auto wrapRect = textRect;
|
||||||
|
wrapRect.adjust(-10, -10, 10, 10);
|
||||||
|
|
||||||
|
// check if we are allowed to draw in our area
|
||||||
|
if (!event->rect().intersects(wrapRect)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// text
|
painter.setBrush(QBrush(background));
|
||||||
rect.setTop(rect.top() + fm.height() * 1.5);
|
painter.setPen(foreground);
|
||||||
painter.drawText(rect, Qt::AlignHCenter, line1);
|
painter.drawRoundedRect(wrapRect, 5.0, 5.0);
|
||||||
rect.setTop(rect.top() + fm.height());
|
|
||||||
painter.drawText(rect, Qt::AlignHCenter, line2);
|
painter.setPen(foreground);
|
||||||
|
painter.setFont(font);
|
||||||
|
painter.drawText(textRect, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
|
||||||
|
|
||||||
painter.restore();
|
painter.restore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user