forked from KDE/breeze
-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
breezedecoration.h
298 lines (224 loc) · 9.1 KB
/
breezedecoration.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#ifndef BREEZE_DECORATION_H
#define BREEZE_DECORATION_H
/*
* SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
* SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "breeze.h"
#include "breezesettings.h"
#include "colortools.h"
#include <KDecoration2/Decoration>
#include <KDecoration2/DecoratedClient>
#include <KDecoration2/DecorationSettings>
#include <QPalette>
#include <QVariant>
#include <QVariantAnimation>
#include <QPainterPath>
#include <memory>
class QVariantAnimation;
namespace KDecoration2
{
class DecorationButton;
class DecorationButtonGroup;
}
namespace Breeze
{
class SizeGrip;
enum struct ButtonSize{
Small,
Large,
FullHeight
};
class Decoration : public KDecoration2::Decoration
{
Q_OBJECT
public:
//* constructor
explicit Decoration(QObject *parent = nullptr, const QVariantList &args = QVariantList());
//* destructor
virtual ~Decoration();
//* paint
void paint(QPainter *painter, const QRect &repaintRegion) override;
//* internal settings
InternalSettingsPtr internalSettings() const
{ return m_internalSettings; }
qreal animationsDuration() const
{ return m_animation->duration();}
//* caption height
int captionHeight() const;
//* icon height
int iconHeight() const;
//*@name active state change animation
//@{
void setOpacity( qreal );
qreal opacity() const
{ return m_opacity; }
//@}
//*@name colors
//@{
QColor titleBarColor(bool returnNonAnimatedColor=false) const;
QColor titleBarColorWithAddedTransparency() const;
QColor titleBarSeparatorColor() const;
QColor accentedWindowOutlineColor() const;
QColor fontMixedAccentWindowOutlineColor() const;
QColor fontColor() const;
//@}
//*@name maximization modes
//@{
inline bool isMaximized() const;
inline bool isMaximizedHorizontally() const;
inline bool isMaximizedVertically() const;
inline bool isLeftEdge() const;
inline bool isRightEdge() const;
inline bool isTopEdge() const;
inline bool isBottomEdge() const;
inline bool hideTitleBar() const;
//@}
std::shared_ptr<QPainterPath> titleBarPath(){ return m_titleBarPath; }
std::shared_ptr<QPainterPath> windowPath(){ return m_windowPath; }
qreal systemScaleFactor(){ return m_systemScaleFactor; }
ButtonSize buttonSize(){ return m_buttonSize; }
qreal scaledCornerRadius(){ return m_scaledCornerRadius; }
std::shared_ptr<SystemButtonColors> systemAccentColors(){ return m_systemAccentColors; }
public Q_SLOTS:
void init() override;
private Q_SLOTS:
void reconfigure();
void recalculateBorders();
void updateOpaque();
void updateBlur();
void updateButtonsGeometry();
void updateButtonsGeometryDelayed();
void updateTitleBar();
void updateAnimationState();
void updateSizeGripVisibility();
void forceUpdateShadow(){ updateShadow(true); }
private:
//* return the rect in which caption will be drawn
QPair<QRect,Qt::Alignment> captionRect() const;
void createButtons();
void calculateWindowAndTitleBarShapes(const bool windowShapeOnly=false);
void paintTitleBar(QPainter *painter, const QRect &repaintRegion);
void updateShadow( const bool force = false );
QSharedPointer<KDecoration2::DecorationShadow> createShadowObject( const float strengthScale );
void setScaledCornerRadius();
void setSystemAccentColors();
//*@name border size
//@{
int borderSize(bool bottom = false) const;
inline bool hasBorders() const;
inline bool hasNoBorders() const;
inline bool hasNoSideBorders() const;
//@}
//*@name size grip
//@{
void createSizeGrip();
void deleteSizeGrip();
SizeGrip* sizeGrip() const
{ return m_sizeGrip; }
//@}
void setScaledTitleBarTopBottomMargins();
void setScaledTitleBarSideMargins();
void setAddedTitleBarOpacity();
qreal titleBarSeparatorHeight() const;
InternalSettingsPtr m_internalSettings;
KDecoration2::DecorationButtonGroup *m_leftButtons = nullptr;
KDecoration2::DecorationButtonGroup *m_rightButtons = nullptr;
//* size grip widget
SizeGrip *m_sizeGrip = nullptr;
//* active state change animation
QVariantAnimation *m_animation;
QVariantAnimation *m_shadowAnimation;
//* active state change opacity
qreal m_opacity = 0;
qreal m_shadowOpacity = 0;
//* tilebar main state opacity
qreal m_addedTitleBarOpacityActive = 1;
qreal m_addedTitleBarOpacityInactive = 1;
//* frame corner radius, scaled according to smallspacing
qreal m_scaledCornerRadius = 3.0;
//* titleBar top margin, scaled according to smallspacing
int m_scaledTitleBarTopMargin = 1;
//* titleBar bottom margin, scaled according to smallspacing
int m_scaledTitleBarBottomMargin = 1;
//* titleBar side margins, scaled according to smallspacing
int m_scaledTitleBarSideMargins = 1;
//* Rectangular area of titlebar without clipped corners
QRect m_titleRect;
//* Exact titlebar path, with clipped rounded corners
std::shared_ptr<QPainterPath> m_titleBarPath = std::make_shared<QPainterPath>();
//* Exact window path, with clipped rounded corners
std::shared_ptr<QPainterPath> m_windowPath = std::make_shared<QPainterPath>();
qreal m_systemScaleFactor = 1.0;
std::shared_ptr<SystemButtonColors> m_systemAccentColors;
ButtonSize m_buttonSize = ButtonSize::Small;
bool m_colorSchemeHasHeaderColor = true;
bool m_toolsAreaWillBeDrawn = true;
};
bool Decoration::hasBorders() const
{
if( m_internalSettings && m_internalSettings->mask() & BorderSize ) return m_internalSettings->borderSize() > InternalSettings::BorderNoSides;
else return settings()->borderSize() > KDecoration2::BorderSize::NoSides;
}
bool Decoration::hasNoBorders() const
{
if( m_internalSettings && m_internalSettings->mask() & BorderSize ) return m_internalSettings->borderSize() == InternalSettings::BorderNone;
else return settings()->borderSize() == KDecoration2::BorderSize::None;
}
bool Decoration::hasNoSideBorders() const
{
if( m_internalSettings && m_internalSettings->mask() & BorderSize ) return m_internalSettings->borderSize() == InternalSettings::BorderNoSides;
else return settings()->borderSize() == KDecoration2::BorderSize::NoSides;
}
bool Decoration::isMaximized() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return c->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isMaximizedHorizontally() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return c->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isMaximizedVertically() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return c->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isLeftEdge() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return (c->isMaximizedHorizontally() || c->adjacentScreenEdges().testFlag( Qt::LeftEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isRightEdge() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return (c->isMaximizedHorizontally() || c->adjacentScreenEdges().testFlag( Qt::RightEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isTopEdge() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return (c->isMaximizedVertically() || c->adjacentScreenEdges().testFlag( Qt::TopEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::isBottomEdge() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return (c->isMaximizedVertically() || c->adjacentScreenEdges().testFlag( Qt::BottomEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows();
}
bool Decoration::hideTitleBar() const
{
auto c = client().toStrongRef();
Q_ASSERT(c);
return m_internalSettings->hideTitleBar() && !c->isShaded();
}
}
#endif