VirtualBox

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

Last change on this file since 62493 was 62493, checked in by vboxsync, 9 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: UIPopupStackViewport.cpp 62493 2016-07-22 18:44:18Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIPopupStackViewport class implementation.
4 */
5
6/*
7 * Copyright (C) 2013-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21/* GUI includes: */
22# include "UIPopupStackViewport.h"
23# include "UIPopupPane.h"
24
25/* Other VBox includes: */
26# include <VBox/sup.h>
27
28#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
29
30
31UIPopupStackViewport::UIPopupStackViewport()
32 : m_iLayoutMargin(1)
33 , m_iLayoutSpacing(1)
34{
35}
36
37bool UIPopupStackViewport::exists(const QString &strPopupPaneID) const
38{
39 /* Is there already popup-pane with the same ID? */
40 return m_panes.contains(strPopupPaneID);
41}
42
43void UIPopupStackViewport::createPopupPane(const QString &strPopupPaneID,
44 const QString &strMessage, const QString &strDetails,
45 const QMap<int, QString> &buttonDescriptions)
46{
47 /* Make sure there is no such popup-pane already: */
48 if (m_panes.contains(strPopupPaneID))
49 {
50 AssertMsgFailed(("Popup-pane already exists!"));
51 return;
52 }
53
54 /* Create new popup-pane: */
55 UIPopupPane *pPopupPane = m_panes[strPopupPaneID] = new UIPopupPane(this,
56 strMessage, strDetails,
57 buttonDescriptions);
58
59 /* Attach popup-pane connection: */
60 connect(this, SIGNAL(sigProposePopupPaneWidth(int)), pPopupPane, SLOT(sltHandleProposalForWidth(int)));
61 connect(pPopupPane, SIGNAL(sigSizeHintChanged()), this, SLOT(sltAdjustGeometry()));
62 connect(pPopupPane, SIGNAL(sigDone(int)), this, SLOT(sltPopupPaneDone(int)));
63
64 /* Show popup-pane: */
65 pPopupPane->show();
66}
67
68void UIPopupStackViewport::updatePopupPane(const QString &strPopupPaneID,
69 const QString &strMessage, const QString &strDetails)
70{
71 /* Make sure there is such popup-pane already: */
72 if (!m_panes.contains(strPopupPaneID))
73 {
74 AssertMsgFailed(("Popup-pane doesn't exists!"));
75 return;
76 }
77
78 /* Get existing popup-pane: */
79 UIPopupPane *pPopupPane = m_panes[strPopupPaneID];
80
81 /* Update message and details: */
82 pPopupPane->setMessage(strMessage);
83 pPopupPane->setDetails(strDetails);
84}
85
86void UIPopupStackViewport::recallPopupPane(const QString &strPopupPaneID)
87{
88 /* Make sure there is such popup-pane already: */
89 if (!m_panes.contains(strPopupPaneID))
90 {
91 AssertMsgFailed(("Popup-pane doesn't exists!"));
92 return;
93 }
94
95 /* Get existing popup-pane: */
96 UIPopupPane *pPopupPane = m_panes[strPopupPaneID];
97
98 /* Recall popup-pane: */
99 pPopupPane->recall();
100}
101
102void UIPopupStackViewport::sltHandleProposalForWidth(int iWidth)
103{
104 /* Subtract layout margins: */
105 iWidth -= 2 * m_iLayoutMargin;
106
107 /* Propagate resulting width to popups: */
108 emit sigProposePopupPaneWidth(iWidth);
109}
110
111void UIPopupStackViewport::sltAdjustGeometry()
112{
113 /* Update size-hint: */
114 updateSizeHint();
115
116 /* Layout content: */
117 layoutContent();
118
119 /* Notify parent popup-stack: */
120 emit sigSizeHintChanged();
121}
122
123void UIPopupStackViewport::sltPopupPaneDone(int iResultCode)
124{
125 /* Make sure the sender is the popup-pane: */
126 UIPopupPane *pPopupPane = qobject_cast<UIPopupPane*>(sender());
127 if (!pPopupPane)
128 {
129 AssertMsgFailed(("Should be called by popup-pane only!"));
130 return;
131 }
132
133 /* Make sure the popup-pane still exists: */
134 const QString strPopupPaneID(m_panes.key(pPopupPane, QString()));
135 if (strPopupPaneID.isNull())
136 {
137 AssertMsgFailed(("Popup-pane already destroyed!"));
138 return;
139 }
140
141 /* Notify listeners about popup-pane removal: */
142 emit sigPopupPaneDone(strPopupPaneID, iResultCode);
143
144 /* Delete popup-pane asyncronously.
145 * To avoid issues with events which already posted: */
146 m_panes.remove(strPopupPaneID);
147 pPopupPane->deleteLater();
148
149 /* Notify listeners about popup-pane removed: */
150 emit sigPopupPaneRemoved(strPopupPaneID);
151
152 /* Adjust geometry: */
153 sltAdjustGeometry();
154
155 /* Make sure this stack still contains popup-panes: */
156 if (!m_panes.isEmpty())
157 return;
158
159 /* Notify listeners about popup-stack: */
160 emit sigPopupPanesRemoved();
161}
162
163void UIPopupStackViewport::updateSizeHint()
164{
165 /* Calculate minimum width-hint: */
166 int iMinimumWidthHint = 0;
167 {
168 /* Take into account all the panes: */
169 foreach (UIPopupPane *pPane, m_panes)
170 iMinimumWidthHint = qMax(iMinimumWidthHint, pPane->minimumSizeHint().width());
171
172 /* And two margins finally: */
173 iMinimumWidthHint += 2 * m_iLayoutMargin;
174 }
175
176 /* Calculate minimum height-hint: */
177 int iMinimumHeightHint = 0;
178 {
179 /* Take into account all the panes: */
180 foreach (UIPopupPane *pPane, m_panes)
181 iMinimumHeightHint += pPane->minimumSizeHint().height();
182
183 /* Take into account all the spacings, if any: */
184 if (!m_panes.isEmpty())
185 iMinimumHeightHint += (m_panes.size() - 1) * m_iLayoutSpacing;
186
187 /* And two margins finally: */
188 iMinimumHeightHint += 2 * m_iLayoutMargin;
189 }
190
191 /* Compose minimum size-hint: */
192 m_minimumSizeHint = QSize(iMinimumWidthHint, iMinimumHeightHint);
193}
194
195void UIPopupStackViewport::layoutContent()
196{
197 /* Get attributes: */
198 int iX = m_iLayoutMargin;
199 int iY = m_iLayoutMargin;
200
201 /* Layout every pane we have: */
202 foreach (UIPopupPane *pPane, m_panes)
203 {
204 /* Get pane attributes: */
205 QSize paneSize = pPane->minimumSizeHint();
206 const int iPaneWidth = paneSize.width();
207 const int iPaneHeight = paneSize.height();
208 /* Adjust geometry for the pane: */
209 pPane->setGeometry(iX, iY, iPaneWidth, iPaneHeight);
210 pPane->layoutContent();
211 /* Increment placeholder: */
212 iY += (iPaneHeight + m_iLayoutSpacing);
213 }
214}
215
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