1 | /* $Id: VBoxSnapshotDetailsDlg.cpp 42382 2012-07-25 09:35:56Z 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 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QDateTime>
|
---|
26 | #include <QPushButton>
|
---|
27 | #include <QScrollArea>
|
---|
28 |
|
---|
29 | /* GUI includes: */
|
---|
30 | #include <VBoxGlobal.h>
|
---|
31 | #include <UIMessageCenter.h>
|
---|
32 | #include <VBoxSnapshotDetailsDlg.h>
|
---|
33 | #include <VBoxUtils.h>
|
---|
34 |
|
---|
35 | /* COM includes: */
|
---|
36 | #include "CMachine.h"
|
---|
37 |
|
---|
38 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
39 |
|
---|
40 | VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent)
|
---|
41 | : QIWithRetranslateUI <QDialog> (aParent)
|
---|
42 | {
|
---|
43 | /* Apply UI decorations */
|
---|
44 | Ui::VBoxSnapshotDetailsDlg::setupUi (this);
|
---|
45 |
|
---|
46 | /* Setup mLbThumbnail label */
|
---|
47 | mLbThumbnail->setCursor (Qt::PointingHandCursor);
|
---|
48 | mLbThumbnail->installEventFilter (this);
|
---|
49 |
|
---|
50 | /* Setup mTeDetails browser */
|
---|
51 | mTeDetails->viewport()->setAutoFillBackground (false);
|
---|
52 | mTeDetails->setFocus();
|
---|
53 |
|
---|
54 | /* Setup connections */
|
---|
55 | connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&)));
|
---|
56 | connect (mButtonBox, SIGNAL (helpRequested()), &msgCenter(), SLOT (sltShowHelpHelpDialog()));
|
---|
57 | }
|
---|
58 |
|
---|
59 | void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot)
|
---|
60 | {
|
---|
61 | mSnapshot = aSnapshot;
|
---|
62 | CMachine machine = mSnapshot.GetMachine();
|
---|
63 |
|
---|
64 | /* Get general properties */
|
---|
65 | mLeName->setText (aSnapshot.GetName());
|
---|
66 | mTeDescription->setText (aSnapshot.GetDescription());
|
---|
67 |
|
---|
68 | /* Get timestamp info */
|
---|
69 | QDateTime timestamp;
|
---|
70 | timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);
|
---|
71 | bool dateTimeToday = timestamp.date() == QDate::currentDate();
|
---|
72 | QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate);
|
---|
73 | mTxTaken->setText (dateTime);
|
---|
74 |
|
---|
75 | /* Get thumbnail if present */
|
---|
76 | ULONG width = 0, height = 0;
|
---|
77 | QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, true, width, height);
|
---|
78 | mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap();
|
---|
79 | QVector <BYTE> screenData = machine.ReadSavedScreenshotPNGToArray (0, width, height);
|
---|
80 | mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap();
|
---|
81 |
|
---|
82 | QGridLayout *lt = qobject_cast <QGridLayout*> (layout());
|
---|
83 | Assert (lt);
|
---|
84 | if (mThumbnail.isNull())
|
---|
85 | {
|
---|
86 | lt->removeWidget (mLbThumbnail);
|
---|
87 | mLbThumbnail->setHidden (true);
|
---|
88 |
|
---|
89 | lt->removeWidget (mLeName);
|
---|
90 | lt->removeWidget (mTxTaken);
|
---|
91 | lt->addWidget (mLeName, 0, 1, 1, 2);
|
---|
92 | lt->addWidget (mTxTaken, 1, 1, 1, 2);
|
---|
93 | }
|
---|
94 | else
|
---|
95 | {
|
---|
96 | lt->removeWidget (mLeName);
|
---|
97 | lt->removeWidget (mTxTaken);
|
---|
98 | lt->addWidget (mLeName, 0, 1);
|
---|
99 | lt->addWidget (mTxTaken, 1, 1);
|
---|
100 |
|
---|
101 | lt->removeWidget (mLbThumbnail);
|
---|
102 | lt->addWidget (mLbThumbnail, 0, 2, 2, 1);
|
---|
103 | mLbThumbnail->setHidden (false);
|
---|
104 | }
|
---|
105 |
|
---|
106 | retranslateUi();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void VBoxSnapshotDetailsDlg::putBackToSnapshot()
|
---|
110 | {
|
---|
111 | AssertReturn (!mSnapshot.isNull(), (void) 0);
|
---|
112 |
|
---|
113 | /* We need a session when we manipulate the snapshot data of a machine. */
|
---|
114 | CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId());
|
---|
115 | if (session.isNull())
|
---|
116 | return;
|
---|
117 |
|
---|
118 | mSnapshot.SetName(mLeName->text());
|
---|
119 | mSnapshot.SetDescription(mTeDescription->toPlainText());
|
---|
120 |
|
---|
121 | /* Close the session again. */
|
---|
122 | session.UnlockMachine();
|
---|
123 | }
|
---|
124 |
|
---|
125 | void VBoxSnapshotDetailsDlg::retranslateUi()
|
---|
126 | {
|
---|
127 | /* Translate uic generated strings */
|
---|
128 | Ui::VBoxSnapshotDetailsDlg::retranslateUi (this);
|
---|
129 |
|
---|
130 | if(mSnapshot.isNull())
|
---|
131 | return;
|
---|
132 |
|
---|
133 | CMachine machine = mSnapshot.GetMachine();
|
---|
134 |
|
---|
135 | setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName()));
|
---|
136 |
|
---|
137 | mLbThumbnail->setToolTip (mScreenshot.isNull() ? QString() : tr ("Click to enlarge the screenshot."));
|
---|
138 |
|
---|
139 | mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */));
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
143 | {
|
---|
144 | Assert (aObject == mLbThumbnail);
|
---|
145 | if (aEvent->type() == QEvent::MouseButtonPress && !mScreenshot.isNull())
|
---|
146 | {
|
---|
147 | VBoxScreenshotViewer *viewer = new VBoxScreenshotViewer (this, mScreenshot, mSnapshot.GetMachine().GetName(), mSnapshot.GetName());
|
---|
148 | viewer->show();
|
---|
149 | }
|
---|
150 | return QDialog::eventFilter (aObject, aEvent);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void VBoxSnapshotDetailsDlg::showEvent (QShowEvent *aEvent)
|
---|
154 | {
|
---|
155 | if (!mLbThumbnail->pixmap() && !mThumbnail.isNull())
|
---|
156 | {
|
---|
157 | mLbThumbnail->setPixmap (mThumbnail.scaled (QSize (1, mLbThumbnail->height()),
|
---|
158 | Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
---|
159 | retranslateUi();
|
---|
160 | }
|
---|
161 |
|
---|
162 | QDialog::showEvent (aEvent);
|
---|
163 | }
|
---|
164 |
|
---|
165 | void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText)
|
---|
166 | {
|
---|
167 | mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty());
|
---|
168 | }
|
---|
169 |
|
---|
170 | VBoxScreenshotViewer::VBoxScreenshotViewer (QWidget *aParent, const QPixmap &aScreenshot,
|
---|
171 | const QString &aSnapshotName, const QString &aMachineName)
|
---|
172 | : QIWithRetranslateUI2 <QWidget> (aParent, Qt::Tool)
|
---|
173 | , mArea (new QScrollArea (this))
|
---|
174 | , mPicture (new QLabel)
|
---|
175 | , mScreenshot (aScreenshot)
|
---|
176 | , mSnapshotName (aSnapshotName)
|
---|
177 | , mMachineName (aMachineName)
|
---|
178 | , mZoomMode (true)
|
---|
179 | {
|
---|
180 | setWindowModality (Qt::ApplicationModal);
|
---|
181 | setCursor (Qt::PointingHandCursor);
|
---|
182 | QVBoxLayout *layout = new QVBoxLayout (this);
|
---|
183 | layout->setMargin (0);
|
---|
184 |
|
---|
185 | mArea->setWidget (mPicture);
|
---|
186 | mArea->setWidgetResizable (true);
|
---|
187 | layout->addWidget (mArea);
|
---|
188 |
|
---|
189 | double aspectRatio = (double) aScreenshot.height() / aScreenshot.width();
|
---|
190 | QSize maxSize = aScreenshot.size() + QSize (mArea->frameWidth() * 2, mArea->frameWidth() * 2);
|
---|
191 | QSize initSize = QSize (640, (int)(640 * aspectRatio)).boundedTo (maxSize);
|
---|
192 |
|
---|
193 | setMaximumSize (maxSize);
|
---|
194 |
|
---|
195 | QRect geo (QPoint (0, 0), initSize);
|
---|
196 | geo.moveCenter (parentWidget()->geometry().center());
|
---|
197 | setGeometry (geo);
|
---|
198 |
|
---|
199 | retranslateUi();
|
---|
200 | }
|
---|
201 |
|
---|
202 | void VBoxScreenshotViewer::retranslateUi()
|
---|
203 | {
|
---|
204 | setWindowTitle (tr ("Screenshot of %1 (%2)").arg (mSnapshotName).arg (mMachineName));
|
---|
205 | }
|
---|
206 |
|
---|
207 | void VBoxScreenshotViewer::showEvent (QShowEvent *aEvent)
|
---|
208 | {
|
---|
209 | adjustPicture();
|
---|
210 | QIWithRetranslateUI2 <QWidget>::showEvent (aEvent);
|
---|
211 | }
|
---|
212 |
|
---|
213 | void VBoxScreenshotViewer::resizeEvent (QResizeEvent *aEvent)
|
---|
214 | {
|
---|
215 | adjustPicture();
|
---|
216 | QIWithRetranslateUI2 <QWidget>::resizeEvent (aEvent);
|
---|
217 | }
|
---|
218 |
|
---|
219 | void VBoxScreenshotViewer::mousePressEvent (QMouseEvent *aEvent)
|
---|
220 | {
|
---|
221 | mZoomMode = !mZoomMode;
|
---|
222 | adjustPicture();
|
---|
223 | QIWithRetranslateUI2 <QWidget>::mousePressEvent (aEvent);
|
---|
224 | }
|
---|
225 |
|
---|
226 | void VBoxScreenshotViewer::keyPressEvent (QKeyEvent *aEvent)
|
---|
227 | {
|
---|
228 | if (aEvent->key() == Qt::Key_Escape)
|
---|
229 | deleteLater();
|
---|
230 | QIWithRetranslateUI2 <QWidget>::keyPressEvent (aEvent);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void VBoxScreenshotViewer::adjustPicture()
|
---|
234 | {
|
---|
235 | if (mZoomMode)
|
---|
236 | {
|
---|
237 | mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
|
---|
238 | mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
|
---|
239 | mPicture->setPixmap (mScreenshot.scaled (mArea->viewport()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
---|
240 | mPicture->setToolTip (tr ("Click to view non-scaled screenshot."));
|
---|
241 | }
|
---|
242 | else
|
---|
243 | {
|
---|
244 | mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
|
---|
245 | mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAsNeeded);
|
---|
246 | mPicture->setPixmap (mScreenshot);
|
---|
247 | mPicture->setToolTip (tr ("Click to view scaled screenshot."));
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|