VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingAnimation.cpp@ 100347

Last change on this file since 100347 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: UISlidingAnimation.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISlidingAnimation class implementation.
4 */
5
6/*
7 * Copyright (C) 2017-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QEvent>
30#include <QHBoxLayout>
31#include <QLabel>
32#include <QVBoxLayout>
33
34/* GUI includes: */
35#include "UIAnimationFramework.h"
36#include "UISlidingAnimation.h"
37
38
39UISlidingAnimation::UISlidingAnimation(Qt::Orientation enmOrientation, bool fReverse, QWidget *pParent /* = 0 */)
40 : QWidget(pParent)
41 , m_enmOrientation(enmOrientation)
42 , m_fReverse(fReverse)
43 , m_pAnimation(0)
44 , m_fIsInProgress(false)
45 , m_pWidget(0)
46 , m_pLabel1(0)
47 , m_pLabel2(0)
48 , m_pWidget1(0)
49 , m_pWidget2(0)
50{
51 /* Prepare: */
52 prepare();
53}
54
55void UISlidingAnimation::setWidgets(QWidget *pWidget1, QWidget *pWidget2)
56{
57 /* Remember rendered widgets: */
58 m_pWidget1 = pWidget1;
59 m_pWidget2 = pWidget2;
60}
61
62void UISlidingAnimation::animate(SlidingDirection enmDirection)
63{
64 /* Mark animation started: */
65 m_fIsInProgress = true;
66
67 /* Acquire parent size: */
68 const QSize parentSize = parentWidget()->size();
69
70 /* Update animation boundaries based on parent size: */
71 switch (m_enmOrientation)
72 {
73 case Qt::Horizontal:
74 {
75 m_startWidgetGeometry = QRect( 0, 0,
76 2 * parentSize.width(), parentSize.height());
77 m_finalWidgetGeometry = QRect(- parentSize.width(), 0,
78 2 * parentSize.width(), parentSize.height());
79 break;
80 }
81 case Qt::Vertical:
82 {
83 m_startWidgetGeometry = QRect(0, 0,
84 parentSize.width(), 2 * parentSize.height());
85 m_finalWidgetGeometry = QRect(0, - parentSize.height(),
86 parentSize.width(), 2 * parentSize.height());
87 break;
88 }
89 }
90 if (m_pAnimation)
91 m_pAnimation->update();
92
93 /* Update label content: */
94 QPixmap pixmap1(parentSize);
95 QPixmap pixmap2(parentSize);
96 m_pWidget1->render(&pixmap1);
97 m_pWidget2->render(&pixmap2);
98 m_pLabel1->setPixmap(pixmap1);
99 m_pLabel2->setPixmap(pixmap2);
100
101 /* Update initial widget geometry: */
102 switch (enmDirection)
103 {
104 case SlidingDirection_Forward:
105 {
106 setWidgetGeometry(m_startWidgetGeometry);
107 emit sigForward();
108 break;
109 }
110 case SlidingDirection_Reverse:
111 {
112 setWidgetGeometry(m_finalWidgetGeometry);
113 emit sigReverse();
114 break;
115 }
116 }
117}
118
119void UISlidingAnimation::sltHandleStateEnteredStart()
120{
121 /* If animation started: */
122 if (m_fIsInProgress)
123 {
124 /* Mark animation finished: */
125 m_fIsInProgress = false;
126 /* And notify listeners: */
127 emit sigAnimationComplete(SlidingDirection_Reverse);
128 }
129}
130
131void UISlidingAnimation::sltHandleStateEnteredFinal()
132{
133 /* If animation started: */
134 if (m_fIsInProgress)
135 {
136 /* Mark animation finished: */
137 m_fIsInProgress = false;
138 /* And notify listeners: */
139 emit sigAnimationComplete(SlidingDirection_Forward);
140 }
141}
142
143void UISlidingAnimation::prepare()
144{
145 /* Create animation: */
146 m_pAnimation = UIAnimation::installPropertyAnimation(this,
147 "widgetGeometry",
148 "startWidgetGeometry", "finalWidgetGeometry",
149 SIGNAL(sigForward()), SIGNAL(sigReverse()), m_fReverse);
150 connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISlidingAnimation::sltHandleStateEnteredStart);
151 connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISlidingAnimation::sltHandleStateEnteredFinal);
152
153 /* Create private sliding widget: */
154 m_pWidget = new QWidget(this);
155 if (m_pWidget)
156 {
157 /* Create layout: */
158 QBoxLayout *pLayout = 0;
159 switch (m_enmOrientation)
160 {
161 case Qt::Horizontal: pLayout = new QHBoxLayout(m_pWidget); break;
162 case Qt::Vertical: pLayout = new QVBoxLayout(m_pWidget); break;
163 }
164 if (pLayout)
165 {
166 /* Configure layout: */
167 pLayout->setSpacing(0);
168 pLayout->setContentsMargins(0, 0, 0, 0);
169
170 /* Create 1st label: */
171 m_pLabel1 = new QLabel;
172 if (m_pLabel1)
173 pLayout->addWidget(m_pLabel1);
174 /* Create 2nd label: */
175 m_pLabel2 = new QLabel;
176 if (m_pLabel2)
177 pLayout->addWidget(m_pLabel2);
178 }
179 }
180
181 /* Assign initial widget geometry: */
182 m_pWidget->setGeometry(0, 0, width(), height());
183}
184
185void UISlidingAnimation::setWidgetGeometry(const QRect &rect)
186{
187 /* Define widget geometry: */
188 if (m_pWidget)
189 m_pWidget->setGeometry(rect);
190}
191
192QRect UISlidingAnimation::widgetGeometry() const
193{
194 /* Return widget geometry: */
195 return m_pWidget ? m_pWidget->geometry() : QRect();
196}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette