VirtualBox

Ignore:
Timestamp:
May 23, 2013 3:16:35 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85971
Message:

FE/Qt: Animation framework rework.

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

Legend:

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

    r46224 r46242  
    272272        src/extensions/graphics/QIGraphicsWidget.h \
    273273        src/globals/UIActionPool.h \
     274        src/globals/UIAnimationFramework.h \
    274275        src/globals/UIExtraDataEventHandler.h \
    275276        src/globals/UIMainEventListener.h \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIAnimationFramework.cpp

    r46195 r46242  
    2727#include "UIAnimationFramework.h"
    2828
    29 QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
    30                                                               const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
    31                                                               const char *pSignalForward, const char *pSignalBackward,
    32                                                               bool fReversive /*= false*/, int iAnimationDuration /*= 300*/)
     29/* static */
     30UIAnimation* UIAnimation::installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
     31                                                   const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
     32                                                   const char *pszSignalForward, const char *pszSignalReverse,
     33                                                   bool fReverse /*= false*/, int iAnimationDuration /*= 300*/)
    3334{
    34     /* State-machine: */
    35     QStateMachine *pStateMachine = new QStateMachine(pTarget);
    36     /* State-machine 'start' state: */
    37     QState *pStateStart = new QState(pStateMachine);
    38     /* State-machine 'final' state: */
    39     QState *pStateFinal = new QState(pStateMachine);
    40 
    41     /* State-machine 'forward' animation: */
    42     QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine);
    43     pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    44     pForwardAnimation->setDuration(iAnimationDuration);
    45     pForwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameStart));
    46     pForwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameFinal));
    47     /* State-machine 'backward' animation: */
    48     QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine);
    49     pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    50     pBackwardAnimation->setDuration(iAnimationDuration);
    51     pBackwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameFinal));
    52     pBackwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameStart));
    53 
    54     /* State-machine state transitions: */
    55     QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pTarget, pSignalForward, pStateFinal);
    56     pDefaultToHovered->addAnimation(pForwardAnimation);
    57     QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pTarget, pSignalBackward, pStateStart);
    58     pHoveredToDefault->addAnimation(pBackwardAnimation);
    59 
    60     /* Initial state is 'start': */
    61     pStateMachine->setInitialState(!fReversive ? pStateStart : pStateFinal);
    62     /* Start hover-machine: */
    63     pStateMachine->start();
    64     /* Return machine: */
    65     return pStateMachine;
     35    /* Return newly created animation-machine: */
     36    return new UIAnimation(pTarget, pszPropertyName,
     37                           pszValuePropertyNameStart, pszValuePropertyNameFinal,
     38                           pszSignalForward, pszSignalReverse,
     39                           fReverse, iAnimationDuration);
    6640}
    6741
     42UIAnimation::UIAnimation(QWidget *pParent, const char *pszPropertyName,
     43                         const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
     44                         const char *pszSignalForward, const char *pszSignalReverse,
     45                         bool fReverse, int iAnimationDuration)
     46    : QObject(pParent)
     47    , m_pszPropertyName(pszPropertyName)
     48    , m_pszValuePropertyNameStart(pszValuePropertyNameStart), m_pszValuePropertyNameFinal(pszValuePropertyNameFinal)
     49    , m_pszSignalForward(pszSignalForward), m_pszSignalReverse(pszSignalReverse)
     50    , m_fReverse(fReverse), m_iAnimationDuration(iAnimationDuration)
     51    , m_pAnimationMachine(0), m_pForwardAnimation(0), m_pReverseAnimation(0)
     52{
     53    /* Prepare: */
     54    prepare();
     55}
     56
     57void UIAnimation::prepare()
     58{
     59    /* Prepare animation-machine: */
     60    m_pAnimationMachine = new QStateMachine(this);
     61    /* Create 'start' and 'final' states: */
     62    QState *pStateStart = new QState(m_pAnimationMachine);
     63    QState *pStateFinal = new QState(m_pAnimationMachine);
     64
     65    /* Prepare 'forward' animation: */
     66    m_pForwardAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
     67    m_pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
     68    m_pForwardAnimation->setDuration(m_iAnimationDuration);
     69    /* Prepare 'reverse' animation: */
     70    m_pReverseAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
     71    m_pReverseAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
     72    m_pReverseAnimation->setDuration(m_iAnimationDuration);
     73
     74    /* Prepare state-transitions: */
     75    QSignalTransition *pStartToFinal = pStateStart->addTransition(parent(), m_pszSignalForward, pStateFinal);
     76    pStartToFinal->addAnimation(m_pForwardAnimation);
     77    QSignalTransition *pFinalToStart = pStateFinal->addTransition(parent(), m_pszSignalReverse, pStateStart);
     78    pFinalToStart->addAnimation(m_pReverseAnimation);
     79
     80    /* Fetch animation-borders: */
     81    update();
     82
     83    /* Choose initial state: */
     84    m_pAnimationMachine->setInitialState(!m_fReverse ? pStateStart : pStateFinal);
     85    /* Start animation-machine: */
     86    m_pAnimationMachine->start();
     87}
     88
     89void UIAnimation::update()
     90{
     91    /* Update 'forward' animation: */
     92    m_pForwardAnimation->setStartValue(parent()->property(m_pszValuePropertyNameStart));
     93    m_pForwardAnimation->setEndValue(parent()->property(m_pszValuePropertyNameFinal));
     94    /* Update 'reverse' animation: */
     95    m_pReverseAnimation->setStartValue(parent()->property(m_pszValuePropertyNameFinal));
     96    m_pReverseAnimation->setEndValue(parent()->property(m_pszValuePropertyNameStart));
     97}
     98
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIAnimationFramework.h

    r46195 r46242  
    2020#define __UIAnimationFramework_h__
    2121
     22/* Qt includes: */
     23#include <QObject>
     24
    2225/* Forward declaration: */
    2326class QStateMachine;
     27class QPropertyAnimation;
    2428
    25 /* UIAnimationFramework namespace: */
    26 namespace UIAnimationFramework
     29/* UIAnimation factory: */
     30class UIAnimation : public QObject
    2731{
    28     /* API: Animation stuff: */
    29     QStateMachine* installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
    30                                             const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
    31                                             const char *pSignalForward, const char *pSignalBackward,
    32                                             bool fReversive = false, int iAnimationDuration = 300);
    33 }
     32    Q_OBJECT;
     33
     34public:
     35
     36    /* API: Factory stuff: */
     37    static UIAnimation* installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
     38                                                 const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
     39                                                 const char *pszSignalForward, const char *pszSignalReverse,
     40                                                 bool fReverse = false, int iAnimationDuration = 300);
     41
     42    /* API: Update stuff: */
     43    void update();
     44
     45protected:
     46
     47    /* Constructor: */
     48    UIAnimation(QWidget *pParent, const char *pszPropertyName,
     49                const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
     50                const char *pszSignalForward, const char *pszSignalReverse,
     51                bool fReverse, int iAnimationDuration);
     52
     53private:
     54
     55    /* Helper: Prepare stuff: */
     56    void prepare();
     57
     58    /* Variables: General stuff: */
     59    const char *m_pszPropertyName;
     60    const char *m_pszValuePropertyNameStart;
     61    const char *m_pszValuePropertyNameFinal;
     62    const char *m_pszSignalForward;
     63    const char *m_pszSignalReverse;
     64    bool m_fReverse;
     65    int m_iAnimationDuration;
     66
     67    /* Variables: Animation-machine stuff: */
     68    QStateMachine *m_pAnimationMachine;
     69    QPropertyAnimation *m_pForwardAnimation;
     70    QPropertyAnimation *m_pReverseAnimation;
     71};
    3472
    3573#endif /* __UIAnimationFramework_h__ */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.cpp

    r46195 r46242  
    3434#include "UIAnimationFramework.h"
    3535
    36 /* Other VBox includes: */
    37 #include <VBox/sup.h>
    38 
    3936
    4037/* Popup-pane text-pane prototype class: */
     
    115112    /* Variables: Focus stuff: */
    116113    bool m_fFocused;
    117     QObject *m_pAnimation;
     114    UIAnimation *m_pAnimation;
    118115};
    119116
     
    308305{
    309306    /* Install 'hover' animation for 'opacity' property: */
    310     UIAnimationFramework::installPropertyAnimation(this, "opacity", "defaultOpacity", "hoveredOpacity",
    311                                                    SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()));
     307    UIAnimation::installPropertyAnimation(this, "opacity", "defaultOpacity", "hoveredOpacity",
     308                                          SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()));
    312309    /* Prepare content: */
    313310    prepareContent();
     
    589586    /* Prepare content: */
    590587    prepareContent();
     588    /* Install geometry animation for 'minimumSizeHint' property: */
     589    m_pAnimation = UIAnimation::installPropertyAnimation(this, "minimumSizeHint", "collapsedSizeHint", "expandedSizeHint",
     590                                                         SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave()));
    591591}
    592592
     
    658658    m_minimumSizeHint = m_fFocused ? m_expandedSizeHint : m_collapsedSizeHint;
    659659
    660     /* And reinstall size-hint animation: */
    661     delete m_pAnimation;
    662     m_pAnimation = UIAnimationFramework::installPropertyAnimation(this, "minimumSizeHint", "collapsedSizeHint", "expandedSizeHint",
    663                                                                   SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave()),
    664                                                                   m_fFocused);
     660    /* Update animation: */
     661    m_pAnimation->update();
    665662}
    666663
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