VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 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: 6.5 KB
Line 
1/* $Id: UIPopupStackViewport.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIPopupStackViewport class implementation.
4 */
5
6/*
7 * Copyright (C) 2013-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/* GUI includes: */
29#include "UIPopupPane.h"
30#include "UIPopupStackViewport.h"
31
32/* Other VBox includes: */
33#include <iprt/assert.h>
34
35
36UIPopupStackViewport::UIPopupStackViewport()
37 : m_iLayoutMargin(1)
38 , m_iLayoutSpacing(1)
39{
40}
41
42bool UIPopupStackViewport::exists(const QString &strID) const
43{
44 /* Is there already popup-pane with the same ID? */
45 return m_panes.contains(strID);
46}
47
48void UIPopupStackViewport::createPopupPane(const QString &strID,
49 const QString &strMessage, const QString &strDetails,
50 const QMap<int, QString> &buttonDescriptions)
51{
52 /* Make sure there is no such popup-pane already: */
53 if (m_panes.contains(strID))
54 {
55 AssertMsgFailed(("Popup-pane already exists!"));
56 return;
57 }
58
59 /* Create new popup-pane: */
60 UIPopupPane *pPopupPane = m_panes[strID] = new UIPopupPane(this,
61 strMessage, strDetails,
62 buttonDescriptions);
63
64 /* Attach popup-pane connection: */
65 connect(this, &UIPopupStackViewport::sigProposePopupPaneSize, pPopupPane, &UIPopupPane::sltHandleProposalForSize);
66 connect(pPopupPane, &UIPopupPane::sigSizeHintChanged, this, &UIPopupStackViewport::sltAdjustGeometry);
67 connect(pPopupPane, &UIPopupPane::sigDone, this, &UIPopupStackViewport::sltPopupPaneDone);
68
69 /* Show popup-pane: */
70 pPopupPane->show();
71}
72
73void UIPopupStackViewport::updatePopupPane(const QString &strID,
74 const QString &strMessage, const QString &strDetails)
75{
76 /* Make sure there is such popup-pane already: */
77 if (!m_panes.contains(strID))
78 {
79 AssertMsgFailed(("Popup-pane doesn't exists!"));
80 return;
81 }
82
83 /* Get existing popup-pane: */
84 UIPopupPane *pPopupPane = m_panes[strID];
85
86 /* Update message and details: */
87 pPopupPane->setMessage(strMessage);
88 pPopupPane->setDetails(strDetails);
89}
90
91void UIPopupStackViewport::recallPopupPane(const QString &strID)
92{
93 /* Make sure there is such popup-pane already: */
94 if (!m_panes.contains(strID))
95 {
96 AssertMsgFailed(("Popup-pane doesn't exists!"));
97 return;
98 }
99
100 /* Get existing popup-pane: */
101 UIPopupPane *pPopupPane = m_panes[strID];
102
103 /* Recall popup-pane: */
104 pPopupPane->recall();
105}
106
107void UIPopupStackViewport::sltHandleProposalForSize(QSize newSize)
108{
109 /* Subtract layout margins: */
110 newSize.setWidth(newSize.width() - 2 * m_iLayoutMargin);
111 newSize.setHeight(newSize.height() - 2 * m_iLayoutMargin);
112
113 /* Propagate resulting size to popups: */
114 emit sigProposePopupPaneSize(newSize);
115}
116
117void UIPopupStackViewport::sltAdjustGeometry()
118{
119 /* Update size-hint: */
120 updateSizeHint();
121
122 /* Layout content: */
123 layoutContent();
124
125 /* Notify parent popup-stack: */
126 emit sigSizeHintChanged();
127}
128
129void UIPopupStackViewport::sltPopupPaneDone(int iResultCode)
130{
131 /* Make sure the sender is the popup-pane: */
132 UIPopupPane *pPopupPane = qobject_cast<UIPopupPane*>(sender());
133 if (!pPopupPane)
134 {
135 AssertMsgFailed(("Should be called by popup-pane only!"));
136 return;
137 }
138
139 /* Make sure the popup-pane still exists: */
140 const QString strID(m_panes.key(pPopupPane, QString()));
141 if (strID.isNull())
142 {
143 AssertMsgFailed(("Popup-pane already destroyed!"));
144 return;
145 }
146
147 /* Notify listeners about popup-pane removal: */
148 emit sigPopupPaneDone(strID, iResultCode);
149
150 /* Delete popup-pane asyncronously.
151 * To avoid issues with events which already posted: */
152 m_panes.remove(strID);
153 pPopupPane->deleteLater();
154
155 /* Notify listeners about popup-pane removed: */
156 emit sigPopupPaneRemoved(strID);
157
158 /* Adjust geometry: */
159 sltAdjustGeometry();
160
161 /* Make sure this stack still contains popup-panes: */
162 if (!m_panes.isEmpty())
163 return;
164
165 /* Notify listeners about popup-stack: */
166 emit sigPopupPanesRemoved();
167}
168
169void UIPopupStackViewport::updateSizeHint()
170{
171 /* Calculate minimum width-hint: */
172 int iMinimumWidthHint = 0;
173 {
174 /* Take into account all the panes: */
175 foreach (UIPopupPane *pPane, m_panes)
176 iMinimumWidthHint = qMax(iMinimumWidthHint, pPane->minimumSizeHint().width());
177
178 /* And two margins finally: */
179 iMinimumWidthHint += 2 * m_iLayoutMargin;
180 }
181
182 /* Calculate minimum height-hint: */
183 int iMinimumHeightHint = 0;
184 {
185 /* Take into account all the panes: */
186 foreach (UIPopupPane *pPane, m_panes)
187 iMinimumHeightHint += pPane->minimumSizeHint().height();
188
189 /* Take into account all the spacings, if any: */
190 if (!m_panes.isEmpty())
191 iMinimumHeightHint += (m_panes.size() - 1) * m_iLayoutSpacing;
192
193 /* And two margins finally: */
194 iMinimumHeightHint += 2 * m_iLayoutMargin;
195 }
196
197 /* Compose minimum size-hint: */
198 m_minimumSizeHint = QSize(iMinimumWidthHint, iMinimumHeightHint);
199}
200
201void UIPopupStackViewport::layoutContent()
202{
203 /* Get attributes: */
204 int iX = m_iLayoutMargin;
205 int iY = m_iLayoutMargin;
206
207 /* Layout every pane we have: */
208 foreach (UIPopupPane *pPane, m_panes)
209 {
210 /* Get pane attributes: */
211 QSize paneSize = pPane->minimumSizeHint();
212 const int iPaneWidth = paneSize.width();
213 const int iPaneHeight = paneSize.height();
214 /* Adjust geometry for the pane: */
215 pPane->setGeometry(iX, iY, iPaneWidth, iPaneHeight);
216 pPane->layoutContent();
217 /* Increment placeholder: */
218 iY += (iPaneHeight + m_iLayoutSpacing);
219 }
220}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use