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