1 | /* $Id: UIGraphicsButton.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGraphicsButton 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_widgets_graphics_UIGraphicsButton_h
|
---|
29 | #define FEQT_INCLUDED_SRC_widgets_graphics_UIGraphicsButton_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QIcon>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QIGraphicsWidget.h"
|
---|
39 |
|
---|
40 | /* Forward declarations: */
|
---|
41 | class QGraphicsSceneMouseEvent;
|
---|
42 | class QGraphicsSceneHoverEvent;
|
---|
43 | class QPropertyAnimation;
|
---|
44 |
|
---|
45 | /** QIGraphicsWidget subclass providing GUI with graphics-button representation. */
|
---|
46 | class UIGraphicsButton : public QIGraphicsWidget
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 |
|
---|
50 | signals:
|
---|
51 |
|
---|
52 | /** Notifies listeners about button was clicked. */
|
---|
53 | void sigButtonClicked();
|
---|
54 |
|
---|
55 | public:
|
---|
56 |
|
---|
57 | /** Click policy. */
|
---|
58 | enum ClickPolicy { ClickPolicy_OnRelease, ClickPolicy_OnPress };
|
---|
59 |
|
---|
60 | /** Constructs graphics button passing @a pParent to the base-class.
|
---|
61 | * @param icon Brings the button icon. */
|
---|
62 | UIGraphicsButton(QIGraphicsWidget *pParent, const QIcon &icon);
|
---|
63 |
|
---|
64 | /** Defines icon scale @a dIndex. */
|
---|
65 | void setIconScaleIndex(double dIndex);
|
---|
66 | /** Returns icon scale index. */
|
---|
67 | double iconScaleIndex() const;
|
---|
68 |
|
---|
69 | /** Defines click @a enmPolicy. */
|
---|
70 | void setClickPolicy(ClickPolicy enmPolicy);
|
---|
71 | /** Returns click policy. */
|
---|
72 | ClickPolicy clickPolicy() const;
|
---|
73 |
|
---|
74 | protected:
|
---|
75 |
|
---|
76 | /** Data enumerator. */
|
---|
77 | enum GraphicsButton
|
---|
78 | {
|
---|
79 | GraphicsButton_Margin,
|
---|
80 | GraphicsButton_IconSize,
|
---|
81 | GraphicsButton_Icon
|
---|
82 | };
|
---|
83 |
|
---|
84 | /** Returns data stored for certain @a iKey: */
|
---|
85 | virtual QVariant data(int iKey) const;
|
---|
86 |
|
---|
87 | /** Returns size-hint of certain @a enmType, restricted by passed @a constraint. */
|
---|
88 | virtual QSizeF sizeHint(Qt::SizeHint enmType, const QSizeF &constraint = QSizeF()) const RT_OVERRIDE;
|
---|
89 |
|
---|
90 | /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
|
---|
91 | virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0) RT_OVERRIDE;
|
---|
92 |
|
---|
93 | /** Handles mouse-press @a pEvent. */
|
---|
94 | virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
|
---|
95 | /** Handles mouse-release @a pEvent. */
|
---|
96 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
|
---|
97 |
|
---|
98 | /** Handles timer @a pEvent. */
|
---|
99 | virtual void timerEvent(QTimerEvent *pEvent) RT_OVERRIDE;
|
---|
100 |
|
---|
101 | /** Updates button.
|
---|
102 | * @todo rename to prepare() */
|
---|
103 | virtual void refresh();
|
---|
104 |
|
---|
105 | private:
|
---|
106 |
|
---|
107 | /** Holds the button icon. */
|
---|
108 | QIcon m_icon;
|
---|
109 |
|
---|
110 | /** Holds the click policy. */
|
---|
111 | ClickPolicy m_enmClickPolicy;
|
---|
112 |
|
---|
113 | /** Holds the delay timer ID. */
|
---|
114 | int m_iDelayId;
|
---|
115 | /** Holds the repeat timer ID. */
|
---|
116 | int m_iRepeatId;
|
---|
117 |
|
---|
118 | /** Holds the icon scale index. */
|
---|
119 | double m_dIconScaleIndex;
|
---|
120 | };
|
---|
121 |
|
---|
122 | #endif /* !FEQT_INCLUDED_SRC_widgets_graphics_UIGraphicsButton_h */
|
---|