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