VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 23 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.3 KB
Line 
1/* $Id: UIChooserItemGroup.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserItemGroup class declaration.
4 */
5
6/*
7 * Copyright (C) 2012-2023 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/* GUI includes: */
35#include "UIChooserItem.h"
36
37/* Forward declarations: */
38class QGraphicsLinearLayout;
39class QLineEdit;
40class UIChooserNodeGroup;
41class UIEditorGroupRename;
42class UIGraphicsButton;
43class UIGraphicsRotatorButton;
44class UIGraphicsScrollArea;
45
46
47/** UIChooserItem extension implementing group item. */
48class UIChooserItemGroup : public UIChooserItem
49{
50 Q_OBJECT;
51 Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);
52
53signals:
54
55 /** @name Item stuff.
56 * @{ */
57 /** Notifies listeners about toggle start. */
58 void sigToggleStarted();
59 /** Notifies listeners about toggle finish. */
60 void sigToggleFinished();
61 /** @} */
62
63 /** @name Layout stuff.
64 * @{ */
65 /** Notifies listeners about @a iMinimumWidthHint change. */
66 void sigMinimumWidthHintChanged(int iMinimumWidthHint);
67 /** @} */
68
69public:
70
71 /** RTTI required for qgraphicsitem_cast. */
72 enum { Type = UIChooserNodeType_Group };
73
74 /** Build item for certain @a pNode, adding it directly to the @a pScene. */
75 UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode);
76 /** Build item for certain @a pNode, passing @a pParent to the base-class. */
77 UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode);
78 /** Destructs group item. */
79 virtual ~UIChooserItemGroup() RT_OVERRIDE;
80
81 /** @name Item stuff.
82 * @{ */
83 /** Returns group node reference. */
84 UIChooserNodeGroup *nodeToGroupType() const;
85 /** Returns item machine id. */
86 QUuid id() const;
87 /** Returns group node type. */
88 UIChooserNodeGroupType groupType() const;
89
90 /** Returns whether group is closed. */
91 bool isClosed() const;
92 /** Closes group in @a fAnimated way if requested. */
93 void close(bool fAnimated = true);
94
95 /** Returns whether group is opened. */
96 bool isOpened() const;
97 /** Opens group in @a fAnimated way if requested. */
98 void open(bool fAnimated = true);
99 /** @} */
100
101 /** @name Children stuff.
102 * @{ */
103 /** Updates positions of favorite items. */
104 void updateFavorites();
105 /** @} */
106
107 /** @name Navigation stuff.
108 * @{ */
109 /** Returns scrolling location value in pixels. */
110 int scrollingValue() const;
111 /** Defines scrolling location @a iValue in pixels. */
112 void setScrollingValue(int iValue);
113 /** Performs scrolling by @a iDelta pixels. */
114 void scrollBy(int iDelta);
115
116 /** Makes sure passed @a pItem is visible within the current root item.
117 * @note Please keep in mind that any group item can be a root, but there
118 * is just one model root item at the same time, accessible via model's
119 * root() getter, and this API can be called for current root item only,
120 * because this is root item who performs actual scrolling, while
121 * @a pItem itself can be on any level of embedding. */
122 void makeSureItemIsVisible(UIChooserItem *pItem);
123
124 /** Class-name used for drag&drop mime-data format. */
125 static QString className();
126 /** @} */
127
128protected:
129
130 /** @name Event-handling stuff.
131 * @{ */
132 /** Handles translation event. */
133 virtual void retranslateUi() RT_OVERRIDE;
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
240private:
241
242 /** Data field types. */
243 enum GroupItemData
244 {
245 /* Layout hints: */
246 GroupItemData_MarginHL,
247 GroupItemData_MarginHR,
248 GroupItemData_MarginV,
249 GroupItemData_HeaderSpacing,
250 GroupItemData_ChildrenSpacing,
251 GroupItemData_ParentIndent,
252 };
253
254 /** @name Prepare/cleanup cascade.
255 * @{ */
256 /** Prepares all. */
257 void prepare();
258 /** Cleanups all. */
259 void cleanup();
260 /** @} */
261
262 /** @name Item stuff.
263 * @{ */
264 /** Returns abstractly stored data value for certain @a iKey. */
265 QVariant data(int iKey) const;
266
267 /** Returns additional height. */
268 int additionalHeight() const;
269 /** Defines @a iAdditionalHeight. */
270 void setAdditionalHeight(int iAdditionalHeight);
271
272 /** Updates animation parameters. */
273 void updateAnimationParameters();
274 /** Updates toggle-button tool-tip. */
275 void updateToggleButtonToolTip();
276 /** @} */
277
278 /** @name Children stuff.
279 * @{ */
280 /** Copies group contents from @a pCopyFrom node recursively. */
281 void copyContents(UIChooserNodeGroup *pCopyFrom);
282
283 /** Returns whether group contains machine with @a uId. */
284 bool isContainsMachine(const QUuid &uId) const;
285 /** Returns whether group contains locked machine. */
286 bool isContainsLockedMachine();
287
288 /** Updates user count info. */
289 void updateItemCountInfo();
290 /** @} */
291
292 /** @name Layout stuff.
293 * @{ */
294 /** Returns minimum width-hint depending on whether @a fGroupOpened. */
295 int minimumWidthHintForGroup(bool fGroupOpened) const;
296 /** Returns minimum height-hint depending on whether @a fGroupOpened. */
297 int minimumHeightHintForGroup(bool fGroupOpened) const;
298 /** Returns minimum size-hint depending on whether @a fGroupOpened. */
299 QSizeF minimumSizeHintForGroup(bool fGroupOpened) const;
300
301 /** Updates visible name. */
302 void updateVisibleName();
303 /** Updates pixmaps. */
304 void updatePixmaps();
305 /** Updates minimum header size. */
306 void updateMinimumHeaderSize();
307 /** Updates layout spacings. */
308 void updateLayoutSpacings();
309 /** @} */
310
311 /** @name Painting stuff.
312 * @{ */
313 /** Paints background using specified @a pPainter and certain @a rect. */
314 void paintBackground(QPainter *pPainter, const QRect &rect);
315 /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
316 void paintFrame(QPainter *pPainter, const QRect &rect);
317 /** Paints header using specified @a pPainter and certain @a rect. */
318 void paintHeader(QPainter *pPainter, const QRect &rect);
319 /** @} */
320
321 /** @name Item stuff.
322 * @{ */
323 /** Holds the graphics scene reference. */
324 QGraphicsScene *m_pScene;
325
326 /** Holds the cached visible name. */
327 QString m_strVisibleName;
328 /** Holds the cached group children info. */
329 QString m_strInfoGroups;
330 /** Holds the cached machine children info. */
331 QString m_strInfoMachines;
332
333 /** Holds root start background darkness. */
334 int m_iRootBackgroundDarknessStart;
335 /** Holds root final background darkness. */
336 int m_iRootBackgroundDarknessFinal;
337 /** Holds item start background darkness. */
338 int m_iItemBackgroundDarknessStart;
339 /** Holds item final background darkness. */
340 int m_iItemBackgroundDarknessFinal;
341 /** Holds item header highlight lightness. */
342 int m_iHighlightLightness;
343
344 /** Holds aditional height. */
345 int m_iAdditionalHeight;
346
347 /** Holds group children pixmap. */
348 QPixmap m_groupsPixmap;
349 /** Holds machine children pixmap. */
350 QPixmap m_machinesPixmap;
351
352 /** Holds the name font. */
353 QFont m_nameFont;
354 /** Holds the info font. */
355 QFont m_infoFont;
356
357 /** Holds the group toggle button instance. */
358 UIGraphicsRotatorButton *m_pToggleButton;
359
360 /** Holds the group name editor instance. */
361 UIEditorGroupRename *m_pNameEditorWidget;
362 /** @} */
363
364 /** @name Children stuff.
365 * @{ */
366 /** Holds the favorite children container instance. */
367 QIGraphicsWidget *m_pContainerFavorite;
368 /** Holds the favorite children layout instance. */
369 QGraphicsLinearLayout *m_pLayoutFavorite;
370
371 /** Holds the children scroll-area instance. */
372 UIGraphicsScrollArea *m_pScrollArea;
373 /** Holds the children container instance. */
374 QIGraphicsWidget *m_pContainer;
375
376 /** Holds the main layout instance. */
377 QGraphicsLinearLayout *m_pLayout;
378 /** Holds the global layout instance. */
379 QGraphicsLinearLayout *m_pLayoutGlobal;
380 /** Holds the group layout instance. */
381 QGraphicsLinearLayout *m_pLayoutGroup;
382 /** Holds the machine layout instance. */
383 QGraphicsLinearLayout *m_pLayoutMachine;
384
385 /** Holds the global children list. */
386 QList<UIChooserItem*> m_globalItems;
387 /** Holds the group children list. */
388 QList<UIChooserItem*> m_groupItems;
389 /** Holds the machine children list. */
390 QList<UIChooserItem*> m_machineItems;
391 /** @} */
392
393 /** @name Layout stuff.
394 * @{ */
395 /** Holds previous minimum width hint. */
396 int m_iPreviousMinimumWidthHint;
397
398 /** Holds cached visible name size. */
399 QSize m_visibleNameSize;
400 /** Holds cached group children pixmap size. */
401 QSize m_pixmapSizeGroups;
402 /** Holds cached machine children pixmap size. */
403 QSize m_pixmapSizeMachines;
404 /** Holds cached group children info size. */
405 QSize m_infoSizeGroups;
406 /** Holds cached machine children info size. */
407 QSize m_infoSizeMachines;
408 /** Holds cached minimum header size. */
409 QSize m_minimumHeaderSize;
410 /** Holds cached toggle button size. */
411 QSize m_toggleButtonSize;
412 /** @} */
413};
414
415
416/** QWidget extension to use as group name editor. */
417class UIEditorGroupRename : public QWidget
418{
419 Q_OBJECT;
420
421signals:
422
423 /** Notifies about group editing finished. */
424 void sigEditingFinished();
425
426public:
427
428 /** Constructs group editor with initial @a strName. */
429 UIEditorGroupRename(const QString &strName);
430
431 /** Returns editor text. */
432 QString text() const;
433 /** Defines editor @a strText. */
434 void setText(const QString &strText);
435
436 /** Defines editor @a font. */
437 void setFont(const QFont &font);
438
439private:
440
441 /** Holds the line-edit instance. */
442 QLineEdit *m_pLineEdit;
443};
444
445
446#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