VirtualBox

Changeset 76988 in vbox


Ignore:
Timestamp:
Jan 25, 2019 1:09:08 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9373: UIGraphicsButton cleanup, refactoring, doxy.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r76867 r76988  
    17531753                                     QPalette::HighlightedText : QPalette::ButtonText));
    17541754
    1755     /* Update buttons: */
    1756     if (m_pToggleButton)
    1757         m_pToggleButton->setParentSelected(model()->currentItems().contains(this));
    1758     if (m_pEnterButton)
    1759         m_pEnterButton->setParentSelected(model()->currentItems().contains(this));
    1760     if (m_pExitButton)
    1761         m_pExitButton->setParentSelected(model()->currentItems().contains(this));
    1762 
    17631755    /* Paint name: */
    17641756    int iNameX = iHorizontalMargin + iParentIndent * level();
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.cpp

    r76987 r76988  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIGraphicsButton class definition.
     3 * VBox Qt GUI - UIGraphicsButton class implementation.
    44 */
    55
     
    3232    : QIGraphicsWidget(pParent)
    3333    , m_icon(icon)
    34     , m_fParentSelected(false)
    3534    , m_enmClickPolicy(ClickPolicy_OnRelease)
    3635    , m_iDelayId(0)
     
    3837    , m_dIconScaleIndex(0)
    3938{
    40     /* Refresh finally: */
    4139    refresh();
    42 }
    43 
    44 void UIGraphicsButton::setParentSelected(bool fParentSelected)
    45 {
    46     if (m_fParentSelected == fParentSelected)
    47         return;
    48     m_fParentSelected = fParentSelected;
    49     update();
    5040}
    5141
     
    8676        case GraphicsButton_Icon:
    8777            return m_icon;
    88         default: break;
     78        default:
     79            break;
    8980    }
    9081    return QVariant();
    9182}
    9283
    93 QSizeF UIGraphicsButton::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    94 {
    95     /* Calculations for minimum size: */
    96     if (which == Qt::MinimumSize)
    97     {
    98         /* Variables: */
    99         int iMargin = data(GraphicsButton_Margin).toInt();
    100         QSize iconSize = data(GraphicsButton_IconSize).toSize();
    101         /* Calculations: */
     84QSizeF UIGraphicsButton::sizeHint(Qt::SizeHint enmType, const QSizeF &constraint /* = QSizeF() */) const
     85{
     86    /* For minimum size-hint: */
     87    if (enmType == Qt::MinimumSize)
     88    {
     89        /* Prepare variables: */
     90        const int iMargin = data(GraphicsButton_Margin).toInt();
     91        const QSize iconSize = data(GraphicsButton_IconSize).toSize();
     92        /* Perform calculations: */
    10293        int iWidth = 2 * iMargin + iconSize.width();
    10394        int iHeight = 2 * iMargin + iconSize.height();
    10495        return QSize(iWidth, iHeight);
    10596    }
     97
    10698    /* Call to base-class: */
    107     return QIGraphicsWidget::sizeHint(which, constraint);
     99    return QIGraphicsWidget::sizeHint(enmType, constraint);
    108100}
    109101
     
    114106    const QIcon icon = data(GraphicsButton_Icon).value<QIcon>();
    115107    const QSize expectedIconSize = data(GraphicsButton_IconSize).toSize();
    116     /* Determine which QWindow this QGraphicsWidget belongs to: */
     108
     109    /* Determine which QWindow this QGraphicsWidget belongs to.
     110     * This is required for proper HiDPI-aware pixmap calculations. */
    117111    QWindow *pWindow = 0;
    118112    if (   scene()
     
    121115        && scene()->views().first()->window())
    122116        pWindow = scene()->views().first()->window()->windowHandle();
    123     /* Acquire pixmap: */
     117
     118    /* Acquire pixmap, adjust it to be in center of button if necessary: */
    124119    const QPixmap pixmap = icon.pixmap(pWindow, expectedIconSize);
    125120    const QSize actualIconSize = pixmap.size() / pixmap.devicePixelRatio();
     
    132127    }
    133128
    134     /* Just draw the pixmap: */
     129    /* Draw the pixmap finally: */
    135130    pPainter->drawPixmap(position, pixmap);
    136131}
     
    205200    /* Refresh geometry: */
    206201    updateGeometry();
    207     /* Resize to minimum size: */
     202    /* Resize to minimum size-hint: */
    208203    resize(minimumSizeHint());
    209204}
    210 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h

    r76987 r76988  
    3333class QPropertyAnimation;
    3434
    35 /* Graphics-button representation: */
     35/** QIGraphicsWidget subclass providing GUI with graphics-button representation. */
    3636class UIGraphicsButton : public QIGraphicsWidget
    3737{
     
    4040signals:
    4141
    42     /* Notify listeners about button was clicked: */
     42    /** Notifies listeners about button was clicked. */
    4343    void sigButtonClicked();
    4444
     
    4848    enum ClickPolicy { ClickPolicy_OnRelease, ClickPolicy_OnPress };
    4949
    50     /* Constructor: */
     50    /** Constructs graphics button passing @a pParent to the base-class.
     51      * @param  icon  Brings the button icon. */
    5152    UIGraphicsButton(QIGraphicsWidget *pParent, const QIcon &icon);
    52 
    53     /* API: Parent stuff: */
    54     void setParentSelected(bool fParentSelected);
    5553
    5654    /** Defines icon scale @a dIndex. */
     
    6664protected:
    6765
    68     /* Data enumerator: */
     66    /** Data enumerator. */
    6967    enum GraphicsButton
    7068    {
     
    7472    };
    7573
    76     /* Data provider: */
     74    /** Returns data stored for certain @a iKey: */
    7775    virtual QVariant data(int iKey) const;
    7876
    79     /* Size hint stuff: */
    80     virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
     77    /** Returns size-hint of certain @a enmType, restricted by passed @a constraint. */
     78    virtual QSizeF sizeHint(Qt::SizeHint enmType, const QSizeF &constraint = QSizeF()) const /* override */;
    8179
    82     /* Paint stuff: */
    83     virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0);
     80    /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
     81    virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0) /* override */;
    8482
    85     /* Mouse handlers: */
    86     virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent);
    87     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent);
     83    /** Handles mouse-press @a pEvent. */
     84    virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) /* override */;
     85    /** Handles mouse-release @a pEvent. */
     86    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent) /* override */;
    8887
    8988    /** Handles timer @a pEvent. */
    9089    virtual void timerEvent(QTimerEvent *pEvent) /* override */;
    9190
    92     /* Helpers: Update stuff: */
     91    /** Updates button.
     92      * @todo rename to prepare() */
    9393    virtual void refresh();
    9494
    9595private:
    9696
    97     /* Variables: */
     97    /** Holds the button icon. */
    9898    QIcon m_icon;
    99     bool m_fParentSelected;
    10099
    101100    /** Holds the click policy. */
     
    112111
    113112#endif /* !FEQT_INCLUDED_SRC_widgets_graphics_UIGraphicsButton_h */
    114 
Note: See TracChangeset for help on using the changeset viewer.

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