VirtualBox

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

Last change on this file since 82781 was 76606, checked in by vboxsync, 5 years ago

FE/Qt: Cleaning out old precompiled header experiment.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use