VirtualBox

Changeset 45508 in vbox for trunk/src


Ignore:
Timestamp:
Apr 12, 2013 9:08:36 AM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Popup-center: Implementing main framework stuff (part 3).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp

    r45505 r45508  
    212212                 "or pressing the host key) in order to use the mouse inside the guest OS.</p>"));
    213213    }
     214}
     215
     216void UIAnimationFramework::installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
     217                                                    int iStartValue, int iFinalValue, int iAnimationDuration,
     218                                                    const char *pSignalForward, const char *pSignalBackward)
     219{
     220    /* State-machine: */
     221    QStateMachine *pStateMachine = new QStateMachine(pParent);
     222    /* State-machine 'start' state: */
     223    QState *pStateStart = new QState(pStateMachine);
     224    /* State-machine 'final' state: */
     225    QState *pStateFinal = new QState(pStateMachine);
     226
     227    /* State-machine 'forward' animation: */
     228    QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
     229    pForwardAnimation->setDuration(iAnimationDuration);
     230    pForwardAnimation->setStartValue(iStartValue);
     231    pForwardAnimation->setEndValue(iFinalValue);
     232    /* State-machine 'backward' animation: */
     233    QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
     234    pBackwardAnimation->setDuration(iAnimationDuration);
     235    pBackwardAnimation->setStartValue(iFinalValue);
     236    pBackwardAnimation->setEndValue(iStartValue);
     237
     238    /* State-machine state transitions: */
     239    QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pParent, pSignalForward, pStateFinal);
     240    pDefaultToHovered->addAnimation(pForwardAnimation);
     241    QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pParent, pSignalBackward, pStateStart);
     242    pHoveredToDefault->addAnimation(pBackwardAnimation);
     243
     244    /* Initial state is 'start': */
     245    pStateMachine->setInitialState(pStateStart);
     246    /* Start hover-machine: */
     247    pStateMachine->start();
    214248}
    215249
     
    369403                    /* Configure button-box: */
    370404                    m_pButtonBox->installEventFilter(pMainFrame);
    371                     QList<int> activeButtons;
    372                     m_pButton1 = createButton(m_iButton1);
    373                     if (m_pButton1)
    374                     {
    375                         activeButtons << m_iButton1;
    376                         connect(m_pButton1, SIGNAL(clicked()), SLOT(done1()));
    377                         if (!m_strButtonText1.isEmpty())
    378                             m_pButton1->setText(m_strButtonText1);
    379                     }
    380                     m_pButton2 = createButton(m_iButton2);
    381                     if (m_pButton2)
    382                     {
    383                         activeButtons << m_iButton2;
    384                         connect(m_pButton2, SIGNAL(clicked()), SLOT(done2()));
    385                         if (!m_strButtonText2.isEmpty())
    386                             m_pButton1->setText(m_strButtonText2);
    387                     }
    388                     m_pButton3 = createButton(m_iButton3);
    389                     if (m_pButton3)
    390                     {
    391                         activeButtons << m_iButton3;
    392                         connect(m_pButton3, SIGNAL(clicked()), SLOT(done3()));
    393                         if (!m_strButtonText3.isEmpty())
    394                             m_pButton1->setText(m_strButtonText3);
    395                     }
     405                    prepareButtons();
    396406                }
    397407            }
     
    400410}
    401411
    402 QPushButton* UIPopupPane::createButton(int iButton)
    403 {
    404     /* Not for AlertButton_NoButton: */
     412void UIPopupPane::prepareButtons()
     413{
     414    /* Prepare descriptions: */
     415    QList<int> descriptions;
     416    descriptions << m_iButton1 << m_iButton2 << m_iButton3;
     417
     418    /* Choose 'escape' button: */
     419    foreach (int iButton, descriptions)
     420        if (iButton & AlertButtonOption_Escape)
     421        {
     422            m_iButtonEsc = iButton & AlertButtonMask;
     423            break;
     424        }
     425
     426    /* Create buttons: */
     427    QList<QPushButton*> buttons = createButtons(m_pButtonBox, descriptions);
     428
     429    /* Install focus-proxy into the 'default' button: */
     430    foreach (QPushButton *pButton, buttons)
     431        if (pButton && pButton->isDefault())
     432        {
     433            setFocusProxy(pButton);
     434            m_pTextPane->setFocusProxy(pButton);
     435            break;
     436        }
     437
     438    /* Prepare button 1: */
     439    m_pButton1 = buttons[0];
     440    if (m_pButton1)
     441    {
     442        connect(m_pButton1, SIGNAL(clicked()), SLOT(done1()));
     443        if (!m_strButtonText1.isEmpty())
     444            m_pButton1->setText(m_strButtonText1);
     445    }
     446    /* Prepare button 2: */
     447    m_pButton2 = buttons[1];
     448    if (m_pButton2)
     449    {
     450        connect(m_pButton2, SIGNAL(clicked()), SLOT(done2()));
     451        if (!m_strButtonText2.isEmpty())
     452            m_pButton1->setText(m_strButtonText2);
     453    }
     454    /* Prepare button 3: */
     455    m_pButton3 = buttons[2];
     456    if (m_pButton3)
     457    {
     458        connect(m_pButton3, SIGNAL(clicked()), SLOT(done3()));
     459        if (!m_strButtonText3.isEmpty())
     460            m_pButton1->setText(m_strButtonText3);
     461    }
     462}
     463
     464void UIPopupPane::done(int iButtonCode)
     465{
     466    /* Close the window: */
     467    close();
     468
     469    /* Notify listeners: */
     470    emit sigDone(iButtonCode);
     471}
     472
     473/* static */
     474int UIPopupPane::parentStatusBarHeight(QWidget *pParent)
     475{
     476    /* Check if passed parent is QMainWindow and contains status-bar: */
     477    if (QMainWindow *pParentWindow = qobject_cast<QMainWindow*>(pParent))
     478        if (pParentWindow->statusBar())
     479            return pParentWindow->statusBar()->height();
     480    /* Zero by default: */
     481    return 0;
     482}
     483
     484/* static */
     485QList<QPushButton*> UIPopupPane::createButtons(QIDialogButtonBox *pButtonBox, const QList<int> descriptions)
     486{
     487    /* Create button according descriptions: */
     488    QList<QPushButton*> buttons;
     489    foreach (int iButton, descriptions)
     490        buttons << createButton(pButtonBox, iButton);
     491    /* Return buttons: */
     492    return buttons;
     493}
     494
     495/* static */
     496QPushButton* UIPopupPane::createButton(QIDialogButtonBox *pButtonBox, int iButton)
     497{
     498    /* Null for AlertButton_NoButton: */
    405499    if (iButton == 0)
    406500        return 0;
     
    411505    switch (iButton & AlertButtonMask)
    412506    {
    413         case AlertButton_Ok:      strText = tr("OK");     role = QDialogButtonBox::AcceptRole; break;
    414         case AlertButton_Cancel:  strText = tr("Cancel"); role = QDialogButtonBox::RejectRole; break;
    415         case AlertButton_Choice1: strText = tr("Yes");    role = QDialogButtonBox::YesRole; break;
    416         case AlertButton_Choice2: strText = tr("No");     role = QDialogButtonBox::NoRole; break;
     507        case AlertButton_Ok:      strText = QIMessageBox::tr("OK");     role = QDialogButtonBox::AcceptRole; break;
     508        case AlertButton_Cancel:  strText = QIMessageBox::tr("Cancel"); role = QDialogButtonBox::RejectRole; break;
     509        case AlertButton_Choice1: strText = QIMessageBox::tr("Yes");    role = QDialogButtonBox::YesRole; break;
     510        case AlertButton_Choice2: strText = QIMessageBox::tr("No");     role = QDialogButtonBox::NoRole; break;
    417511        default: return 0;
    418512    }
    419513
    420514    /* Create push-button: */
    421     QPushButton *pButton = m_pButtonBox->addButton(strText, role);
    422 
    423     /* Configure <default> button: */
     515    QPushButton *pButton = pButtonBox->addButton(strText, role);
     516
     517    /* Configure 'default' button: */
    424518    if (iButton & AlertButtonOption_Default)
    425519    {
    426520        pButton->setDefault(true);
    427521        pButton->setFocusPolicy(Qt::StrongFocus);
    428         setFocusProxy(pButton);
    429         m_pTextPane->setFocusProxy(pButton);
    430522        pButton->setFocus();
    431     }
    432 
    433     /* Configure <escape> button: */
    434     if (iButton & AlertButtonOption_Escape)
    435     {
    436         m_iButtonEsc = iButton & AlertButtonMask;
    437523    }
    438524
    439525    /* Return button: */
    440526    return pButton;
    441 }
    442 
    443 void UIPopupPane::done(int iButtonCode)
    444 {
    445     /* Close the window: */
    446     close();
    447 
    448     /* Notify listeners: */
    449     emit sigDone(iButtonCode);
    450 }
    451 
    452 /* static */
    453 int UIPopupPane::parentStatusBarHeight(QWidget *pParent)
    454 {
    455     /* Check if passed parent is QMainWindow and contains status-bar: */
    456     if (QMainWindow *pParentWindow = qobject_cast<QMainWindow*>(pParent))
    457         if (pParentWindow->statusBar())
    458             return pParentWindow->statusBar()->height();
    459     return 0;
    460527}
    461528
     
    483550    installEventFilter(this);
    484551    /* Install 'hover' animation for 'opacity' property: */
    485     installPropertyAnimation(this, QByteArray("opacity"),
    486                              m_iDefaultOpacity, m_iHoveredOpacity, m_iHoverAnimationDuration,
    487                              SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()));
     552    UIAnimationFramework::installPropertyAnimation(this, QByteArray("opacity"),
     553                                                   m_iDefaultOpacity, m_iHoveredOpacity, m_iHoverAnimationDuration,
     554                                                   SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()));
    488555}
    489556
     
    555622}
    556623
    557 /* static */
    558 void UIPopupPaneFrame::installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
    559                                                 int iStartValue, int iFinalValue, int iAnimationDuration,
    560                                                 const char *pSignalForward, const char *pSignalBackward)
    561 {
    562     /* State-machine: */
    563     QStateMachine *pStateMachine = new QStateMachine(pParent);
    564     /* State-machine 'start' state: */
    565     QState *pStateStart = new QState(pStateMachine);
    566     /* State-machine 'final' state: */
    567     QState *pStateFinal = new QState(pStateMachine);
    568 
    569     /* State-machine 'forward' animation: */
    570     QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
    571     pForwardAnimation->setDuration(iAnimationDuration);
    572     pForwardAnimation->setStartValue(iStartValue);
    573     pForwardAnimation->setEndValue(iFinalValue);
    574     /* State-machine 'backward' animation: */
    575     QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
    576     pBackwardAnimation->setDuration(iAnimationDuration);
    577     pBackwardAnimation->setStartValue(iFinalValue);
    578     pBackwardAnimation->setEndValue(iStartValue);
    579 
    580     /* State-machine state transitions: */
    581     QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pParent, pSignalForward, pStateFinal);
    582     pDefaultToHovered->addAnimation(pForwardAnimation);
    583     QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pParent, pSignalBackward, pStateStart);
    584     pHoveredToDefault->addAnimation(pBackwardAnimation);
    585 
    586     /* Initial state is 'start': */
    587     pStateMachine->setInitialState(pStateStart);
    588     /* Start hover-machine: */
    589     pStateMachine->start();
    590 }
    591 
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h

    r45490 r45508  
    126126inline UIPopupCenter& popupCenter() { return *UIPopupCenter::instance(); }
    127127
     128/* UIAnimationFramework namespace: */
     129namespace UIAnimationFramework
     130{
     131    /* API: Animation stuff: */
     132    void installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
     133                                  int iStartValue, int iFinalValue, int iAnimationDuration,
     134                                  const char *pSignalForward, const char *pSignalBackward);
     135}
     136
    128137/* Popup-pane prototype class: */
    129138class UIPopupPane : public QWidget
     
    174183    /* Helpers: Prepare stuff: */
    175184    void prepareContent();
    176     QPushButton* createButton(int iButton);
     185    void prepareButtons();
    177186
    178187    /* Helper: Complete stuff: */
    179188    void done(int iButtonCode);
    180189
    181     /* Helper: Parent stuff: */
     190    /* Static helpers: Prepare stuff: */
    182191    static int parentStatusBarHeight(QWidget *pParent);
     192    static QList<QPushButton*> createButtons(QIDialogButtonBox *pButtonBox, const QList<int> description);
     193    static QPushButton* createButton(QIDialogButtonBox *pButtonBox, int iButton);
    183194
    184195    /* Variables: */
     
    231242    void setOpacity(int iOpacity) { m_iOpacity = iOpacity; update(); }
    232243
    233     /* Static helper: Animation stuff: */
    234     static void installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
    235                                          int iStartValue, int iFinalValue, int iAnimationDuration,
    236                                          const char *pSignalForward, const char *pSignalBackward);
    237 
    238244    /* Hover-machine stuff: */
    239245    bool m_fHovered;
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