Changeset 68178 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jul 29, 2017 4:17:22 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117270
- 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 21 21 22 22 /* 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> 28 28 29 29 /* 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" 34 34 35 35 /* Other VBox includes: */ 36 # include "iprt/assert.h"36 # include "iprt/assert.h" 37 37 38 38 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 44 44 , m_pLayoutMain(0) 45 45 , m_pLayoutStacked(0) 46 , m_pLayoutButton(0)47 46 , m_pTabBarMachine(0) 48 , m_p Label(0)47 , m_pToolBar(0) 49 48 { 50 49 /* Prepare: */ … … 96 95 } 97 96 98 void UIToolsToolbar::sltHandle ButtonToggle()97 void UIToolsToolbar::sltHandleActionToggle() 99 98 { 100 99 /* Acquire the sender: */ 101 QIToolButton *pButton = sender() ? qobject_cast<QIToolButton*>(sender()) : 0;102 if (!p Button)103 p Button = 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); 104 103 105 /* Handle known buttons: */106 if (m_pLayoutStacked && m_mapButtons.values().contains(pButton))104 /* Handle known actions: */ 105 if (m_pLayoutStacked) 107 106 { 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); 112 109 } 113 114 /* Update label's text: */115 m_pLabel->setText(pButton->text().remove('&'));116 110 } 117 111 … … 122 116 /* Prepare widgets: */ 123 117 prepareWidgets(); 124 /* Prepare connections: */125 prepareConnections();126 127 /* Initialize: */128 sltHandleButtonToggle();129 118 } 130 119 … … 147 136 m_pActionPool->action(UIActionIndexST_M_Tools_M_Machine_Snapshots)->setProperty("ToolTypeMachine", QVariant::fromValue(ToolTypeMachine_Snapshots)); 148 137 } 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); 149 143 } 150 144 … … 152 146 { 153 147 /* Create main layout: */ 154 m_pLayoutMain = new Q GridLayout(this);148 m_pLayoutMain = new QHBoxLayout(this); 155 149 AssertPtrReturnVoid(m_pLayoutMain); 156 150 { 157 151 /* Configure layout: */ 158 152 m_pLayoutMain->setContentsMargins(0, 0, 0, 0); 159 m_pLayoutMain->setHorizontalSpacing(10); 160 m_pLayoutMain->setVerticalSpacing(0); 153 m_pLayoutMain->setSpacing(10); 161 154 162 155 /* Create stacked layout: */ … … 179 172 180 173 /* Add into layout: */ 181 m_pLayoutMain->addLayout(m_pLayoutStacked , 0, 0);174 m_pLayoutMain->addLayout(m_pLayoutStacked); 182 175 } 183 176 184 /* Create sub-layout: */185 m_p LayoutButton = new QHBoxLayout;186 AssertPtrReturnVoid(m_p LayoutButton);177 /* Create toolbar: */ 178 m_pToolBar = new UIToolBar; 179 AssertPtrReturnVoid(m_pToolBar); 187 180 { 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)); 199 187 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); 205 193 206 194 /* 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); 219 196 } 220 197 } 221 198 } 222 199 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 29 29 /* Forward declarations: */ 30 30 class QAction; 31 class QGridLayout;32 31 class QHBoxLayout; 33 class QLabel;34 32 class QStackedLayout; 35 33 class QUuid; 36 34 class QWidget; 37 class QIToolButton;38 35 class UIActionPool; 39 36 class UITabBar; 37 class UIToolBar; 40 38 41 39 … … 55 53 public: 56 54 57 /** Tools action types. */58 enum ActionType { ActionType_Machine };59 60 55 /** Constructs Tools toolbar passing @a pParent to the base-class. 61 56 * @param pActionPool Brings the action-pool to take corresponding actions from. */ … … 73 68 void sltHandleToolChosenMachine(const QUuid &uuid); 74 69 75 /** Handles button toggle. */76 void sltHandle ButtonToggle();70 /** Handles action toggle. */ 71 void sltHandleActionToggle(); 77 72 78 73 private: … … 84 79 /** Prepares widgets. */ 85 80 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();93 81 94 82 /** Holds the action pool reference. */ … … 96 84 97 85 /** Holds the main layout instance. */ 98 Q GridLayout *m_pLayoutMain;86 QHBoxLayout *m_pLayoutMain; 99 87 /** Holds the stacked layout instance. */ 100 88 QStackedLayout *m_pLayoutStacked; 101 /** Holds the button layout instance. */102 QHBoxLayout *m_pLayoutButton;103 89 104 90 /** Holds the Machine tab-bar instance. */ 105 UITabBar *m_pTabBarMachine; 91 UITabBar *m_pTabBarMachine; 92 106 93 /** Holds the map of opened Machine tool IDs. */ 107 94 QMap<ToolTypeMachine, QUuid> m_mapTabIdsMachine; 108 95 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; 114 98 115 99 /** Holds the 'Machine' menu action instances. */
Note:
See TracChangeset
for help on using the changeset viewer.