VirtualBox

Changeset 73842 in vbox


Ignore:
Timestamp:
Aug 22, 2018 5:15:51 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: UISlidingAnimation: Initial implementation.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 edited
2 copied

Legend:

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

    r73600 r73842  
    711711        src/widgets/UIGuestOSTypeSelectionButton.h \
    712712        src/widgets/UILineTextEdit.h \
     713        src/widgets/UISlidingAnimation.h \
    713714        src/widgets/UISlidingWidget.h \
    714715        src/widgets/UITabBar.h \
     
    13891390        src/widgets/UIGuestOSTypeSelectionButton.cpp \
    13901391        src/widgets/UILineTextEdit.cpp \
     1392        src/widgets/UISlidingAnimation.cpp \
    13911393        src/widgets/UISlidingWidget.cpp \
    13921394        src/widgets/UITabBar.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingAnimation.cpp

    r73800 r73842  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UISlidingWidget class implementation.
     3 * VBox Qt GUI - UISlidingAnimation class implementation.
    44 */
    55
     
    1919#include <QEvent>
    2020#include <QHBoxLayout>
     21#include <QLabel>
    2122#include <QVBoxLayout>
    2223
    2324/* GUI includes: */
    2425#include "UIAnimationFramework.h"
    25 #include "UISlidingWidget.h"
     26#include "UISlidingAnimation.h"
    2627
    2728
    28 UISlidingWidget::UISlidingWidget(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
     29UISlidingAnimation::UISlidingAnimation(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
    2930    : QWidget(pParent)
    3031    , m_enmOrientation(enmOrientation)
    31     , m_enmState(State_Start)
    3232    , m_pAnimation(0)
    3333    , m_pWidget(0)
    34     , m_pLayout(0)
     34    , m_pLabel1(0)
     35    , m_pLabel2(0)
    3536    , m_pWidget1(0)
    3637    , m_pWidget2(0)
     
    4041}
    4142
    42 QSize UISlidingWidget::minimumSizeHint() const
     43void UISlidingAnimation::setWidgets(QWidget *pWidget1, QWidget *pWidget2)
    4344{
    44     /* Return maximum of minimum size-hints: */
    45     QSize msh = QSize();
    46     if (m_pWidget1)
    47         msh = msh.expandedTo(m_pWidget1->minimumSizeHint());
    48     if (m_pWidget2)
    49         msh = msh.expandedTo(m_pWidget2->minimumSizeHint());
    50     return msh;
     45    /* Remember rendered widgets: */
     46    m_pWidget1 = pWidget1;
     47    m_pWidget2 = pWidget2;
    5148}
    5249
    53 void UISlidingWidget::setWidgets(QWidget *pWidget1, QWidget *pWidget2)
     50void UISlidingAnimation::animate(SlidingDirection enmDirection)
    5451{
    55     /* Clear animation/widgets if any: */
    56     delete m_pAnimation;
    57     delete m_pWidget1;
    58     delete m_pWidget2;
     52    /* Acquire parent size: */
     53    const QSize parentSize = parentWidget()->size();
    5954
    60     /* Remember widgets: */
    61     m_pWidget1 = pWidget1;
    62     m_pWidget2 = pWidget2;
    63     m_pLayout->addWidget(m_pWidget1);
    64     m_pLayout->addWidget(m_pWidget2);
     55    /* Update animation boundaries based on parent size: */
     56    switch (m_enmOrientation)
     57    {
     58        case Qt::Horizontal:
     59        {
     60            m_startWidgetGeometry = QRect(  0,           0,
     61                                            2 * parentSize.width(), parentSize.height());
     62            m_finalWidgetGeometry = QRect(- parentSize.width(),     0,
     63                                            2 * parentSize.width(), parentSize.height());
     64            break;
     65        }
     66        case Qt::Vertical:
     67        {
     68            m_startWidgetGeometry = QRect(0,         0,
     69                                          parentSize.width(),   2 * parentSize.height());
     70            m_finalWidgetGeometry = QRect(0,       - parentSize.height(),
     71                                          parentSize.width(),   2 * parentSize.height());
     72            break;
     73        }
     74    }
     75    if (m_pAnimation)
     76        m_pAnimation->update();
    6577
    66     /* Install new animation: */
     78    /* Update label content: */
     79    QPixmap pixmap1(parentSize);
     80    QPixmap pixmap2(parentSize);
     81    m_pWidget1->render(&pixmap1);
     82    m_pWidget2->render(&pixmap2);
     83    m_pLabel1->setPixmap(pixmap1);
     84    m_pLabel2->setPixmap(pixmap2);
     85
     86    /* Update initial widget geometry: */
     87    switch (enmDirection)
     88    {
     89        case SlidingDirection_Forward:
     90        {
     91            setWidgetGeometry(m_startWidgetGeometry);
     92            emit sigForward();
     93            break;
     94        }
     95        case SlidingDirection_Reverse:
     96        {
     97            setWidgetGeometry(m_finalWidgetGeometry);
     98            emit sigReverse();
     99            break;
     100        }
     101    }
     102}
     103
     104void UISlidingAnimation::prepare()
     105{
     106    /* Create animation: */
    67107    m_pAnimation = UIAnimation::installPropertyAnimation(this,
    68108                                                         "widgetGeometry",
    69109                                                         "startWidgetGeometry", "finalWidgetGeometry",
    70                                                          SIGNAL(sigForward()), SIGNAL(sigBackward()));
    71     connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISlidingWidget::sltSetStateToStart);
    72     connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISlidingWidget::sltSetStateToFinal);
     110                                                         SIGNAL(sigForward()), SIGNAL(sigReverse()));
     111    connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISlidingAnimation::sltHandleStateEnteredStart);
     112    connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISlidingAnimation::sltHandleStateEnteredFinal);
    73113
    74     /* Update animation: */
    75     updateAnimation();
    76     /* Update widget geometry: */
    77     m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
    78 }
    79 
    80 bool UISlidingWidget::event(QEvent *pEvent)
    81 {
    82     /* Process desired events: */
    83     switch (pEvent->type())
    84     {
    85         case QEvent::LayoutRequest:
    86         {
    87             // WORKAROUND:
    88             // Since we are not connected to
    89             // our children LayoutRequest,
    90             // we should update geometry
    91             // ourselves.
    92             updateGeometry();
    93             break;
    94         }
    95         default:
    96             break;
    97     }
    98 
    99     /* Call to base class: */
    100     return QWidget::event(pEvent);
    101 }
    102 
    103 void UISlidingWidget::resizeEvent(QResizeEvent *pEvent)
    104 {
    105     /* Call to base-class: */
    106     QWidget::resizeEvent(pEvent);
    107 
    108     /* Update animation: */
    109     updateAnimation();
    110     /* Update widget geometry: */
    111     m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
    112 }
    113 
    114 void UISlidingWidget::prepare()
    115 {
    116114    /* Create private sliding widget: */
    117115    m_pWidget = new QWidget(this);
     
    119117    {
    120118        /* Create layout: */
     119        QBoxLayout *pLayout = 0;
    121120        switch (m_enmOrientation)
    122121        {
    123             case Qt::Horizontal: m_pLayout = new QHBoxLayout(m_pWidget); break;
    124             case Qt::Vertical:   m_pLayout = new QVBoxLayout(m_pWidget); break;
     122            case Qt::Horizontal: pLayout = new QHBoxLayout(m_pWidget); break;
     123            case Qt::Vertical:   pLayout = new QVBoxLayout(m_pWidget); break;
    125124        }
    126         if (m_pLayout)
     125        if (pLayout)
    127126        {
    128127            /* Configure layout: */
    129             m_pLayout->setSpacing(0);
    130             m_pLayout->setContentsMargins(0, 0, 0, 0);
     128            pLayout->setSpacing(0);
     129            pLayout->setContentsMargins(0, 0, 0, 0);
     130
     131            /* Create 1st label: */
     132            m_pLabel1 = new QLabel;
     133            if (m_pLabel1)
     134                pLayout->addWidget(m_pLabel1);
     135            /* Create 2nd label: */
     136            m_pLabel2 = new QLabel;
     137            if (m_pLabel2)
     138                pLayout->addWidget(m_pLabel2);
    131139        }
    132140    }
    133141
    134     /* Update animation: */
    135     updateAnimation();
    136     /* Update widget geometry: */
    137     m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
     142    /* Assign initial widget geometry: */
     143    m_pWidget->setGeometry(0, 0, width(), height());
    138144}
    139145
    140 void UISlidingWidget::updateAnimation()
     146void UISlidingAnimation::setWidgetGeometry(const QRect &rect)
    141147{
    142     /* Recalculate sub-window geometry animation boundaries based on size-hint: */
    143     switch (m_enmOrientation)
    144     {
    145         case Qt::Horizontal:
    146         {
    147             m_startWidgetGeometry = QRect(  0,           0,
    148                                             2 * width(), height());
    149             m_finalWidgetGeometry = QRect(- width(),     0,
    150                                             2 * width(), height());
    151             break;
    152         }
    153         case Qt::Vertical:
    154         {
    155             m_startWidgetGeometry = QRect(0,         0,
    156                                           width(),   2 * height());
    157             m_finalWidgetGeometry = QRect(0,       - height(),
    158                                           width(),   2 * height());
    159             break;
    160         }
    161     }
    162 
    163     /* Update animation finally: */
    164     if (m_pAnimation)
    165         m_pAnimation->update();
     148    /* Define widget geometry: */
     149    if (m_pWidget)
     150        m_pWidget->setGeometry(rect);
    166151}
    167152
    168 void UISlidingWidget::setWidgetGeometry(const QRect &rect)
    169 {
    170     /* Apply widget geometry: */
    171     m_pWidget->setGeometry(rect);
    172 }
    173 
    174 QRect UISlidingWidget::widgetGeometry() const
     153QRect UISlidingAnimation::widgetGeometry() const
    175154{
    176155    /* Return widget geometry: */
    177     return m_pWidget->geometry();
     156    return m_pWidget ? m_pWidget->geometry() : QRect();
    178157}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingAnimation.h

    r73799 r73842  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UISlidingWidget class declaration.
     3 * VBox Qt GUI - UISlidingAnimation class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___UISlidingWidget_h___
    19 #define ___UISlidingWidget_h___
     18#ifndef ___UISlidingAnimation_h___
     19#define ___UISlidingAnimation_h___
    2020
    2121/* Qt includes: */
     
    2323
    2424/* Forward declarations: */
    25 class QBoxLayout;
     25class QLabel;
    2626class QRect;
    2727class QWidget;
     
    2929
    3030
    31 /** Some kind of splitter which allows to switch between
    32   * two widgets using horizontal sliding animation. */
    33 class UISlidingWidget : public QWidget
     31/** Sliding direction. */
     32enum SlidingDirection
     33{
     34    SlidingDirection_Forward,
     35    SlidingDirection_Reverse
     36};
     37
     38
     39/** QWidget extension which renders a sliding animation
     40  * while transiting from one widget to another. */
     41class UISlidingAnimation : public QWidget
    3442{
    3543    Q_OBJECT;
     
    4048signals:
    4149
    42     /** Commands to move animation forward. */
     50    /** Commands to move animation in forward direction. */
    4351    void sigForward();
    44     /** Commands to move animation backward. */
    45     void sigBackward();
     52    /** Commands to move animation in reverse direction. */
     53    void sigReverse();
     54
     55    /** Notifies listeners about animation in specified @a enmDirection is complete. */
     56    void sigAnimationComplete(SlidingDirection enmDirection);
    4657
    4758public:
    4859
    49     /** Sliding state. */
    50     enum State
    51     {
    52         State_Start,
    53         State_GoingForward,
    54         State_Final,
    55         State_GoingBackward
    56     };
    57 
    58     /** Constructs sliding widget passing @a pParent to the base-class.
     60    /** Constructs sliding animation passing @a pParent to the base-class.
    5961      * @param  enmOrientation  Brings the widget orientation. */
    60     UISlidingWidget(Qt::Orientation enmOrientation, QWidget *pParent = 0);
    61 
    62     /** Holds the minimum widget size. */
    63     virtual QSize minimumSizeHint() const /* pverride */;
     62    UISlidingAnimation(Qt::Orientation enmOrientation, QWidget *pParent = 0);
    6463
    6564    /** Defines @a pWidget1 and @a pWidget2. */
    6665    void setWidgets(QWidget *pWidget1, QWidget *pWidget2);
    6766
    68     /** Returns sliding state. */
    69     State state() const { return m_enmState; }
    70 
    71     /** Moves animation forward. */
    72     void moveForward() { m_enmState = State_GoingForward; emit sigForward(); }
    73     /** Moves animation backward. */
    74     void moveBackward() { m_enmState = State_GoingBackward; emit sigBackward(); }
    75 
    76 protected:
    77 
    78     /** Handles any Qt @a pEvent. */
    79     virtual bool event(QEvent *pEvent) /* override */;
    80 
    81     /** Handles resize @a pEvent. */
    82     virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     67    /** Animates cached pWidget1 and pWidget2 in passed @a enmDirection. */
     68    void animate(SlidingDirection enmDirection);
    8369
    8470private slots:
    8571
    86     /** Marks state as start. */
    87     void sltSetStateToStart() { m_enmState = State_Start; }
    88     /** Marks state as final. */
    89     void sltSetStateToFinal() { m_enmState = State_Final; }
     72    /** Handles entering for 'Start' state. */
     73    void sltHandleStateEnteredStart() { emit sigAnimationComplete(SlidingDirection_Reverse); }
     74    /** Handles entering for 'Final' state. */
     75    void sltHandleStateEnteredFinal() { emit sigAnimationComplete(SlidingDirection_Forward); }
    9076
    9177private:
     
    9379    /** Prepares all. */
    9480    void prepare();
    95 
    96     /** Updates animation. */
    97     void updateAnimation();
    9881
    9982    /** Defines sub-window geometry. */
     
    10891    /** Holds the widget orientation. */
    10992    Qt::Orientation  m_enmOrientation;
     93    /** Holds the animation instance. */
     94    UIAnimation     *m_pAnimation;
     95    /** Holds sub-window start-geometry. */
     96    QRect            m_startWidgetGeometry;
     97    /** Holds sub-window final-geometry. */
     98    QRect            m_finalWidgetGeometry;
    11099
    111     /** Holds whether we are in animation final state. */
    112     State        m_enmState;
    113     /** Holds the shift left/right animation instance. */
    114     UIAnimation *m_pAnimation;
    115     /** Holds sub-window start-geometry. */
    116     QRect        m_startWidgetGeometry;
    117     /** Holds sub-window final-geometry. */
    118     QRect        m_finalWidgetGeometry;
     100    /** Holds the sliding widget instance. */
     101    QWidget     *m_pWidget;
     102    /** Holds the 1st label instance. */
     103    QLabel      *m_pLabel1;
     104    /** Holds the 2nd label instance. */
     105    QLabel      *m_pLabel2;
    119106
    120     /** Holds the private sliding widget instance. */
    121     QWidget     *m_pWidget;
    122     /** Holds the widget layout instance. */
    123     QBoxLayout  *m_pLayout;
    124     /** Holds the 1st widget reference. */
     107    /** Holds the 1st rendered-widget reference. */
    125108    QWidget     *m_pWidget1;
    126     /** Holds the 2nd widget reference. */
     109    /** Holds the 2nd rendered-widget reference. */
    127110    QWidget     *m_pWidget2;
    128111};
    129112
    130 #endif /* !___UISlidingWidget_h___ */
    131 
     113#endif /* !___UISlidingAnimation_h___ */
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