-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdecorationbutton.h
179 lines (157 loc) · 5.89 KB
/
decorationbutton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include "decorationdefines.h"
#include <kdecoration3/kdecoration3_export.h>
#include <QObject>
#include <QRect>
class QHoverEvent;
class QMouseEvent;
class QPainter;
class QWheelEvent;
namespace KDecoration3
{
class DecorationButtonPrivate;
class Decoration;
/**
* @brief A button to be used in a Decoration.
*
* The DecorationButton is a simple Button which can be used (but doesn't have to) in a Decoration.
* It takes care of the input handling and triggers the correct state change methods on the
* Decoration.
*
* This simplifies the handling of DecorationButtons. A Decoration implementation just needs to
* subclass DecorationButton and implement the paint method. Everything else is handled by the
* DecorationButton.
*
* For positioning the DecorationButtons it's recommended to use a DecorationButtonGroup.
*
* @see Decoration
* @see DecorationButtonGroup
**/
class KDECORATIONS3_EXPORT DecorationButton : public QObject
{
Q_OBJECT
/**
* Whether the DecorationButton is visible. By default this is @c true, OnAllDesktops and
* QuickHelp depend on the DecoratedWindow's state.
**/
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged)
/**
* Whether the DecorationButton is currently pressed.
**/
Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged)
/**
* Whether the DecorationButton is currently hovered.
**/
Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged)
/**
* Whether the DecorationButton is enabled. Only an enabled button accepts hover and mouse
* press events.
**/
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
/**
* Whether the DecorationButton can be checked. This is used for state aware DecorationButtons
* like Maximize, Shade, KeepAbove, KeepBelow and OnAllDesktops.
**/
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged)
/**
* Whether the DecorationButton is checked. A DecorationButton can only be checked if the
* DecorationButton is checkable. Note: the checked state is not changed by clicking the
* DecorationButton. It gets changed if the DecoratedWindow changes it's state, though.
**/
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged)
/**
* The geometry of the DecorationButton in Decoration-local coordinates.
**/
Q_PROPERTY(QRectF geometry READ geometry NOTIFY geometryChanged)
/**
* The mouse buttons the DecorationButton accepts. By default the Qt::LeftButton gets accepted,
* for some types more buttons are accepted.
**/
Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
public:
~DecorationButton() override;
QRectF geometry() const;
QSizeF size() const;
void setGeometry(const QRectF &geometry);
bool isVisible() const;
bool isPressed() const;
bool isHovered() const;
bool isEnabled() const;
bool isChecked() const;
bool isCheckable() const;
DecorationButtonType type() const;
/**
* Returns @c true if @p pos is inside of the button, otherwise returns @c false.
**/
bool contains(const QPointF &pos) const;
Qt::MouseButtons acceptedButtons() const;
void setAcceptedButtons(Qt::MouseButtons buttons);
/**
* Invoked for painting this DecorationButtons. Implementing sub-classes need to implement
* this method. The coordinate system of the QPainter is set to Decoration coordinates.
*
* This method will be invoked from the rendering thread.
*
* @param painter The QPainter to paint this DecorationButton.
* @param repaintArea The area which is going to be repainted in Decoration coordinates
**/
virtual void paint(QPainter *painter, const QRectF &repaintArea) = 0;
Decoration *decoration() const;
bool event(QEvent *event) override;
public Q_SLOTS:
void setEnabled(bool enabled);
void setCheckable(bool checkable);
void setChecked(bool checked);
void setVisible(bool visible);
/**
* Schedules a repaint of the DecorationButton.
* Calling update will eventually result in paint being invoked.
*
* @param rect The area to repaint in Decoration local coordinates, a null QRect updates the complete geometry
* @see paint
**/
void update(const QRectF &rect);
/**
* Schedules a repaint of the DecorationButton.
*
* Overloaded method for convenience.
**/
void update();
Q_SIGNALS:
void clicked(Qt::MouseButton);
void pressed();
void released();
void pointerEntered();
void pointerLeft();
void doubleClicked();
void pressedChanged(bool);
void hoveredChanged(bool);
void enabledChanged(bool);
void checkableChanged(bool);
void checkedChanged(bool);
void geometryChanged(const QRectF &);
void acceptedButtonsChanged(Qt::MouseButtons);
void visibilityChanged(bool);
protected:
explicit DecorationButton(DecorationButtonType type, Decoration *decoration, QObject *parent = nullptr);
virtual void hoverEnterEvent(QHoverEvent *event);
virtual void hoverLeaveEvent(QHoverEvent *event);
virtual void hoverMoveEvent(QHoverEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
private:
class Private;
std::unique_ptr<Private> d;
};
} // namespace
#ifndef K_DOXYGEN
size_t KDECORATIONS3_EXPORT qHash(const KDecoration3::DecorationButtonType &type, size_t seed = 0);
#endif
Q_DECLARE_METATYPE(KDecoration3::DecorationButtonType)