VirtualBox

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

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

scm --update-copyright-year

  • 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 76553 2019-01-01 01:45:53Z 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 ___UIChooserItemGroup_h___
19#define ___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: */
33class QGraphicsScene;
34class QLineEdit;
35class QMenu;
36class QMimeData;
37class QPainter;
38class QStyleOptionGraphicsItem;
39class UIEditorGroupRename;
40class UIGraphicsButton;
41class UIGraphicsRotatorButton;
42
43
44/** UIChooserItem extension implementing group item. */
45class UIChooserItemGroup : public UIChooserItem
46{
47 Q_OBJECT;
48 Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);
49
50signals:
51
52 /** @name Item stuff.
53 * @{ */
54 /** Notifies listeners about toggle start. */
55 void sigToggleStarted();
56 /** Notifies listeners about toggle finish. */
57 void sigToggleFinished();
58 /** @} */
59
60public:
61
62 /** RTTI item type. */
63 enum { Type = UIChooserItemType_Group };
64
65 /** Constructs main-root item, passing pScene to the base-class. */
66 UIChooserItemGroup(QGraphicsScene *pScene);
67 /** Constructs temporary @a fMainRoot item as a @a pCopyFrom, passing pScene to the base-class. */
68 UIChooserItemGroup(QGraphicsScene *pScene, UIChooserItemGroup *pCopyFrom, bool fMainRoot);
69 /** Constructs non-root item with specified @a strName and @a iPosition, @a fOpened if requested, passing pParent to the base-class. */
70 UIChooserItemGroup(UIChooserItem *pParent, const QString &strName, bool fOpened = false, int iPosition = -1);
71 /** Constructs temporary non-root item with specified @a iPosition as a @a pCopyFrom, passing pParent to the base-class. */
72 UIChooserItemGroup(UIChooserItem *pParent, UIChooserItemGroup *pCopyFrom, int iPosition = -1);
73 /** Destructs group item. */
74 virtual ~UIChooserItemGroup() /* override */;
75
76 /** @name Item stuff.
77 * @{ */
78 /** Defines group @a strName. */
79 void setName(const QString &strName);
80
81 /** Closes group in @a fAnimated way if requested. */
82 void close(bool fAnimated = true);
83 /** Returns whether group is closed. */
84 bool isClosed() const;
85
86 /** Opens group in @a fAnimated way if requested. */
87 void open(bool fAnimated = true);
88 /** Returns whether group is opened. */
89 bool isOpened() const;
90 /** @} */
91
92 /** @name Navigation stuff.
93 * @{ */
94 /** Class-name used for drag&drop mime-data format. */
95 static QString className();
96 /** @} */
97
98protected:
99
100 /** @name Event-handling stuff.
101 * @{ */
102 /** Handles translation event. */
103 virtual void retranslateUi() /* override */;
104
105 /** Handles show @a pEvent. */
106 virtual void showEvent(QShowEvent *pEvent) /* override */;
107
108 /** Handles resize @a pEvent. */
109 virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
110
111 /** Handles hover enter @a event. */
112 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
113 /** Handles hover leave @a event. */
114 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
115
116 /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
117 virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
118 /** @} */
119
120 /** @name Item stuff.
121 * @{ */
122 /** Returns RTTI item type. */
123 virtual int type() const /* override */ { return Type; }
124
125 /** Shows item. */
126 virtual void show() /* override */;
127 /** Hides item. */
128 virtual void hide() /* override */;
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 layout. */
183 virtual void updateLayout() /* override */;
184
185 /** Returns minimum width-hint. */
186 virtual int minimumWidthHint() const /* override */;
187 /** Returns minimum height-hint. */
188 virtual int minimumHeightHint() const /* override */;
189
190 /** Returns size-hint.
191 * @param enmWhich Brings size-hint type.
192 * @param constraint Brings size constraint. */
193 virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
194 /** @} */
195
196 /** @name Navigation stuff.
197 * @{ */
198 /** Returns pixmap item representation. */
199 virtual QPixmap toPixmap() /* override */;
200
201 /** Returns whether item drop is allowed.
202 * @param pEvent Brings information about drop event.
203 * @param enmPlace Brings the place of drag token to the drop moment. */
204 virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, DragToken where) const /* override */;
205 /** Processes item drop.
206 * @param pEvent Brings information about drop event.
207 * @param pFromWho Brings the item according to which we choose drop position.
208 * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */
209 virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, DragToken where) /* override */;
210 /** Reset drag token. */
211 virtual void resetDragToken() /* override */;
212
213 /** Returns D&D mime data. */
214 virtual QMimeData *createMimeData() /* override */;
215 /** @} */
216
217private slots:
218
219 /** @name Item stuff.
220 * @{ */
221 /** Handles top-level window remaps. */
222 void sltHandleWindowRemapped();
223
224 /** Handles name editing trigger. */
225 void sltNameEditingFinished();
226
227 /** Handles group toggle start. */
228 void sltGroupToggleStart();
229 /** Handles group toggle finish for group finally @a fToggled. */
230 void sltGroupToggleFinish(bool fToggled);
231
232 /** Handles root indentation. */
233 void sltIndentRoot();
234 /** Handles root unindentation. */
235 void sltUnindentRoot();
236 /** @} */
237
238private:
239
240 /** Data field types. */
241 enum GroupItemData
242 {
243 /* Layout hints: */
244 GroupItemData_HorizonalMargin,
245 GroupItemData_VerticalMargin,
246 GroupItemData_HeaderSpacing,
247 GroupItemData_ChildrenSpacing,
248 GroupItemData_ParentIndent,
249 };
250
251 /** @name Prepare/cleanup cascade.
252 * @{ */
253 /** Prepares all. */
254 void prepare();
255
256 /** Copies group contents @a pFrom one item @a pTo another. */
257 static void copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo);
258 /** @} */
259
260 /** @name Item stuff.
261 * @{ */
262 /** Returns abstractly stored data value for certain @a iKey. */
263 QVariant data(int iKey) const;
264
265 /** Returns whether group is main-root. */
266 bool isMainRoot() const { return m_fMainRoot; }
267
268 /** Returns item's header darkness. */
269 int headerDarkness() const { return m_iHeaderDarkness; }
270
271 /** Defines @a iAdditionalHeight. */
272 void setAdditionalHeight(int iAdditionalHeight);
273 /** Returns additional height. */
274 int additionalHeight() const;
275
276 /** Updates animation parameters. */
277 void updateAnimationParameters();
278 /** Updates toggle-button tool-tip. */
279 void updateToggleButtonToolTip();
280 /** @} */
281
282 /** @name Children stuff.
283 * @{ */
284 /** Returns whether group contains machine with @a uId. */
285 bool isContainsMachine(const QUuid &uId) const;
286 /** Returns whether group contains locked machine. */
287 bool isContainsLockedMachine();
288
289 /** Updates user count info. */
290 void updateItemCountInfo();
291 /** @} */
292
293 /** @name Layout stuff.
294 * @{ */
295 /** Returns minimum width-hint depending on whether @a fGroupOpened. */
296 int minimumWidthHintForGroup(bool fGroupOpened) const;
297 /** Returns minimum height-hint depending on whether @a fGroupOpened. */
298 int minimumHeightHintForGroup(bool fGroupOpened) const;
299 /** Returns minimum size-hint depending on whether @a fGroupOpened. */
300 QSizeF minimumSizeHintForProup(bool fGroupOpened) const;
301
302 /** Updates visible name. */
303 void updateVisibleName();
304 /** Updates pixmaps. */
305 void updatePixmaps();
306 /** Updates minimum header size. */
307 void updateMinimumHeaderSize();
308 /** @} */
309
310 /** @name Painting stuff.
311 * @{ */
312 /** Paints background using specified @a pPainter and certain @a rect. */
313 void paintBackground(QPainter *pPainter, const QRect &rect);
314 /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
315 void paintFrame(QPainter *pPainter, const QRect &rect);
316 /** Paints header using specified @a pPainter and certain @a rect. */
317 void paintHeader(QPainter *pPainter, const QRect &rect);
318 /** @} */
319
320 /** @name Item stuff.
321 * @{ */
322 /** Holds whether group is main-root. */
323 bool m_fMainRoot;
324 /** Holds whether group is closed. */
325 bool m_fClosed;
326
327 /** Holds aditional height. */
328 int m_iAdditionalHeight;
329 /** Holds the header darkness. */
330 int m_iHeaderDarkness;
331
332 /** Holds the cached name. */
333 QString m_strName;
334 /** Holds the cached description. */
335 QString m_strDescription;
336 /** Holds the cached visible name. */
337 QString m_strVisibleName;
338
339 /** Holds the name font. */
340 QFont m_nameFont;
341
342 /** Holds the group toggle button instance. */
343 UIGraphicsRotatorButton *m_pToggleButton;
344 /** Holds the group enter button instance. */
345 UIGraphicsButton *m_pEnterButton;
346 /** Holds the group exit button instance. */
347 UIGraphicsButton *m_pExitButton;
348
349 /** Holds the group name editor instance. */
350 UIEditorGroupRename *m_pNameEditorWidget;
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. */
401class UIEditorGroupRename : public QWidget
402{
403 Q_OBJECT;
404
405signals:
406
407 /** Notifies about group editing finished. */
408 void sigEditingFinished();
409
410public:
411
412 /** Constructs group editor with initial @a strName. */
413 UIEditorGroupRename(const QString &strName);
414
415 /** Returns editor text. */
416 QString text() const;
417 /** Defines editor @a strText. */
418 void setText(const QString &strText);
419
420 /** Defines editor @a font. */
421 void setFont(const QFont &font);
422
423private:
424
425 /** Holds the line-edit instance. */
426 QLineEdit *m_pLineEdit;
427};
428
429
430#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