VirtualBox

Changeset 108001 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 31, 2025 11:58:03 AM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167273
Message:

FE/Qt: bugref:10814: VBox Manager / Tools pane: Extend item class with possibility to have extra-button.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp

    r107981 r108001  
    4040
    4141/* GUI includes: */
     42#include "UICommon.h"
    4243#include "UIImageTools.h"
    4344#include "UITools.h"
     
    186187
    187188UIToolsItem::UIToolsItem(QGraphicsScene *pScene, const QIcon &icon,
    188                          UIToolClass enmClass, UIToolType enmType)
     189                         UIToolClass enmClass, UIToolType enmType,
     190                         bool fExtraButton /* = false */)
    189191    : m_pScene(pScene)
    190192    , m_icon(icon)
    191193    , m_enmClass(enmClass)
    192194    , m_enmType(enmType)
     195    , m_fExtraButton(fExtraButton)
    193196    , m_fHovered(false)
    194197    , m_pHoveringMachine(0)
     
    379382    /* Paint tool info: */
    380383    paintToolInfo(pPainter, rectangle);
     384    /* Paint extra-button if requested: */
     385    if (m_fExtraButton)
     386        paintExtraButton(pPainter, rectangle);
    381387}
    382388
     
    822828}
    823829
     830void UIToolsItem::paintExtraButton(QPainter *pPainter, const QRect &rectangle) const
     831{
     832    /* Save painter: */
     833    pPainter->save();
     834
     835    /* Configure painter: */
     836    pPainter->setRenderHint(QPainter::Antialiasing, true);
     837    /* Acquire background color: */
     838    const QPalette pal = QApplication::palette();
     839    QColor backgroundColor = pal.color(QPalette::Window);
     840
     841    /* Prepare button sub-rect: */
     842    QRect subRect;
     843    subRect.setWidth(rectangle.width() / 6);
     844    subRect.setHeight(rectangle.height() / 2);
     845    subRect.moveTopLeft(QPoint(rectangle.right() - subRect.width() - 2,
     846                               rectangle.bottom() - 3 * rectangle.height() / 4 + 1));
     847
     848    /* Paint button frame: */
     849    QPainterPath painterPath;
     850    painterPath.addRoundedRect(subRect, 4, 4);
     851    QColor backgroundColor1 = uiCommon().isInDarkMode()
     852                            ? backgroundColor.lighter(110)
     853                            : backgroundColor.darker(110);
     854    pPainter->setPen(QPen(backgroundColor1, 2, Qt::SolidLine, Qt::RoundCap));
     855    pPainter->drawPath(QPainterPathStroker().createStroke(painterPath));
     856
     857    /* Fill button body: */
     858    pPainter->setClipPath(painterPath);
     859    QColor backgroundColor2 = uiCommon().isInDarkMode()
     860                            ? backgroundColor.lighter(150)
     861                            : backgroundColor.darker(150);
     862    pPainter->fillRect(subRect, backgroundColor2);
     863
     864    /* Paint arrow: */
     865    pPainter->drawLine(subRect.topLeft() + QPoint(3, 3), QPoint(subRect.right() - 2, subRect.center().y()));
     866    pPainter->drawLine(subRect.bottomLeft() + QPoint(3, -3), QPoint(subRect.right() - 2, subRect.center().y()));
     867
     868    /* Restore painter: */
     869    pPainter->restore();
     870}
     871
    824872/* static */
    825873void UIToolsItem::paintPixmap(QPainter *pPainter, const QPoint &point,
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.h

    r107981 r108001  
    8484
    8585    /** Constructs item on the basis of passed arguments.
    86       * @param  pScene   Brings the scene reference to add item to.
    87       * @param  icon     Brings the item icon.
    88       * @param  enmClass Brings the item class.
    89       * @param  enmType  Brings the item type. */
     86      * @param  pScene        Brings the scene reference to add item to.
     87      * @param  icon          Brings the item icon.
     88      * @param  enmClass      Brings the item class.
     89      * @param  enmType       Brings the item type.
     90      * @param  fExtraButton  Brings whether item should have extra-button. */
    9091    UIToolsItem(QGraphicsScene *pScene, const QIcon &icon,
    91                 UIToolClass enmClass, UIToolType enmType);
     92                UIToolClass enmClass, UIToolType enmType,
     93                bool fExtraButton = false);
    9294    /** Destructs item. */
    9395    virtual ~UIToolsItem() RT_OVERRIDE;
     
    223225          * @param  rectangle  Brings the rectangle to limit painting with. */
    224226        void paintToolInfo(QPainter *pPainter, const QRect &rectangle) const;
     227        /** Paints extra-button using using passed @a pPainter.
     228          * @param  rectangle  Brings the rectangle to limit painting with. */
     229        void paintExtraButton(QPainter *pPainter, const QRect &rectangle) const;
    225230
    226231        /** Paints @a pixmap using passed @a pPainter.
     
    249254        /** Holds the item type. */
    250255        UIToolType      m_enmType;
     256        /** Holds whether item should have extra-button. */
     257        bool            m_fExtraButton;
    251258
    252259        /** Holds the item pixmap. */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette