VirtualBox

Changeset 63837 in vbox for trunk


Ignore:
Timestamp:
Sep 14, 2016 4:29:24 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 31): Selector UI: UISnapshotPane: More suitable encapsulation.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r63835 r63837  
    2121
    2222/* Qt includes: */
     23# include <QApplication>
    2324# include <QDateTime>
    2425# include <QHeaderView>
    2526# include <QMenu>
     27# include <QPointer>
    2628# include <QScrollBar>
    27 # include <QPointer>
    28 # include <QApplication>
    2929# include <QWriteLocker>
    3030
    3131/* GUI includes: */
     32# include "UIConverter.h"
     33# include "UIExtraDataManager.h"
    3234# include "UIIconPool.h"
    3335# include "UIMessageCenter.h"
    34 # include "VBoxSnapshotDetailsDlg.h"
     36# include "UIModalWindowManager.h"
    3537# include "UISnapshotPane.h"
    36 # include "VBoxTakeSnapshotDlg.h"
    37 # include "UIWizardCloneVM.h"
    3838# include "UIToolBar.h"
    3939# include "UIVirtualBoxEventHandler.h"
    40 # include "UIConverter.h"
    41 # include "UIModalWindowManager.h"
    42 # include "UIExtraDataManager.h"
     40# include "UIWizardCloneVM.h"
     41# include "VBoxSnapshotDetailsDlg.h"
     42# include "VBoxTakeSnapshotDlg.h"
    4343
    4444/* COM includes: */
     
    6262
    6363    /** Constructs normal snapshot item (child of tree-widget). */
    64     SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CSnapshot &comSnapshot)
    65         : QTreeWidgetItem(pTreeWidget, ItemType)
    66         , m_pSnapshotWidget(pSnapshotWidget)
    67         , m_fCurrentState(false)
    68         , m_comSnapshot(comSnapshot)
    69     {
    70     }
    71 
     64    SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CSnapshot &comSnapshot);
    7265    /** Constructs normal snapshot item (child of tree-widget-item). */
    73     SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CSnapshot &comSnapshot)
    74         : QTreeWidgetItem(pRootItem, ItemType)
    75         , m_pSnapshotWidget(pSnapshotWidget)
    76         , m_fCurrentState(false)
    77         , m_comSnapshot(comSnapshot)
    78     {
    79     }
     66    SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CSnapshot &comSnapshot);
    8067
    8168    /** Constructs "current state" item (child of tree-widget). */
    82     SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CMachine &comMachine)
    83         : QTreeWidgetItem(pTreeWidget, ItemType)
    84         , m_pSnapshotWidget(pSnapshotWidget)
    85         , m_fCurrentState(true)
    86         , m_comMachine(comMachine)
    87     {
    88         /* Fetch current machine state: */
    89         updateCurrentState(m_comMachine.GetState());
    90     }
    91 
     69    SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CMachine &comMachine);
    9270    /** Constructs "current state" item (child of tree-widget-item). */
    93     SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CMachine &comMachine)
    94         : QTreeWidgetItem(pRootItem, ItemType)
    95         , m_pSnapshotWidget(pSnapshotWidget)
    96         , m_fCurrentState(true)
    97         , m_comMachine(comMachine)
    98     {
    99         /* Fetch current machine state: */
    100         updateCurrentState(m_comMachine.GetState());
    101     }
    102 
    103     /** Returns item data for corresponding @a iColumn and @a iRole. */
    104     QVariant data(int iColumn, int iRole) const
    105     {
    106         switch (iRole)
    107         {
    108             case Qt::DisplayRole:
    109             {
    110                 /* Call to base-class for "current state" item, compose ourselves otherwise: */
    111                 return m_fCurrentState ? QTreeWidgetItem::data(iColumn, iRole) :
    112                                          QString("%1%2")
    113                                              .arg(QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString())
    114                                              .arg(QTreeWidgetItem::data(iColumn, Qt::UserRole).toString());
    115             }
    116             case Qt::SizeHintRole:
    117             {
    118                 /* Determine the icon metric: */
    119                 const QStyle *pStyle = QApplication::style();
    120                 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    121                 /* Determine the minimum size-hint for this tree-widget-item: */
    122                 const QSize baseSizeHint = QTreeWidgetItem::data(iColumn, iRole).toSize();
    123                 /* Determine the effective height-hint for this tree-widget-item: */
    124                 const int iEffectiveHeightHint = qMax(baseSizeHint.height(),
    125                                                       iIconMetric + 2 * 2 /* margins */);
    126                 /* Return size-hint for this tree-widget-item: */
    127                 return QSize(baseSizeHint.width(), iEffectiveHeightHint);
    128             }
    129             default:
    130                 break;
    131         }
    132 
    133         /* Call to base-class: */
    134         return QTreeWidgetItem::data(iColumn, iRole);
    135     }
    136 
    137     /** Returns item text for corresponding @a iColumn. */
    138     QString text(int iColumn) const
    139     {
    140         return QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString();
    141     }
    142 
    143     /** Returns whether this is the "current state" item. */
    144     bool isCurrentStateItem() const
    145     {
    146         return m_comSnapshot.isNull();
    147     }
    148 
    149     /** Calculates and returns the current item level. */
    150     int level() const
    151     {
    152         const QTreeWidgetItem *pItem = this;
    153         int iResult = 0;
    154         while (pItem->parent())
    155         {
    156             ++iResult;
    157             pItem = pItem->parent();
    158         }
    159         return iResult;
    160     }
    161 
    162     /** Returns whether the font is bold. */
    163     bool bold() const { return font(0).bold(); }
    164     /** Defines whether the font is @a fBold. */
    165     void setBold(bool fBold)
    166     {
    167         /* Update font: */
    168         QFont myFont = font(0);
    169         myFont.setBold(fBold);
    170         setFont(0, myFont);
    171 
    172         /* Adjust text: */
    173         adjustText();
    174     }
    175 
    176     /** Returns whether the font is italic. */
    177     bool italic() const { return font(0).italic(); }
    178     /** Defines whether the font is @a fItalic. */
    179     void setItalic(bool fItalic)
    180     {
    181         /* Update font: */
    182         QFont myFont = font(0);
    183         myFont.setItalic(fItalic);
    184         setFont(0, myFont);
    185 
    186         /* Adjust text: */
    187         adjustText();
    188     }
     71    SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CMachine &comMachine);
    18972
    19073    /** Returns item machine. */
     
    19578    QString snapshotID() const { return m_strSnapshotID; }
    19679
     80    /** Returns item data for corresponding @a iColumn and @a iRole. */
     81    QVariant data(int iColumn, int iRole) const;
     82
     83    /** Returns item text for corresponding @a iColumn. */
     84    QString text(int iColumn) const;
     85
     86    /** Returns whether this is the "current state" item. */
     87    bool isCurrentStateItem() const;
     88
     89    /** Calculates and returns the current item level. */
     90    int level() const;
     91
     92    /** Returns whether the font is bold. */
     93    bool bold() const;
     94    /** Defines whether the font is @a fBold. */
     95    void setBold(bool fBold);
     96
     97    /** Returns whether the font is italic. */
     98    bool italic() const;
     99    /** Defines whether the font is @a fItalic. */
     100    void setItalic(bool fItalic);
     101
    197102    /** Recaches the item's contents. */
    198     void recache()
    199     {
    200         /* For "current state" item: */
    201         if (m_fCurrentState)
    202         {
    203             /* Fetch machine information: */
    204             AssertReturnVoid(!m_comMachine.isNull());
    205             m_fCurrentStateModified = m_comMachine.GetCurrentStateModified();
    206             setText(0, m_fCurrentStateModified ?
    207                        UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") :
    208                        UISnapshotPane::tr("Current State", "Current State (Unmodified)"));
    209             m_strDesc = m_fCurrentStateModified ?
    210                         UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") :
    211                         parent() != 0 ?
    212                         UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") :
    213                         QString();
    214         }
    215         /* For others: */
    216         else
    217         {
    218             /* Fetch snapshot information: */
    219             AssertReturnVoid(!m_comSnapshot.isNull());
    220             m_strSnapshotID = m_comSnapshot.GetId();
    221             setText(0, m_comSnapshot.GetName());
    222             m_fOnline = m_comSnapshot.GetOnline();
    223             setIcon(0, m_pSnapshotWidget->snapshotItemIcon(m_fOnline));
    224             m_strDesc = m_comSnapshot.GetDescription();
    225             m_timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000);
    226             m_fCurrentStateModified = false;
    227         }
    228 
    229         /* Adjust text: */
    230         adjustText();
    231         /* Update tool-tip: */
    232         recacheToolTip();
    233     }
     103    void recache();
    234104
    235105    /** Returns current machine state. */
    236     KMachineState getCurrentState() const
    237     {
    238         /* Make sure machine is valid: */
    239         if (m_comMachine.isNull())
    240             return KMachineState_Null;
    241 
    242         /* Return cached state: */
    243         return m_enmMachineState;
    244     }
     106    KMachineState getCurrentState() const;
    245107
    246108    /** Recaches current machine state. */
    247     void updateCurrentState(KMachineState enmState)
    248     {
    249         /* Make sure machine is valid: */
    250         if (m_comMachine.isNull())
    251             return;
    252 
    253         /* Set corresponding icon: */
    254         setIcon(0, gpConverter->toIcon(enmState));
    255         /* Cache new state: */
    256         m_enmMachineState = enmState;
    257         /* Update timestamp: */
    258         m_timestamp.setTime_t(m_comMachine.GetLastStateChange() / 1000);
    259     }
     109    void updateCurrentState(KMachineState enmState);
    260110
    261111    /** Updates item age. */
    262     SnapshotAgeFormat updateAge()
    263     {
    264         /* Prepare age: */
    265         QString strAge;
    266 
    267         /* Age: [date time|%1d ago|%1h ago|%1min ago|%1sec ago] */
    268         SnapshotAgeFormat enmAgeFormat;
    269         const QDateTime now = QDateTime::currentDateTime();
    270         QDateTime then = m_timestamp;
    271         if (then > now)
    272             then = now; /* can happen if the host time is wrong */
    273         if (then.daysTo(now) > 30)
    274         {
    275             strAge = UISnapshotPane::tr(" (%1)").arg(then.toString(Qt::LocalDate));
    276             enmAgeFormat = SnapshotAgeFormat_Max;
    277         }
    278         else if (then.secsTo(now) > 60 * 60 * 24)
    279         {
    280             strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24));
    281             enmAgeFormat = SnapshotAgeFormat_InDays;
    282         }
    283         else if (then.secsTo(now) > 60 * 60)
    284         {
    285             strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60));
    286             enmAgeFormat = SnapshotAgeFormat_InHours;
    287         }
    288         else if (then.secsTo(now) > 60)
    289         {
    290             strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo(now) / 60));
    291             enmAgeFormat = SnapshotAgeFormat_InMinutes;
    292         }
    293         else
    294         {
    295             strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo(now)));
    296             enmAgeFormat = SnapshotAgeFormat_InSeconds;
    297         }
    298 
    299         /* Update data: */
    300         setData(0, Qt::UserRole, strAge);
    301 
    302         /* Return age: */
    303         return enmAgeFormat;
    304     }
     112    SnapshotAgeFormat updateAge();
    305113
    306114protected:
    307115
    308116    /** Adjusts item text. */
    309     void adjustText()
    310     {
    311         /* Make sure item is initialised: */
    312         if (!treeWidget())
    313             return;
    314 
    315         /* Calculate metrics: */
    316         QFontMetrics metrics(font(0));
    317         int iHei0 = (metrics.height() > 16 ?
    318                      metrics.height() /* text */ : 16 /* icon */) +
    319                     2 * 2 /* 2 pixel per margin */;
    320         int iWid0 = metrics.width(text(0)) /* text */ +
    321                     treeWidget()->indentation() /* indent */ +
    322                     16 /* icon */;
    323 
    324         /* Adjust size finally: */
    325         setSizeHint(0, QSize(iWid0, iHei0));
    326     }
     117    void adjustText();
    327118
    328119    /** Recaches item tool-tip. */
    329     void recacheToolTip()
    330     {
    331         /* Is the saved date today? */
    332         const bool fDateTimeToday = m_timestamp.date() == QDate::currentDate();
    333 
    334         /* Compose date time: */
    335         QString strDateTime = fDateTimeToday ?
    336                               m_timestamp.time().toString(Qt::LocalDate) :
    337                               m_timestamp.toString(Qt::LocalDate);
    338 
    339         /* Prepare details: */
    340         QString strDetails;
    341 
    342         /* For snapshot item: */
    343         if (!m_comSnapshot.isNull())
    344         {
    345             /* The current snapshot is always bold: */
    346             if (bold())
    347                 strDetails = UISnapshotPane::tr(" (current, ", "Snapshot details");
    348             else
    349                 strDetails = " (";
    350 
    351             /* Add online/offline information: */
    352             strDetails += m_fOnline ? UISnapshotPane::tr("online)", "Snapshot details")
    353                                     : UISnapshotPane::tr("offline)", "Snapshot details");
    354 
    355             /* Add date/time information: */
    356             if (fDateTimeToday)
    357                 strDateTime = UISnapshotPane::tr("Taken at %1", "Snapshot (time)").arg(strDateTime);
    358             else
    359                 strDateTime = UISnapshotPane::tr("Taken on %1", "Snapshot (date + time)").arg(strDateTime);
    360         }
    361         /* For "current state" item: */
    362         else
    363         {
    364             strDateTime = UISnapshotPane::tr("%1 since %2", "Current State (time or date + time)")
    365                           .arg(gpConverter->toString(m_enmMachineState)).arg(strDateTime);
    366         }
    367 
    368         /* Prepare tool-tip: */
    369         QString strToolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>")
    370                                  .arg(text(0)).arg(strDetails).arg(strDateTime);
    371 
    372         /* Append description if any: */
    373         if (!m_strDesc.isEmpty())
    374             strToolTip += "<hr>" + m_strDesc;
    375 
    376         /* Assign tool-tip finally: */
    377         setToolTip(0, strToolTip);
    378     }
     120    void recacheToolTip();
    379121
    380122private:
     
    407149};
    408150
     151
     152/*********************************************************************************************************************************
     153*   Class SnapshotWgtItem implementation.                                                                                        *
     154*********************************************************************************************************************************/
     155
     156SnapshotWgtItem::SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CSnapshot &comSnapshot)
     157    : QTreeWidgetItem(pTreeWidget, ItemType)
     158    , m_pSnapshotWidget(pSnapshotWidget)
     159    , m_fCurrentState(false)
     160    , m_comSnapshot(comSnapshot)
     161{
     162}
     163
     164SnapshotWgtItem::SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CSnapshot &comSnapshot)
     165    : QTreeWidgetItem(pRootItem, ItemType)
     166    , m_pSnapshotWidget(pSnapshotWidget)
     167    , m_fCurrentState(false)
     168    , m_comSnapshot(comSnapshot)
     169{
     170}
     171
     172SnapshotWgtItem::SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CMachine &comMachine)
     173    : QTreeWidgetItem(pTreeWidget, ItemType)
     174    , m_pSnapshotWidget(pSnapshotWidget)
     175    , m_fCurrentState(true)
     176    , m_comMachine(comMachine)
     177{
     178    /* Fetch current machine state: */
     179    updateCurrentState(m_comMachine.GetState());
     180}
     181
     182SnapshotWgtItem::SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CMachine &comMachine)
     183    : QTreeWidgetItem(pRootItem, ItemType)
     184    , m_pSnapshotWidget(pSnapshotWidget)
     185    , m_fCurrentState(true)
     186    , m_comMachine(comMachine)
     187{
     188    /* Fetch current machine state: */
     189    updateCurrentState(m_comMachine.GetState());
     190}
     191
     192QVariant SnapshotWgtItem::data(int iColumn, int iRole) const
     193{
     194    switch (iRole)
     195    {
     196        case Qt::DisplayRole:
     197        {
     198            /* Call to base-class for "current state" item, compose ourselves otherwise: */
     199            return m_fCurrentState ? QTreeWidgetItem::data(iColumn, iRole) :
     200                                     QString("%1%2")
     201                                         .arg(QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString())
     202                                         .arg(QTreeWidgetItem::data(iColumn, Qt::UserRole).toString());
     203        }
     204        case Qt::SizeHintRole:
     205        {
     206            /* Determine the icon metric: */
     207            const QStyle *pStyle = QApplication::style();
     208            const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
     209            /* Determine the minimum size-hint for this tree-widget-item: */
     210            const QSize baseSizeHint = QTreeWidgetItem::data(iColumn, iRole).toSize();
     211            /* Determine the effective height-hint for this tree-widget-item: */
     212            const int iEffectiveHeightHint = qMax(baseSizeHint.height(),
     213                                                  iIconMetric + 2 * 2 /* margins */);
     214            /* Return size-hint for this tree-widget-item: */
     215            return QSize(baseSizeHint.width(), iEffectiveHeightHint);
     216        }
     217        default:
     218            break;
     219    }
     220
     221    /* Call to base-class: */
     222    return QTreeWidgetItem::data(iColumn, iRole);
     223}
     224
     225QString SnapshotWgtItem::text(int iColumn) const
     226{
     227    return QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString();
     228}
     229
     230bool SnapshotWgtItem::isCurrentStateItem() const
     231{
     232    return m_comSnapshot.isNull();
     233}
     234
     235int SnapshotWgtItem::level() const
     236{
     237    const QTreeWidgetItem *pItem = this;
     238    int iResult = 0;
     239    while (pItem->parent())
     240    {
     241        ++iResult;
     242        pItem = pItem->parent();
     243    }
     244    return iResult;
     245}
     246
     247bool SnapshotWgtItem::bold() const
     248{
     249    return font(0).bold();
     250}
     251
     252void SnapshotWgtItem::setBold(bool fBold)
     253{
     254    /* Update font: */
     255    QFont myFont = font(0);
     256    myFont.setBold(fBold);
     257    setFont(0, myFont);
     258
     259    /* Adjust text: */
     260    adjustText();
     261}
     262
     263bool SnapshotWgtItem::italic() const
     264{
     265    return font(0).italic();
     266}
     267
     268void SnapshotWgtItem::setItalic(bool fItalic)
     269{
     270    /* Update font: */
     271    QFont myFont = font(0);
     272    myFont.setItalic(fItalic);
     273    setFont(0, myFont);
     274
     275    /* Adjust text: */
     276    adjustText();
     277}
     278
     279void SnapshotWgtItem::recache()
     280{
     281    /* For "current state" item: */
     282    if (m_fCurrentState)
     283    {
     284        /* Fetch machine information: */
     285        AssertReturnVoid(!m_comMachine.isNull());
     286        m_fCurrentStateModified = m_comMachine.GetCurrentStateModified();
     287        setText(0, m_fCurrentStateModified ?
     288                   UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") :
     289                   UISnapshotPane::tr("Current State", "Current State (Unmodified)"));
     290        m_strDesc = m_fCurrentStateModified ?
     291                    UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") :
     292                    parent() != 0 ?
     293                    UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") :
     294                    QString();
     295    }
     296    /* For others: */
     297    else
     298    {
     299        /* Fetch snapshot information: */
     300        AssertReturnVoid(!m_comSnapshot.isNull());
     301        m_strSnapshotID = m_comSnapshot.GetId();
     302        setText(0, m_comSnapshot.GetName());
     303        m_fOnline = m_comSnapshot.GetOnline();
     304        setIcon(0, m_pSnapshotWidget->snapshotItemIcon(m_fOnline));
     305        m_strDesc = m_comSnapshot.GetDescription();
     306        m_timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000);
     307        m_fCurrentStateModified = false;
     308    }
     309
     310    /* Adjust text: */
     311    adjustText();
     312    /* Update tool-tip: */
     313    recacheToolTip();
     314}
     315
     316KMachineState SnapshotWgtItem::getCurrentState() const
     317{
     318    /* Make sure machine is valid: */
     319    if (m_comMachine.isNull())
     320        return KMachineState_Null;
     321
     322    /* Return cached state: */
     323    return m_enmMachineState;
     324}
     325
     326void SnapshotWgtItem::updateCurrentState(KMachineState enmState)
     327{
     328    /* Make sure machine is valid: */
     329    if (m_comMachine.isNull())
     330        return;
     331
     332    /* Set corresponding icon: */
     333    setIcon(0, gpConverter->toIcon(enmState));
     334    /* Cache new state: */
     335    m_enmMachineState = enmState;
     336    /* Update timestamp: */
     337    m_timestamp.setTime_t(m_comMachine.GetLastStateChange() / 1000);
     338}
     339
     340SnapshotAgeFormat SnapshotWgtItem::updateAge()
     341{
     342    /* Prepare age: */
     343    QString strAge;
     344
     345    /* Age: [date time|%1d ago|%1h ago|%1min ago|%1sec ago] */
     346    SnapshotAgeFormat enmAgeFormat;
     347    const QDateTime now = QDateTime::currentDateTime();
     348    QDateTime then = m_timestamp;
     349    if (then > now)
     350        then = now; /* can happen if the host time is wrong */
     351    if (then.daysTo(now) > 30)
     352    {
     353        strAge = UISnapshotPane::tr(" (%1)").arg(then.toString(Qt::LocalDate));
     354        enmAgeFormat = SnapshotAgeFormat_Max;
     355    }
     356    else if (then.secsTo(now) > 60 * 60 * 24)
     357    {
     358        strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24));
     359        enmAgeFormat = SnapshotAgeFormat_InDays;
     360    }
     361    else if (then.secsTo(now) > 60 * 60)
     362    {
     363        strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60));
     364        enmAgeFormat = SnapshotAgeFormat_InHours;
     365    }
     366    else if (then.secsTo(now) > 60)
     367    {
     368        strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo(now) / 60));
     369        enmAgeFormat = SnapshotAgeFormat_InMinutes;
     370    }
     371    else
     372    {
     373        strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo(now)));
     374        enmAgeFormat = SnapshotAgeFormat_InSeconds;
     375    }
     376
     377    /* Update data: */
     378    setData(0, Qt::UserRole, strAge);
     379
     380    /* Return age: */
     381    return enmAgeFormat;
     382}
     383
     384void SnapshotWgtItem::adjustText()
     385{
     386    /* Make sure item is initialised: */
     387    if (!treeWidget())
     388        return;
     389
     390    /* Calculate metrics: */
     391    QFontMetrics metrics(font(0));
     392    int iHei0 = (metrics.height() > 16 ?
     393                 metrics.height() /* text */ : 16 /* icon */) +
     394                2 * 2 /* 2 pixel per margin */;
     395    int iWid0 = metrics.width(text(0)) /* text */ +
     396                treeWidget()->indentation() /* indent */ +
     397                16 /* icon */;
     398
     399    /* Adjust size finally: */
     400    setSizeHint(0, QSize(iWid0, iHei0));
     401}
     402
     403void SnapshotWgtItem::recacheToolTip()
     404{
     405    /* Is the saved date today? */
     406    const bool fDateTimeToday = m_timestamp.date() == QDate::currentDate();
     407
     408    /* Compose date time: */
     409    QString strDateTime = fDateTimeToday ?
     410                          m_timestamp.time().toString(Qt::LocalDate) :
     411                          m_timestamp.toString(Qt::LocalDate);
     412
     413    /* Prepare details: */
     414    QString strDetails;
     415
     416    /* For snapshot item: */
     417    if (!m_comSnapshot.isNull())
     418    {
     419        /* The current snapshot is always bold: */
     420        if (bold())
     421            strDetails = UISnapshotPane::tr(" (current, ", "Snapshot details");
     422        else
     423            strDetails = " (";
     424
     425        /* Add online/offline information: */
     426        strDetails += m_fOnline ? UISnapshotPane::tr("online)", "Snapshot details")
     427                                : UISnapshotPane::tr("offline)", "Snapshot details");
     428
     429        /* Add date/time information: */
     430        if (fDateTimeToday)
     431            strDateTime = UISnapshotPane::tr("Taken at %1", "Snapshot (time)").arg(strDateTime);
     432        else
     433            strDateTime = UISnapshotPane::tr("Taken on %1", "Snapshot (date + time)").arg(strDateTime);
     434    }
     435    /* For "current state" item: */
     436    else
     437    {
     438        strDateTime = UISnapshotPane::tr("%1 since %2", "Current State (time or date + time)")
     439                      .arg(gpConverter->toString(m_enmMachineState)).arg(strDateTime);
     440    }
     441
     442    /* Prepare tool-tip: */
     443    QString strToolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>")
     444                             .arg(text(0)).arg(strDetails).arg(strDateTime);
     445
     446    /* Append description if any: */
     447    if (!m_strDesc.isEmpty())
     448        strToolTip += "<hr>" + m_strDesc;
     449
     450    /* Assign tool-tip finally: */
     451    setToolTip(0, strToolTip);
     452}
     453
     454
     455/*********************************************************************************************************************************
     456*   Class UISnapshotPane implementation.                                                                                         *
     457*********************************************************************************************************************************/
    409458
    410459UISnapshotPane::UISnapshotPane(QWidget *pParent)
     
    11181167}
    11191168
     1169void UISnapshotPane::populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem)
     1170{
     1171    /* Create a child of passed item: */
     1172    SnapshotWgtItem *pSnapshotItem = pItem ? new SnapshotWgtItem(this, pItem, comSnapshot) :
     1173                                             new SnapshotWgtItem(this, m_pTreeWidget, comSnapshot);
     1174    /* And recache it's content: */
     1175    pSnapshotItem->recache();
     1176
     1177    /* Mark current snapshot item bold and remember it: */
     1178    CSnapshot comCurrentSnapshot = m_comMachine.GetCurrentSnapshot();
     1179    if (!comCurrentSnapshot.isNull() && comCurrentSnapshot.GetId() == comSnapshot.GetId())
     1180    {
     1181        pSnapshotItem->setBold(true);
     1182        m_pCurrentSnapshotItem = pSnapshotItem;
     1183    }
     1184
     1185    /* Walk through the children recursively: */
     1186    foreach (const CSnapshot &comIteratedSnapshot, comSnapshot.GetChildren())
     1187        populateSnapshots(comIteratedSnapshot, pSnapshotItem);
     1188
     1189    /* Expand the newly created item: */
     1190    pSnapshotItem->setExpanded(true);
     1191    /* And mark it as editable: */
     1192    pSnapshotItem->setFlags(pSnapshotItem->flags() | Qt::ItemIsEditable);
     1193}
     1194
    11201195SnapshotWgtItem *UISnapshotPane::findItem(const QString &strSnapshotID) const
    11211196{
     
    11431218}
    11441219
    1145 void UISnapshotPane::populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem)
    1146 {
    1147     /* Create a child of passed item: */
    1148     SnapshotWgtItem *pSnapshotItem = pItem ? new SnapshotWgtItem(this, pItem, comSnapshot) :
    1149                                              new SnapshotWgtItem(this, m_pTreeWidget, comSnapshot);
    1150     /* And recache it's content: */
    1151     pSnapshotItem->recache();
    1152 
    1153     /* Mark current snapshot item bold and remember it: */
    1154     CSnapshot comCurrentSnapshot = m_comMachine.GetCurrentSnapshot();
    1155     if (!comCurrentSnapshot.isNull() && comCurrentSnapshot.GetId() == comSnapshot.GetId())
    1156     {
    1157         pSnapshotItem->setBold(true);
    1158         m_pCurrentSnapshotItem = pSnapshotItem;
    1159     }
    1160 
    1161     /* Walk through the children recursively: */
    1162     foreach (const CSnapshot &comIteratedSnapshot, comSnapshot.GetChildren())
    1163         populateSnapshots(comIteratedSnapshot, pSnapshotItem);
    1164 
    1165     /* Expand the newly created item: */
    1166     pSnapshotItem->setExpanded(true);
    1167     /* And mark it as editable: */
    1168     pSnapshotItem->setFlags(pSnapshotItem->flags() | Qt::ItemIsEditable);
    1169 }
    1170 
    11711220SnapshotAgeFormat UISnapshotPane::traverseSnapshotAge(QTreeWidgetItem *pItem) const
    11721221{
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r63835 r63837  
    2020
    2121/* Qt includes: */
     22#include <QIcon>
    2223#include <QTimer>
    23 #include <QIcon>
    2424#include <QReadWriteLock>
    2525
    2626/* GUI includes: */
     27#include "QIWithRetranslateUI.h"
    2728#include "UISnapshotPane.gen.h"
    2829#include "VBoxGlobal.h"
    29 #include "QIWithRetranslateUI.h"
    3030
    3131/* COM includes: */
     
    130130    /** Refreshes everything. */
    131131    void refreshAll();
     132    /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */
     133    void populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem);
    132134
    133135    /** Searches for an item with corresponding @a strSnapshotID. */
     
    135137    /** Returns the "current state" item. */
    136138    SnapshotWgtItem *currentStateItem() const;
    137 
    138     /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */
    139     void populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem);
    140139
    141140    /** Searches for smallest snapshot age starting with @a pItem as parent. */
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