VirtualBox

Changeset 73715 in vbox for trunk/src


Ignore:
Timestamp:
Aug 16, 2018 3:35:27 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124394
Message:

FE/Qt: UIActionPool: Merging polymorph action functionality to UIAction base-class, which allows to have names/icons cached/activated depending on defined action state.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r73694 r73715  
    111111    , m_pActionPool(pParent)
    112112    , m_enmActionPoolType(pParent->type())
     113    , m_iState(0)
    113114    , m_fShortcutHidden(false)
    114115{
     
    129130}
    130131
    131 UIActionPolymorphic *UIAction::toActionPolymorphic()
    132 {
    133     return qobject_cast<UIActionPolymorphic*>(this);
    134 }
    135 
    136132UIActionPolymorphicMenu *UIAction::toActionPolymorphicMenu()
    137133{
    138134    return qobject_cast<UIActionPolymorphicMenu*>(this);
     135}
     136
     137void UIAction::setIcon(int iState, const QIcon &icon)
     138{
     139    m_icons.resize(iState + 1);
     140    m_icons[iState] = icon;
     141    updateIcon();
     142}
     143
     144void UIAction::setIcon(const QIcon &icon)
     145{
     146    setIcon(0, icon);
    139147}
    140148
     
    189197    /* Nothing by default: */
    190198    return QString();
     199}
     200
     201void UIAction::updateIcon()
     202{
     203    QAction::setIcon(m_icons.value(m_iState));
    191204}
    192205
     
    316329{
    317330    setCheckable(true);
    318 }
    319 
    320 
    321 /*********************************************************************************************************************************
    322 *   Class UIActionPolymorphic implementation.                                                                                    *
    323 *********************************************************************************************************************************/
    324 
    325 UIActionPolymorphic::UIActionPolymorphic(UIActionPool *pParent,
    326                                          const QString &strIcon /* = QString() */, const QString &strIconDisabled /* = QString() */)
    327     : UIAction(pParent, UIActionType_Polymorphic)
    328     , m_iState(0)
    329 {
    330     if (!strIcon.isNull())
    331         setIcon(UIIconPool::iconSet(strIcon, strIconDisabled));
    332 }
    333 
    334 UIActionPolymorphic::UIActionPolymorphic(UIActionPool *pParent,
    335                                          const QString &strIconNormal, const QString &strIconSmall,
    336                                          const QString &strIconNormalDisabled, const QString &strIconSmallDisabled)
    337     : UIAction(pParent, UIActionType_Polymorphic)
    338     , m_iState(0)
    339 {
    340     setIcon(UIIconPool::iconSetFull(strIconNormal, strIconSmall, strIconNormalDisabled, strIconSmallDisabled));
    341 }
    342 
    343 UIActionPolymorphic::UIActionPolymorphic(UIActionPool *pParent,
    344                                          const QIcon& icon)
    345     : UIAction(pParent, UIActionType_Polymorphic)
    346     , m_iState(0)
    347 {
    348     if (!icon.isNull())
    349         setIcon(icon);
    350331}
    351332
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r73694 r73715  
    2222#include <QAction>
    2323#include <QMenu>
     24#include <QVector>
    2425
    2526/* GUI includes: */
     
    3132class QKeySequence;
    3233class QString;
    33 class UIActionPolymorphic;
    3434class UIActionPolymorphicMenu;
    3535class UIActionPool;
     
    170170    UIActionPool *actionPool() const { return m_pActionPool; }
    171171
    172     /** Casts action to polymorphic-action. */
    173     UIActionPolymorphic *toActionPolymorphic();
    174172    /** Casts action to polymorphic-menu-action. */
    175173    UIActionPolymorphicMenu *toActionPolymorphicMenu();
     174
     175    /** Returns current action state. */
     176    int state() const { return m_iState; }
     177    /** Defines current action @a iState. */
     178    void setState(int iState) { m_iState = iState; updateIcon(); retranslateUi(); }
     179
     180    /** Defines @a icon for certain @a iState. */
     181    void setIcon(int iState, const QIcon &icon);
     182    /** Defines @a icon. */
     183    void setIcon(const QIcon &icon);
    176184
    177185    /** Returns current action name. */
     
    201209    /** Retranslates action. */
    202210    virtual void retranslateUi() = 0;
     211    /** Destructs action. */
    203212    virtual ~UIAction() /* override */ { delete menu(); }
    204213
     
    211220    /** Returns current action name in menu. */
    212221    QString nameInMenu() const;
     222
     223    /** Updates action icon. */
     224    virtual void updateIcon();
    213225
    214226    /** Updates action text accordingly. */
     
    225237    UIActionPoolType  m_enmActionPoolType;
    226238
     239    /** Holds current action state. */
     240    int             m_iState;
     241    /** Holds action icons. */
     242    QVector<QIcon>  m_icons;
    227243    /** Holds the action name. */
    228     QString       m_strName;
     244    QString         m_strName;
    229245    /** Holds the action shortcut. */
    230     QKeySequence  m_shortcut;
     246    QKeySequence    m_shortcut;
    231247    /** Holds whether action shortcut hidden. */
    232     bool          m_fShortcutHidden;
     248    bool            m_fShortcutHidden;
    233249};
    234250
     
    289305      * @param  icon  Brings the icon. */
    290306    UIActionSimple(UIActionPool *pParent,
    291                    const QIcon& icon);
     307                   const QIcon &icon);
    292308};
    293309
     
    325341
    326342
    327 /** Abstract UIAction extension for 'Polymorphic' action type. */
    328 class SHARED_LIBRARY_STUFF UIActionPolymorphic : public UIAction
    329 {
    330     Q_OBJECT;
    331 
    332 public:
    333 
    334     /** Returns current action state. */
    335     int state() const { return m_iState; }
    336     /** Defines current action state. */
    337     void setState(int iState) { m_iState = iState; retranslateUi(); }
    338 
    339 protected:
    340 
    341     /** Constructs polymorphic action passing @a pParent to the base-class.
    342       * @param  strIcon          Brings the normal-icon name.
    343       * @param  strIconDisabled  Brings the disabled-icon name. */
    344     UIActionPolymorphic(UIActionPool *pParent,
    345                         const QString &strIcon = QString(), const QString &strIconDisabled = QString());
    346     /** Constructs polymorphic action passing @a pParent to the base-class.
    347       * @param  strIconNormal          Brings the normal-icon name.
    348       * @param  strIconSmall           Brings the small-icon name.
    349       * @param  strIconNormalDisabled  Brings the normal-disabled-icon name.
    350       * @param  strIconSmallDisabled   Brings the small-disabled-icon name. */
    351     UIActionPolymorphic(UIActionPool *pParent,
    352                         const QString &strIconNormal, const QString &strIconSmall,
    353                         const QString &strIconNormalDisabled, const QString &strIconSmallDisabled);
    354     /** Constructs polymorphic action passing @a pParent to the base-class.
    355       * @param  icon  Brings the icon. */
    356     UIActionPolymorphic(UIActionPool *pParent,
    357                         const QIcon& icon);
    358 
    359 private:
    360 
    361     /** Holds current action state. */
    362     int m_iState;
    363 };
    364 
    365 
    366343/** Abstract UIAction extension for 'Polymorphic Menu' action type. */
    367344class SHARED_LIBRARY_STUFF UIActionPolymorphicMenu : public UIAction
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