| 454 | } |
| 455 | |
| 456 | void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event) |
| 457 | { |
| 458 | executeDelayedItemsLayout(); |
| 459 | |
| 460 | QPainter painter(this->viewport()); |
| 461 | |
| 462 | if (m_cat) { |
| 463 | m_cat->paint(&painter, this->viewport()->rect()); |
| 464 | } |
| 465 | |
| 466 | QStyleOptionViewItem option; |
| 467 | initViewItemOption(&option); |
| 468 | option.widget = this; |
| 469 | |
| 470 | if (model()->rowCount() == 0) { |
| 471 | painter.save(); |
| 472 | QString emptyString = tr("Welcome!") + "\n" + tr("Click \"Add Instance\" to get started."); |
| 473 | |
| 474 | // calculate the rect for the overlay |
| 475 | painter.setRenderHint(QPainter::Antialiasing, true); |
| 476 | QFont font("sans", 20); |
| 477 | font.setBold(true); |
| 478 | |
| 479 | QRect bounds = viewport()->geometry(); |
| 480 | bounds.moveTop(0); |
| 481 | auto innerBounds = bounds; |
| 482 | innerBounds.adjust(10, 10, -10, -10); |
| 483 | |
| 484 | QColor background = QApplication::palette().color(QPalette::WindowText); |
| 485 | QColor foreground = QApplication::palette().color(QPalette::Base); |
| 486 | foreground.setAlpha(190); |
| 487 | painter.setFont(font); |
| 488 | auto fontMetrics = painter.fontMetrics(); |
| 489 | auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString); |
| 490 | textRect.moveCenter(bounds.center()); |
| 491 | |
| 492 | auto wrapRect = textRect; |
| 493 | wrapRect.adjust(-10, -10, 10, 10); |
| 494 | |
| 495 | // check if we are allowed to draw in our area |
| 496 | if (!event->rect().intersects(wrapRect)) { |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | painter.setBrush(QBrush(background)); |
| 501 | painter.setPen(foreground); |
| 502 | painter.drawRoundedRect(wrapRect, 5.0, 5.0); |
| 503 | |
| 504 | painter.setPen(foreground); |
| 505 | painter.setFont(font); |
| 506 | painter.drawText(textRect, Qt::AlignHCenter | Qt::TextWordWrap, emptyString); |
| 507 | |
| 508 | painter.restore(); |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | int wpWidth = viewport()->width(); |
| 513 | option.rect.setWidth(wpWidth); |
nothing calls this directly
no test coverage detected