- Timestamp:
- Apr 11, 2013 5:16:00 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
r45468 r45490 22 22 #include <QPushButton> 23 23 #include <QEvent> 24 #include <QMainWindow> 25 #include <QStatusBar> 26 #include <QPainter> 27 #include <QStateMachine> 28 #include <QPropertyAnimation> 29 #include <QSignalTransition> 24 30 25 31 /* GUI includes: */ … … 70 76 } 71 77 72 void UIPopupCenter::message(QWidget *pParent, 78 void UIPopupCenter::message(QWidget *pParent, const QString &strId, 73 79 const QString &strMessage, const QString &strDetails, 74 const char *pcszAutoConfirmId /*= 0*/,75 80 int iButton1 /*= 0*/, int iButton2 /*= 0*/, int iButton3 /*= 0*/, 76 81 const QString &strButtonText1 /* = QString() */, … … 78 83 const QString &strButtonText3 /* = QString() */) const 79 84 { 80 showPopupBox(pParent, 85 showPopupBox(pParent, strId, 81 86 strMessage, strDetails, 82 87 iButton1, iButton2, iButton3, 83 strButtonText1, strButtonText2, strButtonText3, 84 QString(pcszAutoConfirmId)); 85 } 86 87 void UIPopupCenter::error(QWidget *pParent, 88 const QString &strMessage, const QString &strDetails, 89 const char *pcszAutoConfirmId /*= 0*/) const 90 { 91 message(pParent, 88 strButtonText1, strButtonText2, strButtonText3); 89 } 90 91 void UIPopupCenter::error(QWidget *pParent, const QString &strId, 92 const QString &strMessage, const QString &strDetails) const 93 { 94 message(pParent, strId, 92 95 strMessage, strDetails, 93 pcszAutoConfirmId, 94 AlertButton_Ok | AlertButtonOption_Default); 95 } 96 97 void UIPopupCenter::alert(QWidget *pParent, 98 const QString &strMessage, 99 const char *pcszAutoConfirmId /*= 0*/) const 100 { 101 error(pParent, 102 strMessage, QString(), 103 pcszAutoConfirmId); 104 } 105 106 void UIPopupCenter::question(QWidget *pParent, 96 AlertButton_Ok | AlertButtonOption_Default | AlertButtonOption_Escape); 97 } 98 99 void UIPopupCenter::alert(QWidget *pParent, const QString &strId, 100 const QString &strMessage) const 101 { 102 error(pParent, strId, 103 strMessage, QString()); 104 } 105 106 void UIPopupCenter::question(QWidget *pParent, const QString &strId, 107 107 const QString &strMessage, 108 const char *pcszAutoConfirmId /*= 0*/,109 108 int iButton1 /*= 0*/, int iButton2 /*= 0*/, int iButton3 /*= 0*/, 110 109 const QString &strButtonText1 /*= QString()*/, … … 112 111 const QString &strButtonText3 /*= QString()*/) const 113 112 { 114 message(pParent, 113 message(pParent, strId, 115 114 strMessage, QString(), 116 pcszAutoConfirmId,117 115 iButton1, iButton2, iButton3, 118 116 strButtonText1, strButtonText2, strButtonText3); 119 117 } 120 118 121 void UIPopupCenter::questionBinary(QWidget *pParent, 119 void UIPopupCenter::questionBinary(QWidget *pParent, const QString &strId, 122 120 const QString &strMessage, 123 const char *pcszAutoConfirmId /*= 0*/,124 121 const QString &strOkButtonText /*= QString()*/, 125 122 const QString &strCancelButtonText /*= QString()*/) const 126 123 { 127 question(pParent, 124 question(pParent, strId, 128 125 strMessage, 129 pcszAutoConfirmId,130 126 AlertButton_Ok | AlertButtonOption_Default, 131 127 AlertButton_Cancel | AlertButtonOption_Escape, … … 136 132 } 137 133 138 void UIPopupCenter::questionTrinary(QWidget *pParent, 134 void UIPopupCenter::questionTrinary(QWidget *pParent, const QString &strId, 139 135 const QString &strMessage, 140 const char *pcszAutoConfirmId /*= 0*/,141 136 const QString &strChoice1ButtonText /*= QString()*/, 142 137 const QString &strChoice2ButtonText /*= QString()*/, 143 138 const QString &strCancelButtonText /*= QString()*/) const 144 139 { 145 question(pParent, 140 question(pParent, strId, 146 141 strMessage, 147 pcszAutoConfirmId,148 142 AlertButton_Choice1, 149 143 AlertButton_Choice2 | AlertButtonOption_Default, … … 154 148 } 155 149 156 void UIPopupCenter::showPopupBox(QWidget *pParent, 150 void UIPopupCenter::showPopupBox(QWidget *pParent, const QString &strId, 157 151 const QString &strMessage, const QString &strDetails, 158 152 int iButton1, int iButton2, int iButton3, 159 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3, 160 const QString &strAutoConfirmId) const 153 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3) const 161 154 { 162 155 /* Choose at least one button by 'default': */ 163 156 if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0) 164 iButton1 = AlertButton_Ok | AlertButtonOption_Default ;157 iButton1 = AlertButton_Ok | AlertButtonOption_Default | AlertButtonOption_Escape; 165 158 166 159 /* Create popup-box window: */ 167 160 QWidget *pPopupBoxParent = windowManager().realParentWindow(pParent ? pParent : windowManager().mainWindowShown()); 168 UIPopupPane *pPopupBox = new UIPopupPane(pPopupBoxParent, str AutoConfirmId,161 UIPopupPane *pPopupBox = new UIPopupPane(pPopupBoxParent, strId, 169 162 strMessage, strDetails, 170 163 iButton1, iButton2, iButton3, 171 164 strButtonText1, strButtonText2, strButtonText3); 172 m_popups.insert(str AutoConfirmId, pPopupBox);165 m_popups.insert(strId, pPopupBox); 173 166 connect(pPopupBox, SIGNAL(sigDone(int)), this, SLOT(sltPopupDone(int))); 174 167 pPopupBox->show(); … … 178 171 { 179 172 /* Make sure the sender is popup: */ 180 UIPopupPane *pPopup = qobject_cast<UIPopupPane*>(sender());173 const UIPopupPane *pPopup = qobject_cast<UIPopupPane*>(sender()); 181 174 if (!pPopup) 182 175 return; 183 176 184 /* Get the popup ID: */177 /* Make sure the popup is still exists: */ 185 178 const QString strPopupID(pPopup->id()); 186 187 /* Make sure the popup still here: */188 179 const bool fIsPopupStillHere = m_popups.contains(strPopupID); 189 180 AssertMsg(fIsPopupStillHere, ("Popup already destroyed!")); … … 199 190 } 200 191 192 void UIPopupCenter::remindAboutMouseIntegration(bool fSupportsAbsolute) const 193 { 194 if (fSupportsAbsolute) 195 { 196 alert(0, QString("remindAboutMouseIntegrationOn"), 197 tr("<p>The Virtual Machine reports that the guest OS supports <b>mouse pointer integration</b>. " 198 "This means that you do not need to <i>capture</i> the mouse pointer to be able to use it in your guest OS -- " 199 "all mouse actions you perform when the mouse pointer is over the Virtual Machine's display " 200 "are directly sent to the guest OS. If the mouse is currently captured, it will be automatically uncaptured.</p>" 201 "<p>The mouse icon on the status bar will look like <img src=:/mouse_seamless_16px.png/> to inform you " 202 "that mouse pointer integration is supported by the guest OS and is currently turned on.</p>" 203 "<p><b>Note</b>: Some applications may behave incorrectly in mouse pointer integration mode. " 204 "You can always disable it for the current session (and enable it again) " 205 "by selecting the corresponding action from the menu bar.</p>")); 206 } 207 else 208 { 209 alert(0, QString("remindAboutMouseIntegrationOff"), 210 tr("<p>The Virtual Machine reports that the guest OS does not support <b>mouse pointer integration</b> " 211 "in the current video mode. You need to capture the mouse (by clicking over the VM display " 212 "or pressing the host key) in order to use the mouse inside the guest OS.</p>")); 213 } 214 } 215 201 216 UIPopupPane::UIPopupPane(QWidget *pParent, const QString &strId, 202 217 const QString &strMessage, const QString &strDetails, 203 218 int iButton1, int iButton2, int iButton3, 204 219 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3) 205 : QWidget(pParent , Qt::Window | Qt::FramelessWindowHint)220 : QWidget(pParent) 206 221 , m_fPolished(false) 207 222 , 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 223 , m_strMessage(strMessage), m_strDetails(strDetails) 224 , m_iButton1(iButton1), m_iButton2(iButton2), m_iButton3(iButton3) 225 , m_strButtonText1(strButtonText1), m_strButtonText2(strButtonText2), m_strButtonText3(strButtonText3) 226 , m_iButtonEsc(0) 227 , m_iParentStatusBarHeight(parentStatusBarHeight(pParent)) 228 , m_pMainLayout(0), m_pFrameLayout(0) 229 , m_pTextPane(0), m_pButtonBox(0) 230 , m_pButton1(0), m_pButton2(0), m_pButton3(0) 231 { 232 /* Prepare: */ 233 prepare(); 234 } 235 236 UIPopupPane::~UIPopupPane() 237 { 238 /* Cleanup: */ 239 cleanup(); 240 } 241 242 void UIPopupPane::prepare() 243 { 244 /* Install event-filter to parent: */ 245 parent()->installEventFilter(this); 224 246 /* Prepare content: */ 225 247 prepareContent(); 226 248 } 227 249 228 UIPopupPane::~UIPopupPane()250 void UIPopupPane::cleanup() 229 251 { 230 252 } … … 236 258 return false; 237 259 238 /* Make sure its move|rezize event came: */ 239 if ( pEvent->type() != QEvent::Move 240 && pEvent->type() != QEvent::Resize) 260 /* Make sure its resize event came: */ 261 if (pEvent->type() != QEvent::Resize) 241 262 return false; 242 263 243 /* Process event: */ 264 /* Adjust geometry: */ 265 adjustAccordingParent(); 266 267 /* Do not filter anything: */ 268 return false; 269 } 270 271 void UIPopupPane::showEvent(QShowEvent *pEvent) 272 { 273 /* Make sure we should polish dialog: */ 274 if (m_fPolished) 275 return; 276 277 /* Call to polish-event: */ 278 polishEvent(pEvent); 279 280 /* Mark dialog as polished: */ 281 m_fPolished = true; 282 } 283 284 void UIPopupPane::polishEvent(QShowEvent*) 285 { 286 /* Adjust geometry: */ 287 adjustAccordingParent(); 288 } 289 290 void UIPopupPane::keyPressEvent(QKeyEvent *pEvent) 291 { 292 /* Preprocess Escape key: */ 293 if (pEvent->key() == Qt::Key_Escape && m_iButtonEsc) 294 { 295 done(m_iButtonEsc); 296 return; 297 } 298 /* Handle all the other keys: */ 299 QWidget::keyPressEvent(pEvent); 300 } 301 302 void UIPopupPane::adjustAccordingParent() 303 { 304 /* Get some variables: */ 305 const int iWidth = parentWidget()->width(); 306 const int iHeight = parentWidget()->height(); 307 308 /* Resize popup according parent: */ 309 resize(iWidth, minimumSizeHint().height()); 310 311 /* Move popup according parent: */ 312 move(0, iHeight - height() - m_iParentStatusBarHeight); 313 314 /* Raise popup according parent: */ 315 raise(); 316 317 /* Resize text-pane according new size: */ 318 if (m_pTextPane) 319 { 320 int iMinimumTextWidth = iWidth; 321 int iLeft, iTop, iRight, iBottom; 322 m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom); 323 iMinimumTextWidth -= iLeft; 324 iMinimumTextWidth -= iRight; 325 m_pFrameLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom); 326 iMinimumTextWidth -= iLeft; 327 iMinimumTextWidth -= iRight; 328 m_pTextPane->setMinimumTextWidth(iMinimumTextWidth); 329 } 330 } 331 332 void UIPopupPane::prepareContent() 333 { 334 /* Configure this: */ 335 setFocusPolicy(Qt::StrongFocus); 336 /* Create main-layout: */ 337 m_pMainLayout = new QVBoxLayout(this); 338 { 339 /* Configure layout: */ 340 m_pMainLayout->setContentsMargins(2, 2, 2, 2); 341 m_pMainLayout->setSpacing(0); 342 /* Create main frame: */ 343 UIPopupPaneFrame *pMainFrame = new UIPopupPaneFrame; 344 { 345 /* Add into layout: */ 346 m_pMainLayout->addWidget(pMainFrame); 347 /* Create frame-layout: */ 348 m_pFrameLayout = new QVBoxLayout(pMainFrame); 349 { 350 /* Configure layout: */ 351 m_pFrameLayout->setContentsMargins(15, 0, 15, 0); 352 m_pFrameLayout->setSpacing(0); 353 /* Create message-label: */ 354 m_pTextPane = new QIRichTextLabel; 355 { 356 /* Add into layout: */ 357 m_pFrameLayout->addWidget(m_pTextPane); 358 /* Configure label: */ 359 m_pTextPane->installEventFilter(pMainFrame); 360 m_pTextPane->setText(m_strMessage); 361 m_pTextPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); 362 } 363 /* Create button-box: */ 364 m_pButtonBox = new QIDialogButtonBox; 365 { 366 /* Add into layout: */ 367 m_pFrameLayout->addWidget(m_pButtonBox); 368 /* Configure button-box: */ 369 m_pButtonBox->installEventFilter(pMainFrame); 370 setFocusProxy(m_pButtonBox); 371 QList<int> activeButtons; 372 m_pButton1 = createButton(m_iButton1); 373 if (m_pButton1) 374 { 375 activeButtons << m_iButton1; 376 connect(m_pButton1, SIGNAL(clicked()), SLOT(done1())); 377 if (!m_strButtonText1.isEmpty()) 378 m_pButton1->setText(m_strButtonText1); 379 } 380 m_pButton2 = createButton(m_iButton2); 381 if (m_pButton2) 382 { 383 activeButtons << m_iButton2; 384 connect(m_pButton2, SIGNAL(clicked()), SLOT(done2())); 385 if (!m_strButtonText2.isEmpty()) 386 m_pButton1->setText(m_strButtonText2); 387 } 388 m_pButton3 = createButton(m_iButton3); 389 if (m_pButton3) 390 { 391 activeButtons << m_iButton3; 392 connect(m_pButton3, SIGNAL(clicked()), SLOT(done3())); 393 if (!m_strButtonText3.isEmpty()) 394 m_pButton1->setText(m_strButtonText3); 395 } 396 } 397 } 398 } 399 } 400 } 401 402 QPushButton* UIPopupPane::createButton(int iButton) 403 { 404 /* Not for AlertButton_NoButton: */ 405 if (iButton == 0) 406 return 0; 407 408 /* Prepare button text & role: */ 409 QString strText; 410 QDialogButtonBox::ButtonRole role; 411 switch (iButton & AlertButtonMask) 412 { 413 case AlertButton_Ok: strText = tr("OK"); role = QDialogButtonBox::AcceptRole; break; 414 case AlertButton_Cancel: strText = tr("Cancel"); role = QDialogButtonBox::RejectRole; break; 415 case AlertButton_Choice1: strText = tr("Yes"); role = QDialogButtonBox::YesRole; break; 416 case AlertButton_Choice2: strText = tr("No"); role = QDialogButtonBox::NoRole; break; 417 default: return 0; 418 } 419 420 /* Create push-button: */ 421 QPushButton *pButton = m_pButtonBox->addButton(strText, role); 422 423 /* Configure <default> button: */ 424 if (iButton & AlertButtonOption_Default) 425 { 426 pButton->setDefault(true); 427 pButton->setFocus(); 428 } 429 430 /* Configure <escape> button: */ 431 if (iButton & AlertButtonOption_Escape) 432 { 433 m_iButtonEsc = iButton & AlertButtonMask; 434 } 435 436 /* Return button: */ 437 return pButton; 438 } 439 440 void UIPopupPane::done(int iButtonCode) 441 { 442 /* Close the window: */ 443 close(); 444 445 /* Notify listeners: */ 446 emit sigDone(iButtonCode); 447 } 448 449 /* static */ 450 int UIPopupPane::parentStatusBarHeight(QWidget *pParent) 451 { 452 /* Check if passed parent is QMainWindow and contains status-bar: */ 453 if (QMainWindow *pParentWindow = qobject_cast<QMainWindow*>(pParent)) 454 if (pParentWindow->statusBar()) 455 return pParentWindow->statusBar()->height(); 456 return 0; 457 } 458 459 UIPopupPaneFrame::UIPopupPaneFrame(QWidget *pParent /*= 0*/) 460 : QWidget(pParent) 461 , m_fHovered(false) 462 , m_iDefaultOpacity(128) 463 , m_iHoveredOpacity(230) 464 , m_iOpacity(m_iDefaultOpacity) 465 , m_iHoverAnimationDuration(300) 466 { 467 /* Prepare: */ 468 prepare(); 469 } 470 471 UIPopupPaneFrame::~UIPopupPaneFrame() 472 { 473 /* Cleanup: */ 474 cleanup(); 475 } 476 477 void UIPopupPaneFrame::prepare() 478 { 479 /* Install event-filter: */ 480 installEventFilter(this); 481 /* Install 'hover' animation for 'opacity' property: */ 482 installPropertyAnimation(this, QByteArray("opacity"), 483 m_iDefaultOpacity, m_iHoveredOpacity, m_iHoverAnimationDuration, 484 SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave())); 485 } 486 487 void UIPopupPaneFrame::cleanup() 488 { 489 } 490 491 bool UIPopupPaneFrame::eventFilter(QObject *pObject, QEvent *pEvent) 492 { 493 /* Depending on event-type: */ 244 494 switch (pEvent->type()) 245 495 { 246 /* Move event: */ 247 case QEvent::Move: 496 /* Something is hovered: */ 497 case QEvent::HoverEnter: 498 case QEvent::Enter: 248 499 { 249 moveAccordingParent(); 500 if (!m_fHovered) 501 { 502 m_fHovered = true; 503 emit sigHoverEnter(); 504 } 250 505 break; 251 506 } 252 /* Resize event: */253 case QEvent:: Resize:507 /* Nothing is hovered: */ 508 case QEvent::Leave: 254 509 { 255 resizeAccordingParent(); 510 if (pObject == this && m_fHovered) 511 { 512 m_fHovered = false; 513 emit sigHoverLeave(); 514 } 256 515 break; 257 516 } … … 259 518 default: break; 260 519 } 261 262 /* Do not filter by default: */ 520 /* Do not filter anything: */ 263 521 return false; 264 522 } 265 523 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 524 void UIPopupPaneFrame::paintEvent(QPaintEvent*) 525 { 526 /* Compose painting rectangle: */ 527 const QRect rect(0, 0, width(), height()); 528 529 /* Create painter: */ 530 QPainter painter(this); 531 painter.setRenderHint(QPainter::Antialiasing); 532 533 /* Configure painter clipping: */ 534 QPainterPath path; 535 int iDiameter = 5; 536 QSizeF arcSize(2 * iDiameter, 2 * iDiameter); 537 path.moveTo(iDiameter, 0); 538 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, 0), 90, 90); 539 path.lineTo(path.currentPosition().x(), rect.height() - iDiameter); 540 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -iDiameter), 180, 90); 541 path.lineTo(rect.width() - iDiameter, path.currentPosition().y()); 542 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, -2 * iDiameter), 270, 90); 543 path.lineTo(path.currentPosition().x(), iDiameter); 544 path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * iDiameter, -iDiameter), 0, 90); 545 path.closeSubpath(); 546 painter.setClipPath(path); 547 548 /* Fill with background: */ 549 QColor currentColor(palette().color(QPalette::Window)); 550 QColor newColor(currentColor.red(), currentColor.green(), currentColor.blue(), opacity()); 551 painter.fillRect(rect, newColor); 552 } 553 554 /* static */ 555 void UIPopupPaneFrame::installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName, 556 int iStartValue, int iFinalValue, int iAnimationDuration, 557 const char *pSignalForward, const char *pSignalBackward) 558 { 559 /* State-machine: */ 560 QStateMachine *pStateMachine = new QStateMachine(pParent); 561 /* State-machine 'start' state: */ 562 QState *pStateStart = new QState(pStateMachine); 563 /* State-machine 'final' state: */ 564 QState *pStateFinal = new QState(pStateMachine); 565 566 /* State-machine 'forward' animation: */ 567 QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent); 568 pForwardAnimation->setDuration(iAnimationDuration); 569 pForwardAnimation->setStartValue(iStartValue); 570 pForwardAnimation->setEndValue(iFinalValue); 571 /* State-machine 'backward' animation: */ 572 QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pParent, strPropertyName, pParent); 573 pBackwardAnimation->setDuration(iAnimationDuration); 574 pBackwardAnimation->setStartValue(iFinalValue); 575 pBackwardAnimation->setEndValue(iStartValue); 576 577 /* State-machine state transitions: */ 578 QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pParent, pSignalForward, pStateFinal); 579 pDefaultToHovered->addAnimation(pForwardAnimation); 580 QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pParent, pSignalBackward, pStateStart); 581 pHoveredToDefault->addAnimation(pBackwardAnimation); 582 583 /* Initial state is 'start': */ 584 pStateMachine->setInitialState(pStateStart); 585 /* Start hover-machine: */ 586 pStateMachine->start(); 587 } 588 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h
r45468 r45490 53 53 54 54 /* API: Main message function, used directly only in exceptional cases: */ 55 void message(QWidget *pParent, 55 void message(QWidget *pParent, const QString &strId, 56 56 const QString &strMessage, const QString &strDetails, 57 const char *pcszAutoConfirmId = 0,58 57 int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, 59 58 const QString &strButtonText1 = QString(), … … 63 62 /* API: Wrapper to 'message' function. 64 63 * Provides single OK button: */ 65 void error(QWidget *pParent, 66 const QString &strMessage, const QString &strDetails, 67 const char *pcszAutoConfirmId = 0) const; 64 void error(QWidget *pParent, const QString &strId, 65 const QString &strMessage, const QString &strDetails) const; 68 66 69 67 /* API: Wrapper to 'error' function. 70 68 * Omits details: */ 71 void alert(QWidget *pParent, 72 const QString &strMessage, 73 const char *pcszAutoConfirmId = 0) const; 69 void alert(QWidget *pParent, const QString &strId, 70 const QString &strMessage) const; 74 71 75 72 /* API: Wrapper to 'message' function. 76 73 * Omits details, provides two or three buttons: */ 77 void question(QWidget *pParent, 74 void question(QWidget *pParent, const QString &strId, 78 75 const QString &strMessage, 79 const char *pcszAutoConfirmId = 0,80 76 int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, 81 77 const QString &strButtonText1 = QString(), … … 85 81 /* API: Wrapper to 'question' function, 86 82 * Question providing two buttons (OK and Cancel by default): */ 87 void questionBinary(QWidget *pParent, 83 void questionBinary(QWidget *pParent, const QString &strId, 88 84 const QString &strMessage, 89 const char *pcszAutoConfirmId = 0,90 85 const QString &strOkButtonText = QString(), 91 86 const QString &strCancelButtonText = QString()) const; … … 93 88 /* API: Wrapper to 'question' function, 94 89 * Question providing three buttons (Yes, No and Cancel by default): */ 95 void questionTrinary(QWidget *pParent, 90 void questionTrinary(QWidget *pParent, const QString &strId, 96 91 const QString &strMessage, 97 const char *pcszAutoConfirmId = 0,98 92 const QString &strChoice1ButtonText = QString(), 99 93 const QString &strChoice2ButtonText = QString(), 100 94 const QString &strCancelButtonText = QString()) const; 101 95 96 /* API: Runtime UI stuff: */ 97 void remindAboutMouseIntegration(bool fSupportsAbsolute) const; 98 102 99 private slots: 103 100 … … 112 109 113 110 /* Helper: Popup-box stuff: */ 114 void showPopupBox(QWidget *pParent, 111 void showPopupBox(QWidget *pParent, const QString &strId, 115 112 const QString &strMessage, const QString &strDetails, 116 113 int iButton1, int iButton2, int iButton3, 117 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3, 118 const QString &strAutoConfirmId) const; 114 const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3) const; 119 115 120 116 /* Variables: */ … … 161 157 private: 162 158 159 /* Helpers: Prepare/cleanup stuff: */ 160 void prepare(); 161 void cleanup(); 162 163 163 /* Handler: Event-filter stuff: */ 164 164 bool eventFilter(QObject *pWatched, QEvent *pEvent); … … 167 167 virtual void showEvent(QShowEvent *pEvent); 168 168 virtual void polishEvent(QShowEvent *pEvent); 169 170 /* Helpers: Move/resize stuff: */ 171 void moveAccordingParent();172 void resizeAccordingParent();169 virtual void keyPressEvent(QKeyEvent *pEvent); 170 171 /* Helper: Adjust stuff: */ 172 void adjustAccordingParent(); 173 173 174 174 /* Helpers: Prepare stuff: */ … … 176 176 QPushButton* createButton(int iButton); 177 177 178 /* Helper: */178 /* Helper: Complete stuff: */ 179 179 void done(int iButtonCode); 180 181 /* Helper: Parent stuff: */ 182 static int parentStatusBarHeight(QWidget *pParent); 180 183 181 184 /* Variables: */ … … 185 188 int m_iButton1, m_iButton2, m_iButton3; 186 189 QString m_strButtonText1, m_strButtonText2, m_strButtonText3; 190 int m_iButtonEsc; 191 const int m_iParentStatusBarHeight; 187 192 188 193 /* Widgets: */ 189 194 QVBoxLayout *m_pMainLayout; 195 QVBoxLayout *m_pFrameLayout; 190 196 QIRichTextLabel *m_pTextPane; 197 QIDialogButtonBox *m_pButtonBox; 191 198 QPushButton *m_pButton1, *m_pButton2, *m_pButton3; 192 QIDialogButtonBox *m_pButtonBox;193 199 }; 194 200 201 /* Popup-pane frame prototype class: */ 202 class UIPopupPaneFrame : public QWidget 203 { 204 Q_OBJECT; 205 Q_PROPERTY(int opacity READ opacity WRITE setOpacity); 206 207 signals: 208 209 /* Notifiers: Hover-machine stuff: */ 210 void sigHoverEnter(); 211 void sigHoverLeave(); 212 213 public: 214 215 /* Constructor/destructor: */ 216 UIPopupPaneFrame(QWidget *pParent = 0); 217 ~UIPopupPaneFrame(); 218 219 private: 220 221 /* Helpers: Prepare/cleanup stuff: */ 222 void prepare(); 223 void cleanup(); 224 225 /* Handlers: Event stuff: */ 226 bool eventFilter(QObject *pWatched, QEvent *pEvent); 227 void paintEvent(QPaintEvent *pEvent); 228 229 /* Property: Hover-machine stuff: */ 230 int opacity() const { return m_iOpacity; } 231 void setOpacity(int iOpacity) { m_iOpacity = iOpacity; update(); } 232 233 /* Static helper: Animation stuff: */ 234 static void installPropertyAnimation(QWidget *pParent, const QByteArray &strPropertyName, 235 int iStartValue, int iFinalValue, int iAnimationDuration, 236 const char *pSignalForward, const char *pSignalBackward); 237 238 /* Hover-machine stuff: */ 239 bool m_fHovered; 240 int m_iDefaultOpacity; 241 int m_iHoveredOpacity; 242 int m_iOpacity; 243 int m_iHoverAnimationDuration; 244 }; 245 195 246 #endif /* __UIPopupCenter_h__ */
Note:
See TracChangeset
for help on using the changeset viewer.