1 | /* $Id: UIToolsModel.h 103803 2024-03-12 11:15:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIToolsModel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_manager_tools_UIToolsModel_h
|
---|
29 | #define FEQT_INCLUDED_SRC_manager_tools_UIToolsModel_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMap>
|
---|
36 | #include <QObject>
|
---|
37 | #include <QPointer>
|
---|
38 | #include <QTransform>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "QIWithRetranslateUI.h"
|
---|
42 | #include "UIToolsItem.h"
|
---|
43 |
|
---|
44 | /* COM includes: */
|
---|
45 |
|
---|
46 | /* Forward declaration: */
|
---|
47 | class QGraphicsItem;
|
---|
48 | class QGraphicsScene;
|
---|
49 | class QGraphicsSceneContextMenuEvent;
|
---|
50 | class QMenu;
|
---|
51 | class QPaintDevice;
|
---|
52 | class QTimer;
|
---|
53 | class UIActionPool;
|
---|
54 | class UITools;
|
---|
55 | class UIToolsHandlerMouse;
|
---|
56 | class UIToolsHandlerKeyboard;
|
---|
57 |
|
---|
58 | /** QObject extension used as VM Tools-pane model: */
|
---|
59 | class UIToolsModel : public QIWithRetranslateUI3<QObject>
|
---|
60 | {
|
---|
61 | Q_OBJECT;
|
---|
62 |
|
---|
63 | signals:
|
---|
64 |
|
---|
65 | /** @name General stuff.
|
---|
66 | * @{ */
|
---|
67 | /** Notifies about closing request. */
|
---|
68 | void sigClose();
|
---|
69 | /** @} */
|
---|
70 |
|
---|
71 | /** @name Selection stuff.
|
---|
72 | * @{ */
|
---|
73 | /** Notifies about selection changed.
|
---|
74 | * @param enmType Brings current tool type. */
|
---|
75 | void sigSelectionChanged(UIToolType enmType);
|
---|
76 | /** Notifies about focus changed. */
|
---|
77 | void sigFocusChanged();
|
---|
78 |
|
---|
79 | /** Notifies about group expanding started. */
|
---|
80 | void sigExpandingStarted();
|
---|
81 | /** Notifies about group expanding finished. */
|
---|
82 | void sigExpandingFinished();
|
---|
83 | /** @} */
|
---|
84 |
|
---|
85 | /** @name Layout stuff.
|
---|
86 | * @{ */
|
---|
87 | /** Notifies about item minimum width @a iHint changed. */
|
---|
88 | void sigItemMinimumWidthHintChanged(int iHint);
|
---|
89 | /** Notifies about item minimum height @a iHint changed. */
|
---|
90 | void sigItemMinimumHeightHintChanged(int iHint);
|
---|
91 | /** @} */
|
---|
92 |
|
---|
93 | public:
|
---|
94 |
|
---|
95 | /** Constructs Tools-model passing @a pParent to the base-class.
|
---|
96 | * @param Brings the tools class, it will be fixed one. */
|
---|
97 | UIToolsModel(UIToolClass enmClass, UITools *pParent);
|
---|
98 | /** Destructs Tools-model. */
|
---|
99 | virtual ~UIToolsModel() RT_OVERRIDE;
|
---|
100 |
|
---|
101 | /** @name General stuff.
|
---|
102 | * @{ */
|
---|
103 | /** Inits model. */
|
---|
104 | void init();
|
---|
105 |
|
---|
106 | /** Returns the Tools reference. */
|
---|
107 | UITools *tools() const;
|
---|
108 | /** Returns the action-pool reference. */
|
---|
109 | UIActionPool *actionPool() const;
|
---|
110 | /** Returns the scene reference. */
|
---|
111 | QGraphicsScene *scene() const;
|
---|
112 | /** Returns the paint device reference. */
|
---|
113 | QPaintDevice *paintDevice() const;
|
---|
114 |
|
---|
115 | /** Returns item at @a position, taking into account possible @a deviceTransform. */
|
---|
116 | QGraphicsItem *itemAt(const QPointF &position, const QTransform &deviceTransform = QTransform()) const;
|
---|
117 |
|
---|
118 | /** Defines current tools @a enmType. */
|
---|
119 | void setToolsType(UIToolType enmType);
|
---|
120 | /** Returns current tools type. */
|
---|
121 | UIToolType toolsType() const;
|
---|
122 |
|
---|
123 | /** Defines whether tool items @a fEnabled.*/
|
---|
124 | void setItemsEnabled(bool fEnabled);
|
---|
125 | /** Returns whether tool items enabled.*/
|
---|
126 | bool isItemsEnabled() const;
|
---|
127 |
|
---|
128 | /** Defines restructed tool @a types. */
|
---|
129 | void setRestrictedToolTypes(const QList<UIToolType> &types);
|
---|
130 | /** Returns restricted tool types. */
|
---|
131 | QList<UIToolType> restrictedToolTypes() const;
|
---|
132 |
|
---|
133 | /** Asks parent to close. */
|
---|
134 | void close();
|
---|
135 | /** @} */
|
---|
136 |
|
---|
137 | /** @name Children stuff.
|
---|
138 | * @{ */
|
---|
139 | /** Returns the item list. */
|
---|
140 | QList<UIToolsItem*> items() const;
|
---|
141 |
|
---|
142 | /** Returns the item of passed @a enmType. */
|
---|
143 | UIToolsItem *item(UIToolType enmType) const;
|
---|
144 | /** @} */
|
---|
145 |
|
---|
146 | /** @name Selection stuff.
|
---|
147 | * @{ */
|
---|
148 | /** Defines current @a pItem. */
|
---|
149 | void setCurrentItem(UIToolsItem *pItem);
|
---|
150 | /** Returns current item. */
|
---|
151 | UIToolsItem *currentItem() const;
|
---|
152 |
|
---|
153 | /** Defines focus @a pItem. */
|
---|
154 | void setFocusItem(UIToolsItem *pItem);
|
---|
155 | /** Returns focus item. */
|
---|
156 | UIToolsItem *focusItem() const;
|
---|
157 | /** @} */
|
---|
158 |
|
---|
159 | /** @name Navigation stuff.
|
---|
160 | * @{ */
|
---|
161 | /** Returns navigation item list. */
|
---|
162 | const QList<UIToolsItem*> &navigationList() const;
|
---|
163 | /** Removes @a pItem from navigation list. */
|
---|
164 | void removeFromNavigationList(UIToolsItem *pItem);
|
---|
165 | /** Updates navigation list. */
|
---|
166 | void updateNavigation();
|
---|
167 | /** @} */
|
---|
168 |
|
---|
169 | /** @name Layout stuff.
|
---|
170 | * @{ */
|
---|
171 | /** Updates layout. */
|
---|
172 | void updateLayout();
|
---|
173 | /** @} */
|
---|
174 |
|
---|
175 | public slots:
|
---|
176 |
|
---|
177 | /** @name General stuff.
|
---|
178 | * @{ */
|
---|
179 | /** Handles Tools-view resize. */
|
---|
180 | void sltHandleViewResized() { updateLayout(); }
|
---|
181 | /** @} */
|
---|
182 |
|
---|
183 | /** @name Children stuff.
|
---|
184 | * @{ */
|
---|
185 | /** Handles minimum width hint change. */
|
---|
186 | void sltItemMinimumWidthHintChanged();
|
---|
187 | /** Handles minimum height hint change. */
|
---|
188 | void sltItemMinimumHeightHintChanged();
|
---|
189 | /** @} */
|
---|
190 |
|
---|
191 | protected:
|
---|
192 |
|
---|
193 | /** @name Event handling stuff.
|
---|
194 | * @{ */
|
---|
195 | /** Preprocesses Qt @a pEvent for passed @a pObject. */
|
---|
196 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
|
---|
197 |
|
---|
198 | /** Handles translation event. */
|
---|
199 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
200 | /** @} */
|
---|
201 |
|
---|
202 | private slots:
|
---|
203 |
|
---|
204 | /** @name Selection stuff.
|
---|
205 | * @{ */
|
---|
206 | /** Handles focus item destruction. */
|
---|
207 | void sltFocusItemDestroyed();
|
---|
208 | /** @} */
|
---|
209 |
|
---|
210 | private:
|
---|
211 |
|
---|
212 | /** Data field types. */
|
---|
213 | enum ToolsModelData
|
---|
214 | {
|
---|
215 | /* Layout hints: */
|
---|
216 | ToolsModelData_Margin,
|
---|
217 | ToolsModelData_Spacing,
|
---|
218 | };
|
---|
219 |
|
---|
220 | /** @name Prepare/Cleanup cascade.
|
---|
221 | * @{ */
|
---|
222 | /** Prepares all. */
|
---|
223 | void prepare();
|
---|
224 | /** Prepares scene. */
|
---|
225 | void prepareScene();
|
---|
226 | /** Prepares items. */
|
---|
227 | void prepareItems();
|
---|
228 | /** Prepares handlers. */
|
---|
229 | void prepareHandlers();
|
---|
230 | /** Loads settings. */
|
---|
231 | void loadSettings();
|
---|
232 |
|
---|
233 | /** Loads last tool types. */
|
---|
234 | static void loadLastToolTypes(UIToolType &enmTypeGlobal, UIToolType &enmTypeMachine);
|
---|
235 |
|
---|
236 | /** Cleanups handlers. */
|
---|
237 | void cleanupHandlers();
|
---|
238 | /** Cleanups items. */
|
---|
239 | void cleanupItems();
|
---|
240 | /** Cleanups scene. */
|
---|
241 | void cleanupScene();
|
---|
242 | /** Cleanups all. */
|
---|
243 | void cleanup();
|
---|
244 | /** @} */
|
---|
245 |
|
---|
246 | /** @name General stuff.
|
---|
247 | * @{ */
|
---|
248 | /** Returns abstractly stored data value for certain @a iKey. */
|
---|
249 | QVariant data(int iKey) const;
|
---|
250 | /** @} */
|
---|
251 |
|
---|
252 | /** @name General stuff.
|
---|
253 | * @{ */
|
---|
254 | /** Holds the tools class. */
|
---|
255 | const UIToolClass m_enmClass;
|
---|
256 |
|
---|
257 | /** Holds the Tools reference. */
|
---|
258 | UITools *m_pTools;
|
---|
259 |
|
---|
260 | /** Holds the scene reference. */
|
---|
261 | QGraphicsScene *m_pScene;
|
---|
262 |
|
---|
263 | /** Holds the mouse handler instance. */
|
---|
264 | UIToolsHandlerMouse *m_pMouseHandler;
|
---|
265 | /** Holds the keyboard handler instance. */
|
---|
266 | UIToolsHandlerKeyboard *m_pKeyboardHandler;
|
---|
267 |
|
---|
268 | /** Holds whether items enabled. */
|
---|
269 | bool m_fItemsEnabled;
|
---|
270 |
|
---|
271 | /** Holds a list of restricted tool types. */
|
---|
272 | QList<UIToolType> m_restrictedToolTypes;
|
---|
273 | /** @} */
|
---|
274 |
|
---|
275 | /** @name Children stuff.
|
---|
276 | * @{ */
|
---|
277 | /** Holds the root stack. */
|
---|
278 | QList<UIToolsItem*> m_items;
|
---|
279 | /** @} */
|
---|
280 |
|
---|
281 | /** @name Selection stuff.
|
---|
282 | * @{ */
|
---|
283 | /** Holds the selected item reference. */
|
---|
284 | QPointer<UIToolsItem> m_pCurrentItem;
|
---|
285 | /** Holds the focus item reference. */
|
---|
286 | QPointer<UIToolsItem> m_pFocusItem;
|
---|
287 | /** @} */
|
---|
288 |
|
---|
289 | /** @name Navigation stuff.
|
---|
290 | * @{ */
|
---|
291 | /** Holds the navigation list. */
|
---|
292 | QList<UIToolsItem*> m_navigationList;
|
---|
293 | /** @} */
|
---|
294 | };
|
---|
295 |
|
---|
296 | #endif /* !FEQT_INCLUDED_SRC_manager_tools_UIToolsModel_h */
|
---|