VirtualBox

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

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

© 2023 Oracle
ContactPrivacy policyTerms of Use