VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h@ 103988

Last change on this file since 103988 was 103988, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10624. Adding missing override keywords gcc has found.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1/* $Id: UIChooserItem.h 103988 2024-03-21 13:49:47Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserItem 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_UIChooserItem_h
29#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserItem_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QGraphicsEffect>
36#include <QMimeData>
37#include <QRectF>
38#include <QString>
39#include <QUuid>
40
41/* GUI includes: */
42#include "QIGraphicsWidget.h"
43#include "QIWithRetranslateUI.h"
44#include "UIChooserDefs.h"
45
46/* Forward declaration: */
47class QGraphicsSceneHoverEvent;
48class QGraphicsSceneMouseEvent;
49class QGraphicsSceneDragDropEvent;
50class QPropertyAnimation;
51class QStateMachine;
52class UIActionPool;
53class UIChooserItemGroup;
54class UIChooserItemGlobal;
55class UIChooserItemMachine;
56class UIChooserModel;
57class UIChooserNode;
58
59
60/** A simple QGraphicsEffect extension to mark disabled UIChooserItem.
61 * @note Applies blur and gray scale filters. */
62class UIChooserDisabledItemEffect : public QGraphicsEffect
63{
64 Q_OBJECT;
65
66public:
67
68 /** Constructs blur effect passing @a pParent to the base-class.
69 * @param iBlurRadius Brings the blur effect radius. */
70 UIChooserDisabledItemEffect(int iBlurRadius, QObject *pParent = 0);
71
72protected:
73
74 /** Draws effect with passed @a pPainter. */
75 virtual void draw(QPainter *pPainter) RT_OVERRIDE RT_FINAL;;
76
77private:
78
79 /** Holds the blur effect radius. */
80 int m_iBlurRadius;
81};
82
83
84/** QIGraphicsWidget extension used as interface
85 * for graphics chooser model/view architecture. */
86class UIChooserItem : public QIWithRetranslateUI4<QIGraphicsWidget>
87{
88 Q_OBJECT;
89 Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
90
91signals:
92
93 /** @name Item stuff.
94 * @{ */
95 /** Notifies listeners about hover enter. */
96 void sigHoverEnter();
97 /** Notifies listeners about hover leave. */
98 void sigHoverLeave();
99 /** @} */
100
101public:
102
103 /** Constructs item passing @a pParent to the base-class.
104 * @param pNode Brings the node this item is built for.
105 * @param iDefaultValue Brings default value for hovering animation.
106 * @param iHoveredValue Brings hovered value for hovering animation. */
107 UIChooserItem(UIChooserItem *pParent, UIChooserNode *pNode,
108 int iDefaultValue = 0, int iHoveredValue = 100);
109
110 /** @name Item stuff.
111 * @{ */
112 /** Returns parent reference. */
113 UIChooserItem *parentItem() const { return m_pParent; }
114 /** Returns node reference. */
115 UIChooserNode *node() const { return m_pNode; }
116
117 /** Casts item to group one. */
118 UIChooserItemGroup *toGroupItem();
119 /** Casts item to global one. */
120 UIChooserItemGlobal *toGlobalItem();
121 /** Casts item to machine one. */
122 UIChooserItemMachine *toMachineItem();
123
124 /** Returns model reference. */
125 UIChooserModel *model() const;
126
127 /** Returns whether item is root. */
128 bool isRoot() const;
129
130 /** Returns item name. */
131 QString name() const;
132 /** Returns item full-name. */
133 QString fullName() const;
134 /** Returns item description. */
135 QString description() const;
136 /** Returns item definition. */
137 QString definition() const;
138
139 /** Returns whether item is favorite. */
140 bool isFavorite() const;
141 /** Defines whether item is @a fFavorite. */
142 virtual void setFavorite(bool fFavorite);
143
144 /** Returns item position. */
145 int position() const;
146
147 /** Returns whether item is hovered. */
148 bool isHovered() const;
149
150 /** Returns whether item is selected.
151 * @note Sometimes it's useful to know whether item is selected in model above. */
152 virtual bool isSelected() const;
153 /** Defines item as @a fSelected.
154 * @note Don't forget to call for base-class method when reimplementing it. */
155 virtual void setSelected(bool fSelected);
156
157 /** Starts item editing. */
158 virtual void startEditing() = 0;
159
160 /** Updates item. */
161 virtual void updateItem() = 0;
162 /** Updates item tool-tip. */
163 virtual void updateToolTip() = 0;
164
165 /** Installs event-filter for @a pSource object.
166 * @note Base-class implementation does nothing. */
167 virtual void installEventFilterHelper(QObject *pSource) { Q_UNUSED(pSource); }
168 /** Defines whether visual effect for disabled item is @a fOn. */
169 void setDisabledEffect(bool fOn);
170 /** @} */
171
172 /** @name Children stuff.
173 * @{ */
174 /** Returns children items of certain @a enmType. */
175 virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const = 0;
176
177 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
178 virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) = 0;
179 /** Removes child @a pItem. */
180 virtual void removeItem(UIChooserItem *pItem) = 0;
181
182 /** Searches for a first child item answering to specified @a strSearchTag and @a iSearchFlags. */
183 virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iSearchFlags) = 0;
184
185 /** Searches for a first machine child item. */
186 virtual UIChooserItem *firstMachineItem() = 0;
187 /** @} */
188
189 /** @name Layout stuff.
190 * @{ */
191 /** Updates geometry. */
192 virtual void updateGeometry() RT_OVERRIDE;
193
194 /** Updates layout. */
195 virtual void updateLayout() = 0;
196
197 /** Returns minimum width-hint. */
198 virtual int minimumWidthHint() const = 0;
199 /** Returns minimum height-hint. */
200 virtual int minimumHeightHint() const = 0;
201 /** @} */
202
203 /** @name Navigation stuff.
204 * @{ */
205 /** Makes sure item is visible. */
206 virtual void makeSureItsVisible();
207
208 /** Returns pixmap item representation. */
209 virtual QPixmap toPixmap() = 0;
210
211 /** Returns whether item drop is allowed.
212 * @param pEvent Brings information about drop event.
213 * @param enmPlace Brings the place of drag token to the drop moment. */
214 virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken enmPlace = UIChooserItemDragToken_Off) const = 0;
215 /** Processes item drop.
216 * @param pEvent Brings information about drop event.
217 * @param pFromWho Brings the item according to which we choose drop position.
218 * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */
219 virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho = 0, UIChooserItemDragToken enmPlace = UIChooserItemDragToken_Off) = 0;
220 /** Reset drag token. */
221 virtual void resetDragToken() = 0;
222
223 /** Returns drag token place. */
224 UIChooserItemDragToken dragTokenPlace() const;
225 /** Defines drag token @a enmPlace. */
226 void setDragTokenPlace(UIChooserItemDragToken enmPlace);
227 /** @} */
228
229protected:
230
231 /** @name Event-handling stuff.
232 * @{ */
233 /** Handles hover enter @a event. */
234 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
235 /** Handles hover leave @a event. */
236 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
237
238 /** Handles mouse press @a event. */
239 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
240 /** Handles mouse move @a event. */
241 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
242
243 /** Handles drag move @a event. */
244 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
245 /** Handles drag leave @a event. */
246 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
247 /** Handles drop @a event. */
248 virtual void dropEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
249 /** @} */
250
251 /** @name Item stuff.
252 * @{ */
253 /** Returns item's default animation value. */
254 int defaultValue() const { return m_iDefaultValue; }
255 /** Defines item's default animation @a iValue. */
256 void setDefaultValue(int iValue) { m_iDefaultValue = iValue; update(); }
257
258 /** Returns item's hovered animation value. */
259 int hoveredValue() const { return m_iHoveredValue; }
260 /** Defines item's hovered animation @a iValue. */
261 void setHoveredValue(int iValue) { m_iHoveredValue = iValue; update(); }
262
263 /** Returns item's animated value. */
264 int animatedValue() const { return m_iAnimatedValue; }
265 /** Defines item's animated @a iValue. */
266 void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); }
267 /** @} */
268
269 /** @name Layout stuff.
270 * @{ */
271 /** Returns previous geometry. */
272 QRectF previousGeometry() const { return m_previousGeometry; }
273 /** Defines previous @a geometry. */
274 void setPreviousGeometry(const QRectF &geometry) { m_previousGeometry = geometry; }
275
276 /** Returns @a strText size calculated on the basis of certain @a font and @a pPaintDevice. */
277 static QSize textSize(const QFont &font, QPaintDevice *pPaintDevice, const QString &strText);
278 /** Returns a width of line containing @a iCount of chars calculated on the basis of certain @a font and @a pPaintDevice. */
279 static int textWidth(const QFont &font, QPaintDevice *pPaintDevice, int iCount);
280 /** Compresses @a strText to @a iWidth on the basis of certain @a font and @a pPaintDevice. */
281 static QString compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth);
282 /** @} */
283
284 /** @name Navigation stuff.
285 * @{ */
286 /** Returns D&D mime data. */
287 virtual QMimeData *createMimeData() = 0;
288
289 /** Returns drag token darkness. */
290 int dragTokenDarkness() const { return m_iDragTokenDarkness; }
291 /** @} */
292
293 /** @name Painting stuff.
294 * @{ */
295 /** Paints frame @a rectangle using passed @a pPainter.
296 * @param fIsSelected Brings whether this rectangle should be filled.
297 * @param iRadius Brings the radius of rounded corners. */
298 static void paintFrameRect(QPainter *pPainter, bool fIsSelected, int iRadius,
299 const QRect &rectangle);
300 /** Paints @a pixmap using passed @a pPainter putting its upper-left corner to specified @a point. */
301 static void paintPixmap(QPainter *pPainter, const QPoint &point,
302 const QPixmap &pixmap);
303 /** Paints @a strText using passed @a pPainter putting its upper-left corner to specified @a point.
304 * @param font Brings the text font.
305 * @param pPaintDevice Brings the paint-device reference to initilize painting from. */
306 static void paintText(QPainter *pPainter, QPoint point,
307 const QFont &font, QPaintDevice *pPaintDevice,
308 const QString &strText);
309 /** Paints flat button @a rectangle using passed @a pPainter moving light focus according to passed @a cursorPosition. */
310 static void paintFlatButton(QPainter *pPainter, const QRect &rectangle, const QPoint &cursorPosition);
311 /** @} */
312
313private:
314
315 /** @name Item stuff.
316 * @{ */
317 /** Holds the item's parent item. */
318 UIChooserItem *m_pParent;
319 /** Holds the node this item is built for. */
320 UIChooserNode *m_pNode;
321
322 /** Holds whether item is hovered. */
323 bool m_fHovered;
324 /** Holds whether item is selected. */
325 bool m_fSelected;
326 /** Holds the hovering animation machine instance. */
327 QStateMachine *m_pHoveringMachine;
328 /** Holds the forward hovering animation instance. */
329 QPropertyAnimation *m_pHoveringAnimationForward;
330 /** Holds the backward hovering animation instance. */
331 QPropertyAnimation *m_pHoveringAnimationBackward;
332 /** Holds the animation duration. */
333 int m_iAnimationDuration;
334 /** Holds the default animation value. */
335 int m_iDefaultValue;
336 /** Holds the hovered animation value. */
337 int m_iHoveredValue;
338 /** Holds the animated value. */
339 int m_iAnimatedValue;
340 /** Holds the blur effect instance. */
341 UIChooserDisabledItemEffect *m_pDisabledEffect;
342 /** @} */
343
344 /** @name Layout stuff.
345 * @{ */
346 /** Holds previous geometry. */
347 QRectF m_previousGeometry;
348 /** @} */
349
350 /** @name Navigation stuff.
351 * @{ */
352 /** Holds drag token place. */
353 UIChooserItemDragToken m_enmDragTokenPlace;
354
355 /** Holds drag token darkness. */
356 int m_iDragTokenDarkness;
357 /** @} */
358};
359
360
361/** QMimeData for graphics item interface. */
362class UIChooserItemMimeData : public QMimeData
363{
364 Q_OBJECT;
365
366public:
367
368 /** Constructs mime-data on the basis of passed @a pItem. */
369 UIChooserItemMimeData(UIChooserItem *pItem);
370
371 /** Returns cached item. */
372 UIChooserItem *item() const { return m_pItem; }
373
374 /** Constructs mime-data on the basis of passed @a pItem. */
375 virtual bool hasFormat(const QString &strMimeType) const RT_OVERRIDE;
376
377private:
378
379 /** Holds the cached item. */
380 UIChooserItem *m_pItem;
381};
382
383
384#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItem_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use