VirtualBox

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


Ignore:
Timestamp:
Jan 25, 2019 12:38:01 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128399
Message:

FE/Qt: bugref:9373: UIGraphicsButton improvement allowing to set click policy to be on-release or on-press, where the last one allows for auto-repeat functionality.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.cpp

    r76983 r76987  
    1919#include <QApplication>
    2020#include <QGraphicsScene>
     21#include <QGraphicsSceneMouseEvent>
    2122#include <QGraphicsView>
    2223#include <QPainter>
    2324#include <QStyle>
    24 #include <QGraphicsSceneMouseEvent>
     25#include <QTimerEvent>
    2526
    2627/* GUI includes: */
     
    3233    , m_icon(icon)
    3334    , m_fParentSelected(false)
     35    , m_enmClickPolicy(ClickPolicy_OnRelease)
     36    , m_iDelayId(0)
     37    , m_iRepeatId(0)
    3438    , m_dIconScaleIndex(0)
    3539{
     
    5559{
    5660    return m_dIconScaleIndex;
     61}
     62
     63void UIGraphicsButton::setClickPolicy(ClickPolicy enmPolicy)
     64{
     65    m_enmClickPolicy = enmPolicy;
     66}
     67
     68UIGraphicsButton::ClickPolicy UIGraphicsButton::clickPolicy() const
     69{
     70    return m_enmClickPolicy;
    5771}
    5872
     
    124138void UIGraphicsButton::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
    125139{
     140    /* Call to base-class: */
     141    QIGraphicsWidget::mousePressEvent(pEvent);
     142
    126143    /* Accepting this event allows to get release-event: */
    127144    pEvent->accept();
     145
     146    /* For click-on-press policy: */
     147    if (m_enmClickPolicy == ClickPolicy_OnPress)
     148    {
     149        /* Notify listeners about button click: */
     150        emit sigButtonClicked();
     151        /* Start delay timer: */
     152        m_iDelayId = startTimer(500);
     153    }
    128154}
    129155
     
    132158    /* Call to base-class: */
    133159    QIGraphicsWidget::mouseReleaseEvent(pEvent);
    134     /* Notify listeners about button click: */
    135     emit sigButtonClicked();
     160
     161    /* Depending on click policy: */
     162    switch (m_enmClickPolicy)
     163    {
     164        /* For click-on-release policy: */
     165        case ClickPolicy_OnRelease:
     166        {
     167            /* Notify listeners about button click: */
     168            emit sigButtonClicked();
     169            break;
     170        }
     171        /* For click-on-press policy: */
     172        case ClickPolicy_OnPress:
     173        {
     174            /* We should stop all timers: */
     175            killTimer(m_iDelayId);
     176            killTimer(m_iRepeatId);
     177            m_iDelayId = 0;
     178            m_iRepeatId = 0;
     179            break;
     180        }
     181    }
     182}
     183
     184void UIGraphicsButton::timerEvent(QTimerEvent *pEvent)
     185{
     186    /* For click-on-press policy: */
     187    if (m_enmClickPolicy == ClickPolicy_OnPress)
     188    {
     189        /* We should auto-repeat button click: */
     190        emit sigButtonClicked();
     191
     192        /* For delay timer: */
     193        if (pEvent->timerId() == m_iDelayId)
     194        {
     195            /* We should stop it and start repeat timer: */
     196            killTimer(m_iDelayId);
     197            m_iDelayId = 0;
     198            m_iRepeatId = startTimer(90);
     199        }
     200    }
    136201}
    137202
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsButton.h

    r76983 r76987  
    4545public:
    4646
     47    /** Click policy. */
     48    enum ClickPolicy { ClickPolicy_OnRelease, ClickPolicy_OnPress };
     49
    4750    /* Constructor: */
    4851    UIGraphicsButton(QIGraphicsWidget *pParent, const QIcon &icon);
     
    5558    /** Returns icon scale index. */
    5659    double iconScaleIndex() const;
     60
     61    /** Defines click @a enmPolicy. */
     62    void setClickPolicy(ClickPolicy enmPolicy);
     63    /** Returns click policy. */
     64    ClickPolicy clickPolicy() const;
    5765
    5866protected:
     
    7987    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent);
    8088
     89    /** Handles timer @a pEvent. */
     90    virtual void timerEvent(QTimerEvent *pEvent) /* override */;
     91
    8192    /* Helpers: Update stuff: */
    8293    virtual void refresh();
     
    8899    bool m_fParentSelected;
    89100
     101    /** Holds the click policy. */
     102    ClickPolicy  m_enmClickPolicy;
     103
     104    /** Holds the delay timer ID. */
     105    int  m_iDelayId;
     106    /** Holds the repeat timer ID. */
     107    int  m_iRepeatId;
     108
    90109    /** Holds the icon scale index. */
    91110    double  m_dIconScaleIndex;
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