VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h@ 75183

Last change on this file since 75183 was 75183, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9241: VirtualBox Manager: Forgot something in r126263 (try two).

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette