VirtualBox

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

Last change on this file was 104251, checked in by vboxsync, 8 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the manager UI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
RevLine 
[55401]1/* $Id: UIChooserItem.h 104251 2024-04-09 12:36:47Z vboxsync $ */
[42529]2/** @file
[73424]3 * VBox Qt GUI - UIChooserItem class declaration.
[42529]4 */
5
6/*
[98103]7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
[42529]8 *
[96407]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
[42529]26 */
27
[76581]28#ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserItem_h
29#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserItem_h
[76532]30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
[42529]33
34/* Qt includes: */
[77701]35#include <QGraphicsEffect>
[42529]36#include <QMimeData>
[73927]37#include <QRectF>
[73600]38#include <QString>
[74878]39#include <QUuid>
[42529]40
41/* GUI includes: */
42#include "QIGraphicsWidget.h"
[77567]43#include "UIChooserDefs.h"
[42529]44
45/* Forward declaration: */
[73927]46class QGraphicsSceneHoverEvent;
47class QGraphicsSceneMouseEvent;
48class QGraphicsSceneDragDropEvent;
49class QPropertyAnimation;
50class QStateMachine;
[52202]51class UIActionPool;
[73424]52class UIChooserItemGroup;
[73600]53class UIChooserItemGlobal;
[73424]54class UIChooserItemMachine;
[73927]55class UIChooserModel;
[77636]56class UIChooserNode;
[42529]57
[84583]58
59/** A simple QGraphicsEffect extension to mark disabled UIChooserItem.
60 * @note Applies blur and gray scale filters. */
[77701]61class UIChooserDisabledItemEffect : public QGraphicsEffect
62{
63 Q_OBJECT;
[73927]64
[77701]65public:
66
[84583]67 /** Constructs blur effect passing @a pParent to the base-class.
68 * @param iBlurRadius Brings the blur effect radius. */
[77701]69 UIChooserDisabledItemEffect(int iBlurRadius, QObject *pParent = 0);
70
71protected:
72
[84583]73 /** Draws effect with passed @a pPainter. */
[103988]74 virtual void draw(QPainter *pPainter) RT_OVERRIDE RT_FINAL;;
[84583]75
76private:
77
78 /** Holds the blur effect radius. */
[77701]79 int m_iBlurRadius;
80};
81
82
[73927]83/** QIGraphicsWidget extension used as interface
84 * for graphics chooser model/view architecture. */
[104251]85class UIChooserItem : public QIGraphicsWidget
[42529]86{
87 Q_OBJECT;
[74078]88 Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
[42529]89
90signals:
91
[73948]92 /** @name Item stuff.
[73927]93 * @{ */
94 /** Notifies listeners about hover enter. */
95 void sigHoverEnter();
96 /** Notifies listeners about hover leave. */
97 void sigHoverLeave();
98 /** @} */
[43957]99
[42529]100public:
101
[73927]102 /** Constructs item passing @a pParent to the base-class.
[77636]103 * @param pNode Brings the node this item is built for.
[74960]104 * @param iDefaultValue Brings default value for hovering animation.
105 * @param iHoveredValue Brings hovered value for hovering animation. */
[77636]106 UIChooserItem(UIChooserItem *pParent, UIChooserNode *pNode,
[89172]107 int iDefaultValue = 0, int iHoveredValue = 100);
[42529]108
[73927]109 /** @name Item stuff.
110 * @{ */
[77596]111 /** Returns parent reference. */
[73927]112 UIChooserItem *parentItem() const { return m_pParent; }
[77636]113 /** Returns node reference. */
114 UIChooserNode *node() const { return m_pNode; }
[42529]115
[73927]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();
[42529]122
[73927]123 /** Returns model reference. */
124 UIChooserModel *model() const;
[52202]125
[77596]126 /** Returns whether item is root. */
[77636]127 bool isRoot() const;
[77596]128
129 /** Returns item name. */
[77636]130 QString name() const;
[77596]131 /** Returns item full-name. */
[77636]132 QString fullName() const;
[77596]133 /** Returns item description. */
[77636]134 QString description() const;
[77596]135 /** Returns item definition. */
[77636]136 QString definition() const;
[77596]137
138 /** Returns whether item is favorite. */
[77636]139 bool isFavorite() const;
[77596]140 /** Defines whether item is @a fFavorite. */
141 virtual void setFavorite(bool fFavorite);
142
[77638]143 /** Returns item position. */
144 int position() const;
145
[77596]146 /** Returns whether item is hovered. */
147 bool isHovered() const;
148
[86768]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
[73927]156 /** Starts item editing. */
157 virtual void startEditing() = 0;
[42529]158
[77636]159 /** Updates item. */
160 virtual void updateItem() = 0;
[73927]161 /** Updates item tool-tip. */
162 virtual void updateToolTip() = 0;
[42529]163
[77224]164 /** Installs event-filter for @a pSource object.
165 * @note Base-class implementation does nothing. */
166 virtual void installEventFilterHelper(QObject *pSource) { Q_UNUSED(pSource); }
[84583]167 /** Defines whether visual effect for disabled item is @a fOn. */
168 void setDisabledEffect(bool fOn);
[73927]169 /** @} */
[42529]170
[73927]171 /** @name Children stuff.
172 * @{ */
[77596]173 /** Returns children items of certain @a enmType. */
[83672]174 virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const = 0;
[42734]175
[77596]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
[84625]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;
[73927]183
184 /** Searches for a first machine child item. */
185 virtual UIChooserItem *firstMachineItem() = 0;
186 /** @} */
187
188 /** @name Layout stuff.
189 * @{ */
190 /** Updates geometry. */
[93990]191 virtual void updateGeometry() RT_OVERRIDE;
[73927]192
[73948]193 /** Updates layout. */
[73927]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. */
[77567]213 virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken enmPlace = UIChooserItemDragToken_Off) const = 0;
[73927]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). */
[77567]218 virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho = 0, UIChooserItemDragToken enmPlace = UIChooserItemDragToken_Off) = 0;
[73927]219 /** Reset drag token. */
220 virtual void resetDragToken() = 0;
221
[77596]222 /** Returns drag token place. */
223 UIChooserItemDragToken dragTokenPlace() const;
[73927]224 /** Defines drag token @a enmPlace. */
[77567]225 void setDragTokenPlace(UIChooserItemDragToken enmPlace);
[73927]226 /** @} */
227
[42529]228protected:
229
[73948]230 /** @name Event-handling stuff.
[73927]231 * @{ */
232 /** Handles hover enter @a event. */
[93990]233 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
[73927]234 /** Handles hover leave @a event. */
[93990]235 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
[42529]236
[73927]237 /** Handles mouse press @a event. */
[93990]238 virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
[73927]239 /** Handles mouse move @a event. */
[93990]240 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
[43809]241
[73927]242 /** Handles drag move @a event. */
[93990]243 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
[73927]244 /** Handles drag leave @a event. */
[93990]245 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
[73927]246 /** Handles drop @a event. */
[93990]247 virtual void dropEvent(QGraphicsSceneDragDropEvent *pEvent) RT_OVERRIDE;
[73927]248 /** @} */
[42529]249
[73927]250 /** @name Item stuff.
251 * @{ */
[77596]252 /** Returns item's default animation value. */
253 int defaultValue() const { return m_iDefaultValue; }
[74078]254 /** Defines item's default animation @a iValue. */
255 void setDefaultValue(int iValue) { m_iDefaultValue = iValue; update(); }
[42529]256
[77596]257 /** Returns item's hovered animation value. */
258 int hoveredValue() const { return m_iHoveredValue; }
[74078]259 /** Defines item's hovered animation @a iValue. */
260 void setHoveredValue(int iValue) { m_iHoveredValue = iValue; update(); }
[42872]261
[77596]262 /** Returns item's animated value. */
263 int animatedValue() const { return m_iAnimatedValue; }
[74078]264 /** Defines item's animated @a iValue. */
265 void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); }
[73927]266 /** @} */
[42558]267
[73927]268 /** @name Layout stuff.
269 * @{ */
[77596]270 /** Returns previous geometry. */
[77620]271 QRectF previousGeometry() const { return m_previousGeometry; }
[73927]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);
[74482]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);
[73927]310 /** @} */
311
[42529]312private:
313
[73927]314 /** @name Item stuff.
315 * @{ */
316 /** Holds the item's parent item. */
317 UIChooserItem *m_pParent;
[77636]318 /** Holds the node this item is built for. */
319 UIChooserNode *m_pNode;
[42529]320
[73927]321 /** Holds whether item is hovered. */
[84583]322 bool m_fHovered;
[86768]323 /** Holds whether item is selected. */
324 bool m_fSelected;
[74078]325 /** Holds the hovering animation machine instance. */
[84583]326 QStateMachine *m_pHoveringMachine;
[74078]327 /** Holds the forward hovering animation instance. */
[84583]328 QPropertyAnimation *m_pHoveringAnimationForward;
[74078]329 /** Holds the backward hovering animation instance. */
[84583]330 QPropertyAnimation *m_pHoveringAnimationBackward;
[74078]331 /** Holds the animation duration. */
[84583]332 int m_iAnimationDuration;
[74078]333 /** Holds the default animation value. */
[84583]334 int m_iDefaultValue;
[74078]335 /** Holds the hovered animation value. */
[84583]336 int m_iHoveredValue;
[74078]337 /** Holds the animated value. */
[84583]338 int m_iAnimatedValue;
339 /** Holds the blur effect instance. */
[77701]340 UIChooserDisabledItemEffect *m_pDisabledEffect;
[73927]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. */
[77567]352 UIChooserItemDragToken m_enmDragTokenPlace;
[73927]353
354 /** Holds drag token darkness. */
355 int m_iDragTokenDarkness;
356 /** @} */
[42529]357};
358
[73927]359
360/** QMimeData for graphics item interface. */
[73424]361class UIChooserItemMimeData : public QMimeData
[42529]362{
363 Q_OBJECT;
364
365public:
366
[73927]367 /** Constructs mime-data on the basis of passed @a pItem. */
[73424]368 UIChooserItemMimeData(UIChooserItem *pItem);
[42529]369
[73927]370 /** Returns cached item. */
371 UIChooserItem *item() const { return m_pItem; }
[42529]372
[73927]373 /** Constructs mime-data on the basis of passed @a pItem. */
[93990]374 virtual bool hasFormat(const QString &strMimeType) const RT_OVERRIDE;
[42529]375
376private:
377
[73927]378 /** Holds the cached item. */
[73424]379 UIChooserItem *m_pItem;
[42529]380};
381
382
[76581]383#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItem_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use