VirtualBox

Changeset 85642 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 7, 2020 11:33:29 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9609: A bit of cleanup for action-pool stuff: Merge UIActionPolymorphicMenu class to UIActionMenu, integrating polymorphic functions to latter.

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

Legend:

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

    r85641 r85642  
    208208    {
    209209        case UIActionType_Menu:
    210         case UIActionType_PolymorphicMenu:
    211210        {
    212211            /* For menu types it's very easy: */
     
    255254                           const QString &strIcon, const QString &strIconDisabled)
    256255    : UIAction(pParent, UIActionType_Menu)
     256    , m_pMenu(0)
    257257{
    258258    if (!strIcon.isNull())
     
    265265                           const QString &strIconNormalDisabled, const QString &strIconSmallDisabled)
    266266    : UIAction(pParent, UIActionType_Menu)
     267    , m_pMenu(0)
    267268{
    268269    if (!strIconNormal.isNull())
     
    274275                           const QIcon &icon)
    275276    : UIAction(pParent, UIActionType_Menu)
     277    , m_pMenu(0)
    276278{
    277279    if (!icon.isNull())
     
    280282}
    281283
     284UIActionMenu::~UIActionMenu()
     285{
     286    /* Hide menu: */
     287    hideMenu();
     288    /* Delete menu: */
     289    delete m_pMenu;
     290    m_pMenu = 0;
     291}
     292
    282293void UIActionMenu::setShowToolTip(bool fShowToolTip)
    283294{
    284     UIMenu *pMenu = qobject_cast<UIMenu*>(menu());
    285     AssertPtrReturnVoid(pMenu);
    286     pMenu->setShowToolTip(fShowToolTip);
     295    AssertPtrReturnVoid(m_pMenu);
     296    m_pMenu->setShowToolTip(fShowToolTip);
     297}
     298
     299void UIActionMenu::showMenu()
     300{
     301    /* Show menu if necessary: */
     302    if (!menu())
     303        setMenu(m_pMenu);
     304}
     305
     306void UIActionMenu::hideMenu()
     307{
     308    /* Hide menu if necessary: */
     309    if (menu())
     310        setMenu(0);
    287311}
    288312
     
    290314{
    291315    /* Create menu: */
    292     setMenu(new UIMenu);
    293     AssertPtrReturnVoid(menu());
     316    m_pMenu = new UIMenu;
     317    AssertPtrReturnVoid(m_pMenu);
    294318    {
    295319        /* Prepare menu: */
    296         connect(menu(), &UIMenu::aboutToShow,
     320        connect(m_pMenu, &UIMenu::aboutToShow,
    297321                actionPool(), &UIActionPool::sltHandleMenuPrepare);
     322        /* Show menu: */
     323        showMenu();
    298324    }
    299325}
     
    384410{
    385411    setCheckable(true);
    386 }
    387 
    388 
    389 /*********************************************************************************************************************************
    390 *   Class UIActionPolymorphicMenu implementation.                                                                                *
    391 *********************************************************************************************************************************/
    392 
    393 UIActionPolymorphicMenu::UIActionPolymorphicMenu(UIActionPool *pParent,
    394                                                  const QString &strIcon, const QString &strIconDisabled)
    395     : UIAction(pParent, UIActionType_PolymorphicMenu)
    396     , m_pMenu(0)
    397 {
    398     if (!strIcon.isNull())
    399         setIcon(UIIconPool::iconSet(strIcon, strIconDisabled));
    400     prepare();
    401 }
    402 
    403 UIActionPolymorphicMenu::UIActionPolymorphicMenu(UIActionPool *pParent,
    404                                                  const QString &strIconNormal, const QString &strIconSmall,
    405                                                  const QString &strIconNormalDisabled, const QString &strIconSmallDisabled)
    406     : UIAction(pParent, UIActionType_PolymorphicMenu)
    407     , m_pMenu(0)
    408 {
    409     if (!strIconNormal.isNull())
    410         setIcon(UIIconPool::iconSetFull(strIconNormal, strIconSmall, strIconNormalDisabled, strIconSmallDisabled));
    411     prepare();
    412 }
    413 
    414 UIActionPolymorphicMenu::UIActionPolymorphicMenu(UIActionPool *pParent,
    415                                                  const QIcon &icon)
    416     : UIAction(pParent, UIActionType_PolymorphicMenu)
    417     , m_pMenu(0)
    418 {
    419     if (!icon.isNull())
    420         setIcon(icon);
    421     prepare();
    422 }
    423 
    424 UIActionPolymorphicMenu::~UIActionPolymorphicMenu()
    425 {
    426     /* Hide menu: */
    427     hideMenu();
    428     /* Delete menu: */
    429     delete m_pMenu;
    430     m_pMenu = 0;
    431 }
    432 
    433 void UIActionPolymorphicMenu::setShowToolTip(bool fShowToolTip)
    434 {
    435     UIMenu *pMenu = qobject_cast<UIMenu*>(menu());
    436     if (pMenu)
    437         pMenu->setShowToolTip(fShowToolTip);
    438 }
    439 
    440 void UIActionPolymorphicMenu::showMenu()
    441 {
    442     /* Show menu if necessary: */
    443     if (!menu())
    444         setMenu(m_pMenu);
    445 }
    446 
    447 void UIActionPolymorphicMenu::hideMenu()
    448 {
    449     /* Hide menu if necessary: */
    450     if (menu())
    451         setMenu(0);
    452 }
    453 
    454 void UIActionPolymorphicMenu::prepare()
    455 {
    456     /* Create menu: */
    457     m_pMenu = new UIMenu;
    458     AssertPtrReturnVoid(m_pMenu);
    459     {
    460         /* Prepare menu: */
    461         connect(m_pMenu, &UIMenu::aboutToShow,
    462                 actionPool(), &UIActionPool::sltHandleMenuPrepare);
    463         /* Show menu: */
    464         showMenu();
    465     }
    466412}
    467413
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r85641 r85642  
    5252    UIActionType_Menu,
    5353    UIActionType_Simple,
    54     UIActionType_Toggle,
    55     UIActionType_PolymorphicMenu
     54    UIActionType_Toggle
    5655};
    5756
     
    329328                 const QIcon &icon);
    330329
     330    /** Destructs menu action. */
     331    virtual ~UIActionMenu() /* override */;
     332
    331333    /** Defines whether tool-tip should be shown. */
    332334    void setShowToolTip(bool fShowToolTip);
    333335
     336    /** Shows menu. */
     337    void showMenu();
     338    /** Hides menu. */
     339    void hideMenu();
     340
    334341private:
    335342
    336343    /** Prepares all. */
    337344    void prepare();
     345
     346    /** Holds the menu instance. */
     347    UIMenu *m_pMenu;
    338348};
    339349
     
    415425    /** Prepares all. */
    416426    void prepare();
    417 };
    418 
    419 
    420 /** Abstract UIAction extension for 'Polymorphic Menu' action type. */
    421 class SHARED_LIBRARY_STUFF UIActionPolymorphicMenu : public UIAction
    422 {
    423     Q_OBJECT;
    424 
    425 protected:
    426 
    427     /** Constructs polymorphic menu action passing @a pParent to the base-class.
    428       * @param  strIcon          Brings the normal-icon name.
    429       * @param  strIconDisabled  Brings the disabled-icon name. */
    430     UIActionPolymorphicMenu(UIActionPool *pParent,
    431                             const QString &strIcon = QString(), const QString &strIconDisabled = QString());
    432     /** Constructs polymorphic menu action passing @a pParent to the base-class.
    433       * @param  strIconNormal          Brings the normal-icon name.
    434       * @param  strIconSmall           Brings the small-icon name.
    435       * @param  strIconNormalDisabled  Brings the normal-disabled-icon name.
    436       * @param  strIconSmallDisabled   Brings the small-disabled-icon name. */
    437     UIActionPolymorphicMenu(UIActionPool *pParent,
    438                             const QString &strIconNormal, const QString &strIconSmall,
    439                             const QString &strIconNormalDisabled, const QString &strIconSmallDisabled);
    440     /** Constructs polymorphic menu action passing @a pParent to the base-class.
    441       * @param  icon  Brings the icon. */
    442     UIActionPolymorphicMenu(UIActionPool *pParent,
    443                             const QIcon &icon);
    444 
    445     /** Destructs polymorphic menu action. */
    446     virtual ~UIActionPolymorphicMenu() /* override */;
    447 
    448     /** Defines whether tool-tip should be shown. */
    449     void setShowToolTip(bool fShowToolTip);
    450 
    451     /** Shows menu. */
    452     void showMenu();
    453     /** Hides menu. */
    454     void hideMenu();
    455 
    456 private:
    457 
    458     /** Prepares all. */
    459     void prepare();
    460 
    461 private:
    462 
    463     /** Holds the menu instance. */
    464     UIMenu *m_pMenu;
    465427};
    466428
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolManager.cpp

    r85634 r85642  
    923923
    924924/** Menu action extension, used as 'Start or Show' menu class. */
    925 class UIActionStateManagerCommonStartOrShow : public UIActionPolymorphicMenu
     925class UIActionStateManagerCommonStartOrShow : public UIActionMenu
    926926{
    927927    Q_OBJECT;
     
    931931    /** Constructs action passing @a pParent to the base-class. */
    932932    UIActionStateManagerCommonStartOrShow(UIActionPool *pParent)
    933         : UIActionPolymorphicMenu(pParent,
    934                                   ":/vm_start_32px.png", ":/vm_start_16px.png",
    935                                   ":/vm_start_disabled_32px.png", ":/vm_start_disabled_16px.png")
     933        : UIActionMenu(pParent,
     934                       ":/vm_start_32px.png", ":/vm_start_16px.png",
     935                       ":/vm_start_disabled_32px.png", ":/vm_start_disabled_16px.png")
    936936    {}
    937937
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