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 ************************************************************************/
27 #include "QcAbstractStepValue.h"
28 #include "../QcHelper.h"
30 #include <QDoubleValidator>
32 class QcNumberBox
: public QLineEdit
, QcHelper
, QcAbstractStepValue
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
);
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
& );
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 );
90 void increment( double factor
);
91 void decrement( double factor
);
94 void scrolled( int steps
);
99 void onEditingFinished();
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
);
108 void stepBy( int steps
, float stepSize
);
109 double roundedVal( double val
);
110 QString
stringForVal( double val
);
111 void updateTextColor();
112 inline void doAction();
116 QColor editedTextColor
;
117 QColor normalTextColor
;
119 QDoubleValidator
*_validator
;
124 ValueType _valueType
;
130 class NumberBoxWidget
: public QDoubleSpinBox
132 friend class SCNumberBox
;
138 void setScroll( bool b
);
140 void stepBy( int steps
);
141 void scrollBy( int steps
);
142 void onEditingFinished();
144 virtual void keyPressEvent ( QKeyEvent
* event
);
146 void stepBy( int steps
, float stepSize
);
147 SCAbstractStepValue
*modifier
;