VirtualBox

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

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

Copyright year updates by scm.

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