- Timestamp:
- May 30, 2017 3:23:23 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp
r67144 r67146 5 5 6 6 /* 7 * Copyright (C) 2008-201 6Oracle Corporation7 * Copyright (C) 2008-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 259 259 *********************************************************************************************************************************/ 260 260 261 VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent) 262 : QIWithRetranslateUI <QDialog> (aParent) 263 { 264 /* Apply UI decorations */ 265 Ui::VBoxSnapshotDetailsDlg::setupUi (this); 266 267 /* Setup mLbThumbnail label */ 268 mLbThumbnail->setCursor (Qt::PointingHandCursor); 269 mLbThumbnail->installEventFilter (this); 270 271 /* Setup mTeDetails browser */ 272 mTeDetails->viewport()->setAutoFillBackground (false); 273 mTeDetails->setFocus(); 274 275 /* Setup connections */ 276 connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&))); 277 connect (mButtonBox, SIGNAL (helpRequested()), &msgCenter(), SLOT (sltShowHelpHelpDialog())); 278 } 279 280 void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot) 281 { 282 mSnapshot = aSnapshot; 283 CMachine machine = mSnapshot.GetMachine(); 284 285 /* Get general properties */ 286 mLeName->setText (aSnapshot.GetName()); 287 mTeDescription->setText (aSnapshot.GetDescription()); 288 289 /* Get timestamp info */ 290 QDateTime timestamp; 291 timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000); 292 bool dateTimeToday = timestamp.date() == QDate::currentDate(); 293 QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate); 294 mTxTaken->setText (dateTime); 295 296 /* Get thumbnail if present */ 297 ULONG width = 0, height = 0; 298 QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, KBitmapFormat_BGR0, width, height); 299 mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap(); 300 QVector <BYTE> screenData = machine.ReadSavedScreenshotToArray (0, KBitmapFormat_PNG, width, height); 301 mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap(); 302 303 QGridLayout *lt = qobject_cast <QGridLayout*> (layout()); 304 Assert (lt); 305 if (mThumbnail.isNull()) 306 { 307 lt->removeWidget (mLbThumbnail); 308 mLbThumbnail->setHidden (true); 309 310 lt->removeWidget (mLeName); 311 lt->removeWidget (mTxTaken); 312 lt->addWidget (mLeName, 0, 1, 1, 2); 313 lt->addWidget (mTxTaken, 1, 1, 1, 2); 261 VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg(QWidget *pParent /* = 0 */) 262 : QIWithRetranslateUI<QDialog>(pParent) 263 { 264 /* Prepare: */ 265 prepare(); 266 } 267 268 void VBoxSnapshotDetailsDlg::setData(const CSnapshot &comSnapshot) 269 { 270 /* Cache snapshot: */ 271 m_comSnapshot = comSnapshot; 272 273 /* If there is really a snapshot: */ 274 if (m_comSnapshot.isNotNull()) 275 { 276 /* Read general snapshot properties: */ 277 mLeName->setText(m_comSnapshot.GetName()); 278 mTeDescription->setText(m_comSnapshot.GetDescription()); 279 280 /* Calculate snapshot timestamp info: */ 281 QDateTime timestamp; 282 timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000); 283 bool fDateTimeToday = timestamp.date() == QDate::currentDate(); 284 QString dateTime = fDateTimeToday ? timestamp.time().toString(Qt::LocalDate) : timestamp.toString(Qt::LocalDate); 285 mTxTaken->setText(dateTime); 286 287 /* Read snapshot display contents: */ 288 CMachine comMachine = m_comSnapshot.GetMachine(); 289 ULONG iWidth = 0, iHeight = 0; 290 291 /* Get thumbnail if present: */ 292 QVector<BYTE> thumbData = comMachine.ReadSavedThumbnailToArray(0, KBitmapFormat_BGR0, iWidth, iHeight); 293 m_pixmapThumbnail = thumbData.size() != 0 ? QPixmap::fromImage(QImage(thumbData.data(), 294 iWidth, iHeight, 295 QImage::Format_RGB32).copy()) 296 : QPixmap(); 297 298 /* Get screenshot if present: */ 299 QVector<BYTE> screenData = comMachine.ReadSavedScreenshotToArray(0, KBitmapFormat_PNG, iWidth, iHeight); 300 m_pixmapScreenshot = screenData.size() != 0 ? QPixmap::fromImage(QImage::fromData(screenData.data(), 301 screenData.size(), 302 "PNG")) 303 : QPixmap(); 304 305 // TODO: Check whether layout manipulations are really 306 // necessary, they looks a bit dangerous to me.. 307 QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout()); 308 AssertPtrReturnVoid(pLayout); 309 if (m_pixmapThumbnail.isNull()) 310 { 311 pLayout->removeWidget(mLbThumbnail); 312 mLbThumbnail->setHidden(true); 313 314 pLayout->removeWidget(mLeName); 315 pLayout->removeWidget(mTxTaken); 316 pLayout->addWidget(mLeName, 0, 1, 1, 2); 317 pLayout->addWidget(mTxTaken, 1, 1, 1, 2); 318 } 319 else 320 { 321 pLayout->removeWidget(mLeName); 322 pLayout->removeWidget(mTxTaken); 323 pLayout->addWidget(mLeName, 0, 1); 324 pLayout->addWidget(mTxTaken, 1, 1); 325 326 pLayout->removeWidget(mLbThumbnail); 327 pLayout->addWidget(mLbThumbnail, 0, 2, 2, 1); 328 mLbThumbnail->setHidden(false); 329 } 314 330 } 315 331 else 316 332 { 317 lt->removeWidget (mLeName); 318 lt->removeWidget (mTxTaken); 319 lt->addWidget (mLeName, 0, 1); 320 lt->addWidget (mTxTaken, 1, 1); 321 322 lt->removeWidget (mLbThumbnail); 323 lt->addWidget (mLbThumbnail, 0, 2, 2, 1); 324 mLbThumbnail->setHidden (false); 325 } 326 333 /* Clear snapshot timestamp info: */ 334 mTxTaken->clear(); 335 336 // TODO: Check whether layout manipulations are really 337 // necessary, they looks a bit dangerous to me.. 338 QGridLayout *pLayout = qobject_cast<QGridLayout*>(layout()); 339 AssertPtrReturnVoid(pLayout); 340 { 341 pLayout->removeWidget(mLbThumbnail); 342 mLbThumbnail->setHidden(true); 343 344 pLayout->removeWidget(mLeName); 345 pLayout->removeWidget(mTxTaken); 346 pLayout->addWidget(mLeName, 0, 1, 1, 2); 347 pLayout->addWidget(mTxTaken, 1, 1, 1, 2); 348 } 349 } 350 351 /* Retranslate: */ 327 352 retranslateUi(); 328 353 } 329 354 330 void VBoxSnapshotDetailsDlg::putBackToSnapshot() 331 { 332 AssertReturn (!mSnapshot.isNull(), (void) 0); 355 void VBoxSnapshotDetailsDlg::saveData() 356 { 357 /* Make sure there is a snapshot: */ 358 AssertReturnVoid(m_comSnapshot.isNotNull()); 333 359 334 360 /* We need a session when we manipulate the snapshot data of a machine. */ 335 CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId());336 if ( session.isNull())361 CSession comSession = vboxGlobal().openExistingSession(m_comSnapshot.GetMachine().GetId()); 362 if (comSession.isNull()) 337 363 return; 338 364 339 mSnapshot.SetName(mLeName->text()); 340 mSnapshot.SetDescription(mTeDescription->toPlainText()); 365 /* Save snapshot name: */ 366 m_comSnapshot.SetName(mLeName->text()); 367 /* Save snapshot description: */ 368 m_comSnapshot.SetDescription(mTeDescription->toPlainText()); 341 369 342 370 /* Close the session again. */ 343 session.UnlockMachine(); 344 } 345 346 void VBoxSnapshotDetailsDlg::retranslateUi() 347 { 348 /* Translate uic generated strings */ 349 Ui::VBoxSnapshotDetailsDlg::retranslateUi (this); 350 351 if(mSnapshot.isNull()) 352 return; 353 354 CMachine machine = mSnapshot.GetMachine(); 355 356 setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName())); 357 358 mLbThumbnail->setToolTip (mScreenshot.isNull() ? QString() : tr ("Click to enlarge the screenshot.")); 359 360 mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */)); 361 } 362 363 bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent) 364 { 365 Assert (aObject == mLbThumbnail); 366 if (aEvent->type() == QEvent::MouseButtonPress && !mScreenshot.isNull()) 367 { 368 UIScreenshotViewer *pViewer = new UIScreenshotViewer(mScreenshot, 369 mSnapshot.GetMachine().GetName(), 370 mSnapshot.GetName(), 371 comSession.UnlockMachine(); 372 } 373 374 bool VBoxSnapshotDetailsDlg::eventFilter(QObject *pObject, QEvent *pEvent) 375 { 376 /* We have filter for thumbnail label only: */ 377 AssertReturn(pObject == mLbThumbnail, false); 378 379 /* For a mouse-press event inside the thumbnail area: */ 380 if (pEvent->type() == QEvent::MouseButtonPress && !m_pixmapScreenshot.isNull()) 381 { 382 /* We are creating screenshot viewer and show it: */ 383 UIScreenshotViewer *pViewer = new UIScreenshotViewer(m_pixmapScreenshot, 384 m_comSnapshot.GetMachine().GetName(), 385 m_comSnapshot.GetName(), 371 386 this); 372 387 pViewer->show(); 373 388 pViewer->activateWindow(); 374 389 } 375 return QDialog::eventFilter (aObject, aEvent); 376 } 377 378 void VBoxSnapshotDetailsDlg::showEvent (QShowEvent *aEvent) 379 { 380 if (!mLbThumbnail->pixmap() && !mThumbnail.isNull()) 381 { 382 mLbThumbnail->setPixmap (mThumbnail.scaled (QSize (1, mLbThumbnail->height()), 383 Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); 390 391 /* Call to base-class: */ 392 return QDialog::eventFilter(pObject, pEvent); 393 } 394 395 void VBoxSnapshotDetailsDlg::retranslateUi() 396 { 397 /* Translate uic generated strings: */ 398 Ui::VBoxSnapshotDetailsDlg::retranslateUi(this); 399 400 /* And if snapshot is valid: */ 401 if (!m_comSnapshot.isNull()) 402 { 403 /* Get the machine: */ 404 const CMachine comMachine = m_comSnapshot.GetMachine(); 405 406 /* Translate the picture tool-tip: */ 407 mLbThumbnail->setToolTip(m_pixmapScreenshot.isNull() ? QString() : tr("Click to enlarge the screenshot.")); 408 409 /* Rebuild the details report: */ 410 mTeDetails->setText(vboxGlobal().detailsReport(comMachine, false /* with links? */)); 411 } 412 else 413 { 414 /* Clear the picture tool-tip: */ 415 mLbThumbnail->setToolTip(QString()); 416 417 /* Clear the details report: */ 418 mTeDetails->clear(); 419 } 420 } 421 422 void VBoxSnapshotDetailsDlg::showEvent(QShowEvent *pEvent) 423 { 424 /* Call to base-class: */ 425 QIWithRetranslateUI<QDialog>::showEvent(pEvent); 426 427 /* Make sure we should polish dialog: */ 428 if (m_fPolished) 429 return; 430 431 /* Call to polish-event: */ 432 polishEvent(pEvent); 433 434 /* Mark dialog as polished: */ 435 m_fPolished = true; 436 } 437 438 void VBoxSnapshotDetailsDlg::polishEvent(QShowEvent * /* pEvent */) 439 { 440 /* If we haven't assigned the thumbnail yet, do it now: */ 441 if (!mLbThumbnail->pixmap() && !m_pixmapThumbnail.isNull()) 442 { 443 mLbThumbnail->setPixmap(m_pixmapThumbnail.scaled(QSize(1, mLbThumbnail->height()), 444 Qt::KeepAspectRatioByExpanding, 445 Qt::SmoothTransformation)); 446 /* Make sure tool-tip is translated afterwards: */ 384 447 retranslateUi(); 385 448 } 386 387 QDialog::showEvent (aEvent); 388 } 389 390 void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText) 391 { 392 mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty()); 449 } 450 451 void VBoxSnapshotDetailsDlg::sltHandleNameChange(const QString &strName) 452 { 453 /* Perform snapshot name sanity check: */ 454 mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!strName.trimmed().isEmpty()); 455 } 456 457 void VBoxSnapshotDetailsDlg::prepare() 458 { 459 /* Apply UI decorations: */ 460 Ui::VBoxSnapshotDetailsDlg::setupUi(this); 461 462 /* Layout created in the .ui file: */ 463 { 464 /* Name editor created in the .ui file: */ 465 AssertPtrReturnVoid(mLeName); 466 { 467 /* Configure editor: */ 468 connect(mLeName, &QLineEdit::textChanged, 469 this, &VBoxSnapshotDetailsDlg::sltHandleNameChange); 470 } 471 472 /* Thumbnail label created in the .ui file: */ 473 AssertPtrReturnVoid(mLbThumbnail); 474 { 475 /* Configure thumbnail label: */ 476 mLbThumbnail->setCursor(Qt::PointingHandCursor); 477 mLbThumbnail->installEventFilter(this); 478 } 479 480 /* Details browser created in the .ui file: */ 481 AssertPtrReturnVoid(mTeDetails); 482 { 483 /* Configure details browser: */ 484 mTeDetails->viewport()->setAutoFillBackground(false); 485 mTeDetails->setFocus(); 486 } 487 } 393 488 } 394 489 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.h
r67144 r67146 5 5 6 6 /* 7 * Copyright (C) 2008-201 6Oracle Corporation7 * Copyright (C) 2008-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ VBoxSnapshotDetailsDlg_h__19 #define __ VBoxSnapshotDetailsDlg_h__18 #ifndef ___VBoxSnapshotDetailsDlg_h___ 19 #define ___VBoxSnapshotDetailsDlg_h___ 20 20 21 21 /* GUI includes: */ 22 #include "QIWithRetranslateUI.h" 22 23 #include "VBoxSnapshotDetailsDlg.gen.h" 23 #include "QIWithRetranslateUI.h"24 24 25 25 /* COM includes: */ … … 27 27 28 28 29 class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI <QDialog>, public Ui::VBoxSnapshotDetailsDlg 29 /** QDialog extension providing GUI with snapshot details dialog. */ 30 class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI<QDialog>, public Ui::VBoxSnapshotDetailsDlg 30 31 { 31 32 Q_OBJECT; … … 33 34 public: 34 35 35 VBoxSnapshotDetailsDlg (QWidget *aParent); 36 /** Constructs snapshot details dialog passing @a pParent to the base-class. */ 37 VBoxSnapshotDetailsDlg(QWidget *pParent = 0); 36 38 37 void getFromSnapshot (const CSnapshot &aSnapshot); 38 void putBackToSnapshot(); 39 /** Defines the snapshot @a data. */ 40 void setData(const CSnapshot &comSnapshot); 41 /** Saves the snapshot data. */ 42 void saveData(); 39 43 40 44 protected: 41 45 42 void retranslateUi(); 46 /** Preprocesses any Qt @a pEvent for passed @a pObject. */ 47 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 43 48 44 bool eventFilter (QObject *aObject, QEvent *aEvent); 45 void showEvent (QShowEvent *aEvent); 49 /** Handles translation event. */ 50 virtual void retranslateUi() /* override */; 51 52 /** Handles show @a pEvent. */ 53 virtual void showEvent(QShowEvent *pEvent) /* override */; 54 /** Handles polish @a pEvent. */ 55 virtual void polishEvent(QShowEvent *pEvent); 46 56 47 57 private slots: 48 58 49 void onNameChanged (const QString &aText); 59 /** Handles snapshot @a strName change. */ 60 void sltHandleNameChange(const QString &strName); 50 61 51 62 private: 52 63 53 CSnapshot mSnapshot; 64 /** Prepares all. */ 65 void prepare(); 54 66 55 QPixmap mThumbnail; 56 QPixmap mScreenshot; 67 /** Holds whether this widget was polished. */ 68 bool m_fPolished; 69 70 /** Holds the snapshot object to load data from. */ 71 CSnapshot m_comSnapshot; 72 73 /** Holds the cached thumbnail. */ 74 QPixmap m_pixmapThumbnail; 75 /** Holds the cached screenshot. */ 76 QPixmap m_pixmapScreenshot; 57 77 }; 58 78 59 #endif / / __VBoxSnapshotDetailsDlg_h__79 #endif /* !___VBoxSnapshotDetailsDlg_h___ */ 60 80 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r67121 r67146 1325 1325 /* Show Snapshot Details dialog: */ 1326 1326 QPointer<VBoxSnapshotDetailsDlg> pDlg = new VBoxSnapshotDetailsDlg(this); 1327 pDlg-> getFromSnapshot(comSnapshot);1327 pDlg->setData(comSnapshot); 1328 1328 if (pDlg->exec() == QDialog::Accepted) 1329 pDlg-> putBackToSnapshot();1329 pDlg->saveData(); 1330 1330 if (pDlg) 1331 1331 delete pDlg;
Note:
See TracChangeset
for help on using the changeset viewer.