VirtualBox

Changeset 45696 in vbox


Ignore:
Timestamp:
Apr 24, 2013 1:09:42 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Popup-center: Popup-stack: Better encapsulation for the popup-pane create/update cases.

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

Legend:

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

    r45691 r45696  
    6565}
    6666
    67 void UIPopupCenter::message(QWidget *pParent, const QString &strId,
     67void UIPopupCenter::message(QWidget *pParent, const QString &strPopupPaneID,
    6868                            const QString &strMessage, const QString &strDetails,
    6969                            int iButton1 /*= 0*/, int iButton2 /*= 0*/,
     
    7272                            bool fProposeAutoConfirmation /*= false*/)
    7373{
    74     showPopupPane(pParent, strId,
     74    showPopupPane(pParent, strPopupPaneID,
    7575                  strMessage, strDetails,
    7676                  iButton1, iButton2,
     
    7979}
    8080
    81 void UIPopupCenter::error(QWidget *pParent, const QString &strId,
     81void UIPopupCenter::error(QWidget *pParent, const QString &strPopupPaneID,
    8282                          const QString &strMessage, const QString &strDetails,
    8383                          bool fProposeAutoConfirmation /*= false*/)
    8484{
    85     message(pParent, strId,
     85    message(pParent, strPopupPaneID,
    8686            strMessage, strDetails,
    8787            AlertButton_Ok | AlertButtonOption_Default | AlertButtonOption_Escape /* 1st button */,
     
    9292}
    9393
    94 void UIPopupCenter::alert(QWidget *pParent, const QString &strId,
     94void UIPopupCenter::alert(QWidget *pParent, const QString &strPopupPaneID,
    9595                          const QString &strMessage,
    9696                          bool fProposeAutoConfirmation /*= false*/)
    9797{
    98     error(pParent, strId,
     98    error(pParent, strPopupPaneID,
    9999          strMessage, QString(),
    100100          fProposeAutoConfirmation);
    101101}
    102102
    103 void UIPopupCenter::question(QWidget *pParent, const QString &strId,
     103void UIPopupCenter::question(QWidget *pParent, const QString &strPopupPaneID,
    104104                             const QString &strMessage,
    105105                             int iButton1 /*= 0*/, int iButton2 /*= 0*/,
     
    108108                             bool fProposeAutoConfirmation /*= false*/)
    109109{
    110     message(pParent, strId,
     110    message(pParent, strPopupPaneID,
    111111            strMessage, QString(),
    112112            iButton1, iButton2,
     
    115115}
    116116
    117 void UIPopupCenter::questionBinary(QWidget *pParent, const QString &strId,
     117void UIPopupCenter::questionBinary(QWidget *pParent, const QString &strPopupPaneID,
    118118                                   const QString &strMessage,
    119119                                   const QString &strOkButtonText /*= QString()*/,
     
    121121                                   bool fProposeAutoConfirmation /*= false*/)
    122122{
    123     question(pParent, strId,
     123    question(pParent, strPopupPaneID,
    124124             strMessage,
    125125             AlertButton_Ok | AlertButtonOption_Default,
     
    182182    }
    183183
    184     /* Compose button description map: */
    185     QMap<int, QString> buttonDescriptions;
    186     if (iButton1 != 0 && !buttonDescriptions.contains(iButton1))
    187         buttonDescriptions[iButton1] = strButtonText1;
    188     if (iButton2 != 0 && !buttonDescriptions.contains(iButton2))
    189         buttonDescriptions[iButton2] = strButtonText2;
    190     /* Update corresponding popup-pane: */
    191     pPopupStack->updatePopupPane(strPopupPaneID, strMessage, strDetails, buttonDescriptions, fProposeAutoConfirmation);
     184    /* Looking for the corresponding popup-pane: */
     185    if (pPopupStack->exists(strPopupPaneID))
     186    {
     187        /* Update existing one: */
     188        pPopupStack->updatePopupPane(strPopupPaneID, strMessage, strDetails);
     189    }
     190    else
     191    {
     192        /* Compose button description map: */
     193        QMap<int, QString> buttonDescriptions;
     194        if (iButton1 != 0 && !buttonDescriptions.contains(iButton1))
     195            buttonDescriptions[iButton1] = strButtonText1;
     196        if (iButton2 != 0 && !buttonDescriptions.contains(iButton2))
     197            buttonDescriptions[iButton2] = strButtonText2;
     198        /* Create new one: */
     199        pPopupStack->createPopupPane(strPopupPaneID, strMessage, strDetails,
     200                                     buttonDescriptions, fProposeAutoConfirmation);
     201    }
    192202}
    193203
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h

    r45691 r45696  
    4646
    4747    /* API: Main message function.
    48      * Provides up to two buttons.
     48     * Provides one-two buttons.
    4949     * Used directly only in exceptional cases: */
    50     void message(QWidget *pParent, const QString &strId,
     50    void message(QWidget *pParent, const QString &strPopupPaneID,
    5151                 const QString &strMessage, const QString &strDetails,
    5252                 int iButton1 = 0, int iButton2 = 0,
     
    5757    /* API: Wrapper to 'message' function.
    5858     * Provides single OK button: */
    59     void error(QWidget *pParent, const QString &strId,
     59    void error(QWidget *pParent, const QString &strPopupPaneID,
    6060               const QString &strMessage, const QString &strDetails,
    6161               bool fProposeAutoConfirmation = false);
     
    6363    /* API: Wrapper to 'error' function.
    6464     * Omits details: */
    65     void alert(QWidget *pParent, const QString &strId,
     65    void alert(QWidget *pParent, const QString &strPopupPaneID,
    6666               const QString &strMessage,
    6767               bool fProposeAutoConfirmation = false);
     
    7070     * Omits details, provides up to two buttons.
    7171     * Used directly only in exceptional cases: */
    72     void question(QWidget *pParent, const QString &strId,
     72    void question(QWidget *pParent, const QString &strPopupPaneID,
    7373                  const QString &strMessage,
    7474                  int iButton1 = 0, int iButton2 = 0,
     
    7979    /* API: Wrapper to 'question' function,
    8080     * Question providing two buttons (OK and Cancel by default): */
    81     void questionBinary(QWidget *pParent, const QString &strId,
     81    void questionBinary(QWidget *pParent, const QString &strPopupPaneID,
    8282                        const QString &strMessage,
    8383                        const QString &strOkButtonText = QString(),
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.cpp

    r45691 r45696  
    3838#include <VBox/sup.h>
    3939
    40 void UIAnimationFramework::installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
    41                                                     int iStartValue, int iFinalValue,
    42                                                     const char *pSignalForward, const char *pSignalBackward,
    43                                                     int iAnimationDuration /*= 300*/)
    44 {
    45     /* State-machine: */
    46     QStateMachine *pStateMachine = new QStateMachine(pParent);
    47     /* State-machine 'start' state: */
    48     QState *pStateStart = new QState(pStateMachine);
    49     /* State-machine 'final' state: */
    50     QState *pStateFinal = new QState(pStateMachine);
    51 
    52     /* State-machine 'forward' animation: */
    53     QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
    54     pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    55     pForwardAnimation->setDuration(iAnimationDuration);
    56     pForwardAnimation->setStartValue(iStartValue);
    57     pForwardAnimation->setEndValue(iFinalValue);
    58     /* State-machine 'backward' animation: */
    59     QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent);
    60     pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    61     pBackwardAnimation->setDuration(iAnimationDuration);
    62     pBackwardAnimation->setStartValue(iFinalValue);
    63     pBackwardAnimation->setEndValue(iStartValue);
    64 
    65     /* State-machine state transitions: */
    66     QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pParent, pSignalForward, pStateFinal);
    67     pDefaultToHovered->addAnimation(pForwardAnimation);
    68     QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pParent, pSignalBackward, pStateStart);
    69     pHoveredToDefault->addAnimation(pBackwardAnimation);
    70 
    71     /* Initial state is 'start': */
    72     pStateMachine->setInitialState(pStateStart);
    73     /* Start hover-machine: */
    74     pStateMachine->start();
    75 }
    76 
    77 QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName,
    78                                                               const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal,
     40
     41QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
     42                                                              const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
    7943                                                              const char *pSignalForward, const char *pSignalBackward,
    8044                                                              bool fReversive /*= false*/, int iAnimationDuration /*= 300*/)
     
    8852
    8953    /* State-machine 'forward' animation: */
    90     QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine);
     54    QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine);
    9155    pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    9256    pForwardAnimation->setDuration(iAnimationDuration);
    93     pForwardAnimation->setStartValue(pTarget->property(strValuePropertyNameStart));
    94     pForwardAnimation->setEndValue(pTarget->property(strValuePropertyNameFinal));
     57    pForwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameStart));
     58    pForwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameFinal));
    9559    /* State-machine 'backward' animation: */
    96     QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine);
     60    QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine);
    9761    pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    9862    pBackwardAnimation->setDuration(iAnimationDuration);
    99     pBackwardAnimation->setStartValue(pTarget->property(strValuePropertyNameFinal));
    100     pBackwardAnimation->setEndValue(pTarget->property(strValuePropertyNameStart));
     63    pBackwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameFinal));
     64    pBackwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameStart));
    10165
    10266    /* State-machine state transitions: */
     
    12993    void sigFocusLeave();
    13094
    131     /* Notifier: Animation stuff: */
     95    /* Notifier: Layout stuff: */
    13296    void sigSizeHintChanged();
    13397
     
    148112    bool isAutoConfirmed() const;
    149113
    150     /* API: Size-hint stuff: */
     114    /* API: Layout stuff: */
    151115    QSize minimumSizeHint() const;
    152116    void setMinimumSizeHint(const QSize &minimumSizeHint);
     
    155119private slots:
    156120
    157     /* Handlers: Animation stuff: */
     121    /* Handlers: Focus stuff: */
    158122    void sltFocusEnter();
    159123    void sltFocusLeave();
     
    168132    void retranslateUi();
    169133
    170     /* Helper: Size-hint stuff: */
     134    /* Helper: Layout stuff: */
     135    void updateSizeHint();
     136
     137    /* Property: Focus stuff: */
    171138    QSize collapsedSizeHint() const { return m_collapsedSizeHint; }
    172139    QSize expandedSizeHint() const { return m_expandedSizeHint; }
    173     void updateSizeHint();
    174 
    175     /* Variables: Size-hint stuff: */
     140
     141    /* Variables: Layout stuff: */
    176142    const int m_iLayoutMargin;
    177143    const int m_iLayoutSpacing;
     
    188154    bool m_fProposeAutoConfirmation;
    189155
    190     /* Variables: Animation stuff: */
     156    /* Variables: Focus stuff: */
    191157    bool m_fFocused;
    192158    QObject *m_pAnimation;
     
    233199    static QIcon defaultIcon(int iButtonID);
    234200
    235     /* Widgets: */
     201    /* Variables: Widget stuff: */
    236202    QHBoxLayout *m_pButtonLayout;
    237203    QMap<int, QString> m_buttonDescriptions;
     
    383349{
    384350    /* Install 'hover' animation for 'opacity' property: */
    385     UIAnimationFramework::installPropertyAnimation(this, QByteArray("opacity"),
    386                                                    m_iDefaultOpacity, m_iHoveredOpacity,
     351    UIAnimationFramework::installPropertyAnimation(this, "opacity", "defaultOpacity", "hoveredOpacity",
    387352                                                   SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()));
    388353    /* Prepare content: */
     
    681646        m_pLabel->setFont(currentFont);
    682647        m_pLabel->setWordWrap(true);
     648        m_pLabel->setFocusPolicy(Qt::NoFocus);
    683649    }
    684650    /* Create check-box: */
     
    693659#endif /* !Q_WS_MAC */
    694660        m_pAutoConfirmCheckBox->setFont(currentFont);
     661        m_pAutoConfirmCheckBox->setFocusPolicy(Qt::NoFocus);
    695662    }
    696663    /* Translate UI finally: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.h

    r45691 r45696  
    2929/* Forward declaration: */
    3030class QStateMachine;
    31 class QLabel;
    32 class QPushButton;
    33 class UIPopupPane;
    3431class UIPopupPaneTextPane;
    3532class UIPopupPaneButtonPane;
     
    3936{
    4037    /* API: Animation stuff: */
    41     void installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName,
    42                                   int iStartValue, int iFinalValue,
    43                                   const char *pSignalForward, const char *pSignalBackward,
    44                                   int iAnimationDuration = 300);
    45 
    46     /* API: Animation stuff: */
    47     QStateMachine* installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName,
    48                                             const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal,
     38    QStateMachine* installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName,
     39                                            const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal,
    4940                                            const char *pSignalForward, const char *pSignalBackward,
    5041                                            bool fReversive = false, int iAnimationDuration = 300);
     
    5546{
    5647    Q_OBJECT;
     48    Q_PROPERTY(int defaultOpacity READ defaultOpacity);
     49    Q_PROPERTY(int hoveredOpacity READ hoveredOpacity);
    5750    Q_PROPERTY(int opacity READ opacity WRITE setOpacity);
    5851
     
    116109
    117110    /* Property: Hover stuff: */
     111    int defaultOpacity() const { return m_iDefaultOpacity; }
     112    int hoveredOpacity() const { return m_iHoveredOpacity; }
    118113    int opacity() const { return m_iOpacity; }
    119114    void setOpacity(int iOpacity) { m_iOpacity = iOpacity; update(); }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.cpp

    r45691 r45696  
    4040}
    4141
    42 void UIPopupStack::updatePopupPane(const QString &strPopupPaneID,
     42bool UIPopupStack::exists(const QString &strPopupPaneID) const
     43{
     44    /* Is there already popup-pane with the same ID? */
     45    return m_panes.contains(strPopupPaneID);
     46}
     47
     48void UIPopupStack::createPopupPane(const QString &strPopupPaneID,
    4349                                   const QString &strMessage, const QString &strDetails,
    4450                                   const QMap<int, QString> &buttonDescriptions,
    4551                                   bool fProposeAutoConfirmation)
    4652{
    47     /* Looking for the corresponding popup-pane: */
    48     UIPopupPane *pPopupPane = 0;
    49     /* Is there already popup-pane with the same ID? */
     53    /* Make sure there is no such popup-pane already: */
    5054    if (m_panes.contains(strPopupPaneID))
    5155    {
    52         /* Get existing one: */
    53         pPopupPane = m_panes[strPopupPaneID];
    54         /* Update message and details: */
    55         pPopupPane->setMessage(strMessage);
    56         pPopupPane->setDetails(strDetails);
    57     }
    58     /* There is no popup-pane with the same ID? */
    59     else
    60     {
    61         /* Create new one: */
    62         pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this,
    63                                                                strMessage, strDetails,
    64                                                                buttonDescriptions,
    65                                                                fProposeAutoConfirmation);
    66         /* Attach popup-pane connection: */
    67         connect(pPopupPane, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry()));
    68         connect(pPopupPane, SIGNAL(sigDone(int)), this, SLOT(sltPopupPaneDone(int)));
    69         /* Show popup-pane: */
    70         pPopupPane->show();
    71     }
     56        AssertMsgFailed(("Popup-pane already exists!"));
     57        return;
     58    }
     59
     60    /* Create new popup-pane: */
     61    UIPopupPane *pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this,
     62                                                                        strMessage, strDetails,
     63                                                                        buttonDescriptions,
     64                                                                        fProposeAutoConfirmation);
     65    /* Attach popup-pane connection: */
     66    connect(pPopupPane, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry()));
     67    connect(pPopupPane, SIGNAL(sigDone(int)), this, SLOT(sltPopupPaneDone(int)));
     68    /* Show popup-pane: */
     69    pPopupPane->show();
     70
     71    /* Propagate desired width: */
     72    setDesiredWidth(parentWidget()->width());
     73    /* Adjust geometry: */
     74    sltAdjustGeometry();
     75}
     76
     77void UIPopupStack::updatePopupPane(const QString &strPopupPaneID,
     78                                   const QString &strMessage, const QString &strDetails)
     79{
     80    /* Make sure there is such popup-pane already: */
     81    if (!m_panes.contains(strPopupPaneID))
     82    {
     83        AssertMsgFailed(("Popup-pane doesn't exists!"));
     84        return;
     85    }
     86
     87    /* Get existing popup-pane: */
     88    UIPopupPane *pPopupPane = m_panes[strPopupPaneID];
     89    /* Update message and details: */
     90    pPopupPane->setMessage(strMessage);
     91    pPopupPane->setDetails(strDetails);
    7292
    7393    /* Propagate desired width: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.h

    r45691 r45696  
    3535
    3636    /* Notifier: Popup-pane stuff: */
    37     void sigPopupPaneDone(QString strID, int iResultCode);
     37    void sigPopupPaneDone(QString strPopupPaneID, int iResultCode);
    3838
    3939    /* Notifier: Popup-stack stuff: */
     
    4646
    4747    /* API: Popup-pane stuff: */
    48     void updatePopupPane(const QString &strPopupPaneID,
     48    bool exists(const QString &strPopupPaneID) const;
     49    void createPopupPane(const QString &strPopupPaneID,
    4950                         const QString &strMessage, const QString &strDetails,
    5051                         const QMap<int, QString> &buttonDescriptions,
    5152                         bool fProposeAutoConfirmation);
     53    void updatePopupPane(const QString &strPopupPaneID,
     54                         const QString &strMessage, const QString &strDetails);
    5255
    5356private slots:
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