VirtualBox

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

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

FE/Qt: bugref:9373: VirtualBox Manager: Chooser pane: Integrate Favorite children layout, unused for now.

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

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