[26719] | 1 | /* $Id: VBoxSnapshotDetailsDlg.cpp 35710 2011-01-25 13:14:13Z vboxsync $ */
|
---|
[8740] | 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
| 5 | * VBoxSnapshotDetailsDlg class implementation
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
[28800] | 9 | * Copyright (C) 2008-2009 Oracle Corporation
|
---|
[8740] | 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 |
|
---|
[25526] | 20 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
| 21 | # include "precomp.h"
|
---|
| 22 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
[24732] | 23 | /* Global includes */
|
---|
| 24 | #include <QDateTime>
|
---|
| 25 | #include <QPushButton>
|
---|
| 26 | #include <QScrollArea>
|
---|
| 27 |
|
---|
| 28 | /* Local includes */
|
---|
[8740] | 29 | #include <VBoxGlobal.h>
|
---|
| 30 | #include <VBoxProblemReporter.h>
|
---|
[24732] | 31 | #include <VBoxSnapshotDetailsDlg.h>
|
---|
[8740] | 32 | #include <VBoxUtils.h>
|
---|
[25526] | 33 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
[8740] | 34 |
|
---|
| 35 | VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent)
|
---|
[24732] | 36 | : QIWithRetranslateUI <QDialog> (aParent)
|
---|
[8740] | 37 | {
|
---|
| 38 | /* Apply UI decorations */
|
---|
[9056] | 39 | Ui::VBoxSnapshotDetailsDlg::setupUi (this);
|
---|
[8740] | 40 |
|
---|
[24732] | 41 | /* Setup mLbThumbnail label */
|
---|
| 42 | mLbThumbnail->setCursor (Qt::PointingHandCursor);
|
---|
| 43 | mLbThumbnail->installEventFilter (this);
|
---|
[8740] | 44 |
|
---|
[24732] | 45 | /* Setup mTeDetails browser */
|
---|
| 46 | mTeDetails->viewport()->setAutoFillBackground (false);
|
---|
| 47 | mTeDetails->setFocus();
|
---|
| 48 |
|
---|
[8740] | 49 | /* Setup connections */
|
---|
[24732] | 50 | connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&)));
|
---|
| 51 | connect (mButtonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
|
---|
[8740] | 52 | }
|
---|
| 53 |
|
---|
| 54 | void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot)
|
---|
| 55 | {
|
---|
| 56 | mSnapshot = aSnapshot;
|
---|
[24732] | 57 | CMachine machine = mSnapshot.GetMachine();
|
---|
[8740] | 58 |
|
---|
[24732] | 59 | /* Get general properties */
|
---|
[8740] | 60 | mLeName->setText (aSnapshot.GetName());
|
---|
| 61 | mTeDescription->setText (aSnapshot.GetDescription());
|
---|
| 62 |
|
---|
[24732] | 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;
|
---|
[29354] | 72 | QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, true, width, height);
|
---|
[24737] | 73 | mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap();
|
---|
[29354] | 74 | QVector <BYTE> screenData = machine.ReadSavedScreenshotPNGToArray (0, width, height);
|
---|
[24737] | 75 | mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap();
|
---|
| 76 |
|
---|
[24732] | 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 |
|
---|
[9056] | 101 | retranslateUi();
|
---|
[8740] | 102 | }
|
---|
| 103 |
|
---|
| 104 | void VBoxSnapshotDetailsDlg::putBackToSnapshot()
|
---|
| 105 | {
|
---|
| 106 | AssertReturn (!mSnapshot.isNull(), (void) 0);
|
---|
| 107 |
|
---|
[35710] | 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();
|
---|
[8740] | 118 | }
|
---|
| 119 |
|
---|
[9056] | 120 | void 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 |
|
---|
[24732] | 130 | setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName()));
|
---|
[9056] | 131 |
|
---|
[24737] | 132 | mLbThumbnail->setToolTip (mScreenshot.isNull() ? QString() : tr ("Click to enlarge the screenshot."));
|
---|
| 133 |
|
---|
[24732] | 134 | mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */));
|
---|
[9056] | 135 | }
|
---|
| 136 |
|
---|
[24732] | 137 | bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
| 138 | {
|
---|
| 139 | Assert (aObject == mLbThumbnail);
|
---|
[24737] | 140 | if (aEvent->type() == QEvent::MouseButtonPress && !mScreenshot.isNull())
|
---|
[24732] | 141 | {
|
---|
[24737] | 142 | VBoxScreenshotViewer *viewer = new VBoxScreenshotViewer (this, mScreenshot, mSnapshot.GetMachine().GetName(), mSnapshot.GetName());
|
---|
[24732] | 143 | viewer->show();
|
---|
| 144 | }
|
---|
| 145 | return QDialog::eventFilter (aObject, aEvent);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | void 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 |
|
---|
[8740] | 160 | void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText)
|
---|
| 161 | {
|
---|
| 162 | mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty());
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[24732] | 165 | VBoxScreenshotViewer::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 |
|
---|
[24737] | 184 | double aspectRatio = (double) aScreenshot.height() / aScreenshot.width();
|
---|
[24732] | 185 | QSize maxSize = aScreenshot.size() + QSize (mArea->frameWidth() * 2, mArea->frameWidth() * 2);
|
---|
[25764] | 186 | QSize initSize = QSize (640, (int)(640 * aspectRatio)).boundedTo (maxSize);
|
---|
[24732] | 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 |
|
---|
| 197 | void VBoxScreenshotViewer::retranslateUi()
|
---|
| 198 | {
|
---|
| 199 | setWindowTitle (tr ("Screenshot of %1 (%2)").arg (mSnapshotName).arg (mMachineName));
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | void VBoxScreenshotViewer::showEvent (QShowEvent *aEvent)
|
---|
| 203 | {
|
---|
| 204 | adjustPicture();
|
---|
| 205 | QIWithRetranslateUI2 <QWidget>::showEvent (aEvent);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | void VBoxScreenshotViewer::resizeEvent (QResizeEvent *aEvent)
|
---|
| 209 | {
|
---|
| 210 | adjustPicture();
|
---|
| 211 | QIWithRetranslateUI2 <QWidget>::resizeEvent (aEvent);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void VBoxScreenshotViewer::mousePressEvent (QMouseEvent *aEvent)
|
---|
| 215 | {
|
---|
| 216 | mZoomMode = !mZoomMode;
|
---|
| 217 | adjustPicture();
|
---|
| 218 | QIWithRetranslateUI2 <QWidget>::mousePressEvent (aEvent);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | void VBoxScreenshotViewer::keyPressEvent (QKeyEvent *aEvent)
|
---|
| 222 | {
|
---|
| 223 | if (aEvent->key() == Qt::Key_Escape)
|
---|
| 224 | deleteLater();
|
---|
| 225 | QIWithRetranslateUI2 <QWidget>::keyPressEvent (aEvent);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void 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 |
|
---|