Changeset 73842 in vbox
- Timestamp:
- Aug 22, 2018 5:15:51 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 edited
- 2 copied
-
Makefile.kmk (modified) (2 diffs)
-
src/widgets/UISlidingAnimation.cpp (copied) (copied from trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingWidget.cpp ) (4 diffs)
-
src/widgets/UISlidingAnimation.h (copied) (copied from trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingWidget.h ) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r73600 r73842 711 711 src/widgets/UIGuestOSTypeSelectionButton.h \ 712 712 src/widgets/UILineTextEdit.h \ 713 src/widgets/UISlidingAnimation.h \ 713 714 src/widgets/UISlidingWidget.h \ 714 715 src/widgets/UITabBar.h \ … … 1389 1390 src/widgets/UIGuestOSTypeSelectionButton.cpp \ 1390 1391 src/widgets/UILineTextEdit.cpp \ 1392 src/widgets/UISlidingAnimation.cpp \ 1391 1393 src/widgets/UISlidingWidget.cpp \ 1392 1394 src/widgets/UITabBar.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingAnimation.cpp
r73800 r73842 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UISliding Widgetclass implementation.3 * VBox Qt GUI - UISlidingAnimation class implementation. 4 4 */ 5 5 … … 19 19 #include <QEvent> 20 20 #include <QHBoxLayout> 21 #include <QLabel> 21 22 #include <QVBoxLayout> 22 23 23 24 /* GUI includes: */ 24 25 #include "UIAnimationFramework.h" 25 #include "UISliding Widget.h"26 #include "UISlidingAnimation.h" 26 27 27 28 28 UISliding Widget::UISlidingWidget(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)29 UISlidingAnimation::UISlidingAnimation(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */) 29 30 : QWidget(pParent) 30 31 , m_enmOrientation(enmOrientation) 31 , m_enmState(State_Start)32 32 , m_pAnimation(0) 33 33 , m_pWidget(0) 34 , m_pLayout(0) 34 , m_pLabel1(0) 35 , m_pLabel2(0) 35 36 , m_pWidget1(0) 36 37 , m_pWidget2(0) … … 40 41 } 41 42 42 QSize UISlidingWidget::minimumSizeHint() const 43 void UISlidingAnimation::setWidgets(QWidget *pWidget1, QWidget *pWidget2) 43 44 { 44 /* Return maximum of minimum size-hints: */ 45 QSize msh = QSize(); 46 if (m_pWidget1) 47 msh = msh.expandedTo(m_pWidget1->minimumSizeHint()); 48 if (m_pWidget2) 49 msh = msh.expandedTo(m_pWidget2->minimumSizeHint()); 50 return msh; 45 /* Remember rendered widgets: */ 46 m_pWidget1 = pWidget1; 47 m_pWidget2 = pWidget2; 51 48 } 52 49 53 void UISliding Widget::setWidgets(QWidget *pWidget1, QWidget *pWidget2)50 void UISlidingAnimation::animate(SlidingDirection enmDirection) 54 51 { 55 /* Clear animation/widgets if any: */ 56 delete m_pAnimation; 57 delete m_pWidget1; 58 delete m_pWidget2; 52 /* Acquire parent size: */ 53 const QSize parentSize = parentWidget()->size(); 59 54 60 /* Remember widgets: */ 61 m_pWidget1 = pWidget1; 62 m_pWidget2 = pWidget2; 63 m_pLayout->addWidget(m_pWidget1); 64 m_pLayout->addWidget(m_pWidget2); 55 /* Update animation boundaries based on parent size: */ 56 switch (m_enmOrientation) 57 { 58 case Qt::Horizontal: 59 { 60 m_startWidgetGeometry = QRect( 0, 0, 61 2 * parentSize.width(), parentSize.height()); 62 m_finalWidgetGeometry = QRect(- parentSize.width(), 0, 63 2 * parentSize.width(), parentSize.height()); 64 break; 65 } 66 case Qt::Vertical: 67 { 68 m_startWidgetGeometry = QRect(0, 0, 69 parentSize.width(), 2 * parentSize.height()); 70 m_finalWidgetGeometry = QRect(0, - parentSize.height(), 71 parentSize.width(), 2 * parentSize.height()); 72 break; 73 } 74 } 75 if (m_pAnimation) 76 m_pAnimation->update(); 65 77 66 /* Install new animation: */ 78 /* Update label content: */ 79 QPixmap pixmap1(parentSize); 80 QPixmap pixmap2(parentSize); 81 m_pWidget1->render(&pixmap1); 82 m_pWidget2->render(&pixmap2); 83 m_pLabel1->setPixmap(pixmap1); 84 m_pLabel2->setPixmap(pixmap2); 85 86 /* Update initial widget geometry: */ 87 switch (enmDirection) 88 { 89 case SlidingDirection_Forward: 90 { 91 setWidgetGeometry(m_startWidgetGeometry); 92 emit sigForward(); 93 break; 94 } 95 case SlidingDirection_Reverse: 96 { 97 setWidgetGeometry(m_finalWidgetGeometry); 98 emit sigReverse(); 99 break; 100 } 101 } 102 } 103 104 void UISlidingAnimation::prepare() 105 { 106 /* Create animation: */ 67 107 m_pAnimation = UIAnimation::installPropertyAnimation(this, 68 108 "widgetGeometry", 69 109 "startWidgetGeometry", "finalWidgetGeometry", 70 SIGNAL(sigForward()), SIGNAL(sig Backward()));71 connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISliding Widget::sltSetStateToStart);72 connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISliding Widget::sltSetStateToFinal);110 SIGNAL(sigForward()), SIGNAL(sigReverse())); 111 connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISlidingAnimation::sltHandleStateEnteredStart); 112 connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISlidingAnimation::sltHandleStateEnteredFinal); 73 113 74 /* Update animation: */75 updateAnimation();76 /* Update widget geometry: */77 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);78 }79 80 bool UISlidingWidget::event(QEvent *pEvent)81 {82 /* Process desired events: */83 switch (pEvent->type())84 {85 case QEvent::LayoutRequest:86 {87 // WORKAROUND:88 // Since we are not connected to89 // our children LayoutRequest,90 // we should update geometry91 // ourselves.92 updateGeometry();93 break;94 }95 default:96 break;97 }98 99 /* Call to base class: */100 return QWidget::event(pEvent);101 }102 103 void UISlidingWidget::resizeEvent(QResizeEvent *pEvent)104 {105 /* Call to base-class: */106 QWidget::resizeEvent(pEvent);107 108 /* Update animation: */109 updateAnimation();110 /* Update widget geometry: */111 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);112 }113 114 void UISlidingWidget::prepare()115 {116 114 /* Create private sliding widget: */ 117 115 m_pWidget = new QWidget(this); … … 119 117 { 120 118 /* Create layout: */ 119 QBoxLayout *pLayout = 0; 121 120 switch (m_enmOrientation) 122 121 { 123 case Qt::Horizontal: m_pLayout = new QHBoxLayout(m_pWidget); break;124 case Qt::Vertical: m_pLayout = new QVBoxLayout(m_pWidget); break;122 case Qt::Horizontal: pLayout = new QHBoxLayout(m_pWidget); break; 123 case Qt::Vertical: pLayout = new QVBoxLayout(m_pWidget); break; 125 124 } 126 if ( m_pLayout)125 if (pLayout) 127 126 { 128 127 /* Configure layout: */ 129 m_pLayout->setSpacing(0); 130 m_pLayout->setContentsMargins(0, 0, 0, 0); 128 pLayout->setSpacing(0); 129 pLayout->setContentsMargins(0, 0, 0, 0); 130 131 /* Create 1st label: */ 132 m_pLabel1 = new QLabel; 133 if (m_pLabel1) 134 pLayout->addWidget(m_pLabel1); 135 /* Create 2nd label: */ 136 m_pLabel2 = new QLabel; 137 if (m_pLabel2) 138 pLayout->addWidget(m_pLabel2); 131 139 } 132 140 } 133 141 134 /* Update animation: */ 135 updateAnimation(); 136 /* Update widget geometry: */ 137 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry); 142 /* Assign initial widget geometry: */ 143 m_pWidget->setGeometry(0, 0, width(), height()); 138 144 } 139 145 140 void UISliding Widget::updateAnimation()146 void UISlidingAnimation::setWidgetGeometry(const QRect &rect) 141 147 { 142 /* Recalculate sub-window geometry animation boundaries based on size-hint: */ 143 switch (m_enmOrientation) 144 { 145 case Qt::Horizontal: 146 { 147 m_startWidgetGeometry = QRect( 0, 0, 148 2 * width(), height()); 149 m_finalWidgetGeometry = QRect(- width(), 0, 150 2 * width(), height()); 151 break; 152 } 153 case Qt::Vertical: 154 { 155 m_startWidgetGeometry = QRect(0, 0, 156 width(), 2 * height()); 157 m_finalWidgetGeometry = QRect(0, - height(), 158 width(), 2 * height()); 159 break; 160 } 161 } 162 163 /* Update animation finally: */ 164 if (m_pAnimation) 165 m_pAnimation->update(); 148 /* Define widget geometry: */ 149 if (m_pWidget) 150 m_pWidget->setGeometry(rect); 166 151 } 167 152 168 void UISlidingWidget::setWidgetGeometry(const QRect &rect) 169 { 170 /* Apply widget geometry: */ 171 m_pWidget->setGeometry(rect); 172 } 173 174 QRect UISlidingWidget::widgetGeometry() const 153 QRect UISlidingAnimation::widgetGeometry() const 175 154 { 176 155 /* Return widget geometry: */ 177 return m_pWidget ->geometry();156 return m_pWidget ? m_pWidget->geometry() : QRect(); 178 157 } -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingAnimation.h
r73799 r73842 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UISliding Widgetclass declaration.3 * VBox Qt GUI - UISlidingAnimation class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ___UISliding Widget_h___19 #define ___UISliding Widget_h___18 #ifndef ___UISlidingAnimation_h___ 19 #define ___UISlidingAnimation_h___ 20 20 21 21 /* Qt includes: */ … … 23 23 24 24 /* Forward declarations: */ 25 class Q BoxLayout;25 class QLabel; 26 26 class QRect; 27 27 class QWidget; … … 29 29 30 30 31 /** Some kind of splitter which allows to switch between 32 * two widgets using horizontal sliding animation. */ 33 class UISlidingWidget : public QWidget 31 /** Sliding direction. */ 32 enum SlidingDirection 33 { 34 SlidingDirection_Forward, 35 SlidingDirection_Reverse 36 }; 37 38 39 /** QWidget extension which renders a sliding animation 40 * while transiting from one widget to another. */ 41 class UISlidingAnimation : public QWidget 34 42 { 35 43 Q_OBJECT; … … 40 48 signals: 41 49 42 /** Commands to move animation forward. */50 /** Commands to move animation in forward direction. */ 43 51 void sigForward(); 44 /** Commands to move animation backward. */ 45 void sigBackward(); 52 /** Commands to move animation in reverse direction. */ 53 void sigReverse(); 54 55 /** Notifies listeners about animation in specified @a enmDirection is complete. */ 56 void sigAnimationComplete(SlidingDirection enmDirection); 46 57 47 58 public: 48 59 49 /** Sliding state. */ 50 enum State 51 { 52 State_Start, 53 State_GoingForward, 54 State_Final, 55 State_GoingBackward 56 }; 57 58 /** Constructs sliding widget passing @a pParent to the base-class. 60 /** Constructs sliding animation passing @a pParent to the base-class. 59 61 * @param enmOrientation Brings the widget orientation. */ 60 UISlidingWidget(Qt::Orientation enmOrientation, QWidget *pParent = 0); 61 62 /** Holds the minimum widget size. */ 63 virtual QSize minimumSizeHint() const /* pverride */; 62 UISlidingAnimation(Qt::Orientation enmOrientation, QWidget *pParent = 0); 64 63 65 64 /** Defines @a pWidget1 and @a pWidget2. */ 66 65 void setWidgets(QWidget *pWidget1, QWidget *pWidget2); 67 66 68 /** Returns sliding state. */ 69 State state() const { return m_enmState; } 70 71 /** Moves animation forward. */ 72 void moveForward() { m_enmState = State_GoingForward; emit sigForward(); } 73 /** Moves animation backward. */ 74 void moveBackward() { m_enmState = State_GoingBackward; emit sigBackward(); } 75 76 protected: 77 78 /** Handles any Qt @a pEvent. */ 79 virtual bool event(QEvent *pEvent) /* override */; 80 81 /** Handles resize @a pEvent. */ 82 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 67 /** Animates cached pWidget1 and pWidget2 in passed @a enmDirection. */ 68 void animate(SlidingDirection enmDirection); 83 69 84 70 private slots: 85 71 86 /** Marks state as start. */87 void slt SetStateToStart() { m_enmState = State_Start; }88 /** Marks state as final. */89 void slt SetStateToFinal() { m_enmState = State_Final; }72 /** Handles entering for 'Start' state. */ 73 void sltHandleStateEnteredStart() { emit sigAnimationComplete(SlidingDirection_Reverse); } 74 /** Handles entering for 'Final' state. */ 75 void sltHandleStateEnteredFinal() { emit sigAnimationComplete(SlidingDirection_Forward); } 90 76 91 77 private: … … 93 79 /** Prepares all. */ 94 80 void prepare(); 95 96 /** Updates animation. */97 void updateAnimation();98 81 99 82 /** Defines sub-window geometry. */ … … 108 91 /** Holds the widget orientation. */ 109 92 Qt::Orientation m_enmOrientation; 93 /** Holds the animation instance. */ 94 UIAnimation *m_pAnimation; 95 /** Holds sub-window start-geometry. */ 96 QRect m_startWidgetGeometry; 97 /** Holds sub-window final-geometry. */ 98 QRect m_finalWidgetGeometry; 110 99 111 /** Holds whether we are in animation final state. */ 112 State m_enmState; 113 /** Holds the shift left/right animation instance. */ 114 UIAnimation *m_pAnimation; 115 /** Holds sub-window start-geometry. */ 116 QRect m_startWidgetGeometry; 117 /** Holds sub-window final-geometry. */ 118 QRect m_finalWidgetGeometry; 100 /** Holds the sliding widget instance. */ 101 QWidget *m_pWidget; 102 /** Holds the 1st label instance. */ 103 QLabel *m_pLabel1; 104 /** Holds the 2nd label instance. */ 105 QLabel *m_pLabel2; 119 106 120 /** Holds the private sliding widget instance. */ 121 QWidget *m_pWidget; 122 /** Holds the widget layout instance. */ 123 QBoxLayout *m_pLayout; 124 /** Holds the 1st widget reference. */ 107 /** Holds the 1st rendered-widget reference. */ 125 108 QWidget *m_pWidget1; 126 /** Holds the 2nd widget reference. */109 /** Holds the 2nd rendered-widget reference. */ 127 110 QWidget *m_pWidget2; 128 111 }; 129 112 130 #endif /* !___UISlidingWidget_h___ */ 131 113 #endif /* !___UISlidingAnimation_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.

