VirtualBox

Ignore:
Timestamp:
May 30, 2017 2:47:41 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115820
Message:

FE/Qt: Selector UI: Tools pane: Snapshot pane: Moving screenshot viewer code into corresponding place.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r67068 r67144  
    532532# Sources containing local definitions of classes that use the Q_OBJECT macro.
    533533VirtualBox_QT_MOCSRCS = \
     534        src/VBoxSnapshotDetailsDlg.cpp \
    534535        src/UIVMLogViewer.cpp \
    535536        src/extensions/QIArrowSplitter.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp

    r67143 r67144  
    3737
    3838
    39 /*********************************************************************************************************************************
    40 *   Class VBoxSnapshotDetailsDlg implementation.                                                                                 *
    41 *********************************************************************************************************************************/
    42 
    43 VBoxSnapshotDetailsDlg::VBoxSnapshotDetailsDlg (QWidget *aParent)
    44     : QIWithRetranslateUI <QDialog> (aParent)
    45 {
    46     /* Apply UI decorations */
    47     Ui::VBoxSnapshotDetailsDlg::setupUi (this);
    48 
    49     /* Setup mLbThumbnail label */
    50     mLbThumbnail->setCursor (Qt::PointingHandCursor);
    51     mLbThumbnail->installEventFilter (this);
    52 
    53     /* Setup mTeDetails browser */
    54     mTeDetails->viewport()->setAutoFillBackground (false);
    55     mTeDetails->setFocus();
    56 
    57     /* Setup connections */
    58     connect (mLeName, SIGNAL (textChanged (const QString&)), this, SLOT (onNameChanged (const QString&)));
    59     connect (mButtonBox, SIGNAL (helpRequested()), &msgCenter(), SLOT (sltShowHelpHelpDialog()));
    60 }
    61 
    62 void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot)
    63 {
    64     mSnapshot = aSnapshot;
    65     CMachine machine = mSnapshot.GetMachine();
    66 
    67     /* Get general properties */
    68     mLeName->setText (aSnapshot.GetName());
    69     mTeDescription->setText (aSnapshot.GetDescription());
    70 
    71     /* Get timestamp info */
    72     QDateTime timestamp;
    73     timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);
    74     bool dateTimeToday = timestamp.date() == QDate::currentDate();
    75     QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate);
    76     mTxTaken->setText (dateTime);
    77 
    78     /* Get thumbnail if present */
    79     ULONG width = 0, height = 0;
    80     QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, KBitmapFormat_BGR0, width, height);
    81     mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap();
    82     QVector <BYTE> screenData = machine.ReadSavedScreenshotToArray (0, KBitmapFormat_PNG, width, height);
    83     mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap();
    84 
    85     QGridLayout *lt = qobject_cast <QGridLayout*> (layout());
    86     Assert (lt);
    87     if (mThumbnail.isNull())
    88     {
    89         lt->removeWidget (mLbThumbnail);
    90         mLbThumbnail->setHidden (true);
    91 
    92         lt->removeWidget (mLeName);
    93         lt->removeWidget (mTxTaken);
    94         lt->addWidget (mLeName, 0, 1, 1, 2);
    95         lt->addWidget (mTxTaken, 1, 1, 1, 2);
    96     }
    97     else
    98     {
    99         lt->removeWidget (mLeName);
    100         lt->removeWidget (mTxTaken);
    101         lt->addWidget (mLeName, 0, 1);
    102         lt->addWidget (mTxTaken, 1, 1);
    103 
    104         lt->removeWidget (mLbThumbnail);
    105         lt->addWidget (mLbThumbnail, 0, 2, 2, 1);
    106         mLbThumbnail->setHidden (false);
    107     }
    108 
    109     retranslateUi();
    110 }
    111 
    112 void VBoxSnapshotDetailsDlg::putBackToSnapshot()
    113 {
    114     AssertReturn (!mSnapshot.isNull(), (void) 0);
    115 
    116     /* We need a session when we manipulate the snapshot data of a machine. */
    117     CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId());
    118     if (session.isNull())
    119         return;
    120 
    121     mSnapshot.SetName(mLeName->text());
    122     mSnapshot.SetDescription(mTeDescription->toPlainText());
    123 
    124     /* Close the session again. */
    125     session.UnlockMachine();
    126 }
    127 
    128 void VBoxSnapshotDetailsDlg::retranslateUi()
    129 {
    130     /* Translate uic generated strings */
    131     Ui::VBoxSnapshotDetailsDlg::retranslateUi (this);
    132 
    133     if(mSnapshot.isNull())
    134         return;
    135 
    136     CMachine machine = mSnapshot.GetMachine();
    137 
    138     setWindowTitle (tr ("Details of %1 (%2)").arg (mSnapshot.GetName()).arg (machine.GetName()));
    139 
    140     mLbThumbnail->setToolTip (mScreenshot.isNull() ? QString() : tr ("Click to enlarge the screenshot."));
    141 
    142     mTeDetails->setText (vboxGlobal().detailsReport (machine, false /* with links? */));
    143 }
    144 
    145 bool VBoxSnapshotDetailsDlg::eventFilter (QObject *aObject, QEvent *aEvent)
    146 {
    147     Assert (aObject == mLbThumbnail);
    148     if (aEvent->type() == QEvent::MouseButtonPress && !mScreenshot.isNull())
    149     {
    150         UIScreenshotViewer *pViewer = new UIScreenshotViewer(mScreenshot,
    151                                                              mSnapshot.GetMachine().GetName(),
    152                                                              mSnapshot.GetName(),
    153                                                              this);
    154         pViewer->show();
    155         pViewer->activateWindow();
    156     }
    157     return QDialog::eventFilter (aObject, aEvent);
    158 }
    159 
    160 void VBoxSnapshotDetailsDlg::showEvent (QShowEvent *aEvent)
    161 {
    162     if (!mLbThumbnail->pixmap() && !mThumbnail.isNull())
    163     {
    164         mLbThumbnail->setPixmap (mThumbnail.scaled (QSize (1, mLbThumbnail->height()),
    165                                                     Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
    166         retranslateUi();
    167     }
    168 
    169     QDialog::showEvent (aEvent);
    170 }
    171 
    172 void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText)
    173 {
    174     mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty());
    175 }
     39/** QWiget extension providing GUI with snapshot screenshot viewer widget. */
     40class UIScreenshotViewer : public QIWithRetranslateUI2<QWidget>
     41{
     42    Q_OBJECT;
     43
     44public:
     45
     46    /** Constructs screenshow viewer passing @a pParent to the base-class.
     47      * @param  pixmapScreenshot  Brings the screenshot to show.
     48      * @param  strSnapshotName   Brings the snapshot name.
     49      * @param  strMachineName    Brings the machine name. */
     50    UIScreenshotViewer(const QPixmap &pixmapScreenshot,
     51                       const QString &strSnapshotName,
     52                       const QString &strMachineName,
     53                       QWidget *pParent = 0);
     54
     55protected:
     56
     57    /** Handles translation event. */
     58    virtual void retranslateUi() /* override */;
     59
     60    /** Handles show @a pEvent. */
     61    virtual void showEvent(QShowEvent *pEvent) /* override */;
     62    /** Handles polish @a pEvent. */
     63    virtual void polishEvent(QShowEvent *pEvent);
     64
     65    /** Handles resize @a pEvent. */
     66    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     67
     68    /** Handles mouse press @a pEvent. */
     69    virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
     70    /** Handles key press @a pEvent. */
     71    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
     72
     73private:
     74
     75    /** Prepares all. */
     76    void prepare();
     77
     78    /** Adjusts picture. */
     79    void adjustPicture();
     80
     81    /** Holds whether this widget was polished. */
     82    bool m_fPolished;
     83
     84    /** Holds the screenshot to show. */
     85    QPixmap m_pixmapScreenshot;
     86    /** Holds the snapshot name. */
     87    QString m_strSnapshotName;
     88    /** Holds the machine name. */
     89    QString m_strMachineName;
     90
     91    /** Holds the scroll-area instance. */
     92    QScrollArea *m_pScrollArea;
     93    /** Holds the picture label instance. */
     94    QLabel *m_pLabelPicture;
     95
     96    /** Holds whether we are in zoom mode. */
     97    bool m_fZoomMode;
     98};
    17699
    177100
     
    332255
    333256
     257/*********************************************************************************************************************************
     258*   Class VBoxSnapshotDetailsDlg implementation.                                                                                 *
     259*********************************************************************************************************************************/
     260
     261VBoxSnapshotDetailsDlg::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
     280void 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);
     314    }
     315    else
     316    {
     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
     327    retranslateUi();
     328}
     329
     330void VBoxSnapshotDetailsDlg::putBackToSnapshot()
     331{
     332    AssertReturn (!mSnapshot.isNull(), (void) 0);
     333
     334    /* 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())
     337        return;
     338
     339    mSnapshot.SetName(mLeName->text());
     340    mSnapshot.SetDescription(mTeDescription->toPlainText());
     341
     342    /* Close the session again. */
     343    session.UnlockMachine();
     344}
     345
     346void 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
     363bool 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                                                             this);
     372        pViewer->show();
     373        pViewer->activateWindow();
     374    }
     375    return QDialog::eventFilter (aObject, aEvent);
     376}
     377
     378void 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));
     384        retranslateUi();
     385    }
     386
     387    QDialog::showEvent (aEvent);
     388}
     389
     390void VBoxSnapshotDetailsDlg::onNameChanged (const QString &aText)
     391{
     392    mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!aText.trimmed().isEmpty());
     393}
     394
     395#include "VBoxSnapshotDetailsDlg.moc"
     396
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.h

    r67143 r67144  
    2525/* COM includes: */
    2626#include "CSnapshot.h"
    27 
    28 /* Forward declarations: */
    29 class QScrollArea;
    3027
    3128
     
    6057};
    6158
    62 
    63 /** QWiget extension providing GUI with snapshot screenshot viewer widget. */
    64 class UIScreenshotViewer : public QIWithRetranslateUI2<QWidget>
    65 {
    66     Q_OBJECT;
    67 
    68 public:
    69 
    70     /** Constructs screenshow viewer passing @a pParent to the base-class.
    71       * @param  pixmapScreenshot  Brings the screenshot to show.
    72       * @param  strSnapshotName   Brings the snapshot name.
    73       * @param  strMachineName    Brings the machine name. */
    74     UIScreenshotViewer(const QPixmap &pixmapScreenshot,
    75                        const QString &strSnapshotName,
    76                        const QString &strMachineName,
    77                        QWidget *pParent = 0);
    78 
    79 protected:
    80 
    81     /** Handles translation event. */
    82     virtual void retranslateUi() /* override */;
    83 
    84     /** Handles show @a pEvent. */
    85     virtual void showEvent(QShowEvent *pEvent) /* override */;
    86     /** Handles polish @a pEvent. */
    87     virtual void polishEvent(QShowEvent *pEvent);
    88 
    89     /** Handles resize @a pEvent. */
    90     virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    91 
    92     /** Handles mouse press @a pEvent. */
    93     virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
    94     /** Handles key press @a pEvent. */
    95     virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
    96 
    97 private:
    98 
    99     /** Prepares all. */
    100     void prepare();
    101 
    102     /** Adjusts picture. */
    103     void adjustPicture();
    104 
    105     /** Holds whether this widget was polished. */
    106     bool m_fPolished;
    107 
    108     /** Holds the screenshot to show. */
    109     QPixmap m_pixmapScreenshot;
    110     /** Holds the snapshot name. */
    111     QString m_strSnapshotName;
    112     /** Holds the machine name. */
    113     QString m_strMachineName;
    114 
    115     /** Holds the scroll-area instance. */
    116     QScrollArea *m_pScrollArea;
    117     /** Holds the picture label instance. */
    118     QLabel *m_pLabelPicture;
    119 
    120     /** Holds whether we are in zoom mode. */
    121     bool m_fZoomMode;
    122 };
    123 
    12459#endif // __VBoxSnapshotDetailsDlg_h__
    12560
Note: See TracChangeset for help on using the changeset viewer.

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