1 | /* $Id: UIChooserItemGroup.h 74393 2018-09-20 17:05:11Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserItemGroup class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2018 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 ___UIChooserItemGroup_h___
|
---|
19 | #define ___UIChooserItemGroup_h___
|
---|
20 |
|
---|
21 | /* Qt includes: */
|
---|
22 | #include <QPixmap>
|
---|
23 | #include <QString>
|
---|
24 | #include <QWidget>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "UIChooserItem.h"
|
---|
28 |
|
---|
29 | /* Forward declarations: */
|
---|
30 | class QGraphicsProxyWidget;
|
---|
31 | class QGraphicsScene;
|
---|
32 | class QLineEdit;
|
---|
33 | class QMenu;
|
---|
34 | class QMimeData;
|
---|
35 | class QPainter;
|
---|
36 | class QStyleOptionGraphicsItem;
|
---|
37 | class UIEditorGroupRename;
|
---|
38 | class UIGraphicsButton;
|
---|
39 | class UIGraphicsRotatorButton;
|
---|
40 |
|
---|
41 |
|
---|
42 | /** UIChooserItem extension implementing group item. */
|
---|
43 | class UIChooserItemGroup : public UIChooserItem
|
---|
44 | {
|
---|
45 | Q_OBJECT;
|
---|
46 | Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);
|
---|
47 |
|
---|
48 | signals:
|
---|
49 |
|
---|
50 | /** @name Item stuff.
|
---|
51 | * @{ */
|
---|
52 | /** Notifies listeners about toggle start. */
|
---|
53 | void sigToggleStarted();
|
---|
54 | /** Notifies listeners about toggle finish. */
|
---|
55 | void sigToggleFinished();
|
---|
56 | /** @} */
|
---|
57 |
|
---|
58 | public:
|
---|
59 |
|
---|
60 | /** RTTI item type. */
|
---|
61 | enum { Type = UIChooserItemType_Group };
|
---|
62 |
|
---|
63 | /** Constructs main-root item, passing pScene to the base-class. */
|
---|
64 | UIChooserItemGroup(QGraphicsScene *pScene);
|
---|
65 | /** Constructs temporary @a fMainRoot item as a @a pCopyFrom, passing pScene to the base-class. */
|
---|
66 | UIChooserItemGroup(QGraphicsScene *pScene, UIChooserItemGroup *pCopyFrom, bool fMainRoot);
|
---|
67 | /** Constructs non-root item with specified @a strName and @a iPosition, @a fOpened if requested, passing pParent to the base-class. */
|
---|
68 | UIChooserItemGroup(UIChooserItem *pParent, const QString &strName, bool fOpened = false, int iPosition = -1);
|
---|
69 | /** Constructs temporary non-root item with specified @a iPosition as a @a pCopyFrom, passing pParent to the base-class. */
|
---|
70 | UIChooserItemGroup(UIChooserItem *pParent, UIChooserItemGroup *pCopyFrom, int iPosition = -1);
|
---|
71 | /** Destructs group item. */
|
---|
72 | virtual ~UIChooserItemGroup() /* override */;
|
---|
73 |
|
---|
74 | /** @name Item stuff.
|
---|
75 | * @{ */
|
---|
76 | /** Defines group @a strName. */
|
---|
77 | void setName(const QString &strName);
|
---|
78 |
|
---|
79 | /** Closes group in @a fAnimated way if requested. */
|
---|
80 | void close(bool fAnimated = true);
|
---|
81 | /** Returns whether group is closed. */
|
---|
82 | bool isClosed() const;
|
---|
83 |
|
---|
84 | /** Opens group in @a fAnimated way if requested. */
|
---|
85 | void open(bool fAnimated = true);
|
---|
86 | /** Returns whether group is opened. */
|
---|
87 | bool isOpened() const;
|
---|
88 | /** @} */
|
---|
89 |
|
---|
90 | /** @name Navigation stuff.
|
---|
91 | * @{ */
|
---|
92 | /** Class-name used for drag&drop mime-data format. */
|
---|
93 | static QString className();
|
---|
94 | /** @} */
|
---|
95 |
|
---|
96 | protected:
|
---|
97 |
|
---|
98 | /** @name Event-handling stuff.
|
---|
99 | * @{ */
|
---|
100 | /** Handles translation event. */
|
---|
101 | virtual void retranslateUi() /* override */;
|
---|
102 |
|
---|
103 | /** Handles show @a pEvent. */
|
---|
104 | virtual void showEvent(QShowEvent *pEvent) /* override */;
|
---|
105 |
|
---|
106 | /** Handles resize @a pEvent. */
|
---|
107 | virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
|
---|
108 |
|
---|
109 | /** Handles hover enter @a event. */
|
---|
110 | virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
|
---|
111 | /** Handles hover leave @a event. */
|
---|
112 | virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
|
---|
113 |
|
---|
114 | /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
|
---|
115 | virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
|
---|
116 | /** @} */
|
---|
117 |
|
---|
118 | /** @name Item stuff.
|
---|
119 | * @{ */
|
---|
120 | /** Returns RTTI item type. */
|
---|
121 | virtual int type() const /* override */ { return Type; }
|
---|
122 |
|
---|
123 | /** Shows item. */
|
---|
124 | virtual void show() /* override */;
|
---|
125 | /** Hides item. */
|
---|
126 | virtual void hide() /* override */;
|
---|
127 |
|
---|
128 | /** Starts item editing. */
|
---|
129 | virtual void startEditing() /* override */;
|
---|
130 |
|
---|
131 | /** Updates item tool-tip. */
|
---|
132 | virtual void updateToolTip() /* override */;
|
---|
133 |
|
---|
134 | /** Returns item name. */
|
---|
135 | virtual QString name() const /* override */;
|
---|
136 | /** Returns item description. */
|
---|
137 | virtual QString description() const /* override */;
|
---|
138 | /** Returns item full-name. */
|
---|
139 | virtual QString fullName() const /* override */;
|
---|
140 | /** Returns item definition. */
|
---|
141 | virtual QString definition() const /* override */;
|
---|
142 |
|
---|
143 | /** Handles root status change. */
|
---|
144 | virtual void handleRootStatusChange() /* override */;
|
---|
145 | /** @} */
|
---|
146 |
|
---|
147 | /** @name Children stuff.
|
---|
148 | * @{ */
|
---|
149 | /** Adds child @a pItem to certain @a iPosition. */
|
---|
150 | virtual void addItem(UIChooserItem *pItem, int iPosition) /* override */;
|
---|
151 | /** Removes child @a pItem. */
|
---|
152 | virtual void removeItem(UIChooserItem *pItem) /* override */;
|
---|
153 |
|
---|
154 | /** Replaces children @a items of certain @a enmType. */
|
---|
155 | virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;
|
---|
156 | /** Returns children items of certain @a enmType. */
|
---|
157 | virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
|
---|
158 | /** Returns whether there are children items of certain @a enmType. */
|
---|
159 | virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
|
---|
160 | /** Clears children items of certain @a enmType. */
|
---|
161 | virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;
|
---|
162 |
|
---|
163 | /** Updates all children items with specified @a strId. */
|
---|
164 | virtual void updateAllItems(const QString &strId) /* override */;
|
---|
165 | /** Removes all children items with specified @a strId. */
|
---|
166 | virtual void removeAllItems(const QString &strId) /* override */;
|
---|
167 |
|
---|
168 | /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
|
---|
169 | virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags) /* override */;
|
---|
170 |
|
---|
171 | /** Searches for a first machine child item. */
|
---|
172 | virtual UIChooserItem *firstMachineItem() /* override */;
|
---|
173 |
|
---|
174 | /** Sorts children items. */
|
---|
175 | virtual void sortItems() /* override */;
|
---|
176 | /** @} */
|
---|
177 |
|
---|
178 | /** @name Layout stuff.
|
---|
179 | * @{ */
|
---|
180 | /** Updates layout. */
|
---|
181 | virtual void updateLayout() /* override */;
|
---|
182 |
|
---|
183 | /** Returns minimum width-hint. */
|
---|
184 | virtual int minimumWidthHint() const /* override */;
|
---|
185 | /** Returns minimum height-hint. */
|
---|
186 | virtual int minimumHeightHint() const /* override */;
|
---|
187 |
|
---|
188 | /** Returns size-hint.
|
---|
189 | * @param enmWhich Brings size-hint type.
|
---|
190 | * @param constraint Brings size constraint. */
|
---|
191 | virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
|
---|
192 | /** @} */
|
---|
193 |
|
---|
194 | /** @name Navigation stuff.
|
---|
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, DragToken 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, DragToken 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 | /** Copies group contents @a pFrom one item @a pTo another. */
|
---|
255 | static void copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo);
|
---|
256 | /** @} */
|
---|
257 |
|
---|
258 | /** @name Item stuff.
|
---|
259 | * @{ */
|
---|
260 | /** Returns abstractly stored data value for certain @a iKey. */
|
---|
261 | QVariant data(int iKey) const;
|
---|
262 |
|
---|
263 | /** Returns whether group is main-root. */
|
---|
264 | bool isMainRoot() const { return m_fMainRoot; }
|
---|
265 |
|
---|
266 | /** Returns item's header darkness. */
|
---|
267 | int headerDarkness() const { return m_iHeaderDarkness; }
|
---|
268 |
|
---|
269 | /** Defines @a iAdditionalHeight. */
|
---|
270 | void setAdditionalHeight(int iAdditionalHeight);
|
---|
271 | /** Returns additional height. */
|
---|
272 | int additionalHeight() const;
|
---|
273 |
|
---|
274 | /** Updates animation parameters. */
|
---|
275 | void updateAnimationParameters();
|
---|
276 | /** Updates toggle-button tool-tip. */
|
---|
277 | void updateToggleButtonToolTip();
|
---|
278 | /** @} */
|
---|
279 |
|
---|
280 | /** @name Children stuff.
|
---|
281 | * @{ */
|
---|
282 | /** Returns whether group contains machine with @a strId. */
|
---|
283 | bool isContainsMachine(const QString &strId) const;
|
---|
284 | /** Returns whether group contains locked machine. */
|
---|
285 | bool isContainsLockedMachine();
|
---|
286 |
|
---|
287 | /** Updates user count info. */
|
---|
288 | void updateItemCountInfo();
|
---|
289 | /** @} */
|
---|
290 |
|
---|
291 | /** @name Layout stuff.
|
---|
292 | * @{ */
|
---|
293 | /** Returns minimum width-hint depending on whether @a fGroupOpened. */
|
---|
294 | int minimumWidthHintForGroup(bool fGroupOpened) const;
|
---|
295 | /** Returns minimum height-hint depending on whether @a fGroupOpened. */
|
---|
296 | int minimumHeightHintForGroup(bool fGroupOpened) const;
|
---|
297 | /** Returns minimum size-hint depending on whether @a fGroupOpened. */
|
---|
298 | QSizeF minimumSizeHintForProup(bool fGroupOpened) const;
|
---|
299 |
|
---|
300 | /** Updates visible name. */
|
---|
301 | void updateVisibleName();
|
---|
302 | /** Updates pixmaps. */
|
---|
303 | void updatePixmaps();
|
---|
304 | /** Updates minimum header size. */
|
---|
305 | void updateMinimumHeaderSize();
|
---|
306 | /** @} */
|
---|
307 |
|
---|
308 | /** @name Painting stuff.
|
---|
309 | * @{ */
|
---|
310 | /** Paints background using specified @a pPainter and certain @a rect. */
|
---|
311 | void paintBackground(QPainter *pPainter, const QRect &rect);
|
---|
312 | /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
|
---|
313 | void paintFrameRectangle(QPainter *pPainter, const QRect &rect);
|
---|
314 | /** Paints header using specified @a pPainter and certain @a rect. */
|
---|
315 | void paintHeader(QPainter *pPainter, const QRect &rect);
|
---|
316 | /** @} */
|
---|
317 |
|
---|
318 | /** @name Item stuff.
|
---|
319 | * @{ */
|
---|
320 | /** Holds whether group is main-root. */
|
---|
321 | bool m_fMainRoot;
|
---|
322 | /** Holds whether group is closed. */
|
---|
323 | bool m_fClosed;
|
---|
324 |
|
---|
325 | /** Holds aditional height. */
|
---|
326 | int m_iAdditionalHeight;
|
---|
327 | /** Holds the header darkness. */
|
---|
328 | int m_iHeaderDarkness;
|
---|
329 |
|
---|
330 | /** Holds the cached name. */
|
---|
331 | QString m_strName;
|
---|
332 | /** Holds the cached description. */
|
---|
333 | QString m_strDescription;
|
---|
334 | /** Holds the cached visible name. */
|
---|
335 | QString m_strVisibleName;
|
---|
336 |
|
---|
337 | /** Holds the name font. */
|
---|
338 | QFont m_nameFont;
|
---|
339 |
|
---|
340 | /** Holds the group toggle button instance. */
|
---|
341 | UIGraphicsRotatorButton *m_pToggleButton;
|
---|
342 | /** Holds the group enter button instance. */
|
---|
343 | UIGraphicsButton *m_pEnterButton;
|
---|
344 | /** Holds the group exit button instance. */
|
---|
345 | UIGraphicsButton *m_pExitButton;
|
---|
346 |
|
---|
347 | /** Holds the group name editor instance. */
|
---|
348 | UIEditorGroupRename *m_pNameEditorWidget;
|
---|
349 | /** Holds the group name editor proxy instance. */
|
---|
350 | QGraphicsProxyWidget *m_pNameEditor;
|
---|
351 | /** @} */
|
---|
352 |
|
---|
353 | /** @name Children stuff.
|
---|
354 | * @{ */
|
---|
355 | /** Holds the group children list. */
|
---|
356 | QList<UIChooserItem*> m_groupItems;
|
---|
357 | /** Holds the global children list. */
|
---|
358 | QList<UIChooserItem*> m_globalItems;
|
---|
359 | /** Holds the machine children list. */
|
---|
360 | QList<UIChooserItem*> m_machineItems;
|
---|
361 |
|
---|
362 | /** Holds group children pixmap. */
|
---|
363 | QPixmap m_groupsPixmap;
|
---|
364 | /** Holds machine children pixmap. */
|
---|
365 | QPixmap m_machinesPixmap;
|
---|
366 |
|
---|
367 | /** Holds the cached group children info. */
|
---|
368 | QString m_strInfoGroups;
|
---|
369 | /** Holds the cached machine children info. */
|
---|
370 | QString m_strInfoMachines;
|
---|
371 |
|
---|
372 | /** Holds the children info font. */
|
---|
373 | QFont m_infoFont;
|
---|
374 | /** @} */
|
---|
375 |
|
---|
376 | /** @name Layout stuff.
|
---|
377 | * @{ */
|
---|
378 | /** Holds cached visible name size. */
|
---|
379 | QSize m_visibleNameSize;
|
---|
380 | /** Holds cached group children pixmap size. */
|
---|
381 | QSize m_pixmapSizeGroups;
|
---|
382 | /** Holds cached machine children pixmap size. */
|
---|
383 | QSize m_pixmapSizeMachines;
|
---|
384 | /** Holds cached group children info size. */
|
---|
385 | QSize m_infoSizeGroups;
|
---|
386 | /** Holds cached machine children info size. */
|
---|
387 | QSize m_infoSizeMachines;
|
---|
388 | /** Holds cached minimum header size. */
|
---|
389 | QSize m_minimumHeaderSize;
|
---|
390 | /** Holds cached toggle button size. */
|
---|
391 | QSize m_toggleButtonSize;
|
---|
392 | /** Holds cached enter button size. */
|
---|
393 | QSize m_enterButtonSize;
|
---|
394 | /** Holds cached exit button size. */
|
---|
395 | QSize m_exitButtonSize;
|
---|
396 | /** @} */
|
---|
397 | };
|
---|
398 |
|
---|
399 |
|
---|
400 | /** QWidget extension to use as group name editor. */
|
---|
401 | class UIEditorGroupRename : public QWidget
|
---|
402 | {
|
---|
403 | Q_OBJECT;
|
---|
404 |
|
---|
405 | signals:
|
---|
406 |
|
---|
407 | /** Notifies about group editing finished. */
|
---|
408 | void sigEditingFinished();
|
---|
409 |
|
---|
410 | public:
|
---|
411 |
|
---|
412 | /** Constructs group editor with initial @a strName passing @a pParent to the base-class. */
|
---|
413 | UIEditorGroupRename(const QString &strName, UIChooserItem *pParent);
|
---|
414 |
|
---|
415 | /** Defines editor @a strText. */
|
---|
416 | void setText(const QString &strText);
|
---|
417 | /** Returns editor text. */
|
---|
418 | QString text() const;
|
---|
419 |
|
---|
420 | /** Defines editor @a font. */
|
---|
421 | void setFont(const QFont &font);
|
---|
422 |
|
---|
423 | public slots:
|
---|
424 |
|
---|
425 | /** ACquires keyboard focus. */
|
---|
426 | void setFocus();
|
---|
427 |
|
---|
428 | protected:
|
---|
429 |
|
---|
430 | /** Preprocesses any Qt @a pEvent for passed @a pObject. */
|
---|
431 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
|
---|
432 |
|
---|
433 | private:
|
---|
434 |
|
---|
435 | /** Handles context-menu @a pEvent. */
|
---|
436 | void handleContextMenuEvent(QContextMenuEvent *pEvent);
|
---|
437 |
|
---|
438 | /** Holds the parent reference. */
|
---|
439 | UIChooserItem *m_pParent;
|
---|
440 |
|
---|
441 | /** Holds the line-edit instance. */
|
---|
442 | QLineEdit *m_pLineEdit;
|
---|
443 | /** Holds the conect-menu instance. */
|
---|
444 | QMenu *m_pTemporaryMenu;
|
---|
445 | };
|
---|
446 |
|
---|
447 |
|
---|
448 | #endif /* !___UIChooserItemGroup_h___ */
|
---|