-
Notifications
You must be signed in to change notification settings - Fork 1
/
neumorphic.h
71 lines (62 loc) · 1.8 KB
/
neumorphic.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
#ifndef NEUMORPHIC_H
#define NEUMORPHIC_H
#include <QGraphicsEffect>
#include <QPainter>
#include <QPainterPath>
#include <QDebug>
class Neumorphic : public QGraphicsEffect
{
Q_OBJECT
public:
enum NeumorphicMode
{
NeumorphicMode_Normal = 1,
NeumorphicMode_Inset = 2,
NeumorphicMode_Ridge = 3
};
Neumorphic(QObject *parent = nullptr);
Neumorphic(NeumorphicMode mode, QObject *parent = nullptr);
inline qreal blurRadius() const { return m_blurRadius; }
inline void setBlurRadius(qreal blurRadius)
{
m_blurRadius = blurRadius;
updateBoundingRect();
}
inline qreal opacity() const { return m_opacity; }
inline void setOpacity(qreal opacity)
{
m_opacity = opacity;
updateBoundingRect();
}
inline QPoint offset() const { return m_offset; }
inline void setOffset(int x, int y)
{
m_offset = QPoint(x, y);
updateBoundingRect();
}
inline QColor shadowColor() const { return m_shadowColor.toRgb(); }
inline void setShadowColor(QColor color)
{
m_shadowColor = color.toRgb();
m_shadowColor.setAlpha(m_opacity);
updateBoundingRect();
};
inline QColor highlightColor() const { return m_highlightColor.toRgb(); }
inline void setHighlightColor(QColor color)
{
m_highlightColor = color.toRgb();
m_highlightColor.setAlpha(m_opacity);
updateBoundingRect();
};
protected:
QRectF boundingRectFor(const QRectF &rect) const override;
void draw(QPainter *painter) override;
private:
NeumorphicMode mode;
qreal m_blurRadius;
qreal m_opacity;
QPoint m_offset;
QColor m_shadowColor;
QColor m_highlightColor;
};
#endif // NEUMORPHIC_H