VirtualBox

Changeset 45592 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 17, 2013 4:58:02 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Popup-center, popup-pane: Implementing main framework stuff (part 6).

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

Legend:

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

    r45588 r45592  
    7373}
    7474
     75QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName,
     76                                                              const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal,
     77                                                              const char *pSignalForward, const char *pSignalBackward,
     78                                                              bool fReversive /*= false*/, int iAnimationDuration /*= 300*/)
     79{
     80    /* State-machine: */
     81    QStateMachine *pStateMachine = new QStateMachine(pTarget);
     82    /* State-machine 'start' state: */
     83    QState *pStateStart = new QState(pStateMachine);
     84    /* State-machine 'final' state: */
     85    QState *pStateFinal = new QState(pStateMachine);
     86
     87    /* State-machine 'forward' animation: */
     88    QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine);
     89    pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
     90    pForwardAnimation->setDuration(iAnimationDuration);
     91    pForwardAnimation->setStartValue(pTarget->property(strValuePropertyNameStart));
     92    pForwardAnimation->setEndValue(pTarget->property(strValuePropertyNameFinal));
     93    /* State-machine 'backward' animation: */
     94    QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine);
     95    pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
     96    pBackwardAnimation->setDuration(iAnimationDuration);
     97    pBackwardAnimation->setStartValue(pTarget->property(strValuePropertyNameFinal));
     98    pBackwardAnimation->setEndValue(pTarget->property(strValuePropertyNameStart));
     99
     100    /* State-machine state transitions: */
     101    QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pTarget, pSignalForward, pStateFinal);
     102    pDefaultToHovered->addAnimation(pForwardAnimation);
     103    QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pTarget, pSignalBackward, pStateStart);
     104    pHoveredToDefault->addAnimation(pBackwardAnimation);
     105
     106    /* Initial state is 'start': */
     107    pStateMachine->setInitialState(!fReversive ? pStateStart : pStateFinal);
     108    /* Start hover-machine: */
     109    pStateMachine->start();
     110    /* Return machine: */
     111    return pStateMachine;
     112}
     113
    75114
    76115/* Popup-pane frame prototype class: */
     
    82121signals:
    83122
    84     /* Notifiers: Animation stuff: */
     123    /* Notifiers: Parent propagation stuff: */
    85124    void sigHoverEnter();
    86125    void sigHoverLeave();
     
    119158{
    120159    Q_OBJECT;
    121     Q_PROPERTY(int percentage READ percentage WRITE setPercentage);
    122160
    123161signals:
    124162
    125     /* Notifier: Animation stuff: */
    126     void sigHoverEnter();
    127     void sigHoverLeave();
     163    /* Notifiers: Parent propagation stuff: */
    128164    void sigFocusEnter();
    129165    void sigFocusLeave();
    130     void sigGeometryChanged();
     166
     167    /* Notifier: Animation stuff: */
     168    void sigSizeChanged();
    131169
    132170public:
     
    142180    void setDesiredWidth(int iDesiredWidth);
    143181
    144     /* API: Minimum size-hint stuff: */
     182    /* API: Size-hint stuff: */
    145183    QSize minimumSizeHint() const;
    146 
     184    QSize sizeHint() const;
     185
     186private slots:
     187
     188    /* Handlers: Animation stuff: */
     189    void sltFocusEnter();
     190    void sltFocusLeave();
     191   
    147192private:
    148193
     
    154199    void prepareContent();
    155200
    156     /* Property: Hover stuff: */
    157     int percentage() const { return m_iPercentage; }
    158     void setPercentage(int iPercentage);
     201    /* Helper: Size-hint stuff: */
     202    void updateGeometry();
     203
     204    /* Handler: Animation stuff: */
     205    void resizeEvent(QResizeEvent *pEvent);
    159206
    160207    /* Variables: Label stuff: */
     
    162209    int m_iDesiredWidth;
    163210
    164     /* Variables: Hover stuff: */
    165     const int m_iHoverAnimationDuration;
    166     const int m_iDefaultPercentage;
    167     const int m_iHoveredPercentage;
    168     int m_iPercentage;
     211    /* Variables: Size-hint stuff: */
     212    QSize m_minimumSizeHint;
     213    QSize m_sizeHint;
     214
     215    /* Variables: Animation stuff: */
     216    bool m_fFocused;
     217    QObject *m_pAnimation;
    169218};
    170219
     
    225274    const int iHeight = parentWidget()->height();
    226275
    227     /* Adjust text-pane according parent width: */
    228     if (m_pTextPane)
    229     {
    230         m_pTextPane->setDesiredWidth(iWidth - 2 * m_iMainLayoutMargin
    231                                             - 2 * m_iMainFrameLayoutMargin
    232                                             - m_pButtonBox->minimumSizeHint().width());
    233     }
    234 
    235276    /* Resize popup according parent width: */
    236277    resize(iWidth, minimumSizeHint().height());
     
    268309
    269310        /* Adjust geometry: */
    270         sltAdjustGeomerty();
     311        adjustGeometry();
    271312    }
    272313    /* Other objects subscribed for hovering: */
     
    341382{
    342383    /* Adjust geometry: */
    343     sltAdjustGeomerty();
     384    adjustGeometry();
    344385}
    345386
     
    368409        {
    369410            /* Take into account widgets: */
    370             iMinimumWidthHint += m_pTextPane->minimumSizeHint().width();
     411            iMinimumWidthHint += m_pTextPane->width();
    371412            iMinimumWidthHint += m_iMainFrameLayoutSpacing;
    372413            iMinimumWidthHint += m_pButtonBox->minimumSizeHint().width();
     
    390431        {
    391432            /* Take into account widgets: */
    392             const int iTextPaneHeight = m_pTextPane->minimumSizeHint().height();
     433            const int iTextPaneHeight = m_pTextPane->height();
    393434            const int iButtonBoxHeight = m_pButtonBox->minimumSizeHint().height();
    394435            iMinimumHeightHint += qMax(iTextPaneHeight, iButtonBoxHeight);
     
    403444{
    404445    return QSize(minimumWidthHint(), minimumHeightHint());
     446}
     447
     448void UIPopupPane::adjustGeometry()
     449{
     450    /* Get parent width: */
     451    const int iWidth = parentWidget()->width();
     452
     453    /* Adjust text-pane according parent width: */
     454    if (m_pTextPane)
     455    {
     456        m_pTextPane->setDesiredWidth(iWidth - 2 * m_iMainLayoutMargin
     457                                            - 2 * m_iMainFrameLayoutMargin
     458                                            - m_pButtonBox->minimumSizeHint().width());
     459    }
     460
     461    /* Adjust other widgets: */
     462    sltAdjustGeomerty();
    405463}
    406464
     
    420478        /* Main-frame layout: */
    421479        {
     480            /* Variables: */
     481            const int iTextPaneWidth = m_pTextPane->width();
     482            const int iTextPaneHeight = m_pTextPane->height();
     483            const QSize buttonBoxMinimumSizeHint = m_pButtonBox->minimumSizeHint();
     484            const int iButtonBoxWidth = buttonBoxMinimumSizeHint.width();
     485            const int iButtonBoxHeight = buttonBoxMinimumSizeHint.height();
     486            const int iMaximumHeight = qMax(iTextPaneHeight, iButtonBoxHeight);
     487            const int iMinimumHeight = qMin(iTextPaneHeight, iButtonBoxHeight);
     488            const int iHeightShift = (iMaximumHeight - iMinimumHeight) / 2;
     489            const bool fTextPaneShifted = iTextPaneHeight < iButtonBoxHeight;
    422490            /* Text-pane: */
    423             const int iTextPaneWidth = m_pTextPane->minimumSizeHint().width();
    424491            m_pTextPane->move(m_iMainFrameLayoutMargin,
    425                               m_iMainFrameLayoutMargin);
    426             m_pTextPane->resize(iTextPaneWidth,
    427                                 iMainFrameHeight - 2 * m_iMainFrameLayoutMargin);
     492                              fTextPaneShifted ? m_iMainFrameLayoutMargin + iHeightShift : m_iMainFrameLayoutMargin);
     493            m_pTextPane->resize(iTextPaneWidth, iTextPaneHeight);
    428494            /* Button-box: */
    429             const int iButtonBoxWidth = m_pButtonBox->minimumSizeHint().width();
    430495            m_pButtonBox->move(m_iMainFrameLayoutMargin + iTextPaneWidth + m_iMainFrameLayoutSpacing,
    431496                               m_iMainFrameLayoutMargin);
     
    450515        {
    451516            /* Prepare label: */
    452             connect(m_pTextPane, SIGNAL(sigGeometryChanged()),
     517            connect(m_pTextPane, SIGNAL(sigSizeChanged()),
    453518                    this, SLOT(sltAdjustGeomerty()));
    454519            m_pTextPane->installEventFilter(this);
     
    660725    , m_pLabel(0)
    661726    , m_iDesiredWidth(-1)
    662     , m_iHoverAnimationDuration(300)
    663     , m_iDefaultPercentage(1)
    664     , m_iHoveredPercentage(100)
    665     , m_iPercentage(m_iDefaultPercentage)
     727    , m_fFocused(false)
     728    , m_pAnimation(0)
    666729{
    667730    /* Prepare: */
     
    700763    if (m_iDesiredWidth >= 0)
    701764        /* Return dependent size-hint: */
    702         return QSize(m_iDesiredWidth, (int)(((qreal)percentage() / 100) * m_pLabel->heightForWidth(m_iDesiredWidth)));
     765        return m_minimumSizeHint;
     766    /* Return golden-rule minimum size-hint by default: */
     767    return m_pLabel->minimumSizeHint();
     768}
     769
     770QSize UIPopupPaneTextPane::sizeHint() const
     771{
     772    /* Check if desired-width set: */
     773    if (m_iDesiredWidth >= 0)
     774        /* Return dependent size-hint: */
     775        return m_sizeHint;
    703776    /* Return golden-rule size-hint by default: */
    704     return m_pLabel->minimumSizeHint();
     777    return m_pLabel->sizeHint();
     778}
     779
     780void UIPopupPaneTextPane::sltFocusEnter()
     781{
     782    if (!m_fFocused)
     783    {
     784        m_fFocused = true;
     785        emit sigFocusEnter();
     786    }
     787}
     788
     789void UIPopupPaneTextPane::sltFocusLeave()
     790{
     791    if (m_fFocused)
     792    {
     793        m_fFocused = false;
     794        emit sigFocusLeave();
     795    }
    705796}
    706797
     
    708799{
    709800    /* Propagate parent signals: */
    710     connect(parent(), SIGNAL(sigHoverEnter()), this, SIGNAL(sigHoverEnter()));
    711     connect(parent(), SIGNAL(sigHoverLeave()), this, SIGNAL(sigHoverLeave()));
    712     connect(parent(), SIGNAL(sigFocusEnter()), this, SIGNAL(sigFocusEnter()));
    713     connect(parent(), SIGNAL(sigFocusLeave()), this, SIGNAL(sigFocusLeave()));
    714     /* Install 'focus' animation for 'height' property: */
    715     UIAnimationFramework::installPropertyAnimation(this, QByteArray("percentage"),
    716                                                    m_iDefaultPercentage, m_iHoveredPercentage, m_iHoverAnimationDuration,
    717                                                    SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave()));
     801    connect(parent(), SIGNAL(sigFocusEnter()), this, SLOT(sltFocusEnter()));
     802    connect(parent(), SIGNAL(sigFocusLeave()), this, SLOT(sltFocusLeave()));
    718803    /* Prepare content: */
    719804    prepareContent();
     
    744829            m_pLabel->setWordWrap(true);
    745830        }
    746         /* Activate layout: */
    747         updateGeometry();
    748     }
    749 }
    750 
    751 void UIPopupPaneTextPane::setPercentage(int iPercentage)
    752 {
    753     m_iPercentage = iPercentage;
    754     updateGeometry();
    755     emit sigGeometryChanged();
     831    }
     832}
     833
     834void UIPopupPaneTextPane::updateGeometry()
     835{
     836    /* Recalculate size-hints: */
     837    QFontMetrics fm(m_pLabel->font(), m_pLabel);
     838    m_sizeHint = QSize(m_iDesiredWidth, m_pLabel->heightForWidth(m_iDesiredWidth));
     839    m_minimumSizeHint = QSize(m_iDesiredWidth, fm.height());
     840    /* Update geometry: */
     841    QWidget::updateGeometry();
     842    /* Resize to required size: */
     843    resize(m_fFocused ? sizeHint() : minimumSizeHint());
     844    /* Reinstall animation: */
     845    delete m_pAnimation;
     846    m_pAnimation = UIAnimationFramework::installPropertyAnimation(this, "size", "minimumSizeHint", "sizeHint",
     847                                                                  SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave()),
     848                                                                  m_fFocused);
     849}
     850
     851void UIPopupPaneTextPane::resizeEvent(QResizeEvent*)
     852{
     853    emit sigSizeChanged();
    756854}
    757855
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.h

    r45588 r45592  
    2727
    2828/* Forward declaration: */
     29class QStateMachine;
    2930class QLabel;
    3031class QPushButton;
     
    4142                                  int iStartValue, int iFinalValue, int iAnimationDuration,
    4243                                  const char *pSignalForward, const char *pSignalBackward);
     44
     45    /* API: Animation stuff: */
     46    QStateMachine* installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName,
     47                                            const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal,
     48                                            const char *pSignalForward, const char *pSignalBackward,
     49                                            bool fReversive = false, int iAnimationDuration = 300);
    4350}
    4451
     
    103110    int minimumHeightHint() const;
    104111    QSize minimumSizeHint() const;
     112    void adjustGeometry();
    105113    void updateLayout();
    106114
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