Changeset 47846 in vbox
- Timestamp:
- Aug 19, 2013 3:27:57 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 88139
- 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 7 7 8 8 /* 9 * Copyright (C) 2006-201 2Oracle Corporation9 * Copyright (C) 2006-2013 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 , m_fIsValid(true) 30 30 { 31 } 32 33 QPixmap UIPageValidator::warningPixmap() const 34 { 35 return m_pPage->warningPixmap(); 36 } 37 38 QString UIPageValidator::internalName() const 39 { 40 return m_pPage->internalName(); 41 } 42 43 void 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(); 31 53 } 32 54 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.h
r47570 r47846 6 6 7 7 /* 8 * Copyright (C) 2006-201 2Oracle Corporation8 * Copyright (C) 2006-2013 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 22 /* Qt includes: */ 23 23 #include <QValidator> 24 #include <QPixmap> 24 25 25 26 /* External includes: */ … … 41 42 void sigValidityChanged(UIPageValidator *pValidator); 42 43 44 /* Notifiers: Warning stuff: */ 45 void sigShowWarningIcon(); 46 void sigHideWarningIcon(); 47 43 48 public: 44 49 … … 48 53 /* API: Page stuff: */ 49 54 UISettingsPage* page() const { return m_pPage; } 55 QPixmap warningPixmap() const; 56 QString internalName() const; 50 57 51 58 /* API: Validity stuff: */ … … 55 62 /* API: Message stuff: */ 56 63 QString lastMessage() const { return m_strLastMessage; } 57 void setLastMessage(const QString &strLastMessage) { m_strLastMessage = strLastMessage; }64 void setLastMessage(const QString &strLastMessage); 58 65 59 66 public slots: -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp
r47806 r47846 115 115 /* Prepare warning-pane: */ 116 116 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*))); 119 119 120 120 /* Prepare status-bar: */ … … 229 229 Ui::UISettingsDialog::retranslateUi(this); 230 230 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); 238 235 239 236 #ifndef VBOX_GUI_WITH_TOOLBAR_SETTINGS … … 266 263 return tr("Settings"); 267 264 #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);280 265 } 281 266 … … 302 287 /* Assign validator if necessary: */ 303 288 if (pSettingsPage) 289 { 290 pSettingsPage->setId(cId); 304 291 assignValidator(pSettingsPage); 292 } 305 293 } 306 294 … … 332 320 m_fValid = true; 333 321 m_fSilent = true; 334 setError(QString()); 335 setWarning(QString()); 336 m_pWarningPane->setWarningText(QString()); 322 m_pWarningPane->setWarningLabel(QString()); 337 323 338 324 /* Enumerating all the validators we have: */ … … 350 336 /* Show error first: */ 351 337 if (!pValidator->isValid()) 352 {353 338 m_fValid = false; 354 setError(pValidator->lastMessage());355 m_pWarningPane->setWarningText(m_strErrorHint);356 }357 339 /* Show warning if message is not an error: */ 358 340 else 359 {360 341 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); 367 345 368 346 /* Stop dialog revalidation on first error/warning: */ … … 405 383 } 406 384 407 void UISettingsDialog::sltHandleWarningPaneHovered( )408 { 409 LogRel(("Settings Dialog: Warning- pane hovered.\n"));385 void UISettingsDialog::sltHandleWarningPaneHovered(UIPageValidator *pValidator) 386 { 387 LogRel(("Settings Dialog: Warning-icon hovered: %s.\n", pValidator->internalName().toUtf8().constData())); 410 388 411 389 /* Show corresponding popup: */ … … 413 391 { 414 392 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 397 void UISettingsDialog::sltHandleWarningPaneUnhovered(UIPageValidator *pValidator) 398 { 399 LogRel(("Settings Dialog: Warning-icon unhovered: %s.\n", pValidator->internalName().toUtf8().constData())); 424 400 425 401 /* Recall corresponding popup: */ … … 568 544 connect(pValidator, SIGNAL(sigValidityChanged(UIPageValidator*)), this, SLOT(sltHandleValidityChange(UIPageValidator*))); 569 545 pPage->setValidator(pValidator); 546 m_pWarningPane->registerValidator(pValidator); 570 547 571 548 // TODO: Why here? -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h
r47806 r47846 83 83 virtual QString titleExtension() const; 84 84 85 /* Setters for error/warning: */86 void setError(const QString &strError);87 void setWarning(const QString &strWarning);88 89 85 /* Add settings page: */ 90 86 void addItem(const QString &strBigIcon, const QString &strBigIconDisabled, … … 106 102 /* Handlers: Validation stuff: */ 107 103 void sltHandleValidityChange(UIPageValidator *pValidator); 108 void sltHandleWarningPaneHovered( );109 void sltHandleWarningPaneUnhovered( );104 void sltHandleWarningPaneHovered(UIPageValidator *pValidator); 105 void sltHandleWarningPaneUnhovered(UIPageValidator *pValidator); 110 106 111 107 /* Slot to update whats-this: */ … … 142 138 bool m_fValid; 143 139 bool m_fSilent; 144 QString m_strErrorHint;145 140 QString m_strWarningHint; 146 QString m_strErrorString;147 QString m_strWarningString;148 141 149 142 /* Whats-This stuff: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
r47594 r47846 413 413 } 414 414 if (pSettingsPage) 415 {416 415 pSettingsPage->setDialogType(dialogType()); 417 pSettingsPage->setId(iPageIndex);418 }419 416 } 420 417 } … … 683 680 } 684 681 if (pSettingsPage) 685 {686 682 pSettingsPage->setDialogType(dialogType()); 687 pSettingsPage->setId(iPageIndex);688 }689 683 } 690 684 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIWarningPane.cpp
r47761 r47846 25 25 /* GUI includes: */ 26 26 #include "UIWarningPane.h" 27 #include "QIWidgetValidator.h" 28 29 /* Other VBox includes: */ 30 #include <VBox/sup.h> 27 31 28 32 UIWarningPane::UIWarningPane(QWidget *pParent) 29 33 : QWidget(pParent) 30 , m_pLabelIcon(0) 31 , m_pLabelText(0) 32 , m_fHovered(false) 34 , m_pWarningLabel(0) 33 35 { 34 36 /* Prepare: */ … … 36 38 } 37 39 38 void UIWarningPane::setWarning Pixmap(const QPixmap &pixmap)40 void UIWarningPane::setWarningLabel(const QString &strWarningLabel) 39 41 { 40 m_p LabelIcon->setPixmap(pixmap);42 m_pWarningLabel->setText(strWarningLabel); 41 43 } 42 44 43 void UIWarningPane:: setWarningText(const QString &strText)45 void UIWarningPane::registerValidator(UIPageValidator *pValidator) 44 46 { 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; 46 77 } 47 78 … … 54 85 void UIWarningPane::prepareContent() 55 86 { 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); 61 89 { 62 90 /* 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; 66 96 { 67 /* Configure icon label: */ 68 m_pLabelIcon->setMouseTracking(true); 69 m_pLabelIcon->installEventFilter(this); 97 /* Add into main-layout: */ 98 pMainLayout->addWidget(m_pWarningLabel); 70 99 } 71 /* Create text label: */72 m_pLa belText = new QLabel;100 /* Create layout: */ 101 m_pLayout = new QHBoxLayout; 73 102 { 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); 77 107 } 78 /* Add widgets into layout: */ 79 pLayout->addWidget(m_pLabelIcon); 80 pLayout->addWidget(m_pLabelText); 108 /* Add right stretch: */ 109 pMainLayout->addStretch(); 81 110 } 82 111 } … … 87 116 switch (pEvent->type()) 88 117 { 89 /* Anything is hovered: */118 /* One of icons hovered: */ 90 119 case QEvent::MouseMove: 91 120 { 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)) 94 123 { 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 } 97 135 } 98 136 break; 99 137 } 100 /* Warning-pane is unhovered: */138 /* One of icons unhovered: */ 101 139 case QEvent::Leave: 102 140 { 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)) 105 143 { 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 } 108 155 } 109 156 break; -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIWarningPane.h
r47761 r47846 24 24 25 25 /* Forward declarations: */ 26 class UIPageValidator; 27 class QHBoxLayout; 26 28 class QLabel; 27 29 … … 34 36 35 37 /* Notifiers: Hover stuff: */ 36 void sigHoverEnter( );37 void sigHoverLeave( );38 void sigHoverEnter(UIPageValidator *pValidator); 39 void sigHoverLeave(UIPageValidator *pValidator); 38 40 39 41 public: … … 43 45 44 46 /* 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); 47 51 48 52 private: … … 55 59 bool eventFilter(QObject *pWatched, QEvent *pEvent); 56 60 57 /* Variables: Widgets:*/58 Q Label *m_pLabelIcon;59 QLabel *m_p LabelText;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; 63 67 }; 64 68
Note:
See TracChangeset
for help on using the changeset viewer.