VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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