- Timestamp:
- Sep 26, 2018 4:10:40 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc
r73871 r74482 209 209 <file alias="tools_global_32px.png">images/tools_global_32px.png</file> 210 210 <file alias="tools_machine_32px.png">images/tools_machine_32px.png</file> 211 <file alias="tools_menu_24px.png">images/tools_menu_24px.png</file> 211 212 <file alias="usb_16px.png">images/usb_16px.png</file> 212 213 <file alias="usb_24px.png">images/usb_24px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp
r74246 r74482 445 445 m_fHovered = true; 446 446 emit sigHoverEnter(); 447 update();448 }447 } 448 update(); 449 449 } 450 450 … … 629 629 } 630 630 631 /* static */ 632 void UIChooserItem::paintFlatButton(QPainter *pPainter, const QRect &rectangle, const QPoint &cursorPosition) 633 { 634 /* Save painter: */ 635 pPainter->save(); 636 637 /* Prepare colors: */ 638 const QPalette pal = QApplication::palette(); 639 const QColor color = pal.color(QPalette::Active, QPalette::Mid); 640 641 /* Prepare pen: */ 642 QPen pen; 643 pen.setColor(color.darker(110)); 644 pen.setWidth(0); 645 pPainter->setPen(pen); 646 647 /* Apply clipping path: */ 648 QPainterPath path; 649 path.addRect(rectangle); 650 pPainter->setClipPath(path); 651 652 /* Paint active background: */ 653 QRadialGradient grad(rectangle.center(), rectangle.width(), cursorPosition); 654 grad.setColorAt(0, color.lighter(150)); 655 grad.setColorAt(1, color.lighter(110)); 656 pPainter->fillRect(rectangle, grad); 657 658 /* Paint frame: */ 659 const QRect frameRectangle = rectangle.adjusted(0, 0, -1, -1); 660 pPainter->drawRect(frameRectangle); 661 662 /* Restore painter: */ 663 pPainter->restore(); 664 } 665 631 666 632 667 /********************************************************************************************************************************* -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h
r74084 r74482 311 311 const QFont &font, QPaintDevice *pPaintDevice, 312 312 const QString &strText); 313 /** Paints flat button @a rectangle using passed @a pPainter moving light focus according to passed @a cursorPosition. */ 314 static void paintFlatButton(QPainter *pPainter, const QRect &rectangle, const QPoint &cursorPosition); 313 315 /** @} */ 314 316 -
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 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h
r74481 r74482 46 46 virtual ~UIChooserItemGlobal() /* override */; 47 47 48 /** @name Item stuff. 49 * @{ */ 50 /** Returns whether passed @a position belongs to tools button area. */ 51 bool isToolsButtonArea(const QPoint &position) const; 52 /** @} */ 53 48 54 /** @name Layout stuff. 49 55 * @{ */ … … 177 183 GlobalItemData_Margin, 178 184 GlobalItemData_Spacing, 185 GlobalItemData_ButtonMargin, 179 186 }; 180 187 … … 193 200 /** @name Layout stuff. 194 201 * @{ */ 202 /** Updates pixmaps. */ 203 void updatePixmaps(); 195 204 /** Updates pixmap. */ 196 205 void updatePixmap(); 206 /** Updates tools pixmap. */ 207 void updateToolsPixmap(); 197 208 /** Updates minimum name width. */ 198 209 void updateMinimumNameWidth(); … … 224 235 /** Holds item pixmap. */ 225 236 QPixmap m_pixmap; 237 /** Holds item tools pixmap. */ 238 QPixmap m_toolsPixmap; 226 239 227 240 /** Holds item name. */ … … 240 253 /** Holds pixmap size. */ 241 254 QSize m_pixmapSize; 255 /** Holds tools pixmap size. */ 256 QSize m_toolsPixmapSize; 242 257 /** Holds visible name size. */ 243 258 QSize m_visibleNameSize; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp
r74467 r74482 21 21 22 22 /* Qt includes: */ 23 # include <QGraphicsScene> 24 # include <QGraphicsView> 23 25 # include <QPainter> 24 26 # include <QStyleOptionGraphicsItem> … … 155 157 state != KMachineState_Teleported && 156 158 state != KMachineState_Aborted; 159 } 160 161 bool UIChooserItemMachine::isToolsButtonArea(const QPoint &position) const 162 { 163 const int iFullWidth = geometry().width(); 164 const int iFullHeight = geometry().height(); 165 const int iMargin = data(MachineItemData_Margin).toInt(); 166 const int iButtonMargin = data(MachineItemData_ButtonMargin).toInt(); 167 const int iToolsPixmapX = iFullWidth - iMargin - 1 - m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(); 168 const int iToolsPixmapY = (iFullHeight - m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()) / 2; 169 QRect rect = QRect(iToolsPixmapX, 170 iToolsPixmapY, 171 m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(), 172 m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()); 173 rect.adjust(- iButtonMargin, -iButtonMargin, iButtonMargin, iButtonMargin); 174 return rect.contains(position); 157 175 } 158 176 … … 421 439 iMinorSpacing + 422 440 m_stateTextSize.width(); 423 int i RightColumnWidth = qMax(iTopLineWidth, iBottomLineWidth);441 int iMiddleColumnWidth = qMax(iTopLineWidth, iBottomLineWidth); 424 442 int iMachineItemWidth = m_pixmapSize.width() + 425 443 iMajorSpacing + 426 iRightColumnWidth; 444 iMiddleColumnWidth + 445 iMajorSpacing + 446 m_toolsPixmapSize.width(); 427 447 iProposedWidth += iMachineItemWidth; 428 448 … … 445 465 int iTopLineHeight = qMax(m_visibleNameSize.height(), m_visibleSnapshotNameSize.height()); 446 466 int iBottomLineHeight = qMax(m_statePixmapSize.height(), m_stateTextSize.height()); 447 int i RightColumnHeight = iTopLineHeight +448 iMachineItemTextSpacing +449 iBottomLineHeight;467 int iMiddleColumnHeight = iTopLineHeight + 468 iMachineItemTextSpacing + 469 iBottomLineHeight; 450 470 QList<int> heights; 451 heights << m_pixmapSize.height() << i RightColumnHeight;471 heights << m_pixmapSize.height() << iMiddleColumnHeight << m_toolsPixmapSize.height(); 452 472 int iMaxHeight = 0; 453 473 foreach (int iHeight, heights) … … 628 648 case MachineItemData_TextSpacing: return 0; 629 649 case MachineItemData_ParentIndent: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 3; 650 case MachineItemData_ButtonMargin: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 630 651 631 652 /* Pixmaps: */ … … 645 666 /* Update pixmap: */ 646 667 updatePixmap(); 647 648 668 /* Update state-pixmap: */ 649 669 updateStatePixmap(); 670 /* Update tools-pixmap: */ 671 updateToolsPixmap(); 650 672 } 651 673 … … 687 709 { 688 710 m_statePixmap = statePixmap; 711 update(); 712 } 713 } 714 715 void UIChooserItemMachine::updateToolsPixmap() 716 { 717 /* Determine icon metric: */ 718 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize) * .75; 719 /* Create new tools-pixmap and tools-pixmap size: */ 720 const QIcon toolsIcon = UIIconPool::iconSet(":/tools_menu_24px.png"); 721 AssertReturnVoid(!toolsIcon.isNull()); 722 const QSize toolsPixmapSize = QSize(iIconMetric, iIconMetric); 723 const QPixmap toolsPixmap = toolsIcon.pixmap(gpManager->windowHandle(), toolsPixmapSize); 724 /* Update linked values: */ 725 if (m_toolsPixmapSize != toolsPixmapSize) 726 { 727 m_toolsPixmapSize = toolsPixmapSize; 728 updateGeometry(); 729 } 730 if (m_toolsPixmap.toImage() != toolsPixmap.toImage()) 731 { 732 m_toolsPixmap = toolsPixmap; 689 733 update(); 690 734 } … … 998 1042 { 999 1043 /* Prepare variables: */ 1044 const int iFullWidth = rectangle.width(); 1000 1045 const int iFullHeight = rectangle.height(); 1001 1046 const int iMargin = data(MachineItemData_Margin).toInt(); … … 1004 1049 const int iMachineItemTextSpacing = data(MachineItemData_TextSpacing).toInt(); 1005 1050 const int iParentIndent = data(MachineItemData_ParentIndent).toInt(); 1051 const int iButtonMargin = data(MachineItemData_ButtonMargin).toInt(); 1006 1052 1007 1053 /* Selected item foreground: */ … … 1042 1088 1043 1089 /* Calculate indents: */ 1044 int i RightColumnIndent = iLeftColumnIndent +1045 m_pixmapSize.width() +1046 iMajorSpacing;1047 1048 /* Paint rightcolumn: */1090 int iMiddleColumnIndent = iLeftColumnIndent + 1091 m_pixmapSize.width() + 1092 iMajorSpacing; 1093 1094 /* Paint middle column: */ 1049 1095 { 1050 1096 /* Calculate indents: */ … … 1059 1105 { 1060 1106 /* Prepare variables: */ 1061 int iNameX = i RightColumnIndent;1107 int iNameX = iMiddleColumnIndent; 1062 1108 int iNameY = iTopLineIndent; 1063 1109 /* Paint name: */ … … 1075 1121 1076 1122 /* Calculate indents: */ 1077 int iSnapshotNameIndent = i RightColumnIndent +1123 int iSnapshotNameIndent = iMiddleColumnIndent + 1078 1124 m_visibleNameSize.width() + 1079 1125 iMinorSpacing; 1080 1126 1081 /* Paint rightelement: */1127 /* Paint middle element: */ 1082 1128 if (!snapshotName().isEmpty()) 1083 1129 { … … 1107 1153 { 1108 1154 /* Prepare variables: */ 1109 int iMachineStatePixmapX = i RightColumnIndent;1155 int iMachineStatePixmapX = iMiddleColumnIndent; 1110 1156 int iMachineStatePixmapY = iBottomLineIndent; 1111 1157 /* Paint state pixmap: */ … … 1119 1165 1120 1166 /* Calculate indents: */ 1121 int iMachineStateTextIndent = i RightColumnIndent +1167 int iMachineStateTextIndent = iMiddleColumnIndent + 1122 1168 m_statePixmapSize.width() + 1123 1169 iMinorSpacing; … … 1142 1188 } 1143 1189 } 1190 1191 /* Calculate indents: */ 1192 int iRightColumnIndent = iFullWidth - iMargin - 1 - m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(); 1193 1194 /* Paint right column: */ 1195 if (model()->currentItem() == this) 1196 { 1197 /* Prepare variables: */ 1198 int iToolsPixmapX = iRightColumnIndent; 1199 int iToolsPixmapY = (iFullHeight - m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()) / 2; 1200 QRect buttonRectangle = QRect(iToolsPixmapX, 1201 iToolsPixmapY, 1202 m_toolsPixmap.width() / m_toolsPixmap.devicePixelRatio(), 1203 m_toolsPixmap.height() / m_toolsPixmap.devicePixelRatio()); 1204 buttonRectangle.adjust(- iButtonMargin, -iButtonMargin, iButtonMargin, iButtonMargin); 1205 const QPoint sceneCursorPosition = model()->scene()->views().first()->mapFromGlobal(QCursor::pos()); 1206 const QPoint itemCursorPosition = mapFromScene(sceneCursorPosition).toPoint(); 1207 1208 /* Paint flat button: */ 1209 paintFlatButton(/* Painter: */ 1210 pPainter, 1211 /* Button rectangle: */ 1212 buttonRectangle, 1213 /* Cursor position: */ 1214 itemCursorPosition); 1215 1216 /* Paint pixmap: */ 1217 paintPixmap(/* Painter: */ 1218 pPainter, 1219 /* Point to paint in: */ 1220 QPoint(iToolsPixmapX, iToolsPixmapY), 1221 /* Pixmap to paint: */ 1222 m_toolsPixmap); 1223 } 1144 1224 } 1145 1225 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h
r74467 r74482 57 57 /** Returns whether VM is locked. */ 58 58 bool isLockedMachine() const; 59 60 /** Returns whether passed @a position belongs to tools button area. */ 61 bool isToolsButtonArea(const QPoint &position) const; 59 62 /** @} */ 60 63 … … 196 199 MachineItemData_TextSpacing, 197 200 MachineItemData_ParentIndent, 201 MachineItemData_ButtonMargin, 198 202 /* Pixmaps: */ 199 203 MachineItemData_SettingsButtonPixmap, … … 223 227 /** Updates state pixmap. */ 224 228 void updateStatePixmap(); 229 /** Updates tools pixmap. */ 230 void updateToolsPixmap(); 225 231 /** Updates name. */ 226 232 void updateName(); … … 277 283 /** Holds item state pixmap. */ 278 284 QPixmap m_statePixmap; 285 /** Holds item tools pixmap. */ 286 QPixmap m_toolsPixmap; 279 287 280 288 /** Holds item name. */ … … 305 313 /** Holds state pixmap size. */ 306 314 QSize m_statePixmapSize; 315 /** Holds tools pixmap size. */ 316 QSize m_toolsPixmapSize; 307 317 /** Holds visible name size. */ 308 318 QSize m_visibleNameSize;
Note:
See TracChangeset
for help on using the changeset viewer.