1 | /* $Id: UIChooserItemGroup.h 77826 2019-03-21 14:27:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserItemGroup class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h
|
---|
19 | #define FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "UIChooserItem.h"
|
---|
26 |
|
---|
27 | /* Forward declarations: */
|
---|
28 | class QGraphicsLinearLayout;
|
---|
29 | class QLineEdit;
|
---|
30 | class UIChooserNodeGroup;
|
---|
31 | class UIEditorGroupRename;
|
---|
32 | class UIGraphicsButton;
|
---|
33 | class UIGraphicsRotatorButton;
|
---|
34 | class UIGraphicsScrollArea;
|
---|
35 |
|
---|
36 |
|
---|
37 | /** UIChooserItem extension implementing group item. */
|
---|
38 | class UIChooserItemGroup : public UIChooserItem
|
---|
39 | {
|
---|
40 | Q_OBJECT;
|
---|
41 | Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);
|
---|
42 |
|
---|
43 | signals:
|
---|
44 |
|
---|
45 | /** @name Item stuff.
|
---|
46 | * @{ */
|
---|
47 | /** Notifies listeners about toggle start. */
|
---|
48 | void sigToggleStarted();
|
---|
49 | /** Notifies listeners about toggle finish. */
|
---|
50 | void sigToggleFinished();
|
---|
51 | /** @} */
|
---|
52 |
|
---|
53 | public:
|
---|
54 |
|
---|
55 | /** RTTI required for qgraphicsitem_cast. */
|
---|
56 | enum { Type = UIChooserItemType_Group };
|
---|
57 |
|
---|
58 | /** Build item for certain @a pNode, adding it directly to the @a pScene. */
|
---|
59 | UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode);
|
---|
60 | /** Build item for certain @a pNode, passing @a pParent to the base-class. */
|
---|
61 | UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode);
|
---|
62 | /** Destructs group item. */
|
---|
63 | virtual ~UIChooserItemGroup() /* override */;
|
---|
64 |
|
---|
65 | /** @name Item stuff.
|
---|
66 | * @{ */
|
---|
67 | /** Returns whether group is closed. */
|
---|
68 | bool isClosed() const;
|
---|
69 | /** Closes group in @a fAnimated way if requested. */
|
---|
70 | void close(bool fAnimated = true);
|
---|
71 |
|
---|
72 | /** Returns whether group is opened. */
|
---|
73 | bool isOpened() const;
|
---|
74 | /** Opens group in @a fAnimated way if requested. */
|
---|
75 | void open(bool fAnimated = true);
|
---|
76 | /** @} */
|
---|
77 |
|
---|
78 | /** @name Children stuff.
|
---|
79 | * @{ */
|
---|
80 | /** Updates positions of favorite items. */
|
---|
81 | void updateFavorites();
|
---|
82 | /** @} */
|
---|
83 |
|
---|
84 | /** @name Navigation stuff.
|
---|
85 | * @{ */
|
---|
86 | /** Class-name used for drag&drop mime-data format. */
|
---|
87 | static QString className();
|
---|
88 | /** Makes sure passed child @a pItem is visible. */
|
---|
89 | virtual void makeSureItemIsVisible(UIChooserItem *pItem) /* override */;
|
---|
90 | /** @} */
|
---|
91 |
|
---|
92 | protected:
|
---|
93 |
|
---|
94 | /** @name Event-handling stuff.
|
---|
95 | * @{ */
|
---|
96 | /** Handles translation event. */
|
---|
97 | virtual void retranslateUi() /* override */;
|
---|
98 |
|
---|
99 | /** Handles show @a pEvent. */
|
---|
100 | virtual void showEvent(QShowEvent *pEvent) /* override */;
|
---|
101 |
|
---|
102 | /** Handles resize @a pEvent. */
|
---|
103 | virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
|
---|
104 |
|
---|
105 | /** Handles hover enter @a event. */
|
---|
106 | virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
|
---|
107 | /** Handles hover leave @a event. */
|
---|
108 | virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
|
---|
109 |
|
---|
110 | /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
|
---|
111 | virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 | /** @name Item stuff.
|
---|
115 | * @{ */
|
---|
116 | /** Returns RTTI item type. */
|
---|
117 | virtual int type() const /* override */ { return Type; }
|
---|
118 |
|
---|
119 | /** Starts item editing. */
|
---|
120 | virtual void startEditing() /* override */;
|
---|
121 |
|
---|
122 | /** Updates item. */
|
---|
123 | virtual void updateItem() /* override */;
|
---|
124 | /** Updates item tool-tip. */
|
---|
125 | virtual void updateToolTip() /* override */;
|
---|
126 |
|
---|
127 | /** Installs event-filter for @a pSource object. */
|
---|
128 | virtual void installEventFilterHelper(QObject *pSource) /* override */;
|
---|
129 | /** @} */
|
---|
130 |
|
---|
131 | /** @name Children stuff.
|
---|
132 | * @{ */
|
---|
133 | /** Returns children items of certain @a enmType. */
|
---|
134 | virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
|
---|
135 |
|
---|
136 | /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
|
---|
137 | virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) /* override */;
|
---|
138 | /** Removes child @a pItem. */
|
---|
139 | virtual void removeItem(UIChooserItem *pItem) /* override */;
|
---|
140 |
|
---|
141 | /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
|
---|
142 | virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags) /* override */;
|
---|
143 |
|
---|
144 | /** Searches for a first machine child item. */
|
---|
145 | virtual UIChooserItem *firstMachineItem() /* override */;
|
---|
146 |
|
---|
147 | /** Sorts children items. */
|
---|
148 | virtual void sortItems() /* override */;
|
---|
149 | /** @} */
|
---|
150 |
|
---|
151 | /** @name Layout stuff.
|
---|
152 | * @{ */
|
---|
153 | /** Updates geometry. */
|
---|
154 | virtual void updateGeometry() /* override */;
|
---|
155 |
|
---|
156 | /** Updates layout. */
|
---|
157 | virtual void updateLayout() /* override */;
|
---|
158 |
|
---|
159 | /** Returns minimum width-hint. */
|
---|
160 | virtual int minimumWidthHint() const /* override */;
|
---|
161 | /** Returns minimum height-hint. */
|
---|
162 | virtual int minimumHeightHint() const /* override */;
|
---|
163 |
|
---|
164 | /** Returns size-hint.
|
---|
165 | * @param enmWhich Brings size-hint type.
|
---|
166 | * @param constraint Brings size constraint. */
|
---|
167 | virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
|
---|
168 | /** @} */
|
---|
169 |
|
---|
170 | /** @name Navigation stuff.
|
---|
171 | * @{ */
|
---|
172 | /** Returns pixmap item representation. */
|
---|
173 | virtual QPixmap toPixmap() /* override */;
|
---|
174 |
|
---|
175 | /** Returns whether item drop is allowed.
|
---|
176 | * @param pEvent Brings information about drop event.
|
---|
177 | * @param enmPlace Brings the place of drag token to the drop moment. */
|
---|
178 | virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken where) const /* override */;
|
---|
179 | /** Processes item drop.
|
---|
180 | * @param pEvent Brings information about drop event.
|
---|
181 | * @param pFromWho Brings the item according to which we choose drop position.
|
---|
182 | * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */
|
---|
183 | virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, UIChooserItemDragToken where) /* override */;
|
---|
184 | /** Reset drag token. */
|
---|
185 | virtual void resetDragToken() /* override */;
|
---|
186 |
|
---|
187 | /** Returns D&D mime data. */
|
---|
188 | virtual QMimeData *createMimeData() /* override */;
|
---|
189 | /** @} */
|
---|
190 |
|
---|
191 | private slots:
|
---|
192 |
|
---|
193 | /** @name Item stuff.
|
---|
194 | * @{ */
|
---|
195 | /** Handles top-level window remaps. */
|
---|
196 | void sltHandleWindowRemapped();
|
---|
197 |
|
---|
198 | /** Handles name editing trigger. */
|
---|
199 | void sltNameEditingFinished();
|
---|
200 |
|
---|
201 | /** Handles group toggle start. */
|
---|
202 | void sltGroupToggleStart();
|
---|
203 | /** Handles group toggle finish for group finally @a fToggled. */
|
---|
204 | void sltGroupToggleFinish(bool fToggled);
|
---|
205 |
|
---|
206 | /** Handles root indentation. */
|
---|
207 | void sltIndentRoot();
|
---|
208 | /** Handles root unindentation. */
|
---|
209 | void sltUnindentRoot();
|
---|
210 | /** @} */
|
---|
211 |
|
---|
212 | private:
|
---|
213 |
|
---|
214 | /** Data field types. */
|
---|
215 | enum GroupItemData
|
---|
216 | {
|
---|
217 | /* Layout hints: */
|
---|
218 | GroupItemData_MarginHL,
|
---|
219 | GroupItemData_MarginHR,
|
---|
220 | GroupItemData_MarginV,
|
---|
221 | GroupItemData_HeaderSpacing,
|
---|
222 | GroupItemData_ChildrenSpacing,
|
---|
223 | GroupItemData_ParentIndent,
|
---|
224 | };
|
---|
225 |
|
---|
226 | /** @name Prepare/cleanup cascade.
|
---|
227 | * @{ */
|
---|
228 | /** Prepares all. */
|
---|
229 | void prepare();
|
---|
230 | /** Cleanups all. */
|
---|
231 | void cleanup();
|
---|
232 | /** @} */
|
---|
233 |
|
---|
234 | /** @name Item stuff.
|
---|
235 | * @{ */
|
---|
236 | /** Returns abstractly stored data value for certain @a iKey. */
|
---|
237 | QVariant data(int iKey) const;
|
---|
238 |
|
---|
239 | /** Returns item's header darkness. */
|
---|
240 | int headerDarkness() const { return m_iHeaderDarkness; }
|
---|
241 |
|
---|
242 | /** Returns additional height. */
|
---|
243 | int additionalHeight() const;
|
---|
244 | /** Defines @a iAdditionalHeight. */
|
---|
245 | void setAdditionalHeight(int iAdditionalHeight);
|
---|
246 |
|
---|
247 | /** Updates animation parameters. */
|
---|
248 | void updateAnimationParameters();
|
---|
249 | /** Updates toggle-button tool-tip. */
|
---|
250 | void updateToggleButtonToolTip();
|
---|
251 | /** @} */
|
---|
252 |
|
---|
253 | /** @name Children stuff.
|
---|
254 | * @{ */
|
---|
255 | /** Copies group contents from @a pCopyFrom node recursively. */
|
---|
256 | void copyContents(UIChooserNodeGroup *pCopyFrom);
|
---|
257 |
|
---|
258 | /** Returns whether group contains machine with @a uId. */
|
---|
259 | bool isContainsMachine(const QUuid &uId) const;
|
---|
260 | /** Returns whether group contains locked machine. */
|
---|
261 | bool isContainsLockedMachine();
|
---|
262 |
|
---|
263 | /** Updates user count info. */
|
---|
264 | void updateItemCountInfo();
|
---|
265 | /** @} */
|
---|
266 |
|
---|
267 | /** @name Layout stuff.
|
---|
268 | * @{ */
|
---|
269 | /** Returns minimum width-hint depending on whether @a fGroupOpened. */
|
---|
270 | int minimumWidthHintForGroup(bool fGroupOpened) const;
|
---|
271 | /** Returns minimum height-hint depending on whether @a fGroupOpened. */
|
---|
272 | int minimumHeightHintForGroup(bool fGroupOpened) const;
|
---|
273 | /** Returns minimum size-hint depending on whether @a fGroupOpened. */
|
---|
274 | QSizeF minimumSizeHintForGroup(bool fGroupOpened) const;
|
---|
275 |
|
---|
276 | /** Updates visible name. */
|
---|
277 | void updateVisibleName();
|
---|
278 | /** Updates pixmaps. */
|
---|
279 | void updatePixmaps();
|
---|
280 | /** Updates minimum header size. */
|
---|
281 | void updateMinimumHeaderSize();
|
---|
282 | /** Updates layout spacings. */
|
---|
283 | void updateLayoutSpacings();
|
---|
284 | /** @} */
|
---|
285 |
|
---|
286 | /** @name Painting stuff.
|
---|
287 | * @{ */
|
---|
288 | /** Paints background using specified @a pPainter and certain @a rect. */
|
---|
289 | void paintBackground(QPainter *pPainter, const QRect &rect);
|
---|
290 | /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
|
---|
291 | void paintFrame(QPainter *pPainter, const QRect &rect);
|
---|
292 | /** Paints header using specified @a pPainter and certain @a rect. */
|
---|
293 | void paintHeader(QPainter *pPainter, const QRect &rect);
|
---|
294 | /** @} */
|
---|
295 |
|
---|
296 | /** @name Item stuff.
|
---|
297 | * @{ */
|
---|
298 | /** Holds the graphics scene reference. */
|
---|
299 | QGraphicsScene *m_pScene;
|
---|
300 |
|
---|
301 | /** Holds the cached visible name. */
|
---|
302 | QString m_strVisibleName;
|
---|
303 | /** Holds the cached group children info. */
|
---|
304 | QString m_strInfoGroups;
|
---|
305 | /** Holds the cached machine children info. */
|
---|
306 | QString m_strInfoMachines;
|
---|
307 |
|
---|
308 | /** Holds aditional height. */
|
---|
309 | int m_iAdditionalHeight;
|
---|
310 | /** Holds the header darkness. */
|
---|
311 | int m_iHeaderDarkness;
|
---|
312 |
|
---|
313 | /** Holds group children pixmap. */
|
---|
314 | QPixmap m_groupsPixmap;
|
---|
315 | /** Holds machine children pixmap. */
|
---|
316 | QPixmap m_machinesPixmap;
|
---|
317 |
|
---|
318 | /** Holds the name font. */
|
---|
319 | QFont m_nameFont;
|
---|
320 | /** Holds the info font. */
|
---|
321 | QFont m_infoFont;
|
---|
322 |
|
---|
323 | /** Holds the group toggle button instance. */
|
---|
324 | UIGraphicsRotatorButton *m_pToggleButton;
|
---|
325 | /** Holds the group enter button instance. */
|
---|
326 | UIGraphicsButton *m_pEnterButton;
|
---|
327 | /** Holds the group exit button instance. */
|
---|
328 | UIGraphicsButton *m_pExitButton;
|
---|
329 |
|
---|
330 | /** Holds the group name editor instance. */
|
---|
331 | UIEditorGroupRename *m_pNameEditorWidget;
|
---|
332 | /** @} */
|
---|
333 |
|
---|
334 | /** @name Children stuff.
|
---|
335 | * @{ */
|
---|
336 | /** Holds the favorite children container instance. */
|
---|
337 | QIGraphicsWidget *m_pContainerFavorite;
|
---|
338 | /** Holds the favorite children layout instance. */
|
---|
339 | QGraphicsLinearLayout *m_pLayoutFavorite;
|
---|
340 |
|
---|
341 | /** Holds the children scroll-area instance. */
|
---|
342 | UIGraphicsScrollArea *m_pScrollArea;
|
---|
343 | /** Holds the children container instance. */
|
---|
344 | QIGraphicsWidget *m_pContainer;
|
---|
345 |
|
---|
346 | /** Holds the main layout instance. */
|
---|
347 | QGraphicsLinearLayout *m_pLayout;
|
---|
348 | /** Holds the global layout instance. */
|
---|
349 | QGraphicsLinearLayout *m_pLayoutGlobal;
|
---|
350 | /** Holds the group layout instance. */
|
---|
351 | QGraphicsLinearLayout *m_pLayoutGroup;
|
---|
352 | /** Holds the machine layout instance. */
|
---|
353 | QGraphicsLinearLayout *m_pLayoutMachine;
|
---|
354 |
|
---|
355 | /** Holds the global children list. */
|
---|
356 | QList<UIChooserItem*> m_globalItems;
|
---|
357 | /** Holds the group children list. */
|
---|
358 | QList<UIChooserItem*> m_groupItems;
|
---|
359 | /** Holds the machine children list. */
|
---|
360 | QList<UIChooserItem*> m_machineItems;
|
---|
361 | /** @} */
|
---|
362 |
|
---|
363 | /** @name Layout stuff.
|
---|
364 | * @{ */
|
---|
365 | /** Holds cached visible name size. */
|
---|
366 | QSize m_visibleNameSize;
|
---|
367 | /** Holds cached group children pixmap size. */
|
---|
368 | QSize m_pixmapSizeGroups;
|
---|
369 | /** Holds cached machine children pixmap size. */
|
---|
370 | QSize m_pixmapSizeMachines;
|
---|
371 | /** Holds cached group children info size. */
|
---|
372 | QSize m_infoSizeGroups;
|
---|
373 | /** Holds cached machine children info size. */
|
---|
374 | QSize m_infoSizeMachines;
|
---|
375 | /** Holds cached minimum header size. */
|
---|
376 | QSize m_minimumHeaderSize;
|
---|
377 | /** Holds cached toggle button size. */
|
---|
378 | QSize m_toggleButtonSize;
|
---|
379 | /** Holds cached enter button size. */
|
---|
380 | QSize m_enterButtonSize;
|
---|
381 | /** Holds cached exit button size. */
|
---|
382 | QSize m_exitButtonSize;
|
---|
383 | /** @} */
|
---|
384 | };
|
---|
385 |
|
---|
386 |
|
---|
387 | /** QWidget extension to use as group name editor. */
|
---|
388 | class UIEditorGroupRename : public QWidget
|
---|
389 | {
|
---|
390 | Q_OBJECT;
|
---|
391 |
|
---|
392 | signals:
|
---|
393 |
|
---|
394 | /** Notifies about group editing finished. */
|
---|
395 | void sigEditingFinished();
|
---|
396 |
|
---|
397 | public:
|
---|
398 |
|
---|
399 | /** Constructs group editor with initial @a strName. */
|
---|
400 | UIEditorGroupRename(const QString &strName);
|
---|
401 |
|
---|
402 | /** Returns editor text. */
|
---|
403 | QString text() const;
|
---|
404 | /** Defines editor @a strText. */
|
---|
405 | void setText(const QString &strText);
|
---|
406 |
|
---|
407 | /** Defines editor @a font. */
|
---|
408 | void setFont(const QFont &font);
|
---|
409 |
|
---|
410 | private:
|
---|
411 |
|
---|
412 | /** Holds the line-edit instance. */
|
---|
413 | QLineEdit *m_pLineEdit;
|
---|
414 | };
|
---|
415 |
|
---|
416 |
|
---|
417 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h */
|
---|