- Timestamp:
- Apr 12, 2013 3:01:04 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
r45515 r45522 20 20 /* Qt includes: */ 21 21 #include <QVBoxLayout> 22 #include <QLabel> 22 23 #include <QPushButton> 23 24 #include <QEvent> … … 32 33 #include "UIPopupCenter.h" 33 34 #include "UIModalWindowManager.h" 34 #include "QIRichTextLabel.h"35 35 #include "QIDialogButtonBox.h" 36 36 … … 255 255 , m_fPolished(false) 256 256 , m_strId(strId) 257 , m_iMainLayoutMargin(2), m_iMainFrameLayoutMargin(5), m_iMainFrameLayoutSpacing(5) 257 , m_iMainLayoutMargin(2), m_iMainFrameLayoutMargin(10), m_iMainFrameLayoutSpacing(5) 258 , m_iParentStatusBarHeight(parentStatusBarHeight(pParent)) 258 259 , m_strMessage(strMessage), m_strDetails(strDetails) 259 260 , m_iButton1(iButton1), m_iButton2(iButton2), m_iButton3(iButton3) 260 261 , m_strButtonText1(strButtonText1), m_strButtonText2(strButtonText2), m_strButtonText3(strButtonText3) 261 262 , m_iButtonEsc(0) 262 , m_ iParentStatusBarHeight(parentStatusBarHeight(pParent))263 , m_p TextPane(0), m_pButtonBox(0)263 , m_fHovered(false) 264 , m_pMainFrame(0), m_pTextPane(0), m_pButtonBox(0) 264 265 , m_pButton1(0), m_pButton2(0), m_pButton3(0) 265 266 { … … 272 273 /* Cleanup: */ 273 274 cleanup(); 275 } 276 277 void UIPopupPane::sltAdjustGeomerty() 278 { 279 /* Get parent attributes: */ 280 const int iWidth = parentWidget()->width(); 281 const int iHeight = parentWidget()->height(); 282 283 /* Adjust text-pane according parent width: */ 284 if (m_pTextPane) 285 { 286 m_pTextPane->setDesiredWidth(iWidth - 2 * m_iMainLayoutMargin 287 - 2 * m_iMainFrameLayoutMargin 288 - m_pButtonBox->minimumSizeHint().width()); 289 } 290 291 /* Resize popup according parent width: */ 292 resize(iWidth, minimumSizeHint().height()); 293 294 /* Move popup according parent: */ 295 move(0, iHeight - height() - m_iParentStatusBarHeight); 296 297 /* Raise popup according parent: */ 298 raise(); 299 300 /* Update layout: */ 301 updateLayout(); 274 302 } 275 303 … … 288 316 bool UIPopupPane::eventFilter(QObject *pWatched, QEvent *pEvent) 289 317 { 290 /* Make sure its parent event came: */ 291 if (pWatched != parent()) 292 return false; 293 294 /* Make sure its resize event came: */ 295 if (pEvent->type() != QEvent::Resize) 296 return false; 297 298 /* Adjust geometry: */ 299 adjustAccordingParent(); 300 318 /* If its parent event came: */ 319 if (pWatched == parent()) 320 { 321 /* Make sure its resize event came: */ 322 if (pEvent->type() != QEvent::Resize) 323 return false; 324 325 /* Adjust geometry: */ 326 sltAdjustGeomerty(); 327 } 328 /* Other objects subscribed for hovering: */ 329 else 330 { 331 /* Depending on event-type: */ 332 switch (pEvent->type()) 333 { 334 /* Something is hovered: */ 335 case QEvent::HoverEnter: 336 case QEvent::Enter: 337 { 338 if (!m_fHovered) 339 { 340 m_fHovered = true; 341 emit sigHoverEnter(); 342 } 343 break; 344 } 345 /* Nothing is hovered: */ 346 case QEvent::Leave: 347 { 348 if (pWatched == this && m_fHovered) 349 { 350 m_fHovered = false; 351 emit sigHoverLeave(); 352 } 353 break; 354 } 355 /* Default case: */ 356 default: break; 357 } 358 } 301 359 /* Do not filter anything: */ 302 360 return false; … … 319 377 { 320 378 /* Adjust geometry: */ 321 adjustAccordingParent();379 sltAdjustGeomerty(); 322 380 } 323 381 … … 346 404 { 347 405 /* Take into account widgets: */ 348 const int iTextPaneWidth= m_pTextPane->minimumSizeHint().width();349 const int iButtonBoxWidth = m_pButtonBox->minimumSizeHint().width();350 iMinimumWidthHint += qMax(iTextPaneWidth, iButtonBoxWidth);406 iMinimumWidthHint += m_pTextPane->minimumSizeHint().width(); 407 iMinimumWidthHint += m_iMainFrameLayoutSpacing; 408 iMinimumWidthHint += m_pButtonBox->minimumSizeHint().width(); 351 409 } 352 410 } … … 368 426 { 369 427 /* Take into account widgets: */ 370 iMinimumHeightHint += m_pTextPane->minimumSizeHint().height();371 iMinimumHeightHint += m_iMainFrameLayoutSpacing;372 iMinimumHeightHint += m_pButtonBox->minimumSizeHint().height();428 const int iTextPaneHeight = m_pTextPane->minimumSizeHint().height(); 429 const int iButtonBoxHeight = m_pButtonBox->minimumSizeHint().height(); 430 iMinimumHeightHint += qMax(iTextPaneHeight, iButtonBoxHeight); 373 431 } 374 432 } … … 381 439 { 382 440 return QSize(minimumWidthHint(), minimumHeightHint()); 383 }384 385 void UIPopupPane::adjustAccordingParent()386 {387 /* Get parent attributes: */388 const int iWidth = parentWidget()->width();389 const int iHeight = parentWidget()->height();390 391 /* Adjust text-pane according parent width: */392 if (m_pTextPane)393 {394 m_pTextPane->setMinimumTextWidth(iWidth - 2 * m_iMainLayoutMargin395 - 2 * m_iMainFrameLayoutMargin);396 }397 398 /* Resize popup according parent width: */399 resize(iWidth, minimumSizeHint().height());400 401 /* Move popup according parent: */402 move(0, iHeight - height() - m_iParentStatusBarHeight);403 404 /* Raise popup according parent: */405 raise();406 407 /* Update layout: */408 updateLayout();409 441 } 410 442 … … 421 453 m_pMainFrame->resize(iWidth - 2 * m_iMainLayoutMargin, 422 454 iHeight - 2 * m_iMainLayoutMargin); 423 const int iMainFrame Width = m_pMainFrame->width();455 const int iMainFrameHeight = m_pMainFrame->height(); 424 456 /* Main-frame layout: */ 425 457 { 426 458 /* Text-pane: */ 427 const int iTextPane Height = m_pTextPane->minimumSizeHint().height();459 const int iTextPaneWidth = m_pTextPane->minimumSizeHint().width(); 428 460 m_pTextPane->move(m_iMainFrameLayoutMargin, 429 461 m_iMainFrameLayoutMargin); 430 m_pTextPane->resize(i MainFrameWidth - 2 * m_iMainFrameLayoutMargin,431 i TextPaneHeight);462 m_pTextPane->resize(iTextPaneWidth, 463 iMainFrameHeight - 2 * m_iMainFrameLayoutMargin); 432 464 /* Button-box: */ 433 const int iButtonBox Height = m_pButtonBox->minimumSizeHint().height();434 m_pButtonBox->move(m_iMainFrameLayoutMargin ,435 m_iMainFrameLayoutMargin + iTextPaneHeight + m_iMainFrameLayoutSpacing);436 m_pButtonBox->resize(i MainFrameWidth - 2 * m_iMainFrameLayoutMargin,437 i ButtonBoxHeight);465 const int iButtonBoxWidth = m_pButtonBox->minimumSizeHint().width(); 466 m_pButtonBox->move(m_iMainFrameLayoutMargin + iTextPaneWidth + m_iMainFrameLayoutSpacing, 467 m_iMainFrameLayoutMargin); 468 m_pButtonBox->resize(iButtonBoxWidth, 469 iMainFrameHeight - 2 * m_iMainFrameLayoutMargin); 438 470 } 439 471 } … … 443 475 { 444 476 /* Prepare this: */ 477 installEventFilter(this); 445 478 setFocusPolicy(Qt::StrongFocus); 446 479 /* Create main-frame: */ … … 448 481 { 449 482 /* Prepare frame: */ 450 m_pMainFrame->installEventFilter( m_pMainFrame);483 m_pMainFrame->installEventFilter(this); 451 484 /* Create message-label: */ 452 m_pTextPane = new QIRichTextLabel(m_pMainFrame);485 m_pTextPane = new UIPopupPaneTextPane(m_pMainFrame); 453 486 { 454 487 /* Prepare label: */ 488 connect(m_pTextPane, SIGNAL(sigGeometryChanged()), 489 this, SLOT(sltAdjustGeomerty())); 490 m_pTextPane->installEventFilter(this); 455 491 m_pTextPane->setFocusPolicy(Qt::StrongFocus); 456 m_pTextPane->installEventFilter(m_pMainFrame);457 492 m_pTextPane->setText(m_strMessage); 458 m_pTextPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);459 493 } 460 494 /* Create button-box: */ … … 462 496 { 463 497 /* Prepare button-box: */ 464 m_pButtonBox->installEventFilter(m_pMainFrame); 498 m_pButtonBox->installEventFilter(this); 499 m_pButtonBox->setOrientation(Qt::Vertical); 465 500 prepareButtons(); 466 501 } … … 587 622 UIPopupPaneFrame::UIPopupPaneFrame(QWidget *pParent /*= 0*/) 588 623 : QWidget(pParent) 589 , m_ fHovered(false)624 , m_iHoverAnimationDuration(300) 590 625 , m_iDefaultOpacity(128) 591 626 , m_iHoveredOpacity(230) 592 627 , m_iOpacity(m_iDefaultOpacity) 593 , m_iHoverAnimationDuration(300)594 628 { 595 629 /* Prepare: */ … … 606 640 { 607 641 /* Install 'hover' animation for 'opacity' property: */ 642 connect(parent(), SIGNAL(sigHoverEnter()), this, SIGNAL(sigHoverEnter())); 643 connect(parent(), SIGNAL(sigHoverLeave()), this, SIGNAL(sigHoverLeave())); 608 644 UIAnimationFramework::installPropertyAnimation(this, QByteArray("opacity"), 609 645 m_iDefaultOpacity, m_iHoveredOpacity, m_iHoverAnimationDuration, … … 613 649 void UIPopupPaneFrame::cleanup() 614 650 { 615 }616 617 bool UIPopupPaneFrame::eventFilter(QObject *pObject, QEvent *pEvent)618 {619 /* Depending on event-type: */620 switch (pEvent->type())621 {622 /* Something is hovered: */623 case QEvent::HoverEnter:624 case QEvent::Enter:625 {626 if (!m_fHovered)627 {628 m_fHovered = true;629 emit sigHoverEnter();630 }631 break;632 }633 /* Nothing is hovered: */634 case QEvent::Leave:635 {636 if (pObject == this && m_fHovered)637 {638 m_fHovered = false;639 emit sigHoverLeave();640 }641 break;642 }643 /* Default case: */644 default: break;645 }646 /* Do not filter anything: */647 return false;648 651 } 649 652 … … 678 681 } 679 682 683 UIPopupPaneTextPane::UIPopupPaneTextPane(QWidget *pParent /*= 0*/) 684 : QWidget(pParent) 685 , m_pLabel(0) 686 , m_iDesiredWidth(-1) 687 , m_iHoverAnimationDuration(300) 688 , m_iDefaultPercentage(1) 689 , m_iHoveredPercentage(100) 690 , m_iPercentage(m_iDefaultPercentage) 691 { 692 /* Prepare: */ 693 prepare(); 694 } 695 696 UIPopupPaneTextPane::~UIPopupPaneTextPane() 697 { 698 /* Cleanup: */ 699 cleanup(); 700 } 701 702 void UIPopupPaneTextPane::setText(const QString &strText) 703 { 704 /* Make sure the text is changed: */ 705 if (m_pLabel->text() == strText) 706 return; 707 /* Update the pane for new text: */ 708 m_pLabel->setText(strText); 709 updateGeometry(); 710 } 711 712 void UIPopupPaneTextPane::setDesiredWidth(int iDesiredWidth) 713 { 714 /* Make sure the desired-width is changed: */ 715 if (m_iDesiredWidth == iDesiredWidth) 716 return; 717 /* Update the pane for new desired-width: */ 718 m_iDesiredWidth = iDesiredWidth; 719 updateGeometry(); 720 } 721 722 QSize UIPopupPaneTextPane::minimumSizeHint() const 723 { 724 /* Check if desired-width set: */ 725 if (m_iDesiredWidth >= 0) 726 /* Return dependent size-hint: */ 727 return QSize(m_iDesiredWidth, (int)(((qreal)percentage() / 100) * m_pLabel->heightForWidth(m_iDesiredWidth))); 728 /* Return golden-rule size-hint by default: */ 729 return m_pLabel->minimumSizeHint(); 730 } 731 732 void UIPopupPaneTextPane::prepare() 733 { 734 /* Install 'hover' animation for 'height' property: */ 735 connect(parent(), SIGNAL(sigHoverEnter()), this, SIGNAL(sigHoverEnter())); 736 connect(parent(), SIGNAL(sigHoverLeave()), this, SIGNAL(sigHoverLeave())); 737 UIAnimationFramework::installPropertyAnimation(this, QByteArray("percentage"), 738 m_iDefaultPercentage, m_iHoveredPercentage, m_iHoverAnimationDuration, 739 SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave())); 740 /* Prepare content: */ 741 prepareContent(); 742 } 743 744 void UIPopupPaneTextPane::cleanup() 745 { 746 } 747 748 void UIPopupPaneTextPane::prepareContent() 749 { 750 /* Create main layout: */ 751 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 752 { 753 /* Prepare layout: */ 754 pMainLayout->setContentsMargins(0, 0, 0, 0); 755 pMainLayout->setSpacing(0); 756 /* Create label: */ 757 m_pLabel = new QLabel; 758 { 759 /* Add into layout: */ 760 pMainLayout->addWidget(m_pLabel); 761 /* Prepare label: */ 762 m_pLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 763 m_pLabel->setWordWrap(true); 764 } 765 /* Activate layout: */ 766 updateGeometry(); 767 } 768 } 769 770 void UIPopupPaneTextPane::setPercentage(int iPercentage) 771 { 772 m_iPercentage = iPercentage; 773 updateGeometry(); 774 emit sigGeometryChanged(); 775 } 776 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h
r45515 r45522 31 31 /* Forward declaration: */ 32 32 class QPushButton; 33 class Q IRichTextLabel;33 class QLabel; 34 34 class QIDialogButtonBox; 35 35 class UIPopupPane; 36 36 class UIPopupPaneFrame; 37 class UIPopupPaneTextPane; 37 38 38 39 /* Global popup-center object: */ … … 142 143 signals: 143 144 145 /* Notifiers: Hover stuff: */ 146 void sigHoverEnter(); 147 void sigHoverLeave(); 148 144 149 /* Notifier: Complete stuff: */ 145 150 void sigDone(int iButtonCode) const; … … 164 169 void done3() { done(m_iButton3 & AlertButtonMask); } 165 170 171 /* Handler: Layout stuff: */ 172 void sltAdjustGeomerty(); 173 166 174 private: 167 175 … … 182 190 int minimumHeightHint() const; 183 191 QSize minimumSizeHint() const; 184 void adjustAccordingParent();185 192 void updateLayout(); 186 193 … … 200 207 bool m_fPolished; 201 208 const QString m_strId; 202 int m_iMainLayoutMargin; 203 int m_iMainFrameLayoutMargin; 204 int m_iMainFrameLayoutSpacing; 209 210 /* Variables: Layout stuff: */ 211 const int m_iMainLayoutMargin; 212 const int m_iMainFrameLayoutMargin; 213 const int m_iMainFrameLayoutSpacing; 214 const int m_iParentStatusBarHeight; 215 216 /* Variables: Text stuff: */ 205 217 QString m_strMessage, m_strDetails; 218 219 /* Variables: Button stuff: */ 206 220 int m_iButton1, m_iButton2, m_iButton3; 207 221 QString m_strButtonText1, m_strButtonText2, m_strButtonText3; 208 222 int m_iButtonEsc; 209 const int m_iParentStatusBarHeight; 223 224 /* Variables: Hover stuff: */ 225 bool m_fHovered; 210 226 211 227 /* Widgets: */ 212 228 UIPopupPaneFrame *m_pMainFrame; 213 QIRichTextLabel*m_pTextPane;229 UIPopupPaneTextPane *m_pTextPane; 214 230 QIDialogButtonBox *m_pButtonBox; 215 231 QPushButton *m_pButton1, *m_pButton2, *m_pButton3; … … 224 240 signals: 225 241 226 /* Notifiers: Hover -machinestuff: */242 /* Notifiers: Hover stuff: */ 227 243 void sigHoverEnter(); 228 244 void sigHoverLeave(); … … 241 257 242 258 /* Handlers: Event stuff: */ 243 bool eventFilter(QObject *pWatched, QEvent *pEvent);244 259 void paintEvent(QPaintEvent *pEvent); 245 260 246 /* Property: Hover -machinestuff: */261 /* Property: Hover stuff: */ 247 262 int opacity() const { return m_iOpacity; } 248 263 void setOpacity(int iOpacity) { m_iOpacity = iOpacity; update(); } 249 264 250 /* Hover-machinestuff: */251 bool m_fHovered;252 int m_iDefaultOpacity;253 int m_iHoveredOpacity;265 /* Variables: Hover stuff: */ 266 const int m_iHoverAnimationDuration; 267 const int m_iDefaultOpacity; 268 const int m_iHoveredOpacity; 254 269 int m_iOpacity; 255 int m_iHoverAnimationDuration;256 270 }; 257 271 272 /* Popup-pane text-pane prototype class: */ 273 class UIPopupPaneTextPane : public QWidget 274 { 275 Q_OBJECT; 276 Q_PROPERTY(int percentage READ percentage WRITE setPercentage); 277 278 signals: 279 280 /* Notifiers: Hover stuff: */ 281 void sigHoverEnter(); 282 void sigHoverLeave(); 283 void sigGeometryChanged(); 284 285 public: 286 287 /* Constructor/destructor: */ 288 UIPopupPaneTextPane(QWidget *pParent = 0); 289 ~UIPopupPaneTextPane(); 290 291 /* API: Text stuff: */ 292 void setText(const QString &strText); 293 294 /* API: Set desired width: */ 295 void setDesiredWidth(int iDesiredWidth); 296 297 /* API: Minimum size-hint stuff: */ 298 QSize minimumSizeHint() const; 299 300 private: 301 302 /* Helpers: Prepare/cleanup stuff: */ 303 void prepare(); 304 void cleanup(); 305 306 /* Helper: Content stuff: */ 307 void prepareContent(); 308 309 /* Property: Hover stuff: */ 310 int percentage() const { return m_iPercentage; } 311 void setPercentage(int iPercentage); 312 313 /* Variables: Label stuff: */ 314 QLabel *m_pLabel; 315 int m_iDesiredWidth; 316 317 /* Variables: Hover stuff: */ 318 const int m_iHoverAnimationDuration; 319 const int m_iDefaultPercentage; 320 const int m_iHoveredPercentage; 321 int m_iPercentage; 322 }; 323 258 324 #endif /* __UIPopupCenter_h__ */
Note:
See TracChangeset
for help on using the changeset viewer.