VirtualBox

Changeset 45297 in vbox


Ignore:
Timestamp:
Apr 3, 2013 8:58:04 AM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: QIMessageBox cleanup/rework (part 3).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.cpp

    r45296 r45297  
    4040#endif /* Q_WS_MAC */
    4141
    42 /** @class QIMessageBox
    43  *
    44  *  The QIMessageBox class is a message box similar to QMessageBox.
    45  *  It partly implements the QMessageBox interface and adds some enhanced
    46  *  functionality.
    47  */
    48 
    49 /**
    50  *  See QMessageBox for details.
    51  */
    52 QIMessageBox::QIMessageBox (const QString &aCaption, const QString &aText,
    53                             AlertIconType aIcon, int aButton0, int aButton1, int aButton2,
    54                             QWidget *aParent, const char *aName, bool aModal)
    55     : QIDialog (aParent)
    56     , mText (aText)
    57     , mDetailsIndex (-1)
    58     , mWasDone (false)
    59     , mWasPolished (false)
    60 {
    61     setWindowTitle (aCaption);
    62     /* Necessary to later find some of the message boxes */
    63     setObjectName (aName);
    64     setModal (aModal);
    65 
    66     mButton0 = aButton0;
    67     mButton1 = aButton1;
    68     mButton2 = aButton2;
     42QIMessageBox::QIMessageBox(const QString &strCaption, const QString &strMessage, AlertIconType icon,
     43                           int iButton1 /*= 0*/, int iButton2 /*= 0*/, int iButton3 /*= 0*/, QWidget *pParent /*= 0*/)
     44    : QIDialog(pParent)
     45    , mButton1(iButton1)
     46    , mButton2(iButton2)
     47    , mButton3(iButton3)
     48    , m_strMessage(strMessage)
     49    , m_iDetailsIndex(-1)
     50    , m_fDone(false)
     51{
     52    /* Set alert caption: */
     53    setWindowTitle(strCaption);
    6954
    7055    QVBoxLayout *layout = new QVBoxLayout (this);
     
    8570
    8671    mIconLabel = new QLabel();
    87     mIconLabel->setPixmap (standardPixmap (aIcon));
     72    mIconLabel->setPixmap (standardPixmap (icon));
    8873    mIconLabel->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
    8974    mIconLabel->setAlignment (Qt::AlignHCenter | Qt::AlignTop);
     
    9580    hLayout->addLayout (messageVBoxLayout);
    9681
    97     mTextLabel = new QILabel (aText);
     82    mTextLabel = new QILabel (m_strMessage);
    9883    mTextLabel->setAlignment (Qt::AlignLeft | Qt::AlignTop);
    9984    mTextLabel->setWordWrap (true);
     
    144129    mButtonEsc = 0;
    145130
    146     mButton0PB = createButton (aButton0);
     131    mButton0PB = createButton (iButton1);
    147132    if (mButton0PB)
    148133        connect (mButton0PB, SIGNAL (clicked()), SLOT (done0()));
    149     mButton1PB = createButton (aButton1);
     134    mButton1PB = createButton (iButton2);
    150135    if (mButton1PB)
    151136        connect (mButton1PB, SIGNAL (clicked()), SLOT (done1()));
    152     mButton2PB = createButton (aButton2);
     137    mButton2PB = createButton (iButton3);
    153138    if (mButton2PB)
    154139        connect (mButton2PB, SIGNAL (clicked()), SLOT (done2()));
     
    156141    /* If this is an error message add an "Copy to clipboard" button for easier
    157142     * bug reports. */
    158     if (aIcon == AlertIconType_Critical)
     143    if (icon == AlertIconType_Critical)
    159144    {
    160145        QPushButton *pCopyButton = createButton(AlertButton_Copy);
     
    312297
    313298    mDetailsSplitter->setMultiPaging (mDetailsList.size() > 1);
    314     mDetailsIndex = 0;
     299    m_iDetailsIndex = 0;
    315300    refreshDetails();
    316301}
     
    350335void QIMessageBox::closeEvent (QCloseEvent *e)
    351336{
    352     if (mWasDone)
     337    if (m_fDone)
    353338        e->accept();
    354339    else
     
    356341}
    357342
    358 void QIMessageBox::showEvent (QShowEvent *e)
    359 {
    360     if (!mWasPolished)
    361     {
    362         /* Polishing sub-widgets */
    363         resize (minimumSizeHint());
    364         mTextLabel->useSizeHintForWidth (mTextLabel->width());
    365         mTextLabel->updateGeometry();
    366         setFixedSize(size());
    367         mDetailsSplitter->toggleWidget();
    368         mWasPolished = true;
    369     }
    370 
    371     QIDialog::showEvent (e);
     343void QIMessageBox::polishEvent(QShowEvent *pPolishEvent)
     344{
     345    /* Tune our size: */
     346    resize(minimumSizeHint());
     347    mTextLabel->useSizeHintForWidth(mTextLabel->width());
     348    mTextLabel->updateGeometry();
     349
     350    /* Call to base-class: */
     351    QIDialog::polishEvent(pPolishEvent);
     352
     353    /* Make the size fixed: */
     354    setFixedSize(size());
     355
     356    /* Toggle details-widget: */
     357    mDetailsSplitter->toggleWidget();
    372358}
    373359
     
    375361{
    376362    /* Update message text iteself */
    377     mTextLabel->setText (mText + mDetailsList [mDetailsIndex].first);
     363    mTextLabel->setText (m_strMessage + mDetailsList [m_iDetailsIndex].first);
    378364    /* Update details table */
    379     mDetailsText->setText (mDetailsList [mDetailsIndex].second);
     365    mDetailsText->setText (mDetailsList [m_iDetailsIndex].second);
    380366    setDetailsShown (!mDetailsText->toPlainText().isEmpty());
    381367
     
    383369    if (mDetailsList.size() > 1)
    384370    {
    385         mDetailsSplitter->setButtonEnabled (true, mDetailsIndex < mDetailsList.size() - 1);
    386         mDetailsSplitter->setButtonEnabled (false, mDetailsIndex > 0);
     371        mDetailsSplitter->setButtonEnabled (true, m_iDetailsIndex < mDetailsList.size() - 1);
     372        mDetailsSplitter->setButtonEnabled (false, m_iDetailsIndex > 0);
    387373    }
    388374
    389375    /* Update details label */
    390376    mDetailsSplitter->setName (mDetailsList.size() == 1 ? tr ("&Details") :
    391         tr ("&Details (%1 of %2)").arg (mDetailsIndex + 1).arg (mDetailsList.size()));
     377        tr ("&Details (%1 of %2)").arg (m_iDetailsIndex + 1).arg (mDetailsList.size()));
    392378}
    393379
     
    445431void QIMessageBox::detailsBack()
    446432{
    447     if (mDetailsIndex > 0)
    448     {
    449         -- mDetailsIndex;
     433    if (m_iDetailsIndex > 0)
     434    {
     435        -- m_iDetailsIndex;
    450436        refreshDetails();
    451437    }
     
    454440void QIMessageBox::detailsNext()
    455441{
    456     if (mDetailsIndex < mDetailsList.size() - 1)
    457     {
    458         ++ mDetailsIndex;
     442    if (m_iDetailsIndex < mDetailsList.size() - 1)
     443    {
     444        ++ m_iDetailsIndex;
    459445        refreshDetails();
    460446    }
     
    473459{
    474460    /* Create the error string with all errors. First the html version. */
    475     QString strError = "<html><body><p>" + mText + "</p>";
     461    QString strError = "<html><body><p>" + m_strMessage + "</p>";
    476462    for (int i = 0; i < mDetailsList.size(); ++i)
    477463        strError += mDetailsList.at(i).first + mDetailsList.at(i).second + "<br>";
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h

    r45296 r45297  
    8383public:
    8484
    85     QIMessageBox(const QString &aCaption, const QString &aText,
    86                  AlertIconType aIcon, int aButton0, int aButton1 = 0, int aButton2 = 0,
    87                  QWidget *aParent = 0, const char *aName = 0, bool aModal = TRUE);
     85    /* Constructor: */
     86    QIMessageBox(const QString &strCaption, const QString &strMessage, AlertIconType icon,
     87                 int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, QWidget *pParent = 0);
    8888
    8989    QString buttonText (int aButton) const;
     
    106106
    107107    void closeEvent (QCloseEvent *e);
    108     void showEvent (QShowEvent *e);
     108    void polishEvent(QShowEvent *pPolishEvent);
    109109
    110110    void refreshDetails();
     
    118118    void detailsNext();
    119119
    120     void done0() { mWasDone = true; done (mButton0 & AlertButtonMask); }
    121     void done1() { mWasDone = true; done (mButton1 & AlertButtonMask); }
    122     void done2() { mWasDone = true; done (mButton2 & AlertButtonMask); }
     120    void done0() { m_fDone = true; done (mButton1 & AlertButtonMask); }
     121    void done1() { m_fDone = true; done (mButton2 & AlertButtonMask); }
     122    void done2() { m_fDone = true; done (mButton3 & AlertButtonMask); }
    123123
    124124    void reject();
     
    128128private:
    129129
    130     int mButton0, mButton1, mButton2, mButtonEsc;
     130    int mButton1, mButton2, mButton3, mButtonEsc;
    131131    QLabel *mIconLabel;
    132132    QILabel *mTextLabel;
     
    138138    QSpacerItem *mSpacer;
    139139    QIDialogButtonBox *mButtonBox;
    140     QString mText;
     140    QString m_strMessage;
    141141    QList < QPair <QString, QString> > mDetailsList;
    142     int mDetailsIndex;
    143     bool mWasDone : 1;
    144     bool mWasPolished : 1;
     142    int m_iDetailsIndex;
     143    bool m_fDone : 1;
    145144};
    146145
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r45296 r45297  
    30183018    QPointer<QIMessageBox> pMessageBox = new QIMessageBox(title, strMessage, icon,
    30193019                                                          iButton1, iButton2, iButton3,
    3020                                                           pMessageBoxParent, strAutoConfirmId.toAscii().constData());
     3020                                                          pMessageBoxParent);
    30213021    mwManager().registerNewParent(pMessageBox, pMessageBoxParent);
    30223022
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