VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp@ 35740

Last change on this file since 35740 was 35710, checked in by vboxsync, 13 years ago

FE/Qt4: fix the update of a snapshot name or description

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 8.0 KB
Line 
1/* $Id: VBoxSnapshotDetailsDlg.cpp 35710 2011-01-25 13:14:13Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * VBoxSnapshotDetailsDlg class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2009 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifdef VBOX_WITH_PRECOMPILED_HEADERS
21# include "precomp.h"
22#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
23/* Global includes */
24#include <QDateTime>
25#include <QPushButton>
26#include <QScrollArea>
27
28/* Local includes */
29#include <VBoxGlobal.h>
30#include <VBoxProblemReporter.h>
31#include <VBoxSnapshotDetailsDlg.h>
32#include <VBoxUtils.h>
33#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
34
35VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent)
36 : QIWithRetranslateUI <QDialog> (aParent)
37{
38 /* Apply UI decorations */
39 Ui::VBoxSnapshotDetailsDlg::setupUi (this);
40
41 /* Setup mLbThumbnail label */
42 mLbThumbnail->setCursor (Qt::PointingHandCursor);
43 mLbThumbnail->installEventFilter (this);
44
45 /* Setup mTeDetails browser */
46 mTeDetails->viewport()->setAutoFillBackground (false);
47 mTeDetails->setFocus();
48
49 /* Setup connections */
50 connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&)));
51 connect (mButtonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
52}
53
54void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot)
55{
56 mSnapshot = aSnapshot;
57 CMachine machine = mSnapshot.GetMachine();
58
59 /* Get general properties */
60 mLeName->setText (aSnapshot.GetName());
61 mTeDescription->setText (aSnapshot.GetDescription());
62
63 /* Get timestamp info */
64 QDateTime timestamp;
65 timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);
66 bool dateTimeToday = timestamp.date() == QDate::currentDate();
67 QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate);
68 mTxTaken->setText (dateTime);
69
70 /* Get thumbnail if present */
71 ULONG width = 0, height = 0;
72 QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, true, width, height);
73 mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap();
74 QVector <BYTE> screenData = machine.ReadSavedScreenshotPNGToArray (0, width, height);
75 mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap();
76
77 QGridLayout *lt = qobject_cast <QGridLayout*> (layout());
78 Assert (lt);
79 if (mThumbnail.isNull())
80 {
81 lt->removeWidget (mLbThumbnail);
82 mLbThumbnail->setHidden (true);
83
84 lt->removeWidget (mLeName);
85 lt->removeWidget (mTxTaken);
86 lt->addWidget (mLeName, 0, 1, 1, 2);
87 lt->addWidget (mTxTaken, 1, 1, 1, 2);
88 }
89 else
90 {
91 lt->removeWidget (mLeName);
92 lt->removeWidget (mTxTaken);
93 lt->addWidget (mLeName, 0, 1);
94 lt->addWidget (mTxTaken, 1, 1);
95
96 lt->removeWidget (mLbThumbnail);
97 lt->addWidget (mLbThumbnail, 0, 2, 2, 1);
98 mLbThumbnail->setHidden (false);
99 }
100
101 retranslateUi();
102}
103
104void VBoxSnapshotDetailsDlg::putBackToSnapshot()
105{
106 AssertReturn (!mSnapshot.isNull(), (void) 0);
107
108 /* We need a session when we manipulate the snapshot data of a machine. */
109 CSession session = vboxGlobal().openSession(mSnapshot.GetMachine().GetId(), true);
110 if (session.isNull())
111 return;
112
113 mSnapshot.SetName(mLeName->text());
114 mSnapshot.SetDescription(mTeDescription->toPlainText());
115
116 /* Close the session again. */
117 session.UnlockMachine();
118}
119
120void VBoxSnapshotDetailsDlg::retranslateUi()
121{
122 /* Translate uic generated strings */
123 Ui::VBoxSnapshotDetailsDlg::retranslateUi (this);
124
125 if(mSnapshot.isNull())
126 return;
127
128 CMachine machine = mSnapshot.GetMachine();
129
130 setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName()));
131
132 mLbThumbnail->setToolTip (mScreenshot.isNull() ? QString() : tr ("Click to enlarge the screenshot."));
133
134 mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */));
135}
136
137bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent)
138{
139 Assert (aObject == mLbThumbnail);
140 if (aEvent->type() == QEvent::MouseButtonPress && !mScreenshot.isNull())
141 {
142 VBoxScreenshotViewer *viewer = new VBoxScreenshotViewer (this, mScreenshot, mSnapshot.GetMachine().GetName(), mSnapshot.GetName());
143 viewer->show();
144 }
145 return QDialog::eventFilter (aObject, aEvent);
146}
147
148void VBoxSnapshotDetailsDlg::showEvent (QShowEvent *aEvent)
149{
150 if (!mLbThumbnail->pixmap() && !mThumbnail.isNull())
151 {
152 mLbThumbnail->setPixmap (mThumbnail.scaled (QSize (1, mLbThumbnail->height()),
153 Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
154 retranslateUi();
155 }
156
157 QDialog::showEvent (aEvent);
158}
159
160void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText)
161{
162 mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty());
163}
164
165VBoxScreenshotViewer::VBoxScreenshotViewer (QWidget *aParent, const QPixmap &aScreenshot,
166 const QString &aSnapshotName, const QString &aMachineName)
167 : QIWithRetranslateUI2 <QWidget> (aParent, Qt::Tool)
168 , mArea (new QScrollArea (this))
169 , mPicture (new QLabel)
170 , mScreenshot (aScreenshot)
171 , mSnapshotName (aSnapshotName)
172 , mMachineName (aMachineName)
173 , mZoomMode (true)
174{
175 setWindowModality (Qt::ApplicationModal);
176 setCursor (Qt::PointingHandCursor);
177 QVBoxLayout *layout = new QVBoxLayout (this);
178 layout->setMargin (0);
179
180 mArea->setWidget (mPicture);
181 mArea->setWidgetResizable (true);
182 layout->addWidget (mArea);
183
184 double aspectRatio = (double) aScreenshot.height() / aScreenshot.width();
185 QSize maxSize = aScreenshot.size() + QSize (mArea->frameWidth() * 2, mArea->frameWidth() * 2);
186 QSize initSize = QSize (640, (int)(640 * aspectRatio)).boundedTo (maxSize);
187
188 setMaximumSize (maxSize);
189
190 QRect geo (QPoint (0, 0), initSize);
191 geo.moveCenter (parentWidget()->geometry().center());
192 setGeometry (geo);
193
194 retranslateUi();
195}
196
197void VBoxScreenshotViewer::retranslateUi()
198{
199 setWindowTitle (tr ("Screenshot of %1 (%2)").arg (mSnapshotName).arg (mMachineName));
200}
201
202void VBoxScreenshotViewer::showEvent (QShowEvent *aEvent)
203{
204 adjustPicture();
205 QIWithRetranslateUI2 <QWidget>::showEvent (aEvent);
206}
207
208void VBoxScreenshotViewer::resizeEvent (QResizeEvent *aEvent)
209{
210 adjustPicture();
211 QIWithRetranslateUI2 <QWidget>::resizeEvent (aEvent);
212}
213
214void VBoxScreenshotViewer::mousePressEvent (QMouseEvent *aEvent)
215{
216 mZoomMode = !mZoomMode;
217 adjustPicture();
218 QIWithRetranslateUI2 <QWidget>::mousePressEvent (aEvent);
219}
220
221void VBoxScreenshotViewer::keyPressEvent (QKeyEvent *aEvent)
222{
223 if (aEvent->key() == Qt::Key_Escape)
224 deleteLater();
225 QIWithRetranslateUI2 <QWidget>::keyPressEvent (aEvent);
226}
227
228void VBoxScreenshotViewer::adjustPicture()
229{
230 if (mZoomMode)
231 {
232 mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
233 mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
234 mPicture->setPixmap (mScreenshot.scaled (mArea->viewport()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
235 mPicture->setToolTip (tr ("Click to view non-scaled screenshot."));
236 }
237 else
238 {
239 mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
240 mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAsNeeded);
241 mPicture->setPixmap (mScreenshot);
242 mPicture->setToolTip (tr ("Click to view scaled screenshot."));
243 }
244}
245
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use