VirtualBox

Ignore:
Timestamp:
Jun 4, 2014 1:08:25 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 6660: Advanced extra-data management framework: Integrate GUI_PreviewUpdate.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverter.h

    r50041 r51531  
    8888    }
    8989
     90    /* int <= template class: */
     91    template<class T> int toInternalInteger(const T &data) const
     92    {
     93        if (canConvert<T>())
     94            return ::toInternalInteger(data);
     95        Assert(0); return 0;
     96    }
     97    /* Template class <= int: */
     98    template<class T> T fromInternalInteger(const int &iData) const
     99    {
     100        if (canConvert<T>())
     101            return ::fromInternalInteger<T>(iData);
     102        Assert(0); return T();
     103    }
     104
    90105private:
    91106
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackend.h

    r51484 r51531  
    5858template<class X> X fromInternalString(const QString & /* strData */) { Assert(0); return X(); }
    5959
     60/* Converts passed 'Object of type X' to abstract integer.
     61 * This function returns 0 for any object type until re-determined for specific one. */
     62template<class X> int toInternalInteger(const X & /* xobject */) { Assert(0); return 0; }
     63/* Converts passed abstract integer to 'Object of type X'.
     64 * This function returns default constructed object for any object type until re-determined for specific one. */
     65template<class X> X fromInternalInteger(const int & /* iData */) { Assert(0); return X(); }
     66
    6067/* Declare global canConvert specializations: */
    6168template<> bool canConvert<SizeSuffix>();
     
    7481template<> bool canConvert<UIVisualStateType>();
    7582template<> bool canConvert<DetailsElementType>();
     83template<> bool canConvert<PreviewUpdateIntervalType>();
    7684template<> bool canConvert<GlobalSettingsPageType>();
    7785template<> bool canConvert<MachineSettingsPageType>();
     
    134142template<> QString toInternalString(const DetailsElementType &detailsElementType);
    135143template<> DetailsElementType fromInternalString<DetailsElementType>(const QString &strDetailsElementType);
     144template<> QString toInternalString(const PreviewUpdateIntervalType &previewUpdateIntervalType);
     145template<> PreviewUpdateIntervalType fromInternalString<PreviewUpdateIntervalType>(const QString &strPreviewUpdateIntervalType);
     146template<> int toInternalInteger(const PreviewUpdateIntervalType &previewUpdateIntervalType);
     147template<> PreviewUpdateIntervalType fromInternalInteger<PreviewUpdateIntervalType>(const int &iPreviewUpdateIntervalType);
    136148template<> QString toInternalString(const GlobalSettingsPageType &globalSettingsPageType);
    137149template<> GlobalSettingsPageType fromInternalString<GlobalSettingsPageType>(const QString &strGlobalSettingsPageType);
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp

    r51484 r51531  
    4747template<> bool canConvert<UIVisualStateType>() { return true; }
    4848template<> bool canConvert<DetailsElementType>() { return true; }
     49template<> bool canConvert<PreviewUpdateIntervalType>() { return true; }
    4950template<> bool canConvert<GlobalSettingsPageType>() { return true; }
    5051template<> bool canConvert<MachineSettingsPageType>() { return true; }
     
    822823}
    823824
     825/* QString <= PreviewUpdateIntervalType: */
     826template<> QString toInternalString(const PreviewUpdateIntervalType &previewUpdateIntervalType)
     827{
     828    /* Return corresponding QString representation for passed enum value: */
     829    switch (previewUpdateIntervalType)
     830    {
     831        case PreviewUpdateIntervalType_Disabled: return "disabled";
     832        case PreviewUpdateIntervalType_500ms:    return "500";
     833        case PreviewUpdateIntervalType_1000ms:   return "1000";
     834        case PreviewUpdateIntervalType_2000ms:   return "2000";
     835        case PreviewUpdateIntervalType_5000ms:   return "5000";
     836        case PreviewUpdateIntervalType_10000ms:  return "10000";
     837        default: AssertMsgFailed(("No text for '%d'", previewUpdateIntervalType)); break;
     838    }
     839    /* Return QString() by default: */
     840    return QString();
     841}
     842
     843/* PreviewUpdateIntervalType <= QString: */
     844template<> PreviewUpdateIntervalType fromInternalString<PreviewUpdateIntervalType>(const QString &strPreviewUpdateIntervalType)
     845{
     846    /* Here we have some fancy stuff allowing us
     847     * to search through the keys using 'case-insensitive' rule: */
     848    QStringList keys;   QList<PreviewUpdateIntervalType> values;
     849    keys << "disabled"; values << PreviewUpdateIntervalType_Disabled;
     850    keys << "500";      values << PreviewUpdateIntervalType_500ms;
     851    keys << "1000";     values << PreviewUpdateIntervalType_1000ms;
     852    keys << "2000";     values << PreviewUpdateIntervalType_2000ms;
     853    keys << "5000";     values << PreviewUpdateIntervalType_5000ms;
     854    keys << "10000";    values << PreviewUpdateIntervalType_10000ms;
     855    /* 1000ms type for unknown words: */
     856    if (!keys.contains(strPreviewUpdateIntervalType, Qt::CaseInsensitive))
     857        return PreviewUpdateIntervalType_1000ms;
     858    /* Corresponding type for known words: */
     859    return values.at(keys.indexOf(QRegExp(strPreviewUpdateIntervalType, Qt::CaseInsensitive)));
     860}
     861
     862/* int <= PreviewUpdateIntervalType: */
     863template<> int toInternalInteger(const PreviewUpdateIntervalType &previewUpdateIntervalType)
     864{
     865    /* Return corresponding integer representation for passed enum value: */
     866    switch (previewUpdateIntervalType)
     867    {
     868        case PreviewUpdateIntervalType_Disabled: return 0;
     869        case PreviewUpdateIntervalType_500ms:    return 500;
     870        case PreviewUpdateIntervalType_1000ms:   return 1000;
     871        case PreviewUpdateIntervalType_2000ms:   return 2000;
     872        case PreviewUpdateIntervalType_5000ms:   return 5000;
     873        case PreviewUpdateIntervalType_10000ms:  return 10000;
     874        default: AssertMsgFailed(("No value for '%d'", previewUpdateIntervalType)); break;
     875    }
     876    /* Return 0 by default: */
     877    return 0;
     878}
     879
     880/* PreviewUpdateIntervalType <= int: */
     881template<> PreviewUpdateIntervalType fromInternalInteger<PreviewUpdateIntervalType>(const int &iPreviewUpdateIntervalType)
     882{
     883    /* Add all the enum values into the hash: */
     884    QHash<int, PreviewUpdateIntervalType> hash;
     885    hash.insert(0,     PreviewUpdateIntervalType_Disabled);
     886    hash.insert(500,   PreviewUpdateIntervalType_500ms);
     887    hash.insert(1000,  PreviewUpdateIntervalType_1000ms);
     888    hash.insert(2000,  PreviewUpdateIntervalType_2000ms);
     889    hash.insert(5000,  PreviewUpdateIntervalType_5000ms);
     890    hash.insert(10000, PreviewUpdateIntervalType_10000ms);
     891    /* Make sure hash contains incoming integer representation: */
     892    if (!hash.contains(iPreviewUpdateIntervalType))
     893        AssertMsgFailed(("No value for '%d'", iPreviewUpdateIntervalType));
     894    /* Return corresponding enum value for passed integer representation: */
     895    return hash.value(iPreviewUpdateIntervalType);
     896}
     897
    824898/* QString <= GlobalSettingsPageType: */
    825899template<> QString toInternalString(const GlobalSettingsPageType &globalSettingsPageType)
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r51484 r51531  
    227227Q_DECLARE_METATYPE(DetailsElementType);
    228228
     229/** Selector UI: Preview update interval types. */
     230enum PreviewUpdateIntervalType
     231{
     232    PreviewUpdateIntervalType_Disabled,
     233    PreviewUpdateIntervalType_500ms,
     234    PreviewUpdateIntervalType_1000ms,
     235    PreviewUpdateIntervalType_2000ms,
     236    PreviewUpdateIntervalType_5000ms,
     237    PreviewUpdateIntervalType_10000ms,
     238    PreviewUpdateIntervalType_Max
     239};
     240
    229241
    230242/** Runtime UI: Menu types. */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r51515 r51531  
    427427}
    428428
     429PreviewUpdateIntervalType UIExtraDataManager::selectorWindowPreviewUpdateInterval() const
     430{
     431    return gpConverter->fromInternalString<PreviewUpdateIntervalType>(extraDataString(GUI_PreviewUpdate));
     432}
     433
     434void UIExtraDataManager::setSelectorWindowPreviewUpdateInterval(PreviewUpdateIntervalType interval)
     435{
     436    setExtraDataString(GUI_PreviewUpdate, gpConverter->toInternalString(interval));
     437}
     438
    429439bool UIExtraDataManager::isFirstRun(const QString &strId) const
    430440{
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r51515 r51531  
    151151    /** Defines whether selector-window status-bar @a fVisible. */
    152152    void setSelectorWindowStatusBarVisible(bool fVisible);
     153
     154    /** Returns selector-window preview update interval. */
     155    PreviewUpdateIntervalType selectorWindowPreviewUpdateInterval() const;
     156    /** Defines selector-window preview update @a interval. */
     157    void setSelectorWindowPreviewUpdateInterval(PreviewUpdateIntervalType interval);
    153158
    154159    /** Returns whether this machine started for the first time. */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.cpp

    r51411 r51531  
    2727#include "UIGMachinePreview.h"
    2828#include "UIVirtualBoxEventHandler.h"
    29 #include "UIExtraDataDefs.h"
     29#include "UIExtraDataManager.h"
    3030#include "UIImageTools.h"
     31#include "UIConverter.h"
    3132#include "UIIconPool.h"
    3233#include "VBoxGlobal.h"
     
    3536#include "CConsole.h"
    3637#include "CDisplay.h"
    37 
    38 UpdateIntervalMap CreateUpdateIntervalMap()
    39 {
    40     UpdateIntervalMap map;
    41     map[UpdateInterval_Disabled] = "disabled";
    42     map[UpdateInterval_500ms]    = "500";
    43     map[UpdateInterval_1000ms]   = "1000";
    44     map[UpdateInterval_2000ms]   = "2000";
    45     map[UpdateInterval_5000ms]   = "5000";
    46     map[UpdateInterval_10000ms]  = "10000";
    47     return map;
    48 }
    49 UpdateIntervalMap UIGMachinePreview::m_intervals = CreateUpdateIntervalMap();
    5038
    5139UIGMachinePreview::UIGMachinePreview(QIGraphicsWidget *pParent)
     
    7260    QActionGroup *pUpdateTimeG = new QActionGroup(this);
    7361    pUpdateTimeG->setExclusive(true);
    74     for(int i = 0; i < UpdateInterval_Max; ++i)
     62    for(int i = 0; i < PreviewUpdateIntervalType_Max; ++i)
    7563    {
    7664        QAction *pUpdateTime = new QAction(pUpdateTimeG);
     
    7967        pUpdateTimeG->addAction(pUpdateTime);
    8068        m_pUpdateTimerMenu->addAction(pUpdateTime);
    81         m_actions[static_cast<UpdateInterval>(i)] = pUpdateTime;
    82     }
    83     m_pUpdateTimerMenu->insertSeparator(m_actions[static_cast<UpdateInterval>(UpdateInterval_500ms)]);
    84 
    85     /* Load preview update interval: */
    86     QString strInterval = vboxGlobal().virtualBox().GetExtraData(GUI_PreviewUpdate);
    87     /* Parse loaded value: */
    88     UpdateInterval interval = m_intervals.key(strInterval, UpdateInterval_1000ms);
     69        m_actions[static_cast<PreviewUpdateIntervalType>(i)] = pUpdateTime;
     70    }
     71    m_pUpdateTimerMenu->insertSeparator(m_actions[static_cast<PreviewUpdateIntervalType>(PreviewUpdateIntervalType_500ms)]);
     72
    8973    /* Initialize with the new update interval: */
    90     setUpdateInterval(interval, false);
     74    setUpdateInterval(gEDataManager->selectorWindowPreviewUpdateInterval(), false);
    9175
    9276    /* Setup connections: */
     
    267251    if (pReturn)
    268252    {
    269         UpdateInterval interval = static_cast<UpdateInterval>(pReturn->data().toInt());
     253        PreviewUpdateIntervalType interval = static_cast<PreviewUpdateIntervalType>(pReturn->data().toInt());
    270254        setUpdateInterval(interval, true);
    271255        restart();
     
    275259void UIGMachinePreview::retranslateUi()
    276260{
    277     m_actions.value(UpdateInterval_Disabled)->setText(tr("Update disabled"));
    278     m_actions.value(UpdateInterval_500ms)->setText(tr("Every 0.5 s"));
    279     m_actions.value(UpdateInterval_1000ms)->setText(tr("Every 1 s"));
    280     m_actions.value(UpdateInterval_2000ms)->setText(tr("Every 2 s"));
    281     m_actions.value(UpdateInterval_5000ms)->setText(tr("Every 5 s"));
    282     m_actions.value(UpdateInterval_10000ms)->setText(tr("Every 10 s"));
     261    m_actions.value(PreviewUpdateIntervalType_Disabled)->setText(tr("Update disabled"));
     262    m_actions.value(PreviewUpdateIntervalType_500ms)->setText(tr("Every 0.5 s"));
     263    m_actions.value(PreviewUpdateIntervalType_1000ms)->setText(tr("Every 1 s"));
     264    m_actions.value(PreviewUpdateIntervalType_2000ms)->setText(tr("Every 2 s"));
     265    m_actions.value(PreviewUpdateIntervalType_5000ms)->setText(tr("Every 5 s"));
     266    m_actions.value(PreviewUpdateIntervalType_10000ms)->setText(tr("Every 10 s"));
    283267}
    284268
     
    334318}
    335319
    336 void UIGMachinePreview::setUpdateInterval(UpdateInterval interval, bool fSave)
     320void UIGMachinePreview::setUpdateInterval(PreviewUpdateIntervalType interval, bool fSave)
    337321{
    338322    switch (interval)
    339323    {
    340         case UpdateInterval_Disabled:
     324        case PreviewUpdateIntervalType_Disabled:
    341325        {
    342             m_pUpdateTimer->setInterval(0);
     326            /* Stop the timer: */
    343327            m_pUpdateTimer->stop();
     328            /* And continue with other cases: */
     329        }
     330        case PreviewUpdateIntervalType_500ms:
     331        case PreviewUpdateIntervalType_1000ms:
     332        case PreviewUpdateIntervalType_2000ms:
     333        case PreviewUpdateIntervalType_5000ms:
     334        case PreviewUpdateIntervalType_10000ms:
     335        {
     336            /* Set the timer interval: */
     337            m_pUpdateTimer->setInterval(gpConverter->toInternalInteger(interval));
     338            /* Check corresponding action: */
    344339            m_actions[interval]->setChecked(true);
    345340            break;
    346341        }
    347         case UpdateInterval_500ms:
    348         {
    349             m_pUpdateTimer->setInterval(500);
    350             m_actions[interval]->setChecked(true);
     342        case PreviewUpdateIntervalType_Max:
    351343            break;
    352         }
    353         case UpdateInterval_1000ms:
    354         {
    355             m_pUpdateTimer->setInterval(1000);
    356             m_actions[interval]->setChecked(true);
    357             break;
    358         }
    359         case UpdateInterval_2000ms:
    360         {
    361             m_pUpdateTimer->setInterval(2000);
    362             m_actions[interval]->setChecked(true);
    363             break;
    364         }
    365         case UpdateInterval_5000ms:
    366         {
    367             m_pUpdateTimer->setInterval(5000);
    368             m_actions[interval]->setChecked(true);
    369             break;
    370         }
    371         case UpdateInterval_10000ms:
    372         {
    373             m_pUpdateTimer->setInterval(10000);
    374             m_actions[interval]->setChecked(true);
    375             break;
    376         }
    377         case UpdateInterval_Max: break;
    378     }
    379     if (fSave && m_intervals.contains(interval))
    380         vboxGlobal().virtualBox().SetExtraData(GUI_PreviewUpdate, m_intervals[interval]);
     344    }
     345    if (fSave)
     346        gEDataManager->setSelectorWindowPreviewUpdateInterval(interval);
    381347}
    382348
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGMachinePreview.h

    r50924 r51531  
    2424
    2525/* GUI includes: */
     26#include "QIWithRetranslateUI.h"
    2627#include "UIGDetailsItem.h"
    27 #include "QIWithRetranslateUI.h"
     28#include "UIExtraDataDefs.h"
    2829
    2930/* COM includes: */
     
    3839class QMenu;
    3940class QTimer;
    40 
    41 /* Update interval type: */
    42 enum UpdateInterval
    43 {
    44     UpdateInterval_Disabled,
    45     UpdateInterval_500ms,
    46     UpdateInterval_1000ms,
    47     UpdateInterval_2000ms,
    48     UpdateInterval_5000ms,
    49     UpdateInterval_10000ms,
    50     UpdateInterval_Max
    51 };
    52 typedef QMap<UpdateInterval, QString> UpdateIntervalMap;
    5341
    5442/* Preview window class: */
     
    9785
    9886    /* Helpers: Update stuff: */
    99     void setUpdateInterval(UpdateInterval interval, bool fSave);
     87    void setUpdateInterval(PreviewUpdateIntervalType interval, bool fSave);
    10088    void recalculatePreviewRectangle();
    10189    void restart();
     
    10795    QTimer *m_pUpdateTimer;
    10896    QMenu *m_pUpdateTimerMenu;
    109     QHash<UpdateInterval, QAction*> m_actions;
     97    QHash<PreviewUpdateIntervalType, QAction*> m_actions;
    11098    const int m_iMargin;
    11199    QRect m_vRect;
     
    114102    QImage *m_pPreviewImg;
    115103    QString m_strPreviewName;
    116     static UpdateIntervalMap m_intervals;
    117104};
    118105
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