VirtualBox

Changeset 47846 in vbox


Ignore:
Timestamp:
Aug 19, 2013 3:27:57 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88139
Message:

FE/Qt: Settings Dialog: Warning-pane: Support for multiple warning-icons.

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

Legend:

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

    r47563 r47846  
    77
    88/*
    9  * Copyright (C) 2006-2012 Oracle Corporation
     9 * Copyright (C) 2006-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929    , m_fIsValid(true)
    3030{
     31}
     32
     33QPixmap UIPageValidator::warningPixmap() const
     34{
     35    return m_pPage->warningPixmap();
     36}
     37
     38QString UIPageValidator::internalName() const
     39{
     40    return m_pPage->internalName();
     41}
     42
     43void UIPageValidator::setLastMessage(const QString &strLastMessage)
     44{
     45    /* Remember new message: */
     46    m_strLastMessage = strLastMessage;
     47
     48    /* Should we show corresponding warning icon? */
     49    if (m_strLastMessage.isEmpty())
     50        emit sigHideWarningIcon();
     51    else
     52        emit sigShowWarningIcon();
    3153}
    3254
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.h

    r47570 r47846  
    66
    77/*
    8  * Copyright (C) 2006-2012 Oracle Corporation
     8 * Copyright (C) 2006-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222/* Qt includes: */
    2323#include <QValidator>
     24#include <QPixmap>
    2425
    2526/* External includes: */
     
    4142    void sigValidityChanged(UIPageValidator *pValidator);
    4243
     44    /* Notifiers: Warning stuff: */
     45    void sigShowWarningIcon();
     46    void sigHideWarningIcon();
     47
    4348public:
    4449
     
    4853    /* API: Page stuff: */
    4954    UISettingsPage* page() const { return m_pPage; }
     55    QPixmap warningPixmap() const;
     56    QString internalName() const;
    5057
    5158    /* API: Validity stuff: */
     
    5562    /* API: Message stuff: */
    5663    QString lastMessage() const { return m_strLastMessage; }
    57     void setLastMessage(const QString &strLastMessage) { m_strLastMessage = strLastMessage; }
     64    void setLastMessage(const QString &strLastMessage);
    5865
    5966public slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r47806 r47846  
    115115    /* Prepare warning-pane: */
    116116    m_pWarningPane = new UIWarningPane;
    117     connect(m_pWarningPane, SIGNAL(sigHoverEnter()), this, SLOT(sltHandleWarningPaneHovered()));
    118     connect(m_pWarningPane, SIGNAL(sigHoverLeave()), this, SLOT(sltHandleWarningPaneUnhovered()));
     117    connect(m_pWarningPane, SIGNAL(sigHoverEnter(UIPageValidator*)), this, SLOT(sltHandleWarningPaneHovered(UIPageValidator*)));
     118    connect(m_pWarningPane, SIGNAL(sigHoverLeave(UIPageValidator*)), this, SLOT(sltHandleWarningPaneUnhovered(UIPageValidator*)));
    119119
    120120    /* Prepare status-bar: */
     
    229229    Ui::UISettingsDialog::retranslateUi(this);
    230230
    231     /* Translate error/warning stuff: */
    232     m_strErrorHint = tr("Invalid settings detected");
    233     m_strWarningHint = tr("Non-optimal settings detected");
    234     if (!m_fValid)
    235         m_pWarningPane->setWarningText(m_strErrorHint);
    236     else if (!m_fSilent)
    237         m_pWarningPane->setWarningText(m_strWarningHint);
     231    /* Translate warning stuff: */
     232    m_strWarningHint = tr("Invalid settings detected");
     233    if (!m_fValid || !m_fSilent)
     234        m_pWarningPane->setWarningLabel(m_strWarningHint);
    238235
    239236#ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     
    266263    return tr("Settings");
    267264#endif
    268 }
    269 
    270 void UISettingsDialog::setError(const QString &strError)
    271 {
    272     m_strErrorString = strError.isEmpty() ? QString() :
    273                        QString("<font color=red>%1</font>").arg(strError);
    274 }
    275 
    276 void UISettingsDialog::setWarning(const QString &strWarning)
    277 {
    278     m_strWarningString = strWarning.isEmpty() ? QString() :
    279                          QString("<font color=#ff5400>%1</font>").arg(strWarning);
    280265}
    281266
     
    302287    /* Assign validator if necessary: */
    303288    if (pSettingsPage)
     289    {
     290        pSettingsPage->setId(cId);
    304291        assignValidator(pSettingsPage);
     292    }
    305293}
    306294
     
    332320    m_fValid = true;
    333321    m_fSilent = true;
    334     setError(QString());
    335     setWarning(QString());
    336     m_pWarningPane->setWarningText(QString());
     322    m_pWarningPane->setWarningLabel(QString());
    337323
    338324    /* Enumerating all the validators we have: */
     
    350336            /* Show error first: */
    351337            if (!pValidator->isValid())
    352             {
    353338                m_fValid = false;
    354                 setError(pValidator->lastMessage());
    355                 m_pWarningPane->setWarningText(m_strErrorHint);
    356             }
    357339            /* Show warning if message is not an error: */
    358340            else
    359             {
    360341                m_fSilent = false;
    361                 setWarning(pValidator->lastMessage());
    362                 m_pWarningPane->setWarningText(m_strWarningHint);
    363             }
    364 
    365             /* Configure warning-pane pixmap: */
    366             m_pWarningPane->setWarningPixmap(pFailedSettingsPage->warningPixmap());
     342
     343            /* Configure warning-pane label: */
     344            m_pWarningPane->setWarningLabel(m_strWarningHint);
    367345
    368346            /* Stop dialog revalidation on first error/warning: */
     
    405383}
    406384
    407 void UISettingsDialog::sltHandleWarningPaneHovered()
    408 {
    409     LogRel(("Settings Dialog: Warning-pane hovered.\n"));
     385void UISettingsDialog::sltHandleWarningPaneHovered(UIPageValidator *pValidator)
     386{
     387    LogRel(("Settings Dialog: Warning-icon hovered: %s.\n", pValidator->internalName().toUtf8().constData()));
    410388
    411389    /* Show corresponding popup: */
     
    413391    {
    414392        popupCenter().popup(m_pStack, "SettingsDialogWarning",
    415                             !m_fValid ? m_strErrorString :
    416                             !m_fSilent ? m_strWarningString :
    417                             QString());
    418     }
    419 }
    420 
    421 void UISettingsDialog::sltHandleWarningPaneUnhovered()
    422 {
    423     LogRel(("Settings Dialog: Warning-pane unhovered.\n"));
     393                            pValidator->lastMessage());
     394    }
     395}
     396
     397void UISettingsDialog::sltHandleWarningPaneUnhovered(UIPageValidator *pValidator)
     398{
     399    LogRel(("Settings Dialog: Warning-icon unhovered: %s.\n", pValidator->internalName().toUtf8().constData()));
    424400
    425401    /* Recall corresponding popup: */
     
    568544    connect(pValidator, SIGNAL(sigValidityChanged(UIPageValidator*)), this, SLOT(sltHandleValidityChange(UIPageValidator*)));
    569545    pPage->setValidator(pValidator);
     546    m_pWarningPane->registerValidator(pValidator);
    570547
    571548    // TODO: Why here?
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r47806 r47846  
    8383    virtual QString titleExtension() const;
    8484
    85     /* Setters for error/warning: */
    86     void setError(const QString &strError);
    87     void setWarning(const QString &strWarning);
    88 
    8985    /* Add settings page: */
    9086    void addItem(const QString &strBigIcon, const QString &strBigIconDisabled,
     
    106102    /* Handlers: Validation stuff: */
    107103    void sltHandleValidityChange(UIPageValidator *pValidator);
    108     void sltHandleWarningPaneHovered();
    109     void sltHandleWarningPaneUnhovered();
     104    void sltHandleWarningPaneHovered(UIPageValidator *pValidator);
     105    void sltHandleWarningPaneUnhovered(UIPageValidator *pValidator);
    110106
    111107    /* Slot to update whats-this: */
     
    142138    bool m_fValid;
    143139    bool m_fSilent;
    144     QString m_strErrorHint;
    145140    QString m_strWarningHint;
    146     QString m_strErrorString;
    147     QString m_strWarningString;
    148141
    149142    /* Whats-This stuff: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r47594 r47846  
    413413            }
    414414            if (pSettingsPage)
    415             {
    416415                pSettingsPage->setDialogType(dialogType());
    417                 pSettingsPage->setId(iPageIndex);
    418             }
    419416        }
    420417    }
     
    683680            }
    684681            if (pSettingsPage)
    685             {
    686682                pSettingsPage->setDialogType(dialogType());
    687                 pSettingsPage->setId(iPageIndex);
    688             }
    689683        }
    690684    }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIWarningPane.cpp

    r47761 r47846  
    2525/* GUI includes: */
    2626#include "UIWarningPane.h"
     27#include "QIWidgetValidator.h"
     28
     29/* Other VBox includes: */
     30#include <VBox/sup.h>
    2731
    2832UIWarningPane::UIWarningPane(QWidget *pParent)
    2933    : QWidget(pParent)
    30     , m_pLabelIcon(0)
    31     , m_pLabelText(0)
    32     , m_fHovered(false)
     34    , m_pWarningLabel(0)
    3335{
    3436    /* Prepare: */
     
    3638}
    3739
    38 void UIWarningPane::setWarningPixmap(const QPixmap &pixmap)
     40void UIWarningPane::setWarningLabel(const QString &strWarningLabel)
    3941{
    40     m_pLabelIcon->setPixmap(pixmap);
     42    m_pWarningLabel->setText(strWarningLabel);
    4143}
    4244
    43 void UIWarningPane::setWarningText(const QString &strText)
     45void UIWarningPane::registerValidator(UIPageValidator *pValidator)
    4446{
    45     m_pLabelText->setText(strText);
     47    /* Make sure validator is set! */
     48    AssertPtrReturnVoid(pValidator);
     49
     50    /* Makre sure validator is not registered yet: */
     51    if (m_validators.contains(pValidator))
     52    {
     53        AssertMsgFailed(("Validator is registered already!\n"));
     54        return;
     55    }
     56
     57    /* Register validator: */
     58    m_validators << pValidator;
     59
     60    /* Create icon-label for newly registered validator: */
     61    QLabel *pIconLabel = new QLabel;
     62    {
     63        /* Add icon-label into list: */
     64        m_icons << pIconLabel;
     65        /* Add icon-label into layout: */
     66        m_pLayout->addWidget(pIconLabel);
     67        /* Configure icon-label: */
     68        pIconLabel->setMouseTracking(true);
     69        pIconLabel->installEventFilter(this);
     70        pIconLabel->setPixmap(pValidator->warningPixmap());
     71        connect(pValidator, SIGNAL(sigShowWarningIcon()), pIconLabel, SLOT(show()));
     72        connect(pValidator, SIGNAL(sigHideWarningIcon()), pIconLabel, SLOT(hide()));
     73    }
     74
     75    /* Mark icon as 'non-hovered': */
     76    m_hovered << false;
    4677}
    4778
     
    5485void UIWarningPane::prepareContent()
    5586{
    56     /* Configure self: */
    57     setMouseTracking(true);
    58     installEventFilter(this);
    59     /* Create layout: */
    60     QHBoxLayout *pLayout = new QHBoxLayout(this);
     87    /* Create main-layout: */
     88    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
    6189    {
    6290        /* Configure layout: */
    63         pLayout->setContentsMargins(0, 0, 0, 0);
    64         /* Create icon label: */
    65         m_pLabelIcon = new QLabel;
     91        pMainLayout->setContentsMargins(0, 0, 0, 0);
     92        /* Add left stretch: */
     93        pMainLayout->addStretch();
     94        /* Create warning-label: */
     95        m_pWarningLabel = new QLabel;
    6696        {
    67             /* Configure icon label: */
    68             m_pLabelIcon->setMouseTracking(true);
    69             m_pLabelIcon->installEventFilter(this);
     97            /* Add into main-layout: */
     98            pMainLayout->addWidget(m_pWarningLabel);
    7099        }
    71         /* Create text label: */
    72         m_pLabelText = new QLabel;
     100        /* Create layout: */
     101        m_pLayout = new QHBoxLayout;
    73102        {
    74             /* Configure text label: */
    75             m_pLabelText->setMouseTracking(true);
    76             m_pLabelText->installEventFilter(this);
     103            /* Configure layout: */
     104            m_pLayout->setContentsMargins(0, 0, 0, 0);
     105            /* Add into main-layout: */
     106            pMainLayout->addLayout(m_pLayout);
    77107        }
    78         /* Add widgets into layout: */
    79         pLayout->addWidget(m_pLabelIcon);
    80         pLayout->addWidget(m_pLabelText);
     108        /* Add right stretch: */
     109        pMainLayout->addStretch();
    81110    }
    82111}
     
    87116    switch (pEvent->type())
    88117    {
    89         /* Anything is hovered: */
     118        /* One of icons hovered: */
    90119        case QEvent::MouseMove:
    91120        {
    92             /* Hover warning-pane if not yet hovered: */
    93             if (!m_fHovered)
     121            /* Cast object to label: */
     122            if (QLabel *pIconLabel = qobject_cast<QLabel*>(pWatched))
    94123            {
    95                 m_fHovered = true;
    96                 emit sigHoverEnter();
     124                /* Search for the corresponding icon: */
     125                if (m_icons.contains(pIconLabel))
     126                {
     127                    /* Mark icon-label hovered if not yet: */
     128                    int iIconLabelPosition = m_icons.indexOf(pIconLabel);
     129                    if (!m_hovered[iIconLabelPosition])
     130                    {
     131                        m_hovered[iIconLabelPosition] = true;
     132                        emit sigHoverEnter(m_validators[iIconLabelPosition]);
     133                    }
     134                }
    97135            }
    98136            break;
    99137        }
    100         /* Warning-pane is unhovered: */
     138        /* One of icons unhovered: */
    101139        case QEvent::Leave:
    102140        {
    103             /* Unhover warning-pane if hovered: */
    104             if (pWatched == this && m_fHovered)
     141            /* Cast object to label: */
     142            if (QLabel *pIconLabel = qobject_cast<QLabel*>(pWatched))
    105143            {
    106                 m_fHovered = false;
    107                 emit sigHoverLeave();
     144                /* Search for the corresponding icon: */
     145                if (m_icons.contains(pIconLabel))
     146                {
     147                    /* Mark icon-label unhovered if not yet: */
     148                    int iIconLabelPosition = m_icons.indexOf(pIconLabel);
     149                    if (m_hovered[iIconLabelPosition])
     150                    {
     151                        m_hovered[iIconLabelPosition] = false;
     152                        emit sigHoverLeave(m_validators[iIconLabelPosition]);
     153                    }
     154                }
    108155            }
    109156            break;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIWarningPane.h

    r47761 r47846  
    2424
    2525/* Forward declarations: */
     26class UIPageValidator;
     27class QHBoxLayout;
    2628class QLabel;
    2729
     
    3436
    3537    /* Notifiers: Hover stuff: */
    36     void sigHoverEnter();
    37     void sigHoverLeave();
     38    void sigHoverEnter(UIPageValidator *pValidator);
     39    void sigHoverLeave(UIPageValidator *pValidator);
    3840
    3941public:
     
    4345
    4446    /* API: Warning stuff: */
    45     void setWarningPixmap(const QPixmap &pixmap);
    46     void setWarningText(const QString &strText);
     47    void setWarningLabel(const QString &strWarningLabel);
     48
     49    /* API: Registry stuff: */
     50    void registerValidator(UIPageValidator *pValidator);
    4751
    4852private:
     
    5559    bool eventFilter(QObject *pWatched, QEvent *pEvent);
    5660
    57     /* Variables: Widgets: */
    58     QLabel *m_pLabelIcon;
    59     QLabel *m_pLabelText;
    60 
    61     /* Variable: Hover stuff: */
    62     bool m_fHovered;
     61    /* Variables: */
     62    QHBoxLayout *m_pLayout;
     63    QLabel *m_pWarningLabel;
     64    QList<UIPageValidator*> m_validators;
     65    QList<QLabel*> m_icons;
     66    QList<bool> m_hovered;
    6367};
    6468
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette