VirtualBox

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

Last change on this file since 83672 was 83672, checked in by vboxsync, 5 years ago

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Rename UIChooserItemType to UIChooserNodeType.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 KB
Line 
1/* $Id: UIChooserItemGroup.h 83672 2020-04-10 16:27:16Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserItemGroup class declaration.
4 */
5
6/*
7 * Copyright (C) 2012-2020 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/* GUI includes: */
25#include "UIChooserItem.h"
26
27/* Forward declarations: */
28class QGraphicsLinearLayout;
29class QLineEdit;
30class UIChooserNodeGroup;
31class UIEditorGroupRename;
32class UIGraphicsButton;
33class UIGraphicsRotatorButton;
34class UIGraphicsScrollArea;
35
36
37/** UIChooserItem extension implementing group item. */
38class UIChooserItemGroup : public UIChooserItem
39{
40 Q_OBJECT;
41 Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);
42
43signals:
44
45 /** @name Item stuff.
46 * @{ */
47 /** Notifies listeners about toggle start. */
48 void sigToggleStarted();
49 /** Notifies listeners about toggle finish. */
50 void sigToggleFinished();
51 /** @} */
52
53 /** @name Layout stuff.
54 * @{ */
55 /** Notifies listeners about @a iMinimumWidthHint change. */
56 void sigMinimumWidthHintChanged(int iMinimumWidthHint);
57 /** @} */
58
59public:
60
61 /** RTTI required for qgraphicsitem_cast. */
62 enum { Type = UIChooserNodeType_Group };
63
64 /** Build item for certain @a pNode, adding it directly to the @a pScene. */
65 UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode);
66 /** Build item for certain @a pNode, passing @a pParent to the base-class. */
67 UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode);
68 /** Destructs group item. */
69 virtual ~UIChooserItemGroup() /* override */;
70
71 /** @name Item stuff.
72 * @{ */
73 /** Returns whether group is closed. */
74 bool isClosed() const;
75 /** Closes group in @a fAnimated way if requested. */
76 void close(bool fAnimated = true);
77
78 /** Returns whether group is opened. */
79 bool isOpened() const;
80 /** Opens group in @a fAnimated way if requested. */
81 void open(bool fAnimated = true);
82 /** @} */
83
84 /** @name Children stuff.
85 * @{ */
86 /** Updates positions of favorite items. */
87 void updateFavorites();
88 /** @} */
89
90 /** @name Navigation stuff.
91 * @{ */
92 /** Performs scrolling by @a iDelta pixels. */
93 void scrollBy(int iDelta);
94
95 /** Makes sure passed @a pItem is visible within the current root item.
96 * @note Please keep in mind that any group item can be a root, but there
97 * is just one model root item at the same time, accessible via model's
98 * root() getter, and this API can be called for current root item only,
99 * because this is root item who performs actual scrolling, while
100 * @a pItem itself can be on any level of embedding. */
101 void makeSureItemIsVisible(UIChooserItem *pItem) /* override */;
102
103 /** Class-name used for drag&drop mime-data format. */
104 static QString className();
105 /** @} */
106
107protected:
108
109 /** @name Event-handling stuff.
110 * @{ */
111 /** Handles translation event. */
112 virtual void retranslateUi() /* override */;
113
114 /** Handles show @a pEvent. */
115 virtual void showEvent(QShowEvent *pEvent) /* override */;
116
117 /** Handles resize @a pEvent. */
118 virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
119
120 /** Handles hover enter @a event. */
121 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
122 /** Handles hover leave @a event. */
123 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) /* override */;
124
125 /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
126 virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
127 /** @} */
128
129 /** @name Item stuff.
130 * @{ */
131 /** Returns RTTI item type. */
132 virtual int type() const /* override */ { return Type; }
133
134 /** Starts item editing. */
135 virtual void startEditing() /* override */;
136
137 /** Updates item. */
138 virtual void updateItem() /* override */;
139 /** Updates item tool-tip. */
140 virtual void updateToolTip() /* override */;
141
142 /** Installs event-filter for @a pSource object. */
143 virtual void installEventFilterHelper(QObject *pSource) /* override */;
144 /** @} */
145
146 /** @name Children stuff.
147 * @{ */
148 /** Returns children items of certain @a enmType. */
149 virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const /* override */;
150
151 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
152 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) /* override */;
153 /** Removes child @a pItem. */
154 virtual void removeItem(UIChooserItem *pItem) /* override */;
155
156 /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
157 virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iItemSearchFlags) /* override */;
158
159 /** Searches for a first machine child item. */
160 virtual UIChooserItem *firstMachineItem() /* override */;
161 /** @} */
162
163 /** @name Layout stuff.
164 * @{ */
165 /** Updates geometry. */
166 virtual void updateGeometry() /* override */;
167
168 /** Updates layout. */
169 virtual void updateLayout() /* override */;
170
171 /** Returns minimum width-hint. */
172 virtual int minimumWidthHint() const /* override */;
173 /** Returns minimum height-hint. */
174 virtual int minimumHeightHint() const /* override */;
175
176 /** Returns size-hint.
177 * @param enmWhich Brings size-hint type.
178 * @param constraint Brings size constraint. */
179 virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
180 /** @} */
181
182 /** @name Navigation stuff.
183 * @{ */
184 /** Returns pixmap item representation. */
185 virtual QPixmap toPixmap() /* override */;
186
187 /** Returns whether item drop is allowed.
188 * @param pEvent Brings information about drop event.
189 * @param enmPlace Brings the place of drag token to the drop moment. */
190 virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken where) const /* override */;
191 /** Processes item drop.
192 * @param pEvent Brings information about drop event.
193 * @param pFromWho Brings the item according to which we choose drop position.
194 * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */
195 virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, UIChooserItemDragToken where) /* override */;
196 /** Reset drag token. */
197 virtual void resetDragToken() /* override */;
198
199 /** Returns D&D mime data. */
200 virtual QMimeData *createMimeData() /* override */;
201 /** @} */
202
203private slots:
204
205 /** @name Item stuff.
206 * @{ */
207 /** Handles top-level window remaps. */
208 void sltHandleWindowRemapped();
209
210 /** Handles name editing trigger. */
211 void sltNameEditingFinished();
212
213 /** Handles group toggle start. */
214 void sltGroupToggleStart();
215 /** Handles group toggle finish for group finally @a fToggled. */
216 void sltGroupToggleFinish(bool fToggled);
217
218 /** Handles root indentation. */
219 void sltIndentRoot();
220 /** Handles root unindentation. */
221 void sltUnindentRoot();
222 /** @} */
223
224private:
225
226 /** Data field types. */
227 enum GroupItemData
228 {
229 /* Layout hints: */
230 GroupItemData_MarginHL,
231 GroupItemData_MarginHR,
232 GroupItemData_MarginV,
233 GroupItemData_HeaderSpacing,
234 GroupItemData_ChildrenSpacing,
235 GroupItemData_ParentIndent,
236 };
237
238 /** @name Prepare/cleanup cascade.
239 * @{ */
240 /** Prepares all. */
241 void prepare();
242 /** Cleanups all. */
243 void cleanup();
244 /** @} */
245
246 /** @name Item stuff.
247 * @{ */
248 /** Returns abstractly stored data value for certain @a iKey. */
249 QVariant data(int iKey) const;
250
251 /** Returns item's header darkness. */
252 int headerDarkness() const { return m_iHeaderDarkness; }
253
254 /** Returns additional height. */
255 int additionalHeight() const;
256 /** Defines @a iAdditionalHeight. */
257 void setAdditionalHeight(int iAdditionalHeight);
258
259 /** Updates animation parameters. */
260 void updateAnimationParameters();
261 /** Updates toggle-button tool-tip. */
262 void updateToggleButtonToolTip();
263 /** @} */
264
265 /** @name Children stuff.
266 * @{ */
267 /** Copies group contents from @a pCopyFrom node recursively. */
268 void copyContents(UIChooserNodeGroup *pCopyFrom);
269
270 /** Returns whether group contains machine with @a uId. */
271 bool isContainsMachine(const QUuid &uId) const;
272 /** Returns whether group contains locked machine. */
273 bool isContainsLockedMachine();
274
275 /** Updates user count info. */
276 void updateItemCountInfo();
277 /** @} */
278
279 /** @name Layout stuff.
280 * @{ */
281 /** Returns minimum width-hint depending on whether @a fGroupOpened. */
282 int minimumWidthHintForGroup(bool fGroupOpened) const;
283 /** Returns minimum height-hint depending on whether @a fGroupOpened. */
284 int minimumHeightHintForGroup(bool fGroupOpened) const;
285 /** Returns minimum size-hint depending on whether @a fGroupOpened. */
286 QSizeF minimumSizeHintForGroup(bool fGroupOpened) const;
287
288 /** Updates visible name. */
289 void updateVisibleName();
290 /** Updates pixmaps. */
291 void updatePixmaps();
292 /** Updates minimum header size. */
293 void updateMinimumHeaderSize();
294 /** Updates layout spacings. */
295 void updateLayoutSpacings();
296 /** @} */
297
298 /** @name Painting stuff.
299 * @{ */
300 /** Paints background using specified @a pPainter and certain @a rect. */
301 void paintBackground(QPainter *pPainter, const QRect &rect);
302 /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
303 void paintFrame(QPainter *pPainter, const QRect &rect);
304 /** Paints header using specified @a pPainter and certain @a rect. */
305 void paintHeader(QPainter *pPainter, const QRect &rect);
306 /** @} */
307
308 /** @name Item stuff.
309 * @{ */
310 /** Holds the graphics scene reference. */
311 QGraphicsScene *m_pScene;
312
313 /** Holds the cached visible name. */
314 QString m_strVisibleName;
315 /** Holds the cached group children info. */
316 QString m_strInfoGroups;
317 /** Holds the cached machine children info. */
318 QString m_strInfoMachines;
319
320 /** Holds aditional height. */
321 int m_iAdditionalHeight;
322 /** Holds the header darkness. */
323 int m_iHeaderDarkness;
324
325 /** Holds group children pixmap. */
326 QPixmap m_groupsPixmap;
327 /** Holds machine children pixmap. */
328 QPixmap m_machinesPixmap;
329
330 /** Holds the name font. */
331 QFont m_nameFont;
332 /** Holds the info font. */
333 QFont m_infoFont;
334
335 /** Holds the group toggle button instance. */
336 UIGraphicsRotatorButton *m_pToggleButton;
337
338 /** Holds the group name editor instance. */
339 UIEditorGroupRename *m_pNameEditorWidget;
340 /** @} */
341
342 /** @name Children stuff.
343 * @{ */
344 /** Holds the favorite children container instance. */
345 QIGraphicsWidget *m_pContainerFavorite;
346 /** Holds the favorite children layout instance. */
347 QGraphicsLinearLayout *m_pLayoutFavorite;
348
349 /** Holds the children scroll-area instance. */
350 UIGraphicsScrollArea *m_pScrollArea;
351 /** Holds the children container instance. */
352 QIGraphicsWidget *m_pContainer;
353
354 /** Holds the main layout instance. */
355 QGraphicsLinearLayout *m_pLayout;
356 /** Holds the global layout instance. */
357 QGraphicsLinearLayout *m_pLayoutGlobal;
358 /** Holds the group layout instance. */
359 QGraphicsLinearLayout *m_pLayoutGroup;
360 /** Holds the machine layout instance. */
361 QGraphicsLinearLayout *m_pLayoutMachine;
362
363 /** Holds the global children list. */
364 QList<UIChooserItem*> m_globalItems;
365 /** Holds the group children list. */
366 QList<UIChooserItem*> m_groupItems;
367 /** Holds the machine children list. */
368 QList<UIChooserItem*> m_machineItems;
369 /** @} */
370
371 /** @name Layout stuff.
372 * @{ */
373 /** Holds previous minimum width hint. */
374 int m_iPreviousMinimumWidthHint;
375
376 /** Holds cached visible name size. */
377 QSize m_visibleNameSize;
378 /** Holds cached group children pixmap size. */
379 QSize m_pixmapSizeGroups;
380 /** Holds cached machine children pixmap size. */
381 QSize m_pixmapSizeMachines;
382 /** Holds cached group children info size. */
383 QSize m_infoSizeGroups;
384 /** Holds cached machine children info size. */
385 QSize m_infoSizeMachines;
386 /** Holds cached minimum header size. */
387 QSize m_minimumHeaderSize;
388 /** Holds cached toggle button size. */
389 QSize m_toggleButtonSize;
390 /** @} */
391};
392
393
394/** QWidget extension to use as group name editor. */
395class UIEditorGroupRename : public QWidget
396{
397 Q_OBJECT;
398
399signals:
400
401 /** Notifies about group editing finished. */
402 void sigEditingFinished();
403
404public:
405
406 /** Constructs group editor with initial @a strName. */
407 UIEditorGroupRename(const QString &strName);
408
409 /** Returns editor text. */
410 QString text() const;
411 /** Defines editor @a strText. */
412 void setText(const QString &strText);
413
414 /** Defines editor @a font. */
415 void setFont(const QFont &font);
416
417private:
418
419 /** Holds the line-edit instance. */
420 QLineEdit *m_pLineEdit;
421};
422
423
424#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