1 | /* $Id: UIToolsItem.h 103704 2024-03-06 15:15:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIToolsItem 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_tools_UIToolsItem_h
|
---|
29 | #define FEQT_INCLUDED_SRC_manager_tools_UIToolsItem_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QIcon>
|
---|
36 | #include <QMimeData>
|
---|
37 | #include <QPixmap>
|
---|
38 | #include <QRectF>
|
---|
39 | #include <QString>
|
---|
40 |
|
---|
41 | /* GUI includes: */
|
---|
42 | #include "QIGraphicsWidget.h"
|
---|
43 | #include "UITools.h"
|
---|
44 |
|
---|
45 | /* Forward declaration: */
|
---|
46 | class QPropertyAnimation;
|
---|
47 | class QGraphicsScene;
|
---|
48 | class QGraphicsSceneDragDropEvent;
|
---|
49 | class QGraphicsSceneHoverEvent;
|
---|
50 | class QGraphicsSceneMouseEvent;
|
---|
51 | class QStateMachine;
|
---|
52 | class UIActionPool;
|
---|
53 | class UIToolsItemGroup;
|
---|
54 | class UIToolsItemGlobal;
|
---|
55 | class UIToolsItemMachine;
|
---|
56 | class UIToolsModel;
|
---|
57 |
|
---|
58 | /** QIGraphicsWidget extension used as interface
|
---|
59 | * for graphics Tools-model/view architecture. */
|
---|
60 | class UIToolsItem : public QIGraphicsWidget
|
---|
61 | {
|
---|
62 | Q_OBJECT;
|
---|
63 | Q_PROPERTY(int animatedValue READ animatedValue WRITE setAnimatedValue);
|
---|
64 |
|
---|
65 | signals:
|
---|
66 |
|
---|
67 | /** @name Item stuff.
|
---|
68 | * @{ */
|
---|
69 | /** Notifies listeners about hover enter. */
|
---|
70 | void sigHoverEnter();
|
---|
71 | /** Notifies listeners about hover leave. */
|
---|
72 | void sigHoverLeave();
|
---|
73 | /** @} */
|
---|
74 |
|
---|
75 | /** @name Layout stuff.
|
---|
76 | * @{ */
|
---|
77 | /** Notifies listeners about minimum width @a iHint change. */
|
---|
78 | void sigMinimumWidthHintChanged(int iHint);
|
---|
79 | /** Notifies listeners about minimum height @a iHint change. */
|
---|
80 | void sigMinimumHeightHintChanged(int iHint);
|
---|
81 | /** @} */
|
---|
82 |
|
---|
83 | public:
|
---|
84 |
|
---|
85 | /** Constructs item on the basis of passed arguments.
|
---|
86 | * @param pScene Brings the scene reference to add item to.
|
---|
87 | * @param enmClass Brings the item class.
|
---|
88 | * @param enmType Brings the item type.
|
---|
89 | * @param strName Brings the item name.
|
---|
90 | * @param icon Brings the item icon. */
|
---|
91 | UIToolsItem(QGraphicsScene *pScene,
|
---|
92 | UIToolClass enmClass, UIToolType enmType,
|
---|
93 | const QString &strName, const QIcon &icon);
|
---|
94 | /** Destructs item. */
|
---|
95 | virtual ~UIToolsItem() RT_OVERRIDE;
|
---|
96 |
|
---|
97 | /** @name Item stuff.
|
---|
98 | * @{ */
|
---|
99 | /** Returns model reference. */
|
---|
100 | UIToolsModel *model() const;
|
---|
101 |
|
---|
102 | /** Reconfigures item with new @a enmClass, @a enmType, @a icon and @a strName. */
|
---|
103 | void reconfigure(UIToolClass enmClass, UIToolType enmType,
|
---|
104 | const QIcon &icon, const QString &strName);
|
---|
105 | /** Reconfigures item with @a strName. */
|
---|
106 | void reconfigure(const QString &strName);
|
---|
107 |
|
---|
108 | /** Returns item class. */
|
---|
109 | UIToolClass itemClass() const;
|
---|
110 | /** Returns item type. */
|
---|
111 | UIToolType itemType() const;
|
---|
112 | /** Returns item icon. */
|
---|
113 | const QIcon &icon() const;
|
---|
114 | /** Returns item name. */
|
---|
115 | const QString &name() const;
|
---|
116 |
|
---|
117 | /** Defines whether item is @a fEnabled. */
|
---|
118 | void setEnabled(bool fEnabled);
|
---|
119 |
|
---|
120 | /** Defines whether item is @a fHovered. */
|
---|
121 | void setHovered(bool fHovered);
|
---|
122 | /** Returns whether item is hovered. */
|
---|
123 | bool isHovered() const;
|
---|
124 | /** @} */
|
---|
125 |
|
---|
126 | /** @name Layout stuff.
|
---|
127 | * @{ */
|
---|
128 | /** Updates geometry. */
|
---|
129 | virtual void updateGeometry() RT_OVERRIDE;
|
---|
130 |
|
---|
131 | /** Returns minimum width-hint. */
|
---|
132 | int minimumWidthHint() const;
|
---|
133 | /** Returns minimum height-hint. */
|
---|
134 | int minimumHeightHint() const;
|
---|
135 |
|
---|
136 | /** Returns size-hint.
|
---|
137 | * @param enmWhich Brings size-hint type.
|
---|
138 | * @param constraint Brings size constraint. */
|
---|
139 | virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const RT_OVERRIDE;
|
---|
140 | /** @} */
|
---|
141 |
|
---|
142 | protected:
|
---|
143 |
|
---|
144 | /** @name Event-handling stuff.
|
---|
145 | * @{ */
|
---|
146 | /** Handles show @a pEvent. */
|
---|
147 | virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
148 |
|
---|
149 | /** Handles resize @a pEvent. */
|
---|
150 | virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) RT_OVERRIDE;
|
---|
151 |
|
---|
152 | /** Handles hover enter @a event. */
|
---|
153 | virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
|
---|
154 | /** Handles hover leave @a event. */
|
---|
155 | virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
|
---|
156 |
|
---|
157 | /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
|
---|
158 | virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) RT_OVERRIDE;
|
---|
159 | /** @} */
|
---|
160 |
|
---|
161 | private slots:
|
---|
162 |
|
---|
163 | /** @name Item stuff.
|
---|
164 | * @{ */
|
---|
165 | /** Handles top-level window remaps. */
|
---|
166 | void sltHandleWindowRemapped();
|
---|
167 | /** @} */
|
---|
168 |
|
---|
169 | private:
|
---|
170 |
|
---|
171 | /** Data field types. */
|
---|
172 | enum ToolsItemData
|
---|
173 | {
|
---|
174 | /* Layout hints: */
|
---|
175 | ToolsItemData_Margin,
|
---|
176 | ToolsItemData_Spacing,
|
---|
177 | };
|
---|
178 |
|
---|
179 | /** @name Prepare/cleanup cascade.
|
---|
180 | * @{ */
|
---|
181 | /** Prepares all. */
|
---|
182 | void prepare();
|
---|
183 | /** Prepares hover animation. */
|
---|
184 | void prepareHoverAnimation();
|
---|
185 | /** Prepares connections. */
|
---|
186 | void prepareConnections();
|
---|
187 |
|
---|
188 | /** Cleanups all. */
|
---|
189 | void cleanup();
|
---|
190 | /** @} */
|
---|
191 |
|
---|
192 | /** @name Item stuff.
|
---|
193 | * @{ */
|
---|
194 | /** Returns abstractly stored data value for certain @a iKey. */
|
---|
195 | QVariant data(int iKey) const;
|
---|
196 |
|
---|
197 | /** Defines item's default animation @a iValue. */
|
---|
198 | void setDefaultValue(int iValue) { m_iDefaultValue = iValue; update(); }
|
---|
199 | /** Returns item's default animation value. */
|
---|
200 | int defaultValue() const { return m_iDefaultValue; }
|
---|
201 |
|
---|
202 | /** Defines item's hovered animation @a iValue. */
|
---|
203 | void setHoveredValue(int iValue) { m_iHoveredValue = iValue; update(); }
|
---|
204 | /** Returns item's hovered animation value. */
|
---|
205 | int hoveredValue() const { return m_iHoveredValue; }
|
---|
206 |
|
---|
207 | /** Defines item's animated @a iValue. */
|
---|
208 | void setAnimatedValue(int iValue) { m_iAnimatedValue = iValue; update(); }
|
---|
209 | /** Returns item's animated value. */
|
---|
210 | int animatedValue() const { return m_iAnimatedValue; }
|
---|
211 | /** @} */
|
---|
212 |
|
---|
213 | /** @name Layout stuff.
|
---|
214 | * @{ */
|
---|
215 | /** Defines previous @a geometry. */
|
---|
216 | void setPreviousGeometry(const QRectF &geometry) { m_previousGeometry = geometry; }
|
---|
217 | /** Returns previous geometry. */
|
---|
218 | const QRectF &previousGeometry() const { return m_previousGeometry; }
|
---|
219 |
|
---|
220 | /** Updates pixmap. */
|
---|
221 | void updatePixmap();
|
---|
222 | /** Updates minimum name size. */
|
---|
223 | void updateMinimumNameSize();
|
---|
224 | /** Updates maximum name width. */
|
---|
225 | void updateMaximumNameWidth();
|
---|
226 | /** Updates visible name. */
|
---|
227 | void updateVisibleName();
|
---|
228 |
|
---|
229 | /** Returns monospace text width of line containing @a iCount of chars calculated on the basis of certain @a font and @a pPaintDevice. */
|
---|
230 | static int textWidthMonospace(const QFont &font, QPaintDevice *pPaintDevice, int iCount);
|
---|
231 | /** Compresses @a strText to @a iWidth on the basis of certain @a font and @a pPaintDevice. */
|
---|
232 | static QString compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth);
|
---|
233 | /** @} */
|
---|
234 |
|
---|
235 | /** @name Painting stuff.
|
---|
236 | * @{ */
|
---|
237 | /** Paints background using specified @a pPainter.
|
---|
238 | * @param rectangle Brings the rectangle to fill with background. */
|
---|
239 | void paintBackground(QPainter *pPainter, const QRect &rectangle) const;
|
---|
240 | /** Paints frame using using passed @a pPainter.
|
---|
241 | * @param rectangle Brings the rectangle to stroke with frame. */
|
---|
242 | void paintFrame(QPainter *pPainter, const QRect &rectangle) const;
|
---|
243 | /** Paints tool info using using passed @a pPainter.
|
---|
244 | * @param rectangle Brings the rectangle to limit painting with. */
|
---|
245 | void paintToolInfo(QPainter *pPainter, const QRect &rectangle) const;
|
---|
246 |
|
---|
247 | /** Paints @a pixmap using passed @a pPainter.
|
---|
248 | * @param pOptions Brings the options set with painting data. */
|
---|
249 | static void paintPixmap(QPainter *pPainter, const QPoint &point, const QPixmap &pixmap);
|
---|
250 |
|
---|
251 | /** Paints @a strText using passed @a pPainter.
|
---|
252 | * @param point Brings upper-left corner pixmap should be mapped to.
|
---|
253 | * @param font Brings the text font.
|
---|
254 | * @param pPaintDevice Brings the paint-device reference to initilize painting from. */
|
---|
255 | static void paintText(QPainter *pPainter, QPoint point,
|
---|
256 | const QFont &font, QPaintDevice *pPaintDevice,
|
---|
257 | const QString &strText);
|
---|
258 | /** @} */
|
---|
259 |
|
---|
260 | /** @name Item stuff.
|
---|
261 | * @{ */
|
---|
262 | /** Holds the item parent. */
|
---|
263 | QGraphicsScene *m_pScene;
|
---|
264 | /** Holds the item class. */
|
---|
265 | UIToolClass m_enmClass;
|
---|
266 | /** Holds the item type. */
|
---|
267 | UIToolType m_enmType;
|
---|
268 | /** Holds the item icon. */
|
---|
269 | QIcon m_icon;
|
---|
270 | /** Holds the item name. */
|
---|
271 | QString m_strName;
|
---|
272 |
|
---|
273 | /** Holds the item pixmap. */
|
---|
274 | QPixmap m_pixmap;
|
---|
275 | /** Holds the item visible name. */
|
---|
276 | QString m_strVisibleName;
|
---|
277 |
|
---|
278 | /** Holds name font. */
|
---|
279 | QFont m_nameFont;
|
---|
280 |
|
---|
281 | /** Holds whether item is hovered. */
|
---|
282 | bool m_fHovered;
|
---|
283 | /** Holds the hovering animation machine instance. */
|
---|
284 | QStateMachine *m_pHoveringMachine;
|
---|
285 | /** Holds the forward hovering animation instance. */
|
---|
286 | QPropertyAnimation *m_pHoveringAnimationForward;
|
---|
287 | /** Holds the backward hovering animation instance. */
|
---|
288 | QPropertyAnimation *m_pHoveringAnimationBackward;
|
---|
289 | /** Holds the animation duration. */
|
---|
290 | int m_iAnimationDuration;
|
---|
291 | /** Holds the default animation value. */
|
---|
292 | int m_iDefaultValue;
|
---|
293 | /** Holds the hovered animation value. */
|
---|
294 | int m_iHoveredValue;
|
---|
295 | /** Holds the animated value. */
|
---|
296 | int m_iAnimatedValue;
|
---|
297 |
|
---|
298 | /** Holds start default lightness tone. */
|
---|
299 | int m_iDefaultLightnessStart;
|
---|
300 | /** Holds final default lightness tone. */
|
---|
301 | int m_iDefaultLightnessFinal;
|
---|
302 | /** Holds start hover lightness tone. */
|
---|
303 | int m_iHoverLightnessStart;
|
---|
304 | /** Holds final hover lightness tone. */
|
---|
305 | int m_iHoverLightnessFinal;
|
---|
306 | /** Holds start highlight lightness tone. */
|
---|
307 | int m_iHighlightLightnessStart;
|
---|
308 | /** Holds final highlight lightness tone. */
|
---|
309 | int m_iHighlightLightnessFinal;
|
---|
310 | /** @} */
|
---|
311 |
|
---|
312 | /** @name Layout stuff.
|
---|
313 | * @{ */
|
---|
314 | /** Holds previous geometry. */
|
---|
315 | QRectF m_previousGeometry;
|
---|
316 |
|
---|
317 | /** Holds previous minimum width hint. */
|
---|
318 | int m_iPreviousMinimumWidthHint;
|
---|
319 | /** Holds previous minimum height hint. */
|
---|
320 | int m_iPreviousMinimumHeightHint;
|
---|
321 |
|
---|
322 | /** Holds the pixmap size. */
|
---|
323 | QSize m_pixmapSize;
|
---|
324 | /** Holds minimum name size. */
|
---|
325 | QSize m_minimumNameSize;
|
---|
326 |
|
---|
327 | /** Holds maximum name width. */
|
---|
328 | int m_iMaximumNameWidth;
|
---|
329 | /** @} */
|
---|
330 | };
|
---|
331 |
|
---|
332 | #endif /* !FEQT_INCLUDED_SRC_manager_tools_UIToolsItem_h */
|
---|