Changeset 45468 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Apr 10, 2013 5:02:11 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/globals
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp
r45452 r45468 20 20 /* Qt includes: */ 21 21 #include <QVBoxLayout> 22 #include <QLabel> 22 #include <QPushButton> 23 #include <QEvent> 23 24 24 25 /* GUI includes: */ 25 26 #include "UIPopupCenter.h" 26 #include "QIMessageBox.h"27 27 #include "UIModalWindowManager.h" 28 #include "QIRichTextLabel.h" 29 #include "QIDialogButtonBox.h" 30 31 /* Other VBox includes: */ 32 #include <VBox/sup.h> 28 33 29 34 /* static */ … … 149 154 } 150 155 151 void UIPopupCenter::showPopupBox(QWidget *, 152 const QString &, const QString &, 153 int , int , int , 154 const QString &, const QString &, const QString &, 155 const QString &) const 156 { 157 } 158 156 void UIPopupCenter::showPopupBox(QWidget *pParent, 157 const QString &strMessage, const QString &strDetails, 158 int iButton1, int iButton2, int iButton3, 159 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3, 160 const QString &strAutoConfirmId) const 161 { 162 /* Choose at least one button by 'default': */ 163 if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0) 164 iButton1 = AlertButton_Ok | AlertButtonOption_Default; 165 166 /* Create popup-box window: */ 167 QWidget *pPopupBoxParent = windowManager().realParentWindow(pParent ? pParent : windowManager().mainWindowShown()); 168 UIPopupPane *pPopupBox = new UIPopupPane(pPopupBoxParent, strAutoConfirmId, 169 strMessage, strDetails, 170 iButton1, iButton2, iButton3, 171 strButtonText1, strButtonText2, strButtonText3); 172 m_popups.insert(strAutoConfirmId, pPopupBox); 173 connect(pPopupBox, SIGNAL(sigDone(int)), this, SLOT(sltPopupDone(int))); 174 pPopupBox->show(); 175 } 176 177 void UIPopupCenter::sltPopupDone(int iButtonCode) const 178 { 179 /* Make sure the sender is popup: */ 180 UIPopupPane *pPopup = qobject_cast<UIPopupPane*>(sender()); 181 if (!pPopup) 182 return; 183 184 /* Get the popup ID: */ 185 const QString strPopupID(pPopup->id()); 186 187 /* Make sure the popup still here: */ 188 const bool fIsPopupStillHere = m_popups.contains(strPopupID); 189 AssertMsg(fIsPopupStillHere, ("Popup already destroyed!")); 190 if (!fIsPopupStillHere) 191 return; 192 193 /* Notify listeners: */ 194 emit sigPopupDone(strPopupID, iButtonCode); 195 196 /* Cleanup the popup: */ 197 m_popups.remove(strPopupID); 198 delete pPopup; 199 } 200 201 UIPopupPane::UIPopupPane(QWidget *pParent, const QString &strId, 202 const QString &strMessage, const QString &strDetails, 203 int iButton1, int iButton2, int iButton3, 204 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3) 205 : QWidget(pParent, Qt::Window | Qt::FramelessWindowHint) 206 , m_fPolished(false) 207 , m_strId(strId) 208 , m_strMessage(strMessage) 209 , m_strDetails(strDetails) 210 , m_iButton1(iButton1) 211 , m_iButton2(iButton2) 212 , m_iButton3(iButton3) 213 , m_strButtonText1(strButtonText1) 214 , m_strButtonText2(strButtonText2) 215 , m_strButtonText3(strButtonText3) 216 { 217 /* Make sure popup will NOT be deleted on close: */ 218 setAttribute(Qt::WA_DeleteOnClose, false); 219 /* Install event-filter: */ 220 pParent->installEventFilter(this); 221 /* Configure window: */ 222 setWindowOpacity(0.7); 223 224 /* Prepare content: */ 225 prepareContent(); 226 } 227 228 UIPopupPane::~UIPopupPane() 229 { 230 } 231 232 bool UIPopupPane::eventFilter(QObject *pWatched, QEvent *pEvent) 233 { 234 /* Make sure its parent event came: */ 235 if (pWatched != parent()) 236 return false; 237 238 /* Make sure its move|rezize event came: */ 239 if ( pEvent->type() != QEvent::Move 240 && pEvent->type() != QEvent::Resize) 241 return false; 242 243 /* Process event: */ 244 switch (pEvent->type()) 245 { 246 /* Move event: */ 247 case QEvent::Move: 248 { 249 moveAccordingParent(); 250 break; 251 } 252 /* Resize event: */ 253 case QEvent::Resize: 254 { 255 resizeAccordingParent(); 256 break; 257 } 258 /* Default case: */ 259 default: break; 260 } 261 262 /* Do not filter by default: */ 263 return false; 264 } 265 266 void UIPopupPane::showEvent(QShowEvent *pEvent) 267 { 268 /* Make sure we should polish dialog: */ 269 if (m_fPolished) 270 return; 271 272 /* Call to polish-event: */ 273 polishEvent(pEvent); 274 275 /* Mark dialog as polished: */ 276 m_fPolished = true; 277 } 278 279 void UIPopupPane::polishEvent(QShowEvent*) 280 { 281 /* Tune geometry: */ 282 moveAccordingParent(); 283 resizeAccordingParent(); 284 } 285 286 void UIPopupPane::moveAccordingParent() 287 { 288 /* Move according parent: */ 289 QRect geo = parentWidget()->geometry(); 290 move(geo.x(), geo.y()); 291 } 292 293 void UIPopupPane::resizeAccordingParent() 294 { 295 /* Resize according parent: */ 296 int iWidth = parentWidget()->width(); 297 resize(iWidth, minimumSizeHint().height()); 298 299 /* Resize text-pane according new size: */ 300 int iMinimumTextWidth = iWidth; 301 int iLeft, iTop, iRight, iBottom; 302 m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom); 303 iMinimumTextWidth -= iLeft; 304 iMinimumTextWidth -= iRight; 305 m_pTextPane->setMinimumTextWidth(iMinimumTextWidth); 306 } 307 308 void UIPopupPane::prepareContent() 309 { 310 /* Crete main-layout: */ 311 m_pMainLayout = new QVBoxLayout(this); 312 { 313 /* Configure layout: */ 314 #ifdef Q_WS_MAC 315 m_pMainLayout->setContentsMargins(20, 5, 20, 5); 316 m_pMainLayout->setSpacing(0); 317 #else /* Q_WS_MAC */ 318 m_pMainLayout->setContentsMargins(5, 5, 5, 5); 319 m_pMainLayout->setSpacing(5); 320 #endif /* !Q_WS_MAC */ 321 /* Create message-label: */ 322 m_pTextPane = new QIRichTextLabel; 323 { 324 /* Add into layout: */ 325 m_pMainLayout->addWidget(m_pTextPane); 326 /* Configure label: */ 327 m_pTextPane->setText(m_strMessage); 328 m_pTextPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); 329 } 330 /* Create button-box: */ 331 m_pButtonBox = new QIDialogButtonBox; 332 { 333 /* Add into layout: */ 334 m_pMainLayout->addWidget(m_pButtonBox); 335 /* Configure button-box: */ 336 m_pButton1 = createButton(m_iButton1); 337 if (m_pButton1) 338 { 339 if (!m_strButtonText1.isEmpty()) 340 m_pButton1->setText(m_strButtonText1); 341 connect(m_pButton1, SIGNAL(clicked()), SLOT(done1())); 342 } 343 m_pButton2 = createButton(m_iButton2); 344 if (m_pButton2) 345 { 346 if (!m_strButtonText2.isEmpty()) 347 m_pButton1->setText(m_strButtonText2); 348 connect(m_pButton2, SIGNAL(clicked()), SLOT(done2())); 349 } 350 m_pButton3 = createButton(m_iButton3); 351 if (m_pButton3) 352 { 353 if (!m_strButtonText3.isEmpty()) 354 m_pButton1->setText(m_strButtonText3); 355 connect(m_pButton3, SIGNAL(clicked()), SLOT(done3())); 356 } 357 } 358 } 359 } 360 361 QPushButton* UIPopupPane::createButton(int iButton) 362 { 363 /* Not for AlertButton_NoButton: */ 364 if (iButton == 0) 365 return 0; 366 367 /* Prepare button text & role: */ 368 QString strText; 369 QDialogButtonBox::ButtonRole role; 370 switch (iButton & AlertButtonMask) 371 { 372 case AlertButton_Ok: strText = tr("OK"); role = QDialogButtonBox::AcceptRole; break; 373 case AlertButton_Cancel: strText = tr("Cancel"); role = QDialogButtonBox::RejectRole; break; 374 case AlertButton_Choice1: strText = tr("Yes"); role = QDialogButtonBox::YesRole; break; 375 case AlertButton_Choice2: strText = tr("No"); role = QDialogButtonBox::NoRole; break; 376 case AlertButton_Copy: strText = tr("Copy"); role = QDialogButtonBox::ActionRole; break; 377 default: return 0; 378 } 379 380 /* Create push-button: */ 381 QPushButton *pButton = m_pButtonBox->addButton(strText, role); 382 383 /* Configure <default> button: */ 384 if (iButton & AlertButtonOption_Default) 385 { 386 pButton->setDefault(true); 387 pButton->setFocus(); 388 } 389 390 /* Return button: */ 391 return pButton; 392 } 393 394 void UIPopupPane::done(int iButtonCode) 395 { 396 /* Close the window: */ 397 close(); 398 399 /* Notify listeners: */ 400 emit sigDone(iButtonCode); 401 } 402 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h
r45452 r45468 23 23 #include <QMap> 24 24 #include <QObject> 25 #include <QWidget> 25 26 #include <QPointer> 27 28 /* GUI includes: */ 29 #include "QIMessageBox.h" 30 31 /* Forward declaration: */ 32 class UIPopupPane; 33 class QVBoxLayout; 34 class QPushButton; 35 class QIRichTextLabel; 36 class QIDialogButtonBox; 26 37 27 38 /* Global popup-center object: */ … … 29 40 { 30 41 Q_OBJECT; 42 43 signals: 44 45 /* Notifier: Popup complete stuff: */ 46 void sigPopupDone(QString strId, int iButtonCode) const; 31 47 32 48 public: … … 84 100 const QString &strCancelButtonText = QString()) const; 85 101 102 private slots: 103 104 /* Handler: Popup done stuff: */ 105 void sltPopupDone(int iButtonCode) const; 106 86 107 private: 87 108 … … 98 119 99 120 /* Variables: */ 100 mutable QMap<QString, QPointer< QWidget> > m_popups;121 mutable QMap<QString, QPointer<UIPopupPane> > m_popups; 101 122 102 123 /* Instance stuff: */ … … 109 130 inline UIPopupCenter& popupCenter() { return *UIPopupCenter::instance(); } 110 131 132 /* Popup-pane prototype class: */ 133 class UIPopupPane : public QWidget 134 { 135 Q_OBJECT; 136 137 signals: 138 139 /* Notifier: Complete stuff: */ 140 void sigDone(int iButtonCode) const; 141 142 public: 143 144 /* Constructor/destructor: */ 145 UIPopupPane(QWidget *pParent, const QString &strId, 146 const QString &strMessage, const QString &strDetails, 147 int iButton1, int iButton2, int iButton3, 148 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3); 149 ~UIPopupPane(); 150 151 /* API: Id stuff: */ 152 const QString& id() const { return m_strId; } 153 154 private slots: 155 156 /* Handlers: Done slot variants for every button: */ 157 void done1() { done(m_iButton1 & AlertButtonMask); } 158 void done2() { done(m_iButton2 & AlertButtonMask); } 159 void done3() { done(m_iButton3 & AlertButtonMask); } 160 161 private: 162 163 /* Handler: Event-filter stuff: */ 164 bool eventFilter(QObject *pWatched, QEvent *pEvent); 165 166 /* Handlers: Event stuff: */ 167 virtual void showEvent(QShowEvent *pEvent); 168 virtual void polishEvent(QShowEvent *pEvent); 169 170 /* Helpers: Move/resize stuff: */ 171 void moveAccordingParent(); 172 void resizeAccordingParent(); 173 174 /* Helpers: Prepare stuff: */ 175 void prepareContent(); 176 QPushButton* createButton(int iButton); 177 178 /* Helper: */ 179 void done(int iButtonCode); 180 181 /* Variables: */ 182 bool m_fPolished; 183 const QString m_strId; 184 QString m_strMessage, m_strDetails; 185 int m_iButton1, m_iButton2, m_iButton3; 186 QString m_strButtonText1, m_strButtonText2, m_strButtonText3; 187 188 /* Widgets: */ 189 QVBoxLayout *m_pMainLayout; 190 QIRichTextLabel *m_pTextPane; 191 QPushButton *m_pButton1, *m_pButton2, *m_pButton3; 192 QIDialogButtonBox *m_pButtonBox; 193 }; 194 111 195 #endif /* __UIPopupCenter_h__ */ 112
Note:
See TracChangeset
for help on using the changeset viewer.