-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathKnob.h
161 lines (116 loc) · 4.18 KB
/
Knob.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
/*
* Knob.h - powerful knob-widget
*
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef LMMS_GUI_KNOB_H
#define LMMS_GUI_KNOB_H
#include <memory>
#include <QTextDocument>
#include "FloatModelEditorBase.h"
class QPixmap;
namespace lmms::gui
{
class SimpleTextFloat;
enum class KnobType
{
Dark28, Bright26, Small17, Vintage32, Styled
} ;
void convertPixmapToGrayScale(QPixmap &pixMap);
class LMMS_EXPORT Knob : public FloatModelEditorBase
{
Q_OBJECT
Q_ENUMS( KnobType )
Q_PROPERTY(float innerRadius READ innerRadius WRITE setInnerRadius)
Q_PROPERTY(float outerRadius READ outerRadius WRITE setOuterRadius)
Q_PROPERTY(float centerPointX READ centerPointX WRITE setCenterPointX)
Q_PROPERTY(float centerPointY READ centerPointY WRITE setCenterPointY)
Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth)
// Unfortunately, the gradient syntax doesn't create our gradient
// correctly so we need to do this:
Q_PROPERTY(QColor outerColor READ outerColor WRITE setOuterColor)
Q_PROPERTY(QColor lineActiveColor MEMBER m_lineActiveColor)
Q_PROPERTY(QColor lineInactiveColor MEMBER m_lineInactiveColor)
Q_PROPERTY(QColor arcActiveColor MEMBER m_arcActiveColor)
Q_PROPERTY(QColor arcInactiveColor MEMBER m_arcInactiveColor)
Q_PROPERTY(KnobType knobNum READ knobNum WRITE setknobNum)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
void initUi( const QString & _name ); //!< to be called by ctors
void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum
public:
Knob( KnobType _knob_num, QWidget * _parent = nullptr, const QString & _name = QString() );
Knob( QWidget * _parent = nullptr, const QString & _name = QString() ); //!< default ctor
Knob( const Knob& other ) = delete;
void setLabel( const QString & txt );
void setHtmlLabel( const QString &htmltxt );
void setTotalAngle( float angle );
// Begin styled knob accessors
float innerRadius() const;
void setInnerRadius( float r );
float outerRadius() const;
void setOuterRadius( float r );
KnobType knobNum() const;
void setknobNum( KnobType k );
QPointF centerPoint() const;
float centerPointX() const;
void setCenterPointX( float c );
float centerPointY() const;
void setCenterPointY( float c );
float lineWidth() const;
void setLineWidth( float w );
QColor outerColor() const;
void setOuterColor( const QColor & c );
QColor textColor() const;
void setTextColor( const QColor & c );
protected:
void paintEvent( QPaintEvent * _me ) override;
void changeEvent(QEvent * ev) override;
private:
QLineF calculateLine( const QPointF & _mid, float _radius,
float _innerRadius = 1) const;
void drawKnob( QPainter * _p );
bool updateAngle();
int angleFromValue( float value, float minValue, float maxValue, float totalAngle ) const
{
return static_cast<int>( ( value - 0.5 * ( minValue + maxValue ) ) / ( maxValue - minValue ) * m_totalAngle ) % 360;
}
QString m_label;
bool m_isHtmlLabel;
QTextDocument* m_tdRenderer;
std::unique_ptr<QPixmap> m_knobPixmap;
float m_totalAngle;
int m_angle;
QImage m_cache;
// Styled knob stuff, could break out
QPointF m_centerPoint;
float m_innerRadius;
float m_outerRadius;
float m_lineWidth;
QColor m_outerColor;
QColor m_lineActiveColor;
QColor m_lineInactiveColor;
QColor m_arcActiveColor;
QColor m_arcInactiveColor;
QColor m_textColor;
KnobType m_knobNum;
};
} // namespace lmms::gui
#endif // LMMS_GUI_KNOB_H