- Timestamp:
- Feb 9, 2025 6:03:50 PM (3 months ago)
- svn:sync-xref-src-repo-rev:
- 167424
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/tools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp
r108124 r108125 187 187 188 188 UIToolsItem::UIToolsItem(QGraphicsScene *pScene, const QIcon &icon, 189 UIToolClass enmClass, UIToolType enmType, 190 bool fExtraButton /* = false */) 189 UIToolClass enmClass, UIToolType enmType) 191 190 : m_pScene(pScene) 192 191 , m_icon(icon) 193 192 , m_enmClass(enmClass) 194 193 , m_enmType(enmType) 195 , m_fExtraButton(fExtraButton)196 194 , m_fHovered(false) 197 195 , m_pHoveringMachine(0) … … 402 400 /* Paint tool info: */ 403 401 paintToolInfo(pPainter, rectangle); 404 /* Paint extra-button if requested: */405 if ( m_fExtraButton406 && model()->isAtLeastOneItemHovered())407 paintExtraButton(pPainter, rectangle);408 402 } 409 403 … … 578 572 case ToolsItemData_Spacing: return QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 2; 579 573 case ToolsItemData_Padding: return 4; 580 case ToolsItemData_ExtraButtonWidth: return 10;581 574 582 575 /* Default: */ … … 935 928 } 936 929 937 void UIToolsItem::paintExtraButton(QPainter *pPainter, const QRect &rectangle) const938 {939 /* Prepare variables: */940 const int iPadding = data(ToolsItemData_Padding).toInt();941 const int iButtonWidth = data(ToolsItemData_ExtraButtonWidth).toInt();942 943 /* Save painter: */944 pPainter->save();945 946 /* Configure painter: */947 pPainter->setRenderHint(QPainter::Antialiasing, true);948 /* Acquire background color: */949 const QPalette pal = QApplication::palette();950 #ifdef VBOX_WS_MAC951 const QColor backgroundColor = pal.color(QPalette::Active, QPalette::Window);952 #else /* !VBOX_WS_MAC */953 const QColor windowColor = pal.color(QPalette::Active, QPalette::Window);954 const QColor accentColor = pal.color(QPalette::Active, QPalette::Accent);955 const int iRed = iShift30(windowColor.red(), accentColor.red());956 const int iGreen = iShift30(windowColor.green(), accentColor.green());957 const int iBlue = iShift30(windowColor.blue(), accentColor.blue());958 const QColor backgroundColor = QColor(qRgb(iRed, iGreen, iBlue));959 #endif /* !VBOX_WS_MAC */960 961 /* Prepare button sub-rect: */962 m_extraButtonRect.setWidth(iButtonWidth);963 m_extraButtonRect.setHeight(rectangle.height() / 2);964 m_extraButtonRect.moveTopLeft(QPoint(rectangle.right() - m_extraButtonRect.width() - 2,965 rectangle.bottom() - 3 * rectangle.height() / 4 + 1));966 967 /* Paint button frame: */968 QPainterPath painterPath;969 painterPath.addRoundedRect(m_extraButtonRect, iPadding, iPadding);970 #ifdef VBOX_WS_MAC971 const QColor backgroundColor1 = uiCommon().isInDarkMode()972 ? backgroundColor.lighter(220)973 : backgroundColor.darker(140);974 #else /* !VBOX_WS_MAC */975 const QColor backgroundColor1 = uiCommon().isInDarkMode()976 ? backgroundColor.lighter(140)977 : backgroundColor.darker(120);978 #endif /* !VBOX_WS_MAC */979 pPainter->setPen(QPen(backgroundColor1, 2, Qt::SolidLine, Qt::RoundCap));980 pPainter->drawPath(QPainterPathStroker().createStroke(painterPath));981 982 /* Fill button body: */983 pPainter->setClipPath(painterPath);984 #ifdef VBOX_WS_MAC985 const QColor backgroundColor2 = uiCommon().isInDarkMode()986 ? backgroundColor.lighter(160)987 : backgroundColor.darker(120);988 #else /* !VBOX_WS_MAC */989 const QColor backgroundColor2 = uiCommon().isInDarkMode()990 ? backgroundColor.lighter(105)991 : backgroundColor.darker(105);992 #endif /* !VBOX_WS_MAC */993 pPainter->fillRect(m_extraButtonRect, backgroundColor2);994 995 /* Paint arrow: */996 if (!model()->showItemNames())997 {998 pPainter->drawLine(m_extraButtonRect.topLeft() + QPoint(3, 3),999 QPoint(m_extraButtonRect.right() - 2, m_extraButtonRect.center().y()));1000 pPainter->drawLine(m_extraButtonRect.bottomLeft() + QPoint(3, -3),1001 QPoint(m_extraButtonRect.right() - 2, m_extraButtonRect.center().y()));1002 }1003 else1004 {1005 pPainter->drawLine(m_extraButtonRect.topRight() + QPoint(-3, 3),1006 QPoint(m_extraButtonRect.left() + 3, m_extraButtonRect.center().y()));1007 pPainter->drawLine(m_extraButtonRect.bottomRight() + QPoint(-3, -3),1008 QPoint(m_extraButtonRect.left() + 3, m_extraButtonRect.center().y()));1009 }1010 1011 /* Restore painter: */1012 pPainter->restore();1013 }1014 1015 930 /* static */ 1016 931 void UIToolsItem::paintPixmap(QPainter *pPainter, const QPoint &point, -
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.h
r108106 r108125 87 87 * @param icon Brings the item icon. 88 88 * @param enmClass Brings the item class. 89 * @param enmType Brings the item type. 90 * @param fExtraButton Brings whether item should have extra-button. */ 89 * @param enmType Brings the item type. */ 91 90 UIToolsItem(QGraphicsScene *pScene, const QIcon &icon, 92 UIToolClass enmClass, UIToolType enmType, 93 bool fExtraButton = false); 91 UIToolClass enmClass, UIToolType enmType); 94 92 /** Destructs item. */ 95 93 virtual ~UIToolsItem() RT_OVERRIDE; … … 113 111 UIToolType itemType() const { return m_enmType; } 114 112 115 /** Returns whether item should have extra-button. */116 bool hasExtraButton() const { return m_fExtraButton; }117 118 113 /** Defines whether item is @a fEnabled. */ 119 114 void setEnabled(bool fEnabled); … … 139 134 * @param constraint Brings size constraint. */ 140 135 virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const RT_OVERRIDE; 141 142 /** Returns the extra-button rectangle. */143 QRect extraButtonRect() const { return m_extraButtonRect; }144 136 /** @} */ 145 137 … … 177 169 ToolsItemData_Spacing, 178 170 ToolsItemData_Padding, 179 ToolsItemData_ExtraButtonWidth,180 171 }; 181 172 … … 233 224 * @param rectangle Brings the rectangle to limit painting with. */ 234 225 void paintToolInfo(QPainter *pPainter, const QRect &rectangle) const; 235 /** Paints extra-button using using passed @a pPainter.236 * @param rectangle Brings the rectangle to limit painting with. */237 void paintExtraButton(QPainter *pPainter, const QRect &rectangle) const;238 226 239 227 /** Paints @a pixmap using passed @a pPainter. … … 267 255 /** Holds the item type. */ 268 256 UIToolType m_enmType; 269 /** Holds whether item should have extra-button. */270 bool m_fExtraButton;271 257 272 258 /** Holds the item pixmap. */ … … 317 303 /** Holds the name size. */ 318 304 QSize m_nameSize; 319 320 /** Holds the extra-button rectangle. */321 mutable QRect m_extraButtonRect;322 305 /** @} */ 323 306 }; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsModel.cpp
r108122 r108125 323 323 { 324 324 return m_fShowItemNames; 325 }326 327 bool UIToolsModel::isAtLeastOneItemHovered() const328 {329 foreach (UIToolsItem *pItem, items())330 if (pItem->isHovered())331 return true;332 return false;333 325 } 334 326 … … 503 495 } 504 496 505 void UIToolsModel::sltHandleItemHoverChange()506 {507 /* Just update all the items: */508 foreach (UIToolsItem *pItem, items())509 pItem->update();510 }511 512 497 void UIToolsModel::sltFocusItemDestroyed() 513 498 { … … 651 636 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI, 652 637 this, &UIToolsModel::sltRetranslateUI); 653 654 /* Connect item hover listeners: */655 foreach (UIToolsItem *pItem, m_items)656 {657 connect(pItem, &UIToolsItem::sigHoverEnter,658 this, &UIToolsModel::sltHandleItemHoverChange);659 connect(pItem, &UIToolsItem::sigHoverLeave,660 this, &UIToolsModel::sltHandleItemHoverChange);661 }662 638 } 663 639 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsModel.h
r108120 r108125 132 132 /** Returns whether we should show item names. */ 133 133 bool showItemNames() const; 134 135 /** Returns whether at least one item hovered. */136 bool isAtLeastOneItemHovered() const;137 134 /** @} */ 138 135 … … 191 188 192 189 private slots: 193 194 /** @name Children stuff.195 * @{ */196 /** Handles signal about one of items was [un]hovered. */197 void sltHandleItemHoverChange();198 /** @} */199 190 200 191 /** @name Selection stuff.
Note:
See TracChangeset
for help on using the changeset viewer.