Changeset 45592 in vbox for trunk/src/VBox
- Timestamp:
- Apr 17, 2013 4:58:02 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.cpp
r45588 r45592 73 73 } 74 74 75 QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName, 76 const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal, 77 const char *pSignalForward, const char *pSignalBackward, 78 bool fReversive /*= false*/, int iAnimationDuration /*= 300*/) 79 { 80 /* State-machine: */ 81 QStateMachine *pStateMachine = new QStateMachine(pTarget); 82 /* State-machine 'start' state: */ 83 QState *pStateStart = new QState(pStateMachine); 84 /* State-machine 'final' state: */ 85 QState *pStateFinal = new QState(pStateMachine); 86 87 /* State-machine 'forward' animation: */ 88 QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine); 89 pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic)); 90 pForwardAnimation->setDuration(iAnimationDuration); 91 pForwardAnimation->setStartValue(pTarget->property(strValuePropertyNameStart)); 92 pForwardAnimation->setEndValue(pTarget->property(strValuePropertyNameFinal)); 93 /* State-machine 'backward' animation: */ 94 QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, strPropertyName, pStateMachine); 95 pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic)); 96 pBackwardAnimation->setDuration(iAnimationDuration); 97 pBackwardAnimation->setStartValue(pTarget->property(strValuePropertyNameFinal)); 98 pBackwardAnimation->setEndValue(pTarget->property(strValuePropertyNameStart)); 99 100 /* State-machine state transitions: */ 101 QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pTarget, pSignalForward, pStateFinal); 102 pDefaultToHovered->addAnimation(pForwardAnimation); 103 QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pTarget, pSignalBackward, pStateStart); 104 pHoveredToDefault->addAnimation(pBackwardAnimation); 105 106 /* Initial state is 'start': */ 107 pStateMachine->setInitialState(!fReversive ? pStateStart : pStateFinal); 108 /* Start hover-machine: */ 109 pStateMachine->start(); 110 /* Return machine: */ 111 return pStateMachine; 112 } 113 75 114 76 115 /* Popup-pane frame prototype class: */ … … 82 121 signals: 83 122 84 /* Notifiers: Animation stuff: */123 /* Notifiers: Parent propagation stuff: */ 85 124 void sigHoverEnter(); 86 125 void sigHoverLeave(); … … 119 158 { 120 159 Q_OBJECT; 121 Q_PROPERTY(int percentage READ percentage WRITE setPercentage);122 160 123 161 signals: 124 162 125 /* Notifier: Animation stuff: */ 126 void sigHoverEnter(); 127 void sigHoverLeave(); 163 /* Notifiers: Parent propagation stuff: */ 128 164 void sigFocusEnter(); 129 165 void sigFocusLeave(); 130 void sigGeometryChanged(); 166 167 /* Notifier: Animation stuff: */ 168 void sigSizeChanged(); 131 169 132 170 public: … … 142 180 void setDesiredWidth(int iDesiredWidth); 143 181 144 /* API: Minimum size-hint stuff: */182 /* API: Size-hint stuff: */ 145 183 QSize minimumSizeHint() const; 146 184 QSize sizeHint() const; 185 186 private slots: 187 188 /* Handlers: Animation stuff: */ 189 void sltFocusEnter(); 190 void sltFocusLeave(); 191 147 192 private: 148 193 … … 154 199 void prepareContent(); 155 200 156 /* Property: Hover stuff: */ 157 int percentage() const { return m_iPercentage; } 158 void setPercentage(int iPercentage); 201 /* Helper: Size-hint stuff: */ 202 void updateGeometry(); 203 204 /* Handler: Animation stuff: */ 205 void resizeEvent(QResizeEvent *pEvent); 159 206 160 207 /* Variables: Label stuff: */ … … 162 209 int m_iDesiredWidth; 163 210 164 /* Variables: Hover stuff: */ 165 const int m_iHoverAnimationDuration; 166 const int m_iDefaultPercentage; 167 const int m_iHoveredPercentage; 168 int m_iPercentage; 211 /* Variables: Size-hint stuff: */ 212 QSize m_minimumSizeHint; 213 QSize m_sizeHint; 214 215 /* Variables: Animation stuff: */ 216 bool m_fFocused; 217 QObject *m_pAnimation; 169 218 }; 170 219 … … 225 274 const int iHeight = parentWidget()->height(); 226 275 227 /* Adjust text-pane according parent width: */228 if (m_pTextPane)229 {230 m_pTextPane->setDesiredWidth(iWidth - 2 * m_iMainLayoutMargin231 - 2 * m_iMainFrameLayoutMargin232 - m_pButtonBox->minimumSizeHint().width());233 }234 235 276 /* Resize popup according parent width: */ 236 277 resize(iWidth, minimumSizeHint().height()); … … 268 309 269 310 /* Adjust geometry: */ 270 sltAdjustGeomerty();311 adjustGeometry(); 271 312 } 272 313 /* Other objects subscribed for hovering: */ … … 341 382 { 342 383 /* Adjust geometry: */ 343 sltAdjustGeomerty();384 adjustGeometry(); 344 385 } 345 386 … … 368 409 { 369 410 /* Take into account widgets: */ 370 iMinimumWidthHint += m_pTextPane-> minimumSizeHint().width();411 iMinimumWidthHint += m_pTextPane->width(); 371 412 iMinimumWidthHint += m_iMainFrameLayoutSpacing; 372 413 iMinimumWidthHint += m_pButtonBox->minimumSizeHint().width(); … … 390 431 { 391 432 /* Take into account widgets: */ 392 const int iTextPaneHeight = m_pTextPane-> minimumSizeHint().height();433 const int iTextPaneHeight = m_pTextPane->height(); 393 434 const int iButtonBoxHeight = m_pButtonBox->minimumSizeHint().height(); 394 435 iMinimumHeightHint += qMax(iTextPaneHeight, iButtonBoxHeight); … … 403 444 { 404 445 return QSize(minimumWidthHint(), minimumHeightHint()); 446 } 447 448 void UIPopupPane::adjustGeometry() 449 { 450 /* Get parent width: */ 451 const int iWidth = parentWidget()->width(); 452 453 /* Adjust text-pane according parent width: */ 454 if (m_pTextPane) 455 { 456 m_pTextPane->setDesiredWidth(iWidth - 2 * m_iMainLayoutMargin 457 - 2 * m_iMainFrameLayoutMargin 458 - m_pButtonBox->minimumSizeHint().width()); 459 } 460 461 /* Adjust other widgets: */ 462 sltAdjustGeomerty(); 405 463 } 406 464 … … 420 478 /* Main-frame layout: */ 421 479 { 480 /* Variables: */ 481 const int iTextPaneWidth = m_pTextPane->width(); 482 const int iTextPaneHeight = m_pTextPane->height(); 483 const QSize buttonBoxMinimumSizeHint = m_pButtonBox->minimumSizeHint(); 484 const int iButtonBoxWidth = buttonBoxMinimumSizeHint.width(); 485 const int iButtonBoxHeight = buttonBoxMinimumSizeHint.height(); 486 const int iMaximumHeight = qMax(iTextPaneHeight, iButtonBoxHeight); 487 const int iMinimumHeight = qMin(iTextPaneHeight, iButtonBoxHeight); 488 const int iHeightShift = (iMaximumHeight - iMinimumHeight) / 2; 489 const bool fTextPaneShifted = iTextPaneHeight < iButtonBoxHeight; 422 490 /* Text-pane: */ 423 const int iTextPaneWidth = m_pTextPane->minimumSizeHint().width();424 491 m_pTextPane->move(m_iMainFrameLayoutMargin, 425 m_iMainFrameLayoutMargin); 426 m_pTextPane->resize(iTextPaneWidth, 427 iMainFrameHeight - 2 * m_iMainFrameLayoutMargin); 492 fTextPaneShifted ? m_iMainFrameLayoutMargin + iHeightShift : m_iMainFrameLayoutMargin); 493 m_pTextPane->resize(iTextPaneWidth, iTextPaneHeight); 428 494 /* Button-box: */ 429 const int iButtonBoxWidth = m_pButtonBox->minimumSizeHint().width();430 495 m_pButtonBox->move(m_iMainFrameLayoutMargin + iTextPaneWidth + m_iMainFrameLayoutSpacing, 431 496 m_iMainFrameLayoutMargin); … … 450 515 { 451 516 /* Prepare label: */ 452 connect(m_pTextPane, SIGNAL(sig GeometryChanged()),517 connect(m_pTextPane, SIGNAL(sigSizeChanged()), 453 518 this, SLOT(sltAdjustGeomerty())); 454 519 m_pTextPane->installEventFilter(this); … … 660 725 , m_pLabel(0) 661 726 , m_iDesiredWidth(-1) 662 , m_iHoverAnimationDuration(300) 663 , m_iDefaultPercentage(1) 664 , m_iHoveredPercentage(100) 665 , m_iPercentage(m_iDefaultPercentage) 727 , m_fFocused(false) 728 , m_pAnimation(0) 666 729 { 667 730 /* Prepare: */ … … 700 763 if (m_iDesiredWidth >= 0) 701 764 /* Return dependent size-hint: */ 702 return QSize(m_iDesiredWidth, (int)(((qreal)percentage() / 100) * m_pLabel->heightForWidth(m_iDesiredWidth))); 765 return m_minimumSizeHint; 766 /* Return golden-rule minimum size-hint by default: */ 767 return m_pLabel->minimumSizeHint(); 768 } 769 770 QSize UIPopupPaneTextPane::sizeHint() const 771 { 772 /* Check if desired-width set: */ 773 if (m_iDesiredWidth >= 0) 774 /* Return dependent size-hint: */ 775 return m_sizeHint; 703 776 /* Return golden-rule size-hint by default: */ 704 return m_pLabel->minimumSizeHint(); 777 return m_pLabel->sizeHint(); 778 } 779 780 void UIPopupPaneTextPane::sltFocusEnter() 781 { 782 if (!m_fFocused) 783 { 784 m_fFocused = true; 785 emit sigFocusEnter(); 786 } 787 } 788 789 void UIPopupPaneTextPane::sltFocusLeave() 790 { 791 if (m_fFocused) 792 { 793 m_fFocused = false; 794 emit sigFocusLeave(); 795 } 705 796 } 706 797 … … 708 799 { 709 800 /* Propagate parent signals: */ 710 connect(parent(), SIGNAL(sigHoverEnter()), this, SIGNAL(sigHoverEnter())); 711 connect(parent(), SIGNAL(sigHoverLeave()), this, SIGNAL(sigHoverLeave())); 712 connect(parent(), SIGNAL(sigFocusEnter()), this, SIGNAL(sigFocusEnter())); 713 connect(parent(), SIGNAL(sigFocusLeave()), this, SIGNAL(sigFocusLeave())); 714 /* Install 'focus' animation for 'height' property: */ 715 UIAnimationFramework::installPropertyAnimation(this, QByteArray("percentage"), 716 m_iDefaultPercentage, m_iHoveredPercentage, m_iHoverAnimationDuration, 717 SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave())); 801 connect(parent(), SIGNAL(sigFocusEnter()), this, SLOT(sltFocusEnter())); 802 connect(parent(), SIGNAL(sigFocusLeave()), this, SLOT(sltFocusLeave())); 718 803 /* Prepare content: */ 719 804 prepareContent(); … … 744 829 m_pLabel->setWordWrap(true); 745 830 } 746 /* Activate layout: */ 747 updateGeometry(); 748 } 749 } 750 751 void UIPopupPaneTextPane::setPercentage(int iPercentage) 752 { 753 m_iPercentage = iPercentage; 754 updateGeometry(); 755 emit sigGeometryChanged(); 831 } 832 } 833 834 void UIPopupPaneTextPane::updateGeometry() 835 { 836 /* Recalculate size-hints: */ 837 QFontMetrics fm(m_pLabel->font(), m_pLabel); 838 m_sizeHint = QSize(m_iDesiredWidth, m_pLabel->heightForWidth(m_iDesiredWidth)); 839 m_minimumSizeHint = QSize(m_iDesiredWidth, fm.height()); 840 /* Update geometry: */ 841 QWidget::updateGeometry(); 842 /* Resize to required size: */ 843 resize(m_fFocused ? sizeHint() : minimumSizeHint()); 844 /* Reinstall animation: */ 845 delete m_pAnimation; 846 m_pAnimation = UIAnimationFramework::installPropertyAnimation(this, "size", "minimumSizeHint", "sizeHint", 847 SIGNAL(sigFocusEnter()), SIGNAL(sigFocusLeave()), 848 m_fFocused); 849 } 850 851 void UIPopupPaneTextPane::resizeEvent(QResizeEvent*) 852 { 853 emit sigSizeChanged(); 756 854 } 757 855 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupPane.h
r45588 r45592 27 27 28 28 /* Forward declaration: */ 29 class QStateMachine; 29 30 class QLabel; 30 31 class QPushButton; … … 41 42 int iStartValue, int iFinalValue, int iAnimationDuration, 42 43 const char *pSignalForward, const char *pSignalBackward); 44 45 /* API: Animation stuff: */ 46 QStateMachine* installPropertyAnimation(QWidget *pTarget, const QByteArray &strPropertyName, 47 const QByteArray &strValuePropertyNameStart, const QByteArray &strValuePropertyNameFinal, 48 const char *pSignalForward, const char *pSignalBackward, 49 bool fReversive = false, int iAnimationDuration = 300); 43 50 } 44 51 … … 103 110 int minimumHeightHint() const; 104 111 QSize minimumSizeHint() const; 112 void adjustGeometry(); 105 113 void updateLayout(); 106 114
Note:
See TracChangeset
for help on using the changeset viewer.