VirtualBox

Ignore:
Timestamp:
Nov 17, 2009 5:45:12 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: Thumbnail & screenshot support for snapshot details page.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSnapshotDetailsDlg.h

    r9729 r24732  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#define __VBoxSnapshotDetailsDlg_h__
    2525
     26/* Local includes */
    2627#include "VBoxSnapshotDetailsDlg.gen.h"
    2728#include "QIWithRetranslateUI.h"
    2829#include "COMDefs.h"
    2930
    30 class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI<QDialog>,
    31                                public Ui::VBoxSnapshotDetailsDlg
     31/* Global forwards */
     32class QScrollArea;
     33
     34class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI <QDialog>, public Ui::VBoxSnapshotDetailsDlg
    3235{
    3336    Q_OBJECT;
     
    4447    void retranslateUi();
    4548
     49    bool eventFilter (QObject *aObject, QEvent *aEvent);
     50    void showEvent (QShowEvent *aEvent);
     51
    4652private slots:
    4753
     
    5157
    5258    CSnapshot mSnapshot;
     59
     60    QPixmap mThumbnail;
     61};
     62
     63class VBoxScreenshotViewer : public QIWithRetranslateUI2 <QWidget>
     64{
     65    Q_OBJECT;
     66
     67public:
     68
     69    VBoxScreenshotViewer (QWidget *aParent, const QPixmap &aScreenshot,
     70                          const QString &aSnapshotName, const QString &aMachineName);
     71
     72private:
     73
     74    void retranslateUi();
     75
     76    void showEvent (QShowEvent *aEvent);
     77    void resizeEvent (QResizeEvent *aEvent);
     78    void mousePressEvent (QMouseEvent *aEvent);
     79    void keyPressEvent (QKeyEvent *aEvent);
     80
     81    void adjustPicture();
     82
     83    QScrollArea *mArea;
     84    QLabel *mPicture;
     85
     86    QPixmap mScreenshot;
     87    QString mSnapshotName;
     88    QString mMachineName;
     89
     90    bool mZoomMode;
    5391};
    5492
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp

    r19664 r24732  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 #include <VBoxSnapshotDetailsDlg.h>
     23/* Global includes */
     24#include <QDateTime>
     25#include <QPushButton>
     26#include <QScrollArea>
     27
     28/* Local includes */
    2429#include <VBoxGlobal.h>
    2530#include <VBoxProblemReporter.h>
     31#include <VBoxSnapshotDetailsDlg.h>
    2632#include <VBoxUtils.h>
    2733
    28 /* Qt includes */
    29 #include <QPushButton>
    30 
    3134VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent)
    32     : QIWithRetranslateUI<QDialog> (aParent)
     35    : QIWithRetranslateUI <QDialog> (aParent)
    3336{
    3437    /* Apply UI decorations */
    3538    Ui::VBoxSnapshotDetailsDlg::setupUi (this);
    3639
    37     /* Setup mTeSummary browser. */
    38     mTeSummary->viewport()->setAutoFillBackground (false);
    39     mTeSummary->setFocus();
     40    /* Setup mLbThumbnail label */
     41    mLbThumbnail->setCursor (Qt::PointingHandCursor);
     42    mLbThumbnail->installEventFilter (this);
     43
     44    /* Setup mTeDetails browser */
     45    mTeDetails->viewport()->setAutoFillBackground (false);
     46    mTeDetails->setFocus();
    4047
    4148    /* Setup connections */
    42     connect (mLeName, SIGNAL (textChanged (const QString&)),
    43              this, SLOT (onNameChanged (const QString&)));
    44     connect (mButtonBox, SIGNAL (helpRequested()),
    45              &vboxProblem(), SLOT (showHelpHelpDialog()));
    46 
    47     resize (450, 450);
     49    connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&)));
     50    connect (mButtonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
    4851}
    4952
     
    5154{
    5255    mSnapshot = aSnapshot;
    53     CMachine machine = aSnapshot.GetMachine();
    54 
    55     /* Get properties */
     56    CMachine machine = mSnapshot.GetMachine();
     57
     58    /* Get general properties */
    5659    mLeName->setText (aSnapshot.GetName());
    5760    mTeDescription->setText (aSnapshot.GetDescription());
    5861
     62    /* Get timestamp info */
     63    QDateTime timestamp;
     64    timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);
     65    bool dateTimeToday = timestamp.date() == QDate::currentDate();
     66    QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate);
     67    mTxTaken->setText (dateTime);
     68
     69    /* Get thumbnail if present */
     70    ULONG width = 0, height = 0;
     71    QVector <BYTE> data = machine.ReadSavedThumbnailToArray (true, width, height);
     72    mThumbnail = data.size() != 0 ? QPixmap::fromImage (QImage (data.data(), width, height, QImage::Format_RGB32)) : QPixmap();
     73    QGridLayout *lt = qobject_cast <QGridLayout*> (layout());
     74    Assert (lt);
     75    if (mThumbnail.isNull())
     76    {
     77        lt->removeWidget (mLbThumbnail);
     78        mLbThumbnail->setHidden (true);
     79
     80        lt->removeWidget (mLeName);
     81        lt->removeWidget (mTxTaken);
     82        lt->addWidget (mLeName, 0, 1, 1, 2);
     83        lt->addWidget (mTxTaken, 1, 1, 1, 2);
     84    }
     85    else
     86    {
     87        lt->removeWidget (mLeName);
     88        lt->removeWidget (mTxTaken);
     89        lt->addWidget (mLeName, 0, 1);
     90        lt->addWidget (mTxTaken, 1, 1);
     91
     92        lt->removeWidget (mLbThumbnail);
     93        lt->addWidget (mLbThumbnail, 0, 2, 2, 1);
     94        mLbThumbnail->setHidden (false);
     95    }
     96
    5997    retranslateUi();
    6098}
     
    78116    CMachine machine = mSnapshot.GetMachine();
    79117
    80     setWindowTitle (tr ("Details of %1 (%2)")
    81                     .arg (mSnapshot.GetName()).arg (machine.GetName()));
    82 
    83     /* Compose summary */
    84     mTeSummary->setText (
    85         vboxGlobal().detailsReport (machine, false /* withLinks */));
     118    setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName()));
     119
     120    mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */));
     121}
     122
     123bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent)
     124{
     125    Assert (aObject == mLbThumbnail);
     126    if (aEvent->type() == QEvent::MouseButtonPress)
     127    {
     128        CMachine machine = mSnapshot.GetMachine();
     129
     130        ULONG width = 0, height = 0;
     131        QVector <BYTE> data = machine.ReadSavedScreenshotPNGToArray (width, height);
     132        Assert (data.size());
     133        QPixmap pixmap = QPixmap::fromImage (QImage::fromData (data.data(), data.size(), "PNG"));
     134
     135        VBoxScreenshotViewer *viewer = new VBoxScreenshotViewer (this, pixmap, machine.GetName(), mSnapshot.GetName());
     136        viewer->show();
     137    }
     138    return QDialog::eventFilter (aObject, aEvent);
     139}
     140
     141void VBoxSnapshotDetailsDlg::showEvent (QShowEvent *aEvent)
     142{
     143    if (!mLbThumbnail->pixmap() && !mThumbnail.isNull())
     144    {
     145        mLbThumbnail->setPixmap (mThumbnail.scaled (QSize (1, mLbThumbnail->height()),
     146                                                    Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
     147        retranslateUi();
     148    }
     149
     150    QDialog::showEvent (aEvent);
    86151}
    87152
     
    91156}
    92157
     158VBoxScreenshotViewer::VBoxScreenshotViewer (QWidget *aParent, const QPixmap &aScreenshot,
     159                                            const QString &aSnapshotName, const QString &aMachineName)
     160    : QIWithRetranslateUI2 <QWidget> (aParent, Qt::Tool)
     161    , mArea (new QScrollArea (this))
     162    , mPicture (new QLabel)
     163    , mScreenshot (aScreenshot)
     164    , mSnapshotName (aSnapshotName)
     165    , mMachineName (aMachineName)
     166    , mZoomMode (true)
     167{
     168    setWindowModality (Qt::ApplicationModal);
     169    setCursor (Qt::PointingHandCursor);
     170    QVBoxLayout *layout = new QVBoxLayout (this);
     171    layout->setMargin (0);
     172
     173    mArea->setWidget (mPicture);
     174    mArea->setWidgetResizable (true);
     175    layout->addWidget (mArea);
     176
     177    QSize maxSize = aScreenshot.size() + QSize (mArea->frameWidth() * 2, mArea->frameWidth() * 2);
     178    QSize initSize = QSize (640, 480).boundedTo (maxSize);
     179
     180    setMaximumSize (maxSize);
     181
     182    QRect geo (QPoint (0, 0), initSize);
     183    geo.moveCenter (parentWidget()->geometry().center());
     184    setGeometry (geo);
     185
     186    retranslateUi();
     187}
     188
     189void VBoxScreenshotViewer::retranslateUi()
     190{
     191    setWindowTitle (tr ("Screenshot of %1 (%2)").arg (mSnapshotName).arg (mMachineName));
     192}
     193
     194void VBoxScreenshotViewer::showEvent (QShowEvent *aEvent)
     195{
     196    adjustPicture();
     197    QIWithRetranslateUI2 <QWidget>::showEvent (aEvent);
     198}
     199
     200void VBoxScreenshotViewer::resizeEvent (QResizeEvent *aEvent)
     201{
     202    adjustPicture();
     203    QIWithRetranslateUI2 <QWidget>::resizeEvent (aEvent);
     204}
     205
     206void VBoxScreenshotViewer::mousePressEvent (QMouseEvent *aEvent)
     207{
     208    mZoomMode = !mZoomMode;
     209    adjustPicture();
     210    QIWithRetranslateUI2 <QWidget>::mousePressEvent (aEvent);
     211}
     212
     213void VBoxScreenshotViewer::keyPressEvent (QKeyEvent *aEvent)
     214{
     215    if (aEvent->key() == Qt::Key_Escape)
     216        deleteLater();
     217    QIWithRetranslateUI2 <QWidget>::keyPressEvent (aEvent);
     218}
     219
     220void VBoxScreenshotViewer::adjustPicture()
     221{
     222    if (mZoomMode)
     223    {
     224        mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
     225        mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
     226        mPicture->setPixmap (mScreenshot.scaled (mArea->viewport()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
     227        mPicture->setToolTip (tr ("Click to view non-scaled screenshot."));
     228    }
     229    else
     230    {
     231        mArea->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
     232        mArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAsNeeded);
     233        mPicture->setPixmap (mScreenshot);
     234        mPicture->setToolTip (tr ("Click to view scaled screenshot."));
     235    }
     236}
     237
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSnapshotDetailsDlg.ui

    r23333 r24732  
    1 <ui version="4.0" >
     1<ui version="4.0">
    22 <comment>
    33 VBox frontends: Qt4 GUI ("VirtualBox"):
    44
    5  Copyright (C) 2008 Sun Microsystems, Inc.
     5 Copyright (C) 2008-2009 Sun Microsystems, Inc.
    66
    77 This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 </comment>
    1919 <class>VBoxSnapshotDetailsDlg</class>
    20  <widget class="QDialog" name="VBoxSnapshotDetailsDlg" >
    21   <property name="geometry" >
     20 <widget class="QDialog" name="VBoxSnapshotDetailsDlg">
     21  <property name="geometry">
    2222   <rect>
    2323    <x>0</x>
    2424    <y>0</y>
    25     <width>408</width>
    26     <height>388</height>
     25    <width>450</width>
     26    <height>450</height>
    2727   </rect>
    2828  </property>
    29   <property name="windowTitle" >
    30    <string>VBoxSnapshotDetailsDlg</string>
     29  <property name="windowIcon">
     30   <iconset resource="../VirtualBox1.qrc">:/settings_16px.png</iconset>
    3131  </property>
    32   <property name="windowIcon" >
    33    <iconset resource="../VirtualBox1.qrc" >:/settings_16px.png</iconset>
    34   </property>
    35   <layout class="QVBoxLayout" >
    36    <item>
    37     <widget class="QGroupBox" name="mGbSnapshotDetails" >
    38      <property name="title" >
    39       <string>Snapshot Details</string>
    40      </property>
    41      <layout class="QVBoxLayout" >
    42       <property name="topMargin" >
    43        <number>4</number>
    44       </property>
    45       <item>
    46        <layout class="QVBoxLayout" >
    47         <item>
    48          <widget class="QLabel" name="mTxName" >
    49           <property name="text" >
    50            <string>&amp;Name</string>
    51           </property>
    52           <property name="buddy" >
    53            <cstring>mLeName</cstring>
    54           </property>
    55          </widget>
    56         </item>
    57         <item>
    58          <widget class="QLineEdit" name="mLeName" />
    59         </item>
    60        </layout>
    61       </item>
    62       <item>
    63        <layout class="QVBoxLayout" >
    64         <item>
    65          <widget class="QLabel" name="mTxDescription" >
    66           <property name="text" >
    67            <string>&amp;Description</string>
    68           </property>
    69           <property name="buddy" >
    70            <cstring>mTeDescription</cstring>
    71           </property>
    72          </widget>
    73         </item>
    74         <item>
    75          <widget class="QTextEdit" name="mTeDescription" >
    76           <property name="sizePolicy" >
    77            <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
    78             <horstretch>0</horstretch>
    79             <verstretch>0</verstretch>
    80            </sizepolicy>
    81           </property>
    82           <property name="tabChangesFocus" >
    83            <bool>true</bool>
    84           </property>
    85           <property name="acceptRichText" >
    86            <bool>false</bool>
    87           </property>
    88          </widget>
    89         </item>
    90        </layout>
    91       </item>
    92      </layout>
    93     </widget>
    94    </item>
    95    <item>
    96     <widget class="QGroupBox" name="mGbMachineDetails" >
    97      <property name="title" >
    98       <string>&amp;Machine Details</string>
    99      </property>
    100      <layout class="QVBoxLayout" >
    101       <property name="topMargin" >
    102        <number>4</number>
    103       </property>
    104       <item>
    105        <widget class="QTextEdit" name="mTeSummary" >
    106         <property name="sizePolicy" >
    107          <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
    108           <horstretch>0</horstretch>
    109           <verstretch>0</verstretch>
    110          </sizepolicy>
    111         </property>
    112         <property name="frameShape" >
    113          <enum>QFrame::NoFrame</enum>
    114         </property>
    115         <property name="frameShadow" >
    116          <enum>QFrame::Plain</enum>
    117         </property>
    118         <property name="readOnly" >
    119          <bool>true</bool>
    120         </property>
    121        </widget>
    122       </item>
    123      </layout>
    124     </widget>
    125    </item>
    126    <item>
    127     <widget class="QIDialogButtonBox" name="mButtonBox" >
    128      <property name="standardButtons" >
     32  <layout class="QGridLayout">
     33   <item row="0" column="0">
     34    <widget class="QLabel" name="mLbName">
     35     <property name="text">
     36      <string>&amp;Name:</string>
     37     </property>
     38     <property name="buddy">
     39      <cstring>mLeName</cstring>
     40     </property>
     41     <property name="alignment" >
     42      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
     43     </property>
     44    </widget>
     45   </item>
     46   <item row="0" column="1">
     47    <widget class="QLineEdit" name="mLeName">
     48     <property name="sizePolicy">
     49      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
     50       <horstretch>1</horstretch>
     51       <verstretch>0</verstretch>
     52      </sizepolicy>
     53     </property>
     54    </widget>
     55   </item>
     56   <item row="0" rowspan="2" column="2">
     57    <widget class="QLabel" name="mLbThumbnail">
     58     <property name="sizePolicy">
     59      <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
     60       <horstretch>0</horstretch>
     61       <verstretch>0</verstretch>
     62      </sizepolicy>
     63     </property>
     64     <property name="toolTip">
     65      <string>Click to enlarge the screenshot.</string>
     66     </property>
     67     <property name="frameShape">
     68      <enum>QFrame::Box</enum>
     69     </property>
     70     <property name="frameShadow">
     71      <enum>QFrame::Sunken</enum>
     72     </property>
     73    </widget>
     74   </item>
     75   <item row="1" column="0">
     76    <widget class="QLabel" name="mLbTaken">
     77     <property name="text">
     78      <string>Taken:</string>
     79     </property>
     80     <property name="alignment" >
     81      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
     82     </property>
     83    </widget>
     84   </item>
     85   <item row="1" column="1">
     86    <widget class="QLabel" name="mTxTaken">
     87     <property name="sizePolicy">
     88      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
     89       <horstretch>1</horstretch>
     90       <verstretch>0</verstretch>
     91      </sizepolicy>
     92     </property>
     93    </widget>
     94   </item>
     95   <item row="2" column="0">
     96    <widget class="QLabel" name="mLbDescription">
     97     <property name="text">
     98      <string>&amp;Description:</string>
     99     </property>
     100     <property name="buddy">
     101      <cstring>mTeDescription</cstring>
     102     </property>
     103     <property name="alignment" >
     104      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignTop</set>
     105     </property>
     106    </widget>
     107   </item>
     108   <item row="2" column="1" colspan="2">
     109    <widget class="QTextEdit" name="mTeDescription">
     110     <property name="sizePolicy">
     111      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
     112       <horstretch>1</horstretch>
     113       <verstretch>1</verstretch>
     114      </sizepolicy>
     115     </property>
     116     <property name="tabChangesFocus">
     117      <bool>true</bool>
     118     </property>
     119     <property name="acceptRichText">
     120      <bool>false</bool>
     121     </property>
     122    </widget>
     123   </item>
     124   <item row="3" column="0">
     125    <widget class="QLabel" name="mLbDetails">
     126     <property name="text">
     127      <string>D&amp;etails:</string>
     128     </property>
     129     <property name="buddy">
     130      <cstring>mTeDetails</cstring>
     131     </property>
     132     <property name="alignment" >
     133      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignTop</set>
     134     </property>
     135    </widget>
     136   </item>
     137   <item row="3" column="1" colspan="2">
     138    <widget class="QTextEdit" name="mTeDetails">
     139     <property name="sizePolicy">
     140      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
     141       <horstretch>1</horstretch>
     142       <verstretch>1</verstretch>
     143      </sizepolicy>
     144     </property>
     145     <property name="frameShape">
     146      <enum>QFrame::NoFrame</enum>
     147     </property>
     148     <property name="frameShadow">
     149      <enum>QFrame::Plain</enum>
     150     </property>
     151     <property name="readOnly">
     152      <bool>true</bool>
     153     </property>
     154    </widget>
     155   </item>
     156   <item row="4" column="0" colspan="3">
     157    <widget class="QIDialogButtonBox" name="mButtonBox">
     158     <property name="standardButtons">
    129159      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
    130160     </property>
     
    141171 </customwidgets>
    142172 <resources>
    143   <include location="../VirtualBox1.qrc" />
     173  <include location="../VirtualBox1.qrc"/>
    144174 </resources>
    145175 <connections>
     
    150180   <slot>accept()</slot>
    151181   <hints>
    152     <hint type="sourcelabel" >
     182    <hint type="sourcelabel">
    153183     <x>203</x>
    154184     <y>365</y>
    155185    </hint>
    156     <hint type="destinationlabel" >
     186    <hint type="destinationlabel">
    157187     <x>203</x>
    158188     <y>193</y>
     
    166196   <slot>reject()</slot>
    167197   <hints>
    168     <hint type="sourcelabel" >
     198    <hint type="sourcelabel">
    169199     <x>203</x>
    170200     <y>365</y>
    171201    </hint>
    172     <hint type="destinationlabel" >
     202    <hint type="destinationlabel">
    173203     <x>203</x>
    174204     <y>193</y>
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette