Changeset 74482 in vbox for trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp
- Timestamp:
- Sep 26, 2018 4:10:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp
r74481 r74482 21 21 22 22 /* Qt includes: */ 23 # include <QGraphicsScene> 23 24 # include <QGraphicsSceneMouseEvent> 25 # include <QGraphicsView> 24 26 # include <QPainter> 25 27 # include <QStyleOptionGraphicsItem> … … 61 63 62 64 /* Init: */ 63 updatePixmap ();65 updatePixmaps(); 64 66 65 67 /* Apply language settings: */ … … 90 92 91 93 /* Init: */ 92 updatePixmap ();94 updatePixmaps(); 93 95 94 96 /* Apply language settings: */ … … 122 124 } 123 125 126 bool UIChooserItemGlobal::isToolsButtonArea(const QPoint &position) const 127 { 128 const int iFullWidth = geometry().width(); 129 const int iFullHeight = geometry().height(); 130 const int iMargin = data(GlobalItemData_Margin).toInt(); 131 const int iButtonMargin = data(GlobalItemData_ButtonMargin).toInt(); 132 const int iToolsPixmapX = iFullWidth - iMargin - 1 - m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(); 133 const int iToolsPixmapY = (iFullHeight - m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()) / 2; 134 QRect rect = QRect(iToolsPixmapX, 135 iToolsPixmapY, 136 m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(), 137 m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()); 138 rect.adjust(- iButtonMargin, -iButtonMargin, iButtonMargin, iButtonMargin); 139 return rect.contains(position); 140 } 141 124 142 void UIChooserItemGlobal::setHeightHint(int iHint) 125 143 { … … 152 170 153 171 /* Update pixmaps: */ 154 updatePixmap ();172 updatePixmaps(); 155 173 } 156 174 … … 255 273 { 256 274 /* Update this global-item: */ 257 updatePixmap ();275 updatePixmaps(); 258 276 updateToolTip(); 259 277 … … 316 334 iProposedWidth += (m_pixmapSize.width() + 317 335 iSpacing + 318 m_iMinimumNameWidth); 336 m_iMinimumNameWidth + 337 iSpacing + 338 m_toolsPixmapSize.width()); 319 339 320 340 /* Return result: */ … … 331 351 332 352 /* Global-item content height: */ 333 const int iContentHeight = qMax(m_pixmapSize.height(), m_visibleNameSize.height()); 353 int iContentHeight = qMax(m_pixmapSize.height(), m_visibleNameSize.height()); 354 iContentHeight = qMax(iContentHeight, m_toolsPixmapSize.height()); 334 355 335 356 /* If we have height hint: */ … … 388 409 void UIChooserItemGlobal::sltHandleWindowRemapped() 389 410 { 390 updatePixmap ();411 updatePixmaps(); 391 412 } 392 413 … … 419 440 { 420 441 /* Layout hints: */ 421 case GlobalItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 3 * 2; 422 case GlobalItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 442 case GlobalItemData_Margin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 3 * 2; 443 case GlobalItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 444 case GlobalItemData_ButtonMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 423 445 424 446 /* Default: */ … … 426 448 } 427 449 return QVariant(); 450 } 451 452 void UIChooserItemGlobal::updatePixmaps() 453 { 454 /* Update pixmap: */ 455 updatePixmap(); 456 /* Update tools-pixmap: */ 457 updateToolsPixmap(); 428 458 } 429 459 … … 448 478 { 449 479 m_pixmap = pixmap; 480 update(); 481 } 482 } 483 484 void UIChooserItemGlobal::updateToolsPixmap() 485 { 486 /* Determine icon metric: */ 487 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize) * .75; 488 /* Create new tools-pixmap and tools-pixmap size: */ 489 const QIcon toolsIcon = UIIconPool::iconSet(":/tools_menu_24px.png"); 490 AssertReturnVoid(!toolsIcon.isNull()); 491 const QSize toolsPixmapSize = QSize(iIconMetric, iIconMetric); 492 const QPixmap toolsPixmap = toolsIcon.pixmap(gpManager->windowHandle(), toolsPixmapSize); 493 /* Update linked values: */ 494 if (m_toolsPixmapSize != toolsPixmapSize) 495 { 496 m_toolsPixmapSize = toolsPixmapSize; 497 updateGeometry(); 498 } 499 if (m_toolsPixmap.toImage() != toolsPixmap.toImage()) 500 { 501 m_toolsPixmap = toolsPixmap; 450 502 update(); 451 503 } … … 577 629 { 578 630 /* Prepare variables: */ 631 const int iFullWidth = rectangle.width(); 579 632 const int iFullHeight = rectangle.height(); 580 633 const int iMargin = data(GlobalItemData_Margin).toInt(); 581 634 const int iSpacing = data(GlobalItemData_Spacing).toInt(); 635 const int iButtonMargin = data(GlobalItemData_ButtonMargin).toInt(); 582 636 583 637 /* Selected item foreground: */ … … 619 673 620 674 /* Calculate indents: */ 621 const int i RightColumnIndent = iLeftColumnIndent +622 m_pixmapSize.width() +623 iSpacing;624 625 /* Paint rightcolumn: */675 const int iMiddleColumnIndent = iLeftColumnIndent + 676 m_pixmapSize.width() + 677 iSpacing; 678 679 /* Paint middle column: */ 626 680 { 627 681 /* Prepare variables: */ 628 const int iNameX = i RightColumnIndent;682 const int iNameX = iMiddleColumnIndent; 629 683 const int iNameY = (iFullHeight - m_visibleNameSize.height()) / 2; 630 684 … … 641 695 m_strVisibleName); 642 696 } 643 } 697 698 /* Calculate indents: */ 699 int iRightColumnIndent = iFullWidth - iMargin - 1 - m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(); 700 701 /* Paint right column: */ 702 if (model()->currentItem() == this) 703 { 704 /* Prepare variables: */ 705 int iToolsPixmapX = iRightColumnIndent; 706 int iToolsPixmapY = (iFullHeight - m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()) / 2; 707 QRect buttonRectangle = QRect(iToolsPixmapX, 708 iToolsPixmapY, 709 m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(), 710 m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()); 711 buttonRectangle.adjust(- iButtonMargin, -iButtonMargin, iButtonMargin, iButtonMargin); 712 const QPoint sceneCursorPosition = model()->scene()->views().first()->mapFromGlobal(QCursor::pos()); 713 const QPoint itemCursorPosition = mapFromScene(sceneCursorPosition).toPoint(); 714 715 /* Paint flat button: */ 716 paintFlatButton(/* Painter: */ 717 pPainter, 718 /* Button rectangle: */ 719 buttonRectangle, 720 /* Cursor position: */ 721 itemCursorPosition); 722 723 /* Paint pixmap: */ 724 paintPixmap(/* Painter: */ 725 pPainter, 726 /* Point to paint in: */ 727 QPoint(iToolsPixmapX, iToolsPixmapY), 728 /* Pixmap to paint: */ 729 m_toolsPixmap); 730 } 731 }
Note:
See TracChangeset
for help on using the changeset viewer.