-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradient_edit.h
55 lines (40 loc) · 1.31 KB
/
gradient_edit.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
/*
* SPDX-FileCopyrightText: 2020 Nick Korotysh <[email protected]>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#pragma once
#include <QWidget>
class GradientEdit : public QWidget
{
Q_OBJECT
public:
explicit GradientEdit(QWidget* parent = nullptr)
: GradientEdit(QLinearGradient(), parent) {}
explicit GradientEdit(const QGradient& gradient, QWidget* parent = nullptr);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
bool hasHeightForWidth() const override { return true; }
int heightForWidth(int w) const override { return w; }
inline const QGradient& gradient() const noexcept { return m_gradient; }
public slots:
void setGradient(const QGradient& gradient);
void setGradientType(QGradient::Type type);
void setGradientSpread(QGradient::Spread spread);
void setGradientStops(const QGradientStops& stops);
signals:
void gradientChanged(const QGradient& gradient);
protected:
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void paintEvent(QPaintEvent* event) override;
private:
void updatePoints();
void updateGradient();
private:
QBrush m_background;
QGradient m_gradient;
QVector<QPointF> m_points;
int m_selected_point = -1;
};