class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / QtCollider / widgets / QcNumberBox.h
blobe008c36fac1772fe0397af7ca7390b2e1b909b84
1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program 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 General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef QC_NUMBER_BOX
23 #define QC_NUMBER_BOX
25 #include <QLineEdit>
27 #include "QcAbstractStepValue.h"
28 #include "../QcHelper.h"
30 #include <QDoubleValidator>
32 class QcNumberBox : public QLineEdit, QcHelper, QcAbstractStepValue
34 Q_OBJECT
35 Q_PROPERTY( float shiftScale READ dummyFloat WRITE setShiftScale );
36 Q_PROPERTY( float ctrlScale READ dummyFloat WRITE setCtrlScale );
37 Q_PROPERTY( float altScale READ dummyFloat WRITE setAltScale );
39 Q_PROPERTY( double minimum READ minimum WRITE setMinimum );
40 Q_PROPERTY( double maximum READ maximum WRITE setMaximum );
41 Q_PROPERTY( int decimals READ decimals WRITE setDecimals );
42 Q_PROPERTY( int maxDecimals READ maxDecimals WRITE setMaxDecimals );
43 Q_PROPERTY( int minDecimals READ minDecimals WRITE setMinDecimals );
44 Q_PROPERTY( double value READ value WRITE setValue );
45 Q_PROPERTY( int valueType READ valueType );
46 Q_PROPERTY( QString text READ text WRITE setTextValue );
48 Q_PROPERTY( float step READ dummyFloat WRITE setStep )
49 Q_PROPERTY( float scrollStep READ dummyFloat WRITE setScrollStep )
50 Q_PROPERTY( bool scroll READ dummyBool WRITE setScroll );
52 Q_PROPERTY( QColor normalColor READ dummyColor WRITE setTextColor );
53 Q_PROPERTY( QColor editingColor READ dummyColor WRITE setEditedTextColor );
55 public:
57 enum ValueType {
58 Number,
59 Infinite,
60 InfiniteNegative,
61 NaN,
62 Text
65 QcNumberBox();
66 void setStep( float step_ ) { step = step_;}
67 void setScrollStep( float step_ ) { scrollStep = step_; }
68 void setScroll( bool b ) { scroll = b; }
69 void setLocked( bool );
70 void setTextColor( const QColor& c );
71 void setEditedTextColor( const QColor& c );
72 void setValue( double );
73 Q_INVOKABLE void setInfinite( bool positive = true );
74 Q_INVOKABLE void setNaN();
75 void setTextValue( const QString & );
76 double value() const;
77 int valueType() const { return (int) _valueType; }
78 double minimum() const { return _validator->bottom(); }
79 double maximum() const { return _validator->top(); }
80 void setMinimum( double );
81 void setMaximum( double );
82 int decimals() const { return maxDecimals(); }
83 int minDecimals() const { return _minDec; }
84 int maxDecimals() const { return _maxDec; }
85 void setDecimals( int );
86 void setMinDecimals( int );
87 void setMaxDecimals( int );
89 public Q_SLOTS:
90 void increment( double factor );
91 void decrement( double factor );
93 Q_SIGNALS:
94 void scrolled( int steps );
95 void valueChanged();
96 void action();
98 private Q_SLOTS:
99 void onEditingFinished();
100 void updateText();
101 protected:
102 virtual void keyPressEvent ( QKeyEvent * event );
103 virtual void mouseDoubleClickEvent ( QMouseEvent * event );
104 virtual void mousePressEvent ( QMouseEvent * event );
105 virtual void mouseMoveEvent ( QMouseEvent * event );
106 virtual void wheelEvent ( QWheelEvent * event );
107 private:
108 void stepBy( int steps, float stepSize );
109 double roundedVal( double val );
110 QString stringForVal( double val );
111 void updateTextColor();
112 inline void doAction();
114 bool scroll;
115 int lastPos;
116 QColor editedTextColor;
117 QColor normalTextColor;
119 QDoubleValidator *_validator;
120 float step;
121 float scrollStep;
122 float dragDist;
123 double _value;
124 ValueType _valueType;
125 int _minDec;
126 int _maxDec;
129 #if 0
130 class NumberBoxWidget : public QDoubleSpinBox
132 friend class SCNumberBox;
134 Q_OBJECT
136 public:
137 NumberBoxWidget( );
138 void setScroll( bool b );
139 private Q_SLOTS:
140 void stepBy( int steps );
141 void scrollBy( int steps );
142 void onEditingFinished();
143 protected:
144 virtual void keyPressEvent ( QKeyEvent * event );
145 private:
146 void stepBy( int steps, float stepSize );
147 SCAbstractStepValue *modifier;
148 float scrollStep;
150 #endif
152 #endif