VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/UITakeSnapshotDialog.cpp@ 103578

Last change on this file since 103578 was 103578, checked in by vboxsync, 3 months ago

FE/Qt: UIShortcutPool: macOS no more support CMD+? as the default one help Contents shortcut; Let's use another one like CMD+/ (which is same just with Shift modifier released, because CMD+Shift+? now used for system-wide help Search menu).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1/* $Id: UITakeSnapshotDialog.cpp 103578 2024-02-26 17:29:33Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UITakeSnapshotDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QGridLayout>
30#include <QLabel>
31#include <QLineEdit>
32#include <QPushButton>
33#include <QStyle>
34#include <QWindow>
35
36/* GUI includes: */
37#include "QIDialogButtonBox.h"
38#include "QILabel.h"
39#include "VBoxUtils.h"
40#include "UICommon.h"
41#include "UIDesktopWidgetWatchdog.h"
42#include "UIHelpBrowserDialog.h"
43#include "UIShortcutPool.h"
44#include "UITakeSnapshotDialog.h"
45
46
47UITakeSnapshotDialog::UITakeSnapshotDialog(QWidget *pParent, ulong cImmutableMedia)
48 : QIWithRetranslateUI<QIDialog>(pParent)
49 , m_cImmutableMedia(cImmutableMedia)
50 , m_pLabelIcon(0)
51 , m_pLabelName(0), m_pEditorName(0)
52 , m_pLabelDescription(0), m_pEditorDescription(0)
53 , m_pLabelInfo(0)
54 , m_pButtonBox(0)
55{
56 prepare();
57}
58
59void UITakeSnapshotDialog::setIcon(const QIcon &icon)
60{
61 m_icon = icon;
62 updatePixmap();
63}
64
65void UITakeSnapshotDialog::setName(const QString &strName)
66{
67 m_pEditorName->setText(strName);
68}
69
70QString UITakeSnapshotDialog::name() const
71{
72 return m_pEditorName->text();
73}
74
75QString UITakeSnapshotDialog::description() const
76{
77 return m_pEditorDescription->toPlainText();
78}
79
80bool UITakeSnapshotDialog::event(QEvent *pEvent)
81{
82 /* Handle know event types: */
83 switch (pEvent->type())
84 {
85 case QEvent::Show:
86 case QEvent::ScreenChangeInternal:
87 {
88 /* Update pixmap: */
89 updatePixmap();
90 break;
91 }
92 default:
93 break;
94 }
95
96 /* Call to base-class: */
97 return QIWithRetranslateUI<QIDialog>::event(pEvent);
98}
99
100void UITakeSnapshotDialog::retranslateUi()
101{
102 setWindowTitle(tr("Take Snapshot of Virtual Machine"));
103 m_pLabelName->setText(tr("Snapshot &Name"));
104 m_pEditorName->setToolTip(tr("Holds the snapshot name"));
105 m_pLabelDescription->setText(tr("Snapshot &Description"));
106 m_pEditorDescription->setToolTip(tr("Holds the snapshot description"));
107 m_pLabelInfo->setText(tr("Warning: You are taking a snapshot of a running machine which has %n immutable image(s) "
108 "attached to it. As long as you are working from this snapshot the immutable image(s) "
109 "will not be reset to avoid loss of data.", "", m_cImmutableMedia));
110
111 if (m_pButtonBox)
112 {
113 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Ok"));
114 m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
115 m_pButtonBox->button(QDialogButtonBox::Help)->setText(tr("Help"));
116
117 m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Take Snapshot and close the dialog"));
118 m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close dialog without taking a snapshot"));
119 m_pButtonBox->button(QDialogButtonBox::Help)->setStatusTip(tr("Show dialog help"));
120
121 m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
122
123 if (m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString().isEmpty())
124 m_pButtonBox->button(QDialogButtonBox::Ok)->setToolTip(tr("Accept"));
125 else
126 m_pButtonBox->button(QDialogButtonBox::Ok)->setToolTip(tr("Accept (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
127
128 if (m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString().isEmpty())
129 m_pButtonBox->button(QDialogButtonBox::Cancel)->setToolTip(tr("Cancel"));
130 else
131 m_pButtonBox->button(QDialogButtonBox::Cancel)->setToolTip(tr("Cancel (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString()));
132
133 if (m_pButtonBox->button(QDialogButtonBox::Help)->shortcut().toString().isEmpty())
134 m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(tr("Show Help"));
135 else
136 m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(tr("Show Help (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Help)->shortcut().toString()));
137 }
138}
139
140void UITakeSnapshotDialog::sltHandleNameChanged(const QString &strName)
141{
142 /* Update button state depending on snapshot name value: */
143 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!strName.trimmed().isEmpty());
144}
145
146void UITakeSnapshotDialog::prepare()
147{
148 /* Prepare contents: */
149 prepareContents();
150
151 /* Apply language settings: */
152 retranslateUi();
153
154 /* Invent minimum size: */
155 QSize minimumSize;
156 const int iHostScreen = UIDesktopWidgetWatchdog::screenNumber(parentWidget());
157 if (iHostScreen >= 0 && iHostScreen < UIDesktopWidgetWatchdog::screenCount())
158 {
159 /* On the basis of current host-screen geometry if possible: */
160 const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);
161 if (screenGeometry.isValid())
162 minimumSize = screenGeometry.size() / 4;
163 }
164 /* Fallback to default size if we failed: */
165 if (minimumSize.isNull())
166 minimumSize = QSize(800, 600);
167 /* Resize to initial size: */
168 setMinimumSize(minimumSize);
169}
170
171void UITakeSnapshotDialog::prepareContents()
172{
173 /* Create layout: */
174 QGridLayout *pLayout = new QGridLayout(this);
175 if (pLayout)
176 {
177 /* Configure layout: */
178#ifdef VBOX_WS_MAC
179 pLayout->setSpacing(20);
180 pLayout->setContentsMargins(40, 20, 40, 20);
181#else
182 pLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) * 2);
183#endif
184
185 /* Create sub-layout: */
186 QVBoxLayout *pSubLayout1 = new QVBoxLayout;
187 if (pSubLayout1)
188 {
189 /* Create icon label: */
190 m_pLabelIcon = new QLabel;
191 if (m_pLabelIcon)
192 {
193 /* Configure label: */
194 m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
195
196 /* Add into layout: */
197 pSubLayout1->addWidget(m_pLabelIcon);
198 }
199
200 /* Add stretch: */
201 pSubLayout1->addStretch();
202
203 /* Add into layout: */
204 pLayout->addLayout(pSubLayout1, 0, 0, 2, 1);
205 }
206
207 /* Create sub-layout 2: */
208 QVBoxLayout *pSubLayout2 = new QVBoxLayout;
209 if (pSubLayout2)
210 {
211 /* Configure layout: */
212#ifdef VBOX_WS_MAC
213 pSubLayout2->setSpacing(5);
214#else
215 pSubLayout2->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);
216#endif
217
218 /* Create name label: */
219 m_pLabelName = new QLabel;
220 if (m_pLabelName)
221 {
222 /* Add into layout: */
223 pSubLayout2->addWidget(m_pLabelName);
224 }
225
226 /* Create name editor: */
227 m_pEditorName = new QLineEdit;
228 if (m_pEditorName)
229 {
230 /* Configure editor: */
231 m_pLabelName->setBuddy(m_pEditorName);
232 connect(m_pEditorName, &QLineEdit::textChanged,
233 this, &UITakeSnapshotDialog::sltHandleNameChanged);
234
235 /* Add into layout: */
236 pSubLayout2->addWidget(m_pEditorName);
237 }
238
239 /* Add into layout: */
240 pLayout->addLayout(pSubLayout2, 0, 1);
241 }
242
243 /* Create sub-layout 3: */
244 QVBoxLayout *pSubLayout3 = new QVBoxLayout;
245 if (pSubLayout3)
246 {
247 /* Configure layout: */
248#ifdef VBOX_WS_MAC
249 pSubLayout3->setSpacing(5);
250#else
251 pSubLayout3->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);
252#endif
253
254 /* Create description label: */
255 m_pLabelDescription = new QLabel;
256 if (m_pLabelDescription)
257 {
258 /* Add into layout: */
259 pSubLayout3->addWidget(m_pLabelDescription);
260 }
261
262 /* Create description editor: */
263 m_pEditorDescription = new QTextEdit;
264 if (m_pEditorDescription)
265 {
266 /* Configure editor: */
267 m_pLabelDescription->setBuddy(m_pEditorDescription);
268
269 /* Add into layout: */
270 pSubLayout3->addWidget(m_pEditorDescription);
271 }
272
273 /* Add into layout: */
274 pLayout->addLayout(pSubLayout3, 1, 1);
275 }
276
277 /* Create information label: */
278 m_pLabelInfo = new QILabel;
279 if (m_pLabelInfo)
280 {
281 /* Configure label: */
282 m_pLabelInfo->setWordWrap(true);
283 m_pLabelInfo->useSizeHintForWidth(400);
284
285 /* Hide if machine have no immutable attachments: */
286 if (!m_cImmutableMedia)
287 m_pLabelInfo->setHidden(true);
288
289 /* Add into layout: */
290 pLayout->addWidget(m_pLabelInfo, 2, 0, 1, 2);
291 }
292
293 /* Create button-box: */
294 m_pButtonBox = new QIDialogButtonBox;
295 if (m_pButtonBox)
296 {
297 /* Configure button-box: */
298 m_pButtonBox->setStandardButtons( QDialogButtonBox::Ok
299 | QDialogButtonBox::Cancel
300 | QDialogButtonBox::Help);
301 connect(m_pButtonBox, &QIDialogButtonBox::accepted,
302 this, &UITakeSnapshotDialog::accept);
303 connect(m_pButtonBox, &QIDialogButtonBox::rejected,
304 this, &UITakeSnapshotDialog::reject);
305 connect(m_pButtonBox->button(QIDialogButtonBox::Help), &QPushButton::pressed,
306 m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
307 m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
308 uiCommon().setHelpKeyword(m_pButtonBox->button(QIDialogButtonBox::Help), "snapshots");
309
310 /* Add into layout: */
311 pLayout->addWidget(m_pButtonBox, 3, 0, 1, 2);
312 }
313 }
314}
315
316void UITakeSnapshotDialog::updatePixmap()
317{
318 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
319 const qreal fDevicePixelRatio = windowHandle() ? windowHandle()->devicePixelRatio() : 1;
320 m_pLabelIcon->setPixmap(m_icon.pixmap(QSize(iIconMetric, iIconMetric), fDevicePixelRatio));
321}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use