VirtualBox

Ignore:
Timestamp:
Jul 29, 2017 4:17:22 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
117270
Message:

FE/Qt: bugref:8900: UIToolsToolbar: Move buttons part onto UIToolBar rails, it appeared much easier to maintain.

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

Legend:

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

    r68175 r68178  
    2121
    2222/* Qt includes: */
    23 #include <QAction>
    24 #include <QButtonGroup>
    25 #include <QLabel>
    26 #include <QStackedLayout>
    27 #include <QUuid>
     23# include <QAction>
     24# include <QButtonGroup>
     25# include <QLabel>
     26# include <QStackedLayout>
     27# include <QToolButton>
    2828
    2929/* GUI includes: */
    30 #include "QIToolButton.h"
    31 #include "UIActionPoolSelector.h"
    32 #include "UITabBar.h"
    33 #include "UIToolsToolbar.h"
     30# include "UIActionPoolSelector.h"
     31# include "UITabBar.h"
     32# include "UIToolBar.h"
     33# include "UIToolsToolbar.h"
    3434
    3535/* Other VBox includes: */
    36 #include "iprt/assert.h"
     36# include "iprt/assert.h"
    3737
    3838#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    4444    , m_pLayoutMain(0)
    4545    , m_pLayoutStacked(0)
    46     , m_pLayoutButton(0)
    4746    , m_pTabBarMachine(0)
    48     , m_pLabel(0)
     47    , m_pToolBar(0)
    4948{
    5049    /* Prepare: */
     
    9695}
    9796
    98 void UIToolsToolbar::sltHandleButtonToggle()
     97void UIToolsToolbar::sltHandleActionToggle()
    9998{
    10099    /* Acquire the sender: */
    101     QIToolButton *pButton = sender() ? qobject_cast<QIToolButton*>(sender()) : 0;
    102     if (!pButton)
    103         pButton = m_mapButtons.value(m_mapButtons.keys().first());
     100    UIAction *pAction = sender() ? qobject_cast<UIAction*>(sender()) : 0;
     101    if (!pAction)
     102        pAction = m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine);
    104103
    105     /* Handle known buttons: */
    106     if (m_pLayoutStacked && m_mapButtons.values().contains(pButton))
     104    /* Handle known actions: */
     105    if (m_pLayoutStacked)
    107106    {
    108         switch (m_mapButtons.key(pButton))
    109         {
    110             case ActionType_Machine: m_pLayoutStacked->setCurrentWidget(m_pTabBarMachine); break;
    111         }
     107        if (pAction == m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine))
     108            m_pLayoutStacked->setCurrentWidget(m_pTabBarMachine);
    112109    }
    113 
    114     /* Update label's text: */
    115     m_pLabel->setText(pButton->text().remove('&'));
    116110}
    117111
     
    122116    /* Prepare widgets: */
    123117    prepareWidgets();
    124     /* Prepare connections: */
    125     prepareConnections();
    126 
    127     /* Initialize: */
    128     sltHandleButtonToggle();
    129118}
    130119
     
    147136        m_pActionPool->action(UIActionIndexST_M_Tools_M_Machine_Snapshots)->setProperty("ToolTypeMachine", QVariant::fromValue(ToolTypeMachine_Snapshots));
    148137    }
     138
     139    /* Configure 'Machine' toggle action: */
     140    m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine)->setMenu(pMenuMachine);
     141    connect(m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine), &UIAction::toggled,
     142            this, &UIToolsToolbar::sltHandleActionToggle);
    149143}
    150144
     
    152146{
    153147    /* Create main layout: */
    154     m_pLayoutMain = new QGridLayout(this);
     148    m_pLayoutMain = new QHBoxLayout(this);
    155149    AssertPtrReturnVoid(m_pLayoutMain);
    156150    {
    157151        /* Configure layout: */
    158152        m_pLayoutMain->setContentsMargins(0, 0, 0, 0);
    159         m_pLayoutMain->setHorizontalSpacing(10);
    160         m_pLayoutMain->setVerticalSpacing(0);
     153        m_pLayoutMain->setSpacing(10);
    161154
    162155        /* Create stacked layout: */
     
    179172
    180173            /* Add into layout: */
    181             m_pLayoutMain->addLayout(m_pLayoutStacked, 0, 0);
     174            m_pLayoutMain->addLayout(m_pLayoutStacked);
    182175        }
    183176
    184         /* Create sub-layout: */
    185         m_pLayoutButton = new QHBoxLayout;
    186         AssertPtrReturnVoid(m_pLayoutButton);
     177        /* Create toolbar: */
     178        m_pToolBar = new UIToolBar;
     179        AssertPtrReturnVoid(m_pToolBar);
    187180        {
    188             /* Create exclusive button-group: */
    189             QButtonGroup *pButtonGroup = new QButtonGroup(this);
    190             AssertPtrReturnVoid(pButtonGroup);
    191             {
    192                 /* Create button 'Machine': */
    193                 m_mapButtons[ActionType_Machine] = prepareSectionButton(m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine));
    194                 QIToolButton *pButtonMachine = m_mapButtons.value(ActionType_Machine, 0);
    195                 AssertPtrReturnVoid(pButtonMachine);
    196                 {
    197                     /* Confgure button: */
    198                     pButtonMachine->setMenu(m_pActionPool->action(UIActionIndexST_M_Tools_M_Machine)->menu());
     181            /* Configure toolbar: */
     182            m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
     183            // TODO: Get rid of hard-coded stuff:
     184            const QSize toolBarIconSize = m_pToolBar->iconSize();
     185            if (toolBarIconSize.width() < 32 || toolBarIconSize.height() < 32)
     186                m_pToolBar->setIconSize(QSize(32, 32));
    199187
    200                     /* Add into button-group / layout: */
    201                     pButtonGroup->addButton(pButtonMachine);
    202                     m_pLayoutButton->addWidget(pButtonMachine);
    203                 }
    204             }
     188            /* Add actions: */
     189            UIAction *pActionMachine = m_pActionPool->action(UIActionIndexST_M_Tools_T_Machine);
     190            m_pToolBar->addAction(pActionMachine);
     191            QToolButton *pNamedMenuToolButton = qobject_cast<QToolButton*>(m_pToolBar->widgetForAction(pActionMachine));
     192            pNamedMenuToolButton->setPopupMode(QToolButton::InstantPopup);
    205193
    206194            /* Add into layout: */
    207             m_pLayoutMain->addLayout(m_pLayoutButton, 0, 1);
    208         }
    209 
    210         /* Create label: */
    211         m_pLabel = new QLabel;
    212         AssertPtrReturnVoid(m_pLabel);
    213         {
    214             /* Configure label: */
    215             m_pLabel->setAlignment(Qt::AlignTop | Qt::AlignCenter);
    216 
    217             /* Add into layout: */
    218             m_pLayoutMain->addWidget(m_pLabel, 1, 1);
     195            m_pLayoutMain->addWidget(m_pToolBar);
    219196        }
    220197    }
    221198}
    222199
    223 /* static */
    224 QIToolButton *UIToolsToolbar::prepareSectionButton(QAction *pAction)
    225 {
    226     /* Create button: */
    227     QIToolButton *pButton = new QIToolButton;
    228     AssertPtrReturn(pButton, 0);
    229     {
    230         /* Confgure button: */
    231         pButton->setIconSize(QSize(32, 32));
    232         pButton->setPopupMode(QToolButton::InstantPopup);
    233         pButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    234 
    235         /* Load action state to button: */
    236         pButton->setIcon(pAction->icon());
    237         pButton->setText(pAction->text());
    238         pButton->setToolTip(pAction->toolTip());
    239         pButton->setChecked(pAction->isChecked());
    240 
    241         /* Link button and action: */
    242         connect(pButton, &QIToolButton::toggled, pAction, &QAction::setChecked);
    243         connect(pAction, &QAction::toggled, pButton, &QIToolButton::setChecked);
    244     }
    245     /* Return button: */
    246     return pButton;
    247 }
    248 
    249 void UIToolsToolbar::prepareConnections()
    250 {
    251     /* Prepare connections: */
    252     if (m_mapButtons.contains(ActionType_Machine))
    253         connect(m_mapButtons.value(ActionType_Machine), &QIToolButton::toggled, this, &UIToolsToolbar::sltHandleButtonToggle);
    254 }
    255 
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIToolsToolbar.h

    r68175 r68178  
    2929/* Forward declarations: */
    3030class QAction;
    31 class QGridLayout;
    3231class QHBoxLayout;
    33 class QLabel;
    3432class QStackedLayout;
    3533class QUuid;
    3634class QWidget;
    37 class QIToolButton;
    3835class UIActionPool;
    3936class UITabBar;
     37class UIToolBar;
    4038
    4139
     
    5553public:
    5654
    57     /** Tools action types. */
    58     enum ActionType { ActionType_Machine };
    59 
    6055    /** Constructs Tools toolbar passing @a pParent to the base-class.
    6156      * @param  pActionPool  Brings the action-pool to take corresponding actions from. */
     
    7368    void sltHandleToolChosenMachine(const QUuid &uuid);
    7469
    75     /** Handles button toggle. */
    76     void sltHandleButtonToggle();
     70    /** Handles action toggle. */
     71    void sltHandleActionToggle();
    7772
    7873private:
     
    8479    /** Prepares widgets. */
    8580    void prepareWidgets();
    86     /** Prepares section button. */
    87     static QIToolButton *prepareSectionButton(QAction *pAction);
    88     /** Prepares connections. */
    89     void prepareConnections();
    90 
    91     /** Rebuilds toolbar shape. */
    92     void rebuildShape();
    9381
    9482    /** Holds the action pool reference. */
     
    9684
    9785    /** Holds the main layout instance. */
    98     QGridLayout    *m_pLayoutMain;
     86    QHBoxLayout    *m_pLayoutMain;
    9987    /** Holds the stacked layout instance. */
    10088    QStackedLayout *m_pLayoutStacked;
    101     /** Holds the button layout instance. */
    102     QHBoxLayout    *m_pLayoutButton;
    10389
    10490    /** Holds the Machine tab-bar instance. */
    105     UITabBar                     *m_pTabBarMachine;
     91    UITabBar *m_pTabBarMachine;
     92
    10693    /** Holds the map of opened Machine tool IDs. */
    10794    QMap<ToolTypeMachine, QUuid>  m_mapTabIdsMachine;
    10895
    109     /** Holds the map of action wrapping buttons. */
    110     QMap<ActionType, QIToolButton*>  m_mapButtons;
    111 
    112     /** Holds the status label instance. */
    113     QLabel *m_pLabel;
     96    /** Holds the toolbar instance. */
     97    UIToolBar *m_pToolBar;
    11498
    11599    /** Holds the 'Machine' menu action instances. */
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