VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISlidingWidget.cpp

Last change on this file was 106061, checked in by vboxsync, 4 weeks 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.4 KB
RevLine 
[68152]1/* $Id: UISlidingWidget.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISlidingWidget class implementation.
4 */
5
6/*
[106061]7 * Copyright (C) 2017-2024 Oracle and/or its affiliates.
[68152]8 *
[96407]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
[68152]26 */
27
28/* Qt includes: */
[68287]29#include <QEvent>
[68152]30#include <QHBoxLayout>
[73799]31#include <QVBoxLayout>
[68152]32
33/* GUI includes: */
[68166]34#include "UIAnimationFramework.h"
[68152]35#include "UISlidingWidget.h"
36
37
[73799]38UISlidingWidget::UISlidingWidget(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
[68152]39 : QWidget(pParent)
[73799]40 , m_enmOrientation(enmOrientation)
[73598]41 , m_enmState(State_Start)
[68152]42 , m_pAnimation(0)
43 , m_pWidget(0)
44 , m_pLayout(0)
45 , m_pWidget1(0)
46 , m_pWidget2(0)
47{
48 /* Prepare: */
49 prepare();
50}
51
52QSize UISlidingWidget::minimumSizeHint() const
53{
54 /* Return maximum of minimum size-hints: */
55 QSize msh = QSize();
56 if (m_pWidget1)
57 msh = msh.expandedTo(m_pWidget1->minimumSizeHint());
58 if (m_pWidget2)
59 msh = msh.expandedTo(m_pWidget2->minimumSizeHint());
60 return msh;
61}
62
63void UISlidingWidget::setWidgets(QWidget *pWidget1, QWidget *pWidget2)
64{
65 /* Clear animation/widgets if any: */
66 delete m_pAnimation;
67 delete m_pWidget1;
68 delete m_pWidget2;
69
70 /* Remember widgets: */
71 m_pWidget1 = pWidget1;
72 m_pWidget2 = pWidget2;
73 m_pLayout->addWidget(m_pWidget1);
74 m_pLayout->addWidget(m_pWidget2);
75
76 /* Install new animation: */
77 m_pAnimation = UIAnimation::installPropertyAnimation(this,
78 "widgetGeometry",
79 "startWidgetGeometry", "finalWidgetGeometry",
80 SIGNAL(sigForward()), SIGNAL(sigBackward()));
81 connect(m_pAnimation, &UIAnimation::sigStateEnteredStart, this, &UISlidingWidget::sltSetStateToStart);
82 connect(m_pAnimation, &UIAnimation::sigStateEnteredFinal, this, &UISlidingWidget::sltSetStateToFinal);
83
84 /* Update animation: */
85 updateAnimation();
86 /* Update widget geometry: */
[73598]87 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
[68152]88}
89
[68287]90bool UISlidingWidget::event(QEvent *pEvent)
91{
92 /* Process desired events: */
93 switch (pEvent->type())
94 {
95 case QEvent::LayoutRequest:
96 {
97 // WORKAROUND:
98 // Since we are not connected to
99 // our children LayoutRequest,
100 // we should update geometry
101 // ourselves.
102 updateGeometry();
103 break;
104 }
105 default:
106 break;
107 }
108
109 /* Call to base class: */
110 return QWidget::event(pEvent);
111}
112
[68152]113void UISlidingWidget::resizeEvent(QResizeEvent *pEvent)
114{
115 /* Call to base-class: */
116 QWidget::resizeEvent(pEvent);
117
118 /* Update animation: */
119 updateAnimation();
120 /* Update widget geometry: */
[73598]121 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
[68152]122}
123
124void UISlidingWidget::prepare()
125{
126 /* Create private sliding widget: */
127 m_pWidget = new QWidget(this);
128 if (m_pWidget)
129 {
130 /* Create layout: */
[73799]131 switch (m_enmOrientation)
132 {
133 case Qt::Horizontal: m_pLayout = new QHBoxLayout(m_pWidget); break;
134 case Qt::Vertical: m_pLayout = new QVBoxLayout(m_pWidget); break;
135 }
[68152]136 if (m_pLayout)
137 {
138 /* Configure layout: */
139 m_pLayout->setSpacing(0);
140 m_pLayout->setContentsMargins(0, 0, 0, 0);
141 }
142 }
143
144 /* Update animation: */
145 updateAnimation();
146 /* Update widget geometry: */
[73598]147 m_pWidget->setGeometry(m_enmState == State_Final ? m_finalWidgetGeometry : m_startWidgetGeometry);
[68152]148}
149
150void UISlidingWidget::updateAnimation()
151{
152 /* Recalculate sub-window geometry animation boundaries based on size-hint: */
[73799]153 switch (m_enmOrientation)
154 {
155 case Qt::Horizontal:
156 {
157 m_startWidgetGeometry = QRect( 0, 0,
158 2 * width(), height());
159 m_finalWidgetGeometry = QRect(- width(), 0,
160 2 * width(), height());
161 break;
162 }
163 case Qt::Vertical:
164 {
[73800]165 m_startWidgetGeometry = QRect(0, 0,
166 width(), 2 * height());
167 m_finalWidgetGeometry = QRect(0, - height(),
168 width(), 2 * height());
[73799]169 break;
170 }
171 }
[68152]172
173 /* Update animation finally: */
174 if (m_pAnimation)
175 m_pAnimation->update();
176}
177
178void UISlidingWidget::setWidgetGeometry(const QRect &rect)
179{
180 /* Apply widget geometry: */
181 m_pWidget->setGeometry(rect);
182}
183
184QRect UISlidingWidget::widgetGeometry() const
185{
186 /* Return widget geometry: */
187 return m_pWidget->geometry();
188}
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