VirtualBox

Changeset 109019 in vbox


Ignore:
Timestamp:
Apr 17, 2025 3:57:03 PM (3 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168548
Message:

FE/Qt: bugref:10814: VBox Manager / Tools pane: Animate tool-items text label underline for hovering trigger.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r108978 r109019  
    980980        src/manager/UIVirtualMachineItemCloud.cpp \
    981981        src/manager/chooser/UIChooserAbstractModel.cpp \
     982        src/manager/tools/UIToolsItem.cpp \
    982983        src/manager/tools/UIToolsModel.cpp \
    983984        src/activity/overview/UIVMActivityOverviewWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp

    r109016 r109019  
    3131#include <QGraphicsScene>
    3232#include <QPainter>
     33#include <QPropertyAnimation>
     34#include <QSignalTransition>
     35#include <QStateMachine>
    3336#include <QStyle>
    3437#include <QStyleOptionGraphicsItem>
     
    175178    UIToolsItem *item() const { return qobject_cast<UIToolsItem*>(object()); }
    176179};
     180
     181
     182/** QObject extension used as animation engine object. */
     183class UIToolsItemAnimationEngine : public QObject
     184{
     185    Q_OBJECT;
     186
     187signals:
     188
     189    /** Initiates transition to hovered state. */
     190    void sigHovered();
     191    /** Initiates transition to unhovered state. */
     192    void sigUnhovered();
     193
     194public:
     195
     196    /** Constructs animation engine passing @a pParent to the base-class. */
     197    UIToolsItemAnimationEngine(UIToolsItem *pParent);
     198
     199private:
     200
     201    /** Prepares everything. */
     202    void prepare();
     203    /** Prepares machine. */
     204    void prepareMachine();
     205    /** Prepares connections. */
     206    void prepareConnections();
     207
     208    /** Inits engine. */
     209    void init();
     210
     211    /** Holds the parent item reference. */
     212    UIToolsItem *m_pParent;
     213
     214    /** Holds the state-machine instance. */
     215    QStateMachine *m_pMachine;
     216
     217    /** Holds the Unhovered state instance. */
     218    QState *m_pStateUnhovered;
     219    /** Holds the Hovered state instance. */
     220    QState *m_pStateHovered;
     221};
     222
     223
     224/** QPropertyAnimation extension used as tool-item animation wrapper. */
     225class UIToolsItemAnimation : public QPropertyAnimation
     226{
     227    Q_OBJECT;
     228
     229public:
     230
     231    /** Constructs tool-item animation passing @a pParent to the base-class.
     232      * @param  pTarget       Brings the object animation alters property for.
     233      * @param  propertyName  Brings the name of property inside the @a pTarget.
     234      * @param  fForward      Brings whether animation goes to iValue or from it. */
     235    UIToolsItemAnimation(QObject *pTarget, const QByteArray &propertyName, QObject *pParent, bool fForward);
     236};
     237
     238
     239/*********************************************************************************************************************************
     240*   Class UIToolsItemAnimationEngine implementation.                                                                             *
     241*********************************************************************************************************************************/
     242
     243UIToolsItemAnimationEngine::UIToolsItemAnimationEngine(UIToolsItem *pParent)
     244    : QObject(pParent)
     245    , m_pParent(pParent)
     246    , m_pMachine(0)
     247    , m_pStateUnhovered(0)
     248    , m_pStateHovered(0)
     249{
     250    prepare();
     251}
     252
     253void UIToolsItemAnimationEngine::prepare()
     254{
     255    /* Prepare everything: */
     256    prepareMachine();
     257    prepareConnections();
     258
     259    /* Init can be async,
     260     * but for now it's Ok that way. */
     261    init();
     262}
     263
     264void UIToolsItemAnimationEngine::prepareMachine()
     265{
     266    /* Prepare animation machine: */
     267    m_pMachine = new QStateMachine(this);
     268    if (m_pMachine)
     269    {
     270        /* Prepare states: */
     271        m_pStateUnhovered = new QState(m_pMachine);
     272        m_pStateHovered = new QState(m_pMachine);
     273
     274        /* Configure Unhovered state: */
     275        if (m_pStateUnhovered)
     276        {
     277            m_pStateUnhovered->assignProperty(m_pParent, "hoveringProgress", 0);
     278
     279            /* Add Unhovered=>Hovered state transition: */
     280            QSignalTransition *pTrnUnhoveredToHovered =
     281                m_pStateUnhovered->addTransition(this, SIGNAL(sigHovered()), m_pStateHovered);
     282            if (pTrnUnhoveredToHovered)
     283            {
     284                /* Create animation for hoveringProgress: */
     285                UIToolsItemAnimation *pAnmUnhoveredToHovered =
     286                    new UIToolsItemAnimation(m_pParent, "hoveringProgress", this, true);
     287                pTrnUnhoveredToHovered->addAnimation(pAnmUnhoveredToHovered);
     288            }
     289        }
     290
     291        /* Configure Hovered state: */
     292        if (m_pStateHovered)
     293        {
     294            m_pStateHovered->assignProperty(m_pParent, "hoveringProgress", 100);
     295
     296            /* Add Hovered=>Unhovered state transition: */
     297            QSignalTransition *pTrnHoveredToUnhovered =
     298                m_pStateHovered->addTransition(this, SIGNAL(sigUnhovered()), m_pStateUnhovered);
     299            if (pTrnHoveredToUnhovered)
     300            {
     301                /* Create animation for hoveringProgress: */
     302                UIToolsItemAnimation *pAnmHoveredToUnhovered =
     303                    new UIToolsItemAnimation(m_pParent, "hoveringProgress", this, false);
     304                pTrnHoveredToUnhovered->addAnimation(pAnmHoveredToUnhovered);
     305            }
     306        }
     307    }
     308}
     309
     310void UIToolsItemAnimationEngine::prepareConnections()
     311{
     312    connect(m_pParent, &UIToolsItem::sigHovered, this, &UIToolsItemAnimationEngine::sigHovered);
     313    connect(m_pParent, &UIToolsItem::sigUnhovered, this, &UIToolsItemAnimationEngine::sigUnhovered);
     314}
     315
     316void UIToolsItemAnimationEngine::init()
     317{
     318    /* Define initial animation state: */
     319    m_pMachine->setInitialState(m_pParent->isHovered() ? m_pStateHovered : m_pStateUnhovered);
     320    m_pMachine->start();
     321}
     322
     323
     324/*********************************************************************************************************************************
     325*   Class UIToolsItemAnimation implementation.                                                                                   *
     326*********************************************************************************************************************************/
     327
     328UIToolsItemAnimation::UIToolsItemAnimation(QObject *pTarget, const QByteArray &propertyName, QObject *pParent, bool fForward)
     329    : QPropertyAnimation(pTarget, propertyName, pParent)
     330{
     331    setEasingCurve(QEasingCurve(QEasingCurve::OutQuart));
     332    setStartValue(fForward ? 0 : 100);
     333    setEndValue(fForward ? 100 : 0);
     334    setDuration(300);
     335}
    177336
    178337
     
    190349    , m_iPreviousMinimumWidthHint(0)
    191350    , m_iPreviousMinimumHeightHint(0)
     351    , m_pAnimationEngine(0)
     352    , m_iHoveringProgress(0)
    192353{
    193354    prepare();
     
    360521            QToolTip::showText(posAtScreen, name());
    361522        }
     523
     524        /* Notify listeners: */
     525        emit sigHovered();
    362526    }
    363527
     
    374538        /* Hide tooltip for good: */
    375539        QToolTip::hideText();
     540
     541        /* Notify listeners: */
     542        emit sigUnhovered();
    376543    }
    377544}
     
    415582    updatePixmap();
    416583    updateNameSize();
     584
     585    /* Create animation engine: */
     586    m_pAnimationEngine = new UIToolsItemAnimationEngine(this);
    417587}
    418588
     
    698868                                                                       || model()->currentItem(itemClass()) == this);
    699869        if (fCondition1 || fCondition2)
     870        {
     871            /* Acquire font: */
     872            const QFont fnt = data(Qt::FontRole).value<QFont>();
     873
     874            /* Paint text: */
    700875            paintText(/* Painter: */
    701876                      pPainter,
     
    703878                      QPoint(iNameX, iNameY),
    704879                      /* Font to paint text: */
    705                       data(Qt::FontRole).value<QFont>(),
     880                      fnt,
    706881                      /* Paint device: */
    707882                      model()->paintDevice(),
    708883                      /* Text to paint: */
    709884                      m_strName);
     885
     886            /* Paint animated underline: */
     887            if (hoveringProgress())
     888            {
     889                QFontMetrics fm(fnt);
     890                const double fRatio = (double)hoveringProgress() / 100;
     891                const int iLength = fRatio * fm.horizontalAdvance(m_strName);
     892                pPainter->drawLine(QPoint(iNameX, iNameY + fm.height()),
     893                                   QPoint(iNameX + iLength, iNameY + fm.height()));
     894            }
     895        }
    710896    }
    711897}
     
    786972    pPainter->restore();
    787973}
     974
     975void UIToolsItem::setHoveringProgress(int iProgress)
     976{
     977    m_iHoveringProgress = iProgress;
     978    update();
     979}
     980
     981
     982#include "UIToolsItem.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.h

    r109005 r109019  
    4444class QGraphicsScene;
    4545class QGraphicsSceneHoverEvent;
     46class UIToolsItemAnimationEngine;
    4647class UIToolsModel;
    4748
     
    5152{
    5253    Q_OBJECT;
     54    Q_PROPERTY(int hoveringProgress READ hoveringProgress WRITE setHoveringProgress);
    5355
    5456signals:
     57
     58    /** @name Item stuff.
     59      * @{ */
     60        /** Notifies listeners about item hovered. */
     61        void sigHovered();
     62        /** Notifies listeners about item unhovered. */
     63        void sigUnhovered();
     64    /** @} */
    5565
    5666    /** @name Layout stuff.
     
    102112        /** Defines whether item is @a fHidden by the @a enmReason. */
    103113        void setHiddenByReason(bool fHidden, HidingReason enmReason);
     114
     115        /** Returns whether item is hovered. */
     116        bool isHovered() const { return m_fHovered; }
    104117    /** @} */
    105118
     
    210223                                       const QColor &color,
    211224                                       int iPadding);
     225    /** @} */
     226
     227    /** @name Animation stuff.
     228     * @{ */
     229        /** Returns hovering progress. */
     230        int hoveringProgress() const { return m_iHoveringProgress; }
     231        /** Defines hovering @a iProgress. */
     232        void setHoveringProgress(int iProgress);
    212233    /** @} */
    213234
     
    247268        QSize  m_nameSize;
    248269    /** @} */
     270
     271    /** @name Animation stuff.
     272     * @{ */
     273        /** Holds the animation engine instance. */
     274        UIToolsItemAnimationEngine *m_pAnimationEngine;
     275
     276        /** Holds the hovering progress. */
     277        int  m_iHoveringProgress;
     278    /** @} */
    249279};
    250280
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