1 /* 2 Copyright (C) 2008, 2009 Andres Cabrera 3 mantaraya36@gmail.com 4 5 This file is part of CsoundQt. 6 7 CsoundQt is free software; you can redistribute it 8 and/or modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 CsoundQt is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with Csound; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 20 02111-1307 USA 21 */ 22 23 #ifndef QUTEKNOB_H 24 #define QUTEKNOB_H 25 26 #include "qutewidget.h" 27 #include "selectcolorbutton.h" 28 29 /* QVdial: A knob with vertical dragging instead of circular 30 * 31 */ 32 class QVdial: public QDial { 33 Q_OBJECT 34 35 public: 36 QVdial (QWidget *parent = nullptr) QDial(parent)37 : QDial(parent) 38 , m_dragging(false) 39 , m_scale_factor(1.0) 40 , m_temp_scale_factor(1.0) 41 , m_draw_value(true) 42 , m_decimals(2) 43 , m_display_min(0.0) 44 , m_display_max(1.0) 45 , m_color(QColor(245, 124, 0)) 46 , m_textcolor(QColor(81, 41, 0)) 47 , m_bordercolor(QColor(245, 124, 0)) 48 , m_border(0) 49 , m_flat(true) 50 , m_degrees(300) 51 , m_intDisplay(true) 52 {} 53 virtual ~QVdial() override; setScaleFactor(double factor)54 void setScaleFactor(double factor) { m_scale_factor = factor; } setDecimals(int decimals)55 void setDecimals(int decimals) { m_decimals = decimals; } setDisplayRange(double min,double max)56 void setDisplayRange(double min, double max) { 57 m_display_min = min; 58 m_display_max = max; 59 max = qAbs(max); 60 if(max < 100) 61 m_decimals = 2; 62 else if(max < 1000) 63 m_decimals = 1; 64 else 65 m_decimals = 0; 66 } setDrawValue(bool enable)67 void setDrawValue(bool enable) { m_draw_value = enable; } setColor(QColor color)68 void setColor(QColor color) { 69 if(!color.isValid()) { 70 qDebug() << "QVdial::setColor: invalid color"; 71 return; 72 } 73 m_color = color; } getColor()74 QColor getColor() { return m_color; } setTextColor(QColor c)75 void setTextColor(QColor c) { m_textcolor = c; } 76 getTextColor()77 QColor getTextColor() { return m_textcolor; } 78 setFlatStyle(bool enable)79 void setFlatStyle(bool enable) { m_flat = enable; } setIntegerMode(bool enable)80 void setIntegerMode(bool enable) { m_intDisplay = enable; } setBorder(int width,QColor color)81 void setBorder(int width, QColor color) { 82 m_border = width; 83 m_bordercolor = color; 84 } 85 setValueFromDisplayValue(double display_value)86 void setValueFromDisplayValue(double display_value) { 87 double delta = (display_value - m_display_min) / (m_display_max-m_display_min); 88 double minval = (double)this->minimum(); 89 double flvalue = delta * (this->maximum() - minval) + minval; 90 setValue((int)flvalue); 91 } 92 displayValue()93 double displayValue() { 94 return ((double)this->value()/(double)this->maximum()) * 95 (m_display_max - m_display_min) + m_display_min; 96 } getDegreeRange()97 int getDegreeRange() { 98 return m_degrees; 99 } 100 101 protected: 102 virtual void mousePressEvent (QMouseEvent *event) override; 103 virtual void mouseReleaseEvent (QMouseEvent *event) override; 104 virtual void mouseMoveEvent (QMouseEvent *event) override; 105 virtual void paintEvent(QPaintEvent *event) override; 106 virtual void mouseDoubleClickEvent (QMouseEvent *event) override; 107 108 private: 109 bool m_dragging; 110 QPoint m_mouse_press_point; 111 int m_base_value; 112 double m_scale_factor; 113 double m_temp_scale_factor; 114 bool m_draw_value; 115 int m_decimals; 116 double m_display_min; 117 double m_display_max; 118 QColor m_color; 119 QColor m_textcolor; 120 QColor m_bordercolor; 121 int m_border; 122 bool m_flat; 123 int m_degrees; 124 bool m_intDisplay; 125 126 signals: 127 void doubleClick(); 128 }; 129 130 131 class QuteKnob : public QuteWidget 132 { 133 Q_OBJECT 134 public: 135 QuteKnob(QWidget *parent); 136 ~QuteKnob(); 137 138 virtual void setWidgetGeometry(int x, int y, int width, int height); 139 virtual QString getWidgetLine(); 140 virtual QString getCsladspaLine(); 141 virtual QString getCabbageLine(); 142 virtual QString getQml(); 143 virtual QString getWidgetXmlText(); 144 virtual QString getWidgetType(); 145 // virtual void setResolution(double resolution); 146 void setRange(double min, double max); 147 virtual void setMidiValue(int value); acceptsMidi()148 virtual bool acceptsMidi() {return true;} 149 150 virtual void refreshWidget(); 151 virtual void applyInternalProperties(); 152 153 virtual void setColor(QColor c); 154 virtual void setTextColor(QColor c); 155 156 protected: 157 virtual void createPropertiesDialog(); 158 virtual void applyProperties(); 159 160 protected slots: 161 void selectKnobColor(); 162 void selectKnobTextColor(); 163 void setValueFromDialog(); 164 void knobChanged(int value); 165 166 private: 167 void setInternalValue(double value); 168 QDoubleSpinBox *minSpinBox; 169 QDoubleSpinBox *maxSpinBox; 170 QDoubleSpinBox *resolutionSpinBox; 171 QCheckBox *displayValueCheckBox; 172 QCheckBox *flatStyleCheckBox; 173 SelectColorButton *knobColorButton; 174 SelectColorButton *knobTextColorButton; 175 QCheckBox *intModeCheckBox; 176 QSpinBox *borderWidthSpinBox; 177 SelectColorButton *borderColorButton; 178 179 }; 180 181 #endif 182