VirtualBox

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

Last change on this file since 93990 was 93990, checked in by vboxsync, 3 years ago

FE/Qt: Replaced /* override */ comments with RT_OVERRIDE. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.0 KB
Line 
1/* $Id: UIChooserItemGroup.h 93990 2022-02-28 15:34:57Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserItemGroup class declaration.
4 */
5
6/*
7 * Copyright (C) 2012-2022 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() RT_OVERRIDE;
70
71 /** @name Item stuff.
72 * @{ */
73 /** Returns group node reference. */
74 UIChooserNodeGroup *nodeToGroupType() const;
75 /** Returns item machine id. */
76 QUuid id() const;
77 /** Returns group node type. */
78 UIChooserNodeGroupType groupType() const;
79
80 /** Returns whether group is closed. */
81 bool isClosed() const;
82 /** Closes group in @a fAnimated way if requested. */
83 void close(bool fAnimated = true);
84
85 /** Returns whether group is opened. */
86 bool isOpened() const;
87 /** Opens group in @a fAnimated way if requested. */
88 void open(bool fAnimated = true);
89 /** @} */
90
91 /** @name Children stuff.
92 * @{ */
93 /** Updates positions of favorite items. */
94 void updateFavorites();
95 /** @} */
96
97 /** @name Navigation stuff.
98 * @{ */
99 /** Returns scrolling location value in pixels. */
100 int scrollingValue() const;
101 /** Defines scrolling location @a iValue in pixels. */
102 void setScrollingValue(int iValue);
103 /** Performs scrolling by @a iDelta pixels. */
104 void scrollBy(int iDelta);
105
106 /** Makes sure passed @a pItem is visible within the current root item.
107 * @note Please keep in mind that any group item can be a root, but there
108 * is just one model root item at the same time, accessible via model's
109 * root() getter, and this API can be called for current root item only,
110 * because this is root item who performs actual scrolling, while
111 * @a pItem itself can be on any level of embedding. */
112 void makeSureItemIsVisible(UIChooserItem *pItem);
113
114 /** Class-name used for drag&drop mime-data format. */
115 static QString className();
116 /** @} */
117
118protected:
119
120 /** @name Event-handling stuff.
121 * @{ */
122 /** Handles translation event. */
123 virtual void retranslateUi() RT_OVERRIDE;
124
125 /** Handles show @a pEvent. */
126 virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
127
128 /** Handles resize @a pEvent. */
129 virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) RT_OVERRIDE;
130
131 /** Handles hover enter @a event. */
132 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
133 /** Handles hover leave @a event. */
134 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
135
136 /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
137 virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) RT_OVERRIDE;
138 /** @} */
139
140 /** @name Item stuff.
141 * @{ */
142 /** Returns RTTI item type. */
143 virtual int type() const RT_OVERRIDE { return Type; }
144
145 /** Starts item editing. */
146 virtual void startEditing() RT_OVERRIDE;
147
148 /** Updates item. */
149 virtual void updateItem() RT_OVERRIDE;
150 /** Updates item tool-tip. */
151 virtual void updateToolTip() RT_OVERRIDE;
152
153 /** Installs event-filter for @a pSource object. */
154 virtual void installEventFilterHelper(QObject *pSource) RT_OVERRIDE;
155 /** @} */
156
157 /** @name Children stuff.
158 * @{ */
159 /** Returns children items of certain @a enmType. */
160 virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const RT_OVERRIDE;
161
162 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
163 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) RT_OVERRIDE;
164 /** Removes child @a pItem. */
165 virtual void removeItem(UIChooserItem *pItem) RT_OVERRIDE;
166
167 /** Searches for a first child item answering to specified @a strSearchTag and @a iSearchFlags. */
168 virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iSearchFlags) RT_OVERRIDE;
169
170 /** Searches for a first machine child item. */
171 virtual UIChooserItem *firstMachineItem() RT_OVERRIDE;
172 /** @} */
173
174 /** @name Layout stuff.
175 * @{ */
176 /** Updates geometry. */
177 virtual void updateGeometry() RT_OVERRIDE;
178
179 /** Updates layout. */
180 virtual void updateLayout() RT_OVERRIDE;
181
182 /** Returns minimum width-hint. */
183 virtual int minimumWidthHint() const RT_OVERRIDE;
184 /** Returns minimum height-hint. */
185 virtual int minimumHeightHint() const RT_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 RT_OVERRIDE;
191 /** @} */
192
193 /** @name Navigation stuff.
194 * @{ */
195 /** Returns pixmap item representation. */
196 virtual QPixmap toPixmap() RT_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, UIChooserItemDragToken where) const RT_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, UIChooserItemDragToken where) RT_OVERRIDE;
207 /** Reset drag token. */
208 virtual void resetDragToken() RT_OVERRIDE;
209
210 /** Returns D&D mime data. */
211 virtual QMimeData *createMimeData() RT_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
230private:
231
232 /** Data field types. */
233 enum GroupItemData
234 {
235 /* Layout hints: */
236 GroupItemData_MarginHL,
237 GroupItemData_MarginHR,
238 GroupItemData_MarginV,
239 GroupItemData_HeaderSpacing,
240 GroupItemData_ChildrenSpacing,
241 GroupItemData_ParentIndent,
242 };
243
244 /** @name Prepare/cleanup cascade.
245 * @{ */
246 /** Prepares all. */
247 void prepare();
248 /** Cleanups all. */
249 void cleanup();
250 /** @} */
251
252 /** @name Item stuff.
253 * @{ */
254 /** Returns abstractly stored data value for certain @a iKey. */
255 QVariant data(int iKey) const;
256
257 /** Returns additional height. */
258 int additionalHeight() const;
259 /** Defines @a iAdditionalHeight. */
260 void setAdditionalHeight(int iAdditionalHeight);
261
262 /** Updates animation parameters. */
263 void updateAnimationParameters();
264 /** Updates toggle-button tool-tip. */
265 void updateToggleButtonToolTip();
266 /** @} */
267
268 /** @name Children stuff.
269 * @{ */
270 /** Copies group contents from @a pCopyFrom node recursively. */
271 void copyContents(UIChooserNodeGroup *pCopyFrom);
272
273 /** Returns whether group contains machine with @a uId. */
274 bool isContainsMachine(const QUuid &uId) const;
275 /** Returns whether group contains locked machine. */
276 bool isContainsLockedMachine();
277
278 /** Updates user count info. */
279 void updateItemCountInfo();
280 /** @} */
281
282 /** @name Layout stuff.
283 * @{ */
284 /** Returns minimum width-hint depending on whether @a fGroupOpened. */
285 int minimumWidthHintForGroup(bool fGroupOpened) const;
286 /** Returns minimum height-hint depending on whether @a fGroupOpened. */
287 int minimumHeightHintForGroup(bool fGroupOpened) const;
288 /** Returns minimum size-hint depending on whether @a fGroupOpened. */
289 QSizeF minimumSizeHintForGroup(bool fGroupOpened) const;
290
291 /** Updates visible name. */
292 void updateVisibleName();
293 /** Updates pixmaps. */
294 void updatePixmaps();
295 /** Updates minimum header size. */
296 void updateMinimumHeaderSize();
297 /** Updates layout spacings. */
298 void updateLayoutSpacings();
299 /** @} */
300
301 /** @name Painting stuff.
302 * @{ */
303 /** Paints background using specified @a pPainter and certain @a rect. */
304 void paintBackground(QPainter *pPainter, const QRect &rect);
305 /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
306 void paintFrame(QPainter *pPainter, const QRect &rect);
307 /** Paints header using specified @a pPainter and certain @a rect. */
308 void paintHeader(QPainter *pPainter, const QRect &rect);
309 /** @} */
310
311 /** @name Item stuff.
312 * @{ */
313 /** Holds the graphics scene reference. */
314 QGraphicsScene *m_pScene;
315
316 /** Holds the cached visible name. */
317 QString m_strVisibleName;
318 /** Holds the cached group children info. */
319 QString m_strInfoGroups;
320 /** Holds the cached machine children info. */
321 QString m_strInfoMachines;
322
323 /** Holds root start background darkness. */
324 int m_iRootBackgroundDarknessStart;
325 /** Holds root final background darkness. */
326 int m_iRootBackgroundDarknessFinal;
327 /** Holds item start background darkness. */
328 int m_iItemBackgroundDarknessStart;
329 /** Holds item final background darkness. */
330 int m_iItemBackgroundDarknessFinal;
331 /** Holds item header highlight lightness. */
332 int m_iHighlightLightness;
333
334 /** Holds aditional height. */
335 int m_iAdditionalHeight;
336
337 /** Holds group children pixmap. */
338 QPixmap m_groupsPixmap;
339 /** Holds machine children pixmap. */
340 QPixmap m_machinesPixmap;
341
342 /** Holds the name font. */
343 QFont m_nameFont;
344 /** Holds the info font. */
345 QFont m_infoFont;
346
347 /** Holds the group toggle button instance. */
348 UIGraphicsRotatorButton *m_pToggleButton;
349
350 /** Holds the group name editor instance. */
351 UIEditorGroupRename *m_pNameEditorWidget;
352 /** @} */
353
354 /** @name Children stuff.
355 * @{ */
356 /** Holds the favorite children container instance. */
357 QIGraphicsWidget *m_pContainerFavorite;
358 /** Holds the favorite children layout instance. */
359 QGraphicsLinearLayout *m_pLayoutFavorite;
360
361 /** Holds the children scroll-area instance. */
362 UIGraphicsScrollArea *m_pScrollArea;
363 /** Holds the children container instance. */
364 QIGraphicsWidget *m_pContainer;
365
366 /** Holds the main layout instance. */
367 QGraphicsLinearLayout *m_pLayout;
368 /** Holds the global layout instance. */
369 QGraphicsLinearLayout *m_pLayoutGlobal;
370 /** Holds the group layout instance. */
371 QGraphicsLinearLayout *m_pLayoutGroup;
372 /** Holds the machine layout instance. */
373 QGraphicsLinearLayout *m_pLayoutMachine;
374
375 /** Holds the global children list. */
376 QList<UIChooserItem*> m_globalItems;
377 /** Holds the group children list. */
378 QList<UIChooserItem*> m_groupItems;
379 /** Holds the machine children list. */
380 QList<UIChooserItem*> m_machineItems;
381 /** @} */
382
383 /** @name Layout stuff.
384 * @{ */
385 /** Holds previous minimum width hint. */
386 int m_iPreviousMinimumWidthHint;
387
388 /** Holds cached visible name size. */
389 QSize m_visibleNameSize;
390 /** Holds cached group children pixmap size. */
391 QSize m_pixmapSizeGroups;
392 /** Holds cached machine children pixmap size. */
393 QSize m_pixmapSizeMachines;
394 /** Holds cached group children info size. */
395 QSize m_infoSizeGroups;
396 /** Holds cached machine children info size. */
397 QSize m_infoSizeMachines;
398 /** Holds cached minimum header size. */
399 QSize m_minimumHeaderSize;
400 /** Holds cached toggle button size. */
401 QSize m_toggleButtonSize;
402 /** @} */
403};
404
405
406/** QWidget extension to use as group name editor. */
407class UIEditorGroupRename : public QWidget
408{
409 Q_OBJECT;
410
411signals:
412
413 /** Notifies about group editing finished. */
414 void sigEditingFinished();
415
416public:
417
418 /** Constructs group editor with initial @a strName. */
419 UIEditorGroupRename(const QString &strName);
420
421 /** Returns editor text. */
422 QString text() const;
423 /** Defines editor @a strText. */
424 void setText(const QString &strText);
425
426 /** Defines editor @a font. */
427 void setFont(const QFont &font);
428
429private:
430
431 /** Holds the line-edit instance. */
432 QLineEdit *m_pLineEdit;
433};
434
435
436#endif /* !FEQT_INCLUDED_SRC_manager_chooser_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