AudioDial.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef SV_AUDIO_DIAL_H
16 #define SV_AUDIO_DIAL_H
17 
41 #include <QDial>
42 #include <map>
43 
44 class RangeMapper;
45 class QMenu;
46 
60 class AudioDial : public QDial
61 {
62  Q_OBJECT
63  Q_PROPERTY( QColor knobColor READ getKnobColor WRITE setKnobColor )
64  Q_PROPERTY( QColor meterColor READ getMeterColor WRITE setMeterColor )
65  Q_PROPERTY( bool mouseDial READ getMouseDial WRITE setMouseDial )
66 
67 public:
68  AudioDial(QWidget *parent = 0);
69  ~AudioDial();
70 
71  const QColor& getKnobColor() const { return m_knobColor; }
72  const QColor& getMeterColor() const { return m_meterColor; }
73  bool getMouseDial() const { return m_mouseDial; }
74 
75  void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete
76  const RangeMapper *rangeMapper() const { return m_rangeMapper; }
77  double mappedValue() const;
78 
79  int defaultValue() const { return m_defaultValue; }
80 
81  void setShowToolTip(bool show);
82  void setProvideContextMenu(bool provide);
83 
84 signals:
85  void mouseEntered();
86  void mouseLeft();
87 
88 public slots:
93  void setKnobColor(const QColor &color);
94 
100  void setMeterColor(const QColor &color);
101 
106  void setMouseDial(bool mouseDial);
107 
108  void setDefaultValue(int defaultValue);
109 
110  void setValue(int value);
111 
112  void setDefaultMappedValue(double mappedValue);
113 
114  void setMappedValue(double mappedValue);
115 
116  void setToDefault();
117 
118  void edit();
119 
120 protected:
121  void drawTick(QPainter &paint, double angle, int size, bool internal);
122  void paintEvent(QPaintEvent *) override;
123 
124  // Alternate mouse behavior event handlers.
125  void mousePressEvent(QMouseEvent *pMouseEvent) override;
126  void mouseMoveEvent(QMouseEvent *pMouseEvent) override;
127  void mouseReleaseEvent(QMouseEvent *pMouseEvent) override;
128  void mouseDoubleClickEvent(QMouseEvent *pMouseEvent) override;
129  void enterEvent(QEvent *) override;
130  void leaveEvent(QEvent *) override;
131 
132 protected slots:
133  void updateMappedValue(int value);
134  void contextMenuRequested(const QPoint &);
135 
136 private:
137  QColor m_knobColor;
138  QColor m_meterColor;
139 
144 
145  // Alternate mouse behavior tracking.
148  QPoint m_posMouse;
149 
152 
153  QString m_title;
154 
156 
157  RangeMapper *m_rangeMapper;
158 };
159 
160 
161 #endif // __AudioDial_h
162 
163 // end of AudioDial.h
void setMappedValue(double mappedValue)
Definition: AudioDial.cpp:420
QPoint m_posMouse
Definition: AudioDial.h:148
void mouseMoveEvent(QMouseEvent *pMouseEvent) override
Definition: AudioDial.cpp:616
void mouseDoubleClickEvent(QMouseEvent *pMouseEvent) override
Definition: AudioDial.cpp:537
bool m_mousePressed
Definition: AudioDial.h:147
void setDefaultValue(int defaultValue)
Definition: AudioDial.cpp:398
void setMeterColor(const QColor &color)
Set the colour of the meter (the highlighted area around the knob that shows the current value)...
Definition: AudioDial.cpp:385
double m_mappedValue
Definition: AudioDial.h:142
void setDefaultMappedValue(double mappedValue)
Definition: AudioDial.cpp:412
void mouseReleaseEvent(QMouseEvent *pMouseEvent) override
Definition: AudioDial.cpp:636
void enterEvent(QEvent *) override
Definition: AudioDial.cpp:646
void setMouseDial(bool mouseDial)
Specify that the dial should respond to radial mouse movements in the same way as QDial...
Definition: AudioDial.cpp:392
QColor meterColor
Definition: AudioDial.h:64
void setToDefault()
Definition: AudioDial.cpp:509
void setProvideContextMenu(bool provide)
Definition: AudioDial.cpp:449
void mousePressEvent(QMouseEvent *pMouseEvent) override
Definition: AudioDial.cpp:522
bool m_provideContextMenu
Definition: AudioDial.h:151
QString m_title
Definition: AudioDial.h:153
bool m_mouseDial
Definition: AudioDial.h:146
QMenu * m_lastContextMenu
Definition: AudioDial.h:155
double mappedValue() const
Definition: AudioDial.cpp:455
void leaveEvent(QEvent *) override
Definition: AudioDial.cpp:653
const RangeMapper * rangeMapper() const
Definition: AudioDial.h:76
AudioDial is a nicer-looking QDial that by default reacts to mouse movement on horizontal and vertica...
Definition: AudioDial.h:60
void paintEvent(QPaintEvent *) override
Definition: AudioDial.cpp:142
bool m_showTooltip
Definition: AudioDial.h:150
bool mouseDial
Definition: AudioDial.h:65
QColor knobColor
Definition: AudioDial.h:63
void setValue(int value)
Definition: AudioDial.cpp:406
const QColor & getMeterColor() const
Definition: AudioDial.h:72
const QColor & getKnobColor() const
Definition: AudioDial.h:71
int defaultValue() const
Definition: AudioDial.h:79
QColor m_knobColor
Definition: AudioDial.h:137
void mouseEntered()
int m_defaultValue
Definition: AudioDial.h:140
RangeMapper * m_rangeMapper
Definition: AudioDial.h:157
void edit()
Definition: AudioDial.cpp:550
void mouseLeft()
void setKnobColor(const QColor &color)
Set the colour of the knob.
Definition: AudioDial.cpp:378
void setRangeMapper(RangeMapper *mapper)
Definition: AudioDial.cpp:126
void contextMenuRequested(const QPoint &)
Definition: AudioDial.cpp:104
void drawTick(QPainter &paint, double angle, int size, bool internal)
Definition: AudioDial.cpp:350
double m_defaultMappedValue
Definition: AudioDial.h:141
void updateMappedValue(int value)
Definition: AudioDial.cpp:465
bool getMouseDial() const
Definition: AudioDial.h:73
QColor m_meterColor
Definition: AudioDial.h:138
bool m_noMappedUpdate
Definition: AudioDial.h:143
void setShowToolTip(bool show)
Definition: AudioDial.cpp:440