| 452 | } |
| 453 | |
| 454 | void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event) |
| 455 | { |
| 456 | executeDelayedItemsLayout(); |
| 457 | |
| 458 | QPainter painter(this->viewport()); |
| 459 | |
| 460 | if (m_catVisible) { |
| 461 | painter.setOpacity(APPLICATION->settings()->get("CatOpacity").toFloat() / 100); |
| 462 | int widWidth = this->viewport()->width(); |
| 463 | int widHeight = this->viewport()->height(); |
| 464 | if (m_catPixmap.width() < widWidth) |
| 465 | widWidth = m_catPixmap.width(); |
| 466 | if (m_catPixmap.height() < widHeight) |
| 467 | widHeight = m_catPixmap.height(); |
| 468 | auto pixmap = m_catPixmap.scaled(widWidth, widHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
| 469 | QRect rectOfPixmap = pixmap.rect(); |
| 470 | rectOfPixmap.moveBottomRight(this->viewport()->rect().bottomRight()); |
| 471 | painter.drawPixmap(rectOfPixmap.topLeft(), pixmap); |
| 472 | painter.setOpacity(1.0); |
| 473 | } |
| 474 | |
| 475 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 476 | QStyleOptionViewItem option; |
| 477 | initViewItemOption(&option); |
| 478 | #else |
| 479 | QStyleOptionViewItem option = viewOptions(); |
| 480 | #endif |
| 481 | option.widget = this; |
| 482 | |
| 483 | if (model()->rowCount() == 0) { |
| 484 | painter.save(); |
| 485 | QString emptyString = tr("Welcome!") + "\n" + tr("Click \"Add Instance\" to get started."); |
| 486 | |
| 487 | // calculate the rect for the overlay |
| 488 | painter.setRenderHint(QPainter::Antialiasing, true); |
| 489 | QFont font("sans", 20); |
| 490 | font.setBold(true); |
| 491 | |
| 492 | QRect bounds = viewport()->geometry(); |
| 493 | bounds.moveTop(0); |
| 494 | auto innerBounds = bounds; |
| 495 | innerBounds.adjust(10, 10, -10, -10); |
| 496 | |
| 497 | QColor background = QApplication::palette().color(QPalette::WindowText); |
| 498 | QColor foreground = QApplication::palette().color(QPalette::Base); |
| 499 | foreground.setAlpha(190); |
| 500 | painter.setFont(font); |
| 501 | auto fontMetrics = painter.fontMetrics(); |
| 502 | auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString); |
| 503 | textRect.moveCenter(bounds.center()); |
| 504 | |
| 505 | auto wrapRect = textRect; |
| 506 | wrapRect.adjust(-10, -10, 10, 10); |
| 507 | |
| 508 | // check if we are allowed to draw in our area |
| 509 | if (!event->rect().intersects(wrapRect)) { |
| 510 | return; |
| 511 | } |
nothing calls this directly
no test coverage detected