Changeset 90290 in vbox for trunk/src/VBox
- Timestamp:
- Jul 22, 2021 2:40:08 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r90288 r90290 846 846 src/notificationcenter/UINotificationObject.h \ 847 847 src/notificationcenter/UINotificationObjectItem.h \ 848 src/notificationcenter/UINotificationProgressTask.h \ 848 849 src/settings/UISettingsDialog.h \ 849 850 src/settings/UISettingsDialogSpecific.h \ … … 1395 1396 src/notificationcenter/UINotificationObject.cpp \ 1396 1397 src/notificationcenter/UINotificationObjectItem.cpp \ 1398 src/notificationcenter/UINotificationProgressTask.cpp \ 1397 1399 src/objects/UIRichTextString.cpp \ 1398 1400 src/settings/UISettingsDefs.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.cpp
r90288 r90290 18 18 /* GUI includes: */ 19 19 #include "UINotificationObject.h" 20 #include "UINotificationProgressTask.h" 20 21 22 23 /********************************************************************************************************************************* 24 * Class UINotificationObject implementation. * 25 *********************************************************************************************************************************/ 21 26 22 27 UINotificationObject::UINotificationObject() … … 28 33 emit sigAboutToClose(); 29 34 } 35 36 37 /********************************************************************************************************************************* 38 * Class UINotificationProgress implementation. * 39 *********************************************************************************************************************************/ 40 41 UINotificationProgress::UINotificationProgress() 42 : m_pTask(0) 43 , m_uPercent(0) 44 { 45 } 46 47 UINotificationProgress::~UINotificationProgress() 48 { 49 delete m_pTask; 50 m_pTask = 0; 51 } 52 53 ulong UINotificationProgress::percent() const 54 { 55 return m_uPercent; 56 } 57 58 bool UINotificationProgress::isCancelable() const 59 { 60 return m_pTask->isCancelable(); 61 } 62 63 QString UINotificationProgress::error() const 64 { 65 return m_pTask->errorMessage(); 66 } 67 68 void UINotificationProgress::handle() 69 { 70 /* Prepare task: */ 71 m_pTask = new UINotificationProgressTask(this); 72 if (m_pTask) 73 { 74 connect(m_pTask, &UIProgressTask::sigProgressStarted, 75 this, &UINotificationProgress::sigProgressStarted); 76 connect(m_pTask, &UIProgressTask::sigProgressChange, 77 this, &UINotificationProgress::sltHandleProgressChange); 78 connect(m_pTask, &UIProgressTask::sigProgressFinished, 79 this, &UINotificationProgress::sltHandleProgressFinished); 80 } 81 82 /* And start it finally: */ 83 m_pTask->start(); 84 } 85 86 void UINotificationProgress::close() 87 { 88 /* Cancel task: */ 89 m_pTask->cancel(); 90 /* Call to base-class: */ 91 UINotificationObject::close(); 92 } 93 94 void UINotificationProgress::sltHandleProgressChange(ulong uPercent) 95 { 96 m_uPercent = uPercent; 97 emit sigProgressChange(uPercent); 98 } 99 100 void UINotificationProgress::sltHandleProgressFinished() 101 { 102 m_uPercent = 100; 103 emit sigProgressFinished(); 104 } -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.h
r90288 r90290 28 28 #include "UILibraryDefs.h" 29 29 30 /* COM includes: */ 31 #include "CProgress.h" 32 33 /* Forward declarations: */ 34 class UINotificationProgressTask; 35 30 36 /** QObject-based notification-object. */ 31 37 class SHARED_LIBRARY_STUFF UINotificationObject : public QObject … … 56 62 }; 57 63 64 /** UINotificationObject extension for notification-progress. */ 65 class SHARED_LIBRARY_STUFF UINotificationProgress : public UINotificationObject 66 { 67 Q_OBJECT; 68 69 signals: 70 71 /** Notifies listeners about progress started. */ 72 void sigProgressStarted(); 73 /** Notifies listeners about progress changed. 74 * @param uPercent Brings new progress percentage value. */ 75 void sigProgressChange(ulong uPercent); 76 /** Notifies listeners about progress finished. */ 77 void sigProgressFinished(); 78 79 public: 80 81 /** Constructs notification-progress. */ 82 UINotificationProgress(); 83 /** Destructs notification-progress. */ 84 virtual ~UINotificationProgress() /* override final */; 85 86 /** Creates and returns started progress-wrapper. */ 87 virtual CProgress createProgress(COMResult &comResult) = 0; 88 89 /** Returns current progress percentage value. */ 90 ulong percent() const; 91 /** Returns whether progress is cancelable. */ 92 bool isCancelable() const; 93 /** Returns error-message if any. */ 94 QString error() const; 95 96 /** Handles notification-object being added. */ 97 virtual void handle() /* override final */; 98 99 public slots: 100 101 /** Stops the progress and notifies model about closing. */ 102 virtual void close() /* override final */; 103 104 private slots: 105 106 /** Handles signal about progress changed. 107 * @param uPercent Brings new progress percentage value. */ 108 void sltHandleProgressChange(ulong uPercent); 109 /** Handles signal about progress finished. */ 110 void sltHandleProgressFinished(); 111 112 private: 113 114 /** Holds the instance of progress-task being wrapped by this notification-progress. */ 115 UINotificationProgressTask *m_pTask; 116 117 /** Holds the last cached progress percentage value. */ 118 ulong m_uPercent; 119 }; 120 58 121 #endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationObject_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.cpp
r90288 r90290 23 23 #include <QPainter> 24 24 #include <QPaintEvent> 25 #include <QProgressBar> 25 26 #include <QVBoxLayout> 26 27 … … 161 162 162 163 /********************************************************************************************************************************* 163 * Namespace UINotificationItem implementation.*164 * Class UINotificationProgressItem implementation. * 164 165 *********************************************************************************************************************************/ 165 166 167 UINotificationProgressItem::UINotificationProgressItem(QWidget *pParent, UINotificationProgress *pProgress /* = 0 */) 168 : UINotificationObjectItem(pParent, pProgress) 169 , m_pProgressBar(0) 170 { 171 /* Main layout was prepared in base-class: */ 172 if (m_pLayoutMain) 173 { 174 /* Name label was prepared in base-class: */ 175 if (m_pLabelName) 176 m_pLabelName->setText(progress()->name()); 177 /* Details label was prepared in base-class: */ 178 if (m_pLabelDetails) 179 { 180 m_pLabelDetails->setText(progress()->details()); 181 int iHint = m_pLabelName->minimumSizeHint().width() 182 + m_pLayoutUpper->spacing() 183 + m_pButtonClose->minimumSizeHint().width(); 184 m_pLabelDetails->setMinimumTextWidth(iHint); 185 } 186 187 /* Prepare progress-bar: */ 188 m_pProgressBar = new QProgressBar(this); 189 if (m_pProgressBar) 190 { 191 m_pProgressBar->setMinimum(0); 192 m_pProgressBar->setMaximum(100); 193 m_pProgressBar->setValue(progress()->percent()); 194 195 m_pLayoutMain->addWidget(m_pProgressBar); 196 } 197 } 198 199 /* Prepare progress connections: */ 200 connect(progress(), &UINotificationProgress::sigProgressStarted, 201 this, &UINotificationProgressItem::sltHandleProgressStarted); 202 connect(progress(), &UINotificationProgress::sigProgressChange, 203 this, &UINotificationProgressItem::sltHandleProgressChange); 204 connect(progress(), &UINotificationProgress::sigProgressFinished, 205 this, &UINotificationProgressItem::sltHandleProgressFinished); 206 } 207 208 void UINotificationProgressItem::sltHandleProgressStarted() 209 { 210 /* Init close-button and progress-bar states: */ 211 if (m_pButtonClose) 212 m_pButtonClose->setEnabled(progress()->isCancelable()); 213 if (m_pProgressBar) 214 m_pProgressBar->setValue(0); 215 } 216 217 void UINotificationProgressItem::sltHandleProgressChange(ulong uPercent) 218 { 219 /* Update close-button and progress-bar states: */ 220 if (m_pButtonClose) 221 m_pButtonClose->setEnabled(progress()->isCancelable()); 222 if (m_pProgressBar) 223 m_pProgressBar->setValue(uPercent); 224 } 225 226 void UINotificationProgressItem::sltHandleProgressFinished() 227 { 228 /* Finalize close-button and progress-bar states: */ 229 if (m_pButtonClose) 230 m_pButtonClose->setEnabled(true); 231 if (m_pProgressBar) 232 m_pProgressBar->setValue(100); 233 /* Update details with error text if any: */ 234 if (m_pLabelDetails) 235 { 236 const QString strDetails = progress()->details(); 237 const QString strError = progress()->error(); 238 const QString strFullDetails = strError.isNull() 239 ? strDetails 240 : QString("%1<br>%2").arg(strDetails, strError); 241 m_pLabelDetails->setText(strFullDetails); 242 } 243 } 244 245 UINotificationProgress *UINotificationProgressItem::progress() const 246 { 247 return qobject_cast<UINotificationProgress*>(m_pObject); 248 } 249 250 251 /********************************************************************************************************************************* 252 * Namespace UINotificationProgressItem implementation. * 253 *********************************************************************************************************************************/ 254 166 255 UINotificationObjectItem *UINotificationItem::create(QWidget *pParent, UINotificationObject *pObject) 167 256 { 257 /* Handle known types: */ 258 if (pObject->inherits("UINotificationProgress")) 259 return new UINotificationProgressItem(pParent, static_cast<UINotificationProgress*>(pObject)); 168 260 /* Handle defaults: */ 169 261 return new UINotificationObjectItem(pParent, pObject); -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.h
r90288 r90290 28 28 class QHBoxLayout; 29 29 class QLabel; 30 class QProgressBar; 30 31 class QVBoxLayout; 31 32 class QIRichTextLabel; 32 33 class QIToolButton; 33 34 class UINotificationObject; 35 class UINotificationProgress; 34 36 35 37 /** QWidget-based notification-object item. */ … … 72 74 }; 73 75 76 /** UINotificationObjectItem extension for notification-progress. */ 77 class UINotificationProgressItem : public UINotificationObjectItem 78 { 79 Q_OBJECT; 80 81 public: 82 83 /** Constructs notification-progress item, passing @a pParent to the base-class. 84 * @param pProgress Brings the notification-progress this item created for. */ 85 UINotificationProgressItem(QWidget *pParent, UINotificationProgress *pProgress = 0); 86 87 protected: 88 89 /** Holds the progress-bar instance. */ 90 QProgressBar *m_pProgressBar; 91 92 private slots: 93 94 /** Handles signal about progress started. */ 95 void sltHandleProgressStarted(); 96 /** Handles signal about progress changed. 97 * @param uPercent Brings new progress percentage value. */ 98 void sltHandleProgressChange(ulong uPercent); 99 /** Handles signal about progress finished. */ 100 void sltHandleProgressFinished(); 101 102 private: 103 104 /** Holds the notification-progress this item created for. */ 105 UINotificationProgress *progress() const; 106 }; 107 74 108 /** Notification-object factory. */ 75 109 namespace UINotificationItem
Note:
See TracChangeset
for help on using the changeset viewer.