LMMS
Loading...
Searching...
No Matches
Knob.h
Go to the documentation of this file.
1/*
2 * Knob.h - powerful knob-widget
3 *
4 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_GUI_KNOB_H
26#define LMMS_GUI_KNOB_H
27
28#include <memory>
29
31
32
33
34namespace lmms::gui
35{
36
37
42
43
44void convertPixmapToGrayScale(QPixmap &pixMap);
45
46class LMMS_EXPORT Knob : public FloatModelEditorBase
47{
48 Q_OBJECT
49 Q_ENUMS( KnobType )
50
53
56
58
59 // Unfortunately, the gradient syntax doesn't create our gradient
60 // correctly so we need to do this:
62
63 Q_PROPERTY(QColor lineActiveColor MEMBER m_lineActiveColor)
64 Q_PROPERTY(QColor lineInactiveColor MEMBER m_lineInactiveColor)
65 Q_PROPERTY(QColor arcActiveColor MEMBER m_arcActiveColor)
66 Q_PROPERTY(QColor arcInactiveColor MEMBER m_arcInactiveColor)
67
69
71
72 void initUi( const QString & _name );
73 void onKnobNumUpdated();
74
75public:
82 enum class LabelRendering
83 {
89 WidgetFont,
90
97 LegacyFixedFontSize
98 };
99
107 Knob( KnobType _knob_num, QWidget * _parent = nullptr, const QString & _name = QString() );
108
118 Knob(KnobType knobNum, const QString& labelText, QWidget* parent = nullptr, LabelRendering labelRendering = LabelRendering::WidgetFont, const QString& name = QString());
119
129 Knob(KnobType knobNum, const QString& labelText, int labelPixelSize, QWidget* parent, const QString& name = QString());
130
131 Knob( QWidget * _parent = nullptr, const QString & _name = QString() );
132
133 Knob( const Knob& other ) = delete;
134
135 const QString& getLabel() const;
136 void setLabel(const QString& txt);
137
138 void setTotalAngle( float angle );
139
140 // Begin styled knob accessors
141 float innerRadius() const;
142 void setInnerRadius( float r );
143
144 float outerRadius() const;
145 void setOuterRadius( float r );
146
147 KnobType knobNum() const;
148 void setknobNum( KnobType k );
149
150 QPointF centerPoint() const;
151 float centerPointX() const;
152 void setCenterPointX( float c );
153 float centerPointY() const;
154 void setCenterPointY( float c );
155
156 float lineWidth() const;
157 void setLineWidth( float w );
158
159 QColor outerColor() const;
160 void setOuterColor( const QColor & c );
161
162 QColor textColor() const;
163 void setTextColor( const QColor & c );
164
165
166protected:
167 void paintEvent(QPaintEvent*) override;
168
169 void changeEvent(QEvent * ev) override;
170
186
195 void setFixedFontSizeLabelRendering();
196
197private:
198 QLineF calculateLine( const QPointF & _mid, float _radius,
199 float _innerRadius = 1) const;
200
201 void drawKnob( QPainter * _p );
202 void drawLabel(QPainter& p);
203 bool updateAngle();
204
205 int angleFromValue( float value, float minValue, float maxValue, float totalAngle ) const
206 {
207 return static_cast<int>( ( value - 0.5 * ( minValue + maxValue ) ) / ( maxValue - minValue ) * m_totalAngle ) % 360;
208 }
209
210 void updateFixedSize();
211
212 QString m_label;
214
215 std::unique_ptr<QPixmap> m_knobPixmap;
216
219 QImage m_cache;
220
221 // Styled knob stuff, could break out
227
232
234
236};
237
238} // namespace lmms::gui
239
240#endif // LMMS_GUI_KNOB_H
#define READ(addr)
Definition Ay_Cpu.cpp:92
#define WRITE(addr, data)
Definition Ay_Cpu.cpp:93
T value() const
Definition AutomatableModelView.h:59
FloatModelEditorBase(DirectionOfManipulation directionOfManipulation=DirectionOfManipulation::Vertical, QWidget *_parent=nullptr, const QString &_name=QString())
default ctor
Definition FloatModelEditorBase.cpp:50
Definition Knob.h:47
void setCenterPointY(float c)
Definition Knob.cpp:300
void initUi(const QString &_name)
to be called by ctors
Definition Knob.cpp:76
QColor arcActiveColor
Definition Knob.h:65
QColor m_arcActiveColor
Definition Knob.h:230
QColor arcInactiveColor
Definition Knob.h:66
const QString & getLabel() const
Definition Knob.cpp:146
Knob(KnobType _knob_num, QWidget *_parent=nullptr, const QString &_name=QString())
Construct a Knob with the given style and no label.
Definition Knob.cpp:40
float innerRadius
Definition Knob.h:51
QColor m_textColor
Definition Knob.h:233
void setCenterPointX(float c)
Definition Knob.cpp:286
int angleFromValue(float value, float minValue, float maxValue, float totalAngle) const
Definition Knob.h:205
void setTotalAngle(float angle)
Definition Knob.cpp:206
bool fixedFontSizeLabelRendering() const
Definition Knob.h:185
float outerRadius
Definition Knob.h:52
float centerPointY
Definition Knob.h:55
void setLineWidth(float w)
Definition Knob.cpp:314
std::unique_ptr< QPixmap > m_knobPixmap
Definition Knob.h:215
QColor lineActiveColor
Definition Knob.h:63
QColor textColor
Definition Knob.h:70
QImage m_cache
Definition Knob.h:219
void paintEvent(QPaintEvent *) override
Definition Knob.cpp:503
QPointF m_centerPoint
Definition Knob.h:222
float centerPointX
Definition Knob.h:54
QColor m_arcInactiveColor
Definition Knob.h:231
float m_lineWidth
Definition Knob.h:225
LabelRendering
Determines how the label of the knob is rendered.
Definition Knob.h:83
Knob(const Knob &other)=delete
QPointF centerPoint() const
Definition Knob.cpp:272
QColor lineInactiveColor
Definition Knob.h:64
float m_totalAngle
Definition Knob.h:217
KnobType knobNum
Definition Knob.h:68
bool m_fixedFontSizeLabelRendering
Definition Knob.h:213
KnobType m_knobNum
Definition Knob.h:235
void setOuterRadius(float r)
Definition Knob.cpp:244
QColor m_lineActiveColor
Definition Knob.h:228
void setknobNum(KnobType k)
Definition Knob.cpp:260
QColor m_outerColor
Definition Knob.h:226
void setLabel(const QString &txt)
Definition Knob.cpp:152
QColor m_lineInactiveColor
Definition Knob.h:229
float lineWidth
Definition Knob.h:57
void changeEvent(QEvent *ev) override
Definition Knob.cpp:511
int m_angle
Definition Knob.h:218
float m_outerRadius
Definition Knob.h:224
void setTextColor(const QColor &c)
Definition Knob.cpp:342
void setOuterColor(const QColor &c)
Definition Knob.cpp:328
QColor outerColor
Definition Knob.h:61
QString m_label
Definition Knob.h:212
float m_innerRadius
Definition Knob.h:223
void setInnerRadius(float r)
Definition Knob.cpp:230
void onKnobNumUpdated()
to be called when you updated m_knobNum
Definition Knob.cpp:112
UINT_D64 w
Definition inflate.c:942
register unsigned k
Definition inflate.c:946
static const char * name
Definition pugl.h:1582
static uintptr_t parent
Definition pugl.h:1644
Definition AudioPortAudio.cpp:223
void convertPixmapToGrayScale(QPixmap &pixMap)
Definition Knob.cpp:534
KnobType
Definition Knob.h:39
@ Dark28
Definition Knob.h:40
@ Vintage32
Definition Knob.h:40
@ Styled
Definition Knob.h:40
@ Small17
Definition Knob.h:40
@ Bright26
Definition Knob.h:40
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
int r
Definition crypt.c:458
#define const
Definition zconf.h:137