VirtualBox

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

Last change on this file since 52958 was 52958, checked in by vboxsync, 10 years ago

Main: merged IMachine::readSavedThumbnailToArray and readSavedThumbnailPNGToArray

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