Skip to content

Commit

Permalink
qtcollider: QSlider: improvements regarding 'step' and rounding
Browse files Browse the repository at this point in the history
* Implement pixelStep method
* Set default step to 0.
* Whenever in/decrementing, use max(step, pixelStep)
* When value changes, round it to step modified by modifier keys
  (other kits always round to unmodified step)
* Do not round when step itself changes
  (unlike other kits)

* Also, replace all floats with doubles
  • Loading branch information
jleben committed Mar 14, 2012
1 parent f28fc2a commit 0f24601
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
31 changes: 27 additions & 4 deletions QtCollider/widgets/QcSlider.cpp
Expand Up @@ -31,28 +31,49 @@ QC_DECLARE_QWIDGET_FACTORY(QcSlider);
QcSlider::QcSlider() :
QtCollider::Style::Client(this),
_value(0.0),
_step(0.01),
_step(0.0),
_hndLen(20)
{
setFocusPolicy( Qt::StrongFocus );
setOrientation( Qt::Vertical );
}

double QcSlider::pixelStep()
{
using namespace QtCollider::Style;

QRect contRect( sunkenContentsRect(rect()) );
int range = (_ort == Qt::Horizontal) ? contRect.width() : contRect.height();
range -= _hndLen;

if(range > 0)
return 1.0 / range;
else
return 0.0;
}

void QcSlider::setValue( double val )
{
double step = _step;
modifyStep(&step);
if (step) val = qRound(val / step) * step;

_value = qBound(0.0, val, 1.0);

update();
}

void QcSlider::increment( double factor )
{
setValue( _step * factor + _value );
double step = qMax(_step, pixelStep());
setValue( step * factor + _value );
update();
}

void QcSlider::decrement( double factor )
{
setValue( - _step * factor + _value );
double step = qMax(_step, pixelStep());
setValue( - step * factor + _value );
update();
}

Expand Down Expand Up @@ -103,7 +124,9 @@ void QcSlider::mouseMoveEvent ( QMouseEvent *e )

void QcSlider::wheelEvent ( QWheelEvent *e )
{
double dval = e->delta() / 120.0 * _step;
double step = qMax(_step, pixelStep());
modifyStep(&step);
double dval = e->delta() / 120.0 * step;
setValue( _value + dval );
Q_EMIT( action() );
}
Expand Down
8 changes: 5 additions & 3 deletions QtCollider/widgets/QcSlider.h
Expand Up @@ -31,10 +31,11 @@
class QcSlider : public QWidget, QcHelper, QcAbstractStepValue, QtCollider::Style::Client
{
Q_OBJECT
Q_PROPERTY( float shiftScale READ dummyFloat WRITE setShiftScale );
Q_PROPERTY( float ctrlScale READ dummyFloat WRITE setCtrlScale );
Q_PROPERTY( float altScale READ dummyFloat WRITE setAltScale );
Q_PROPERTY( double shiftScale READ dummyFloat WRITE setShiftScale );
Q_PROPERTY( double ctrlScale READ dummyFloat WRITE setCtrlScale );
Q_PROPERTY( double altScale READ dummyFloat WRITE setAltScale );
Q_PROPERTY( double step READ step WRITE setStep )
Q_PROPERTY( double pixelStep READ pixelStep )
Q_PROPERTY( double value READ value WRITE setValue );
Q_PROPERTY( QColor grooveColor READ grooveColor WRITE setGrooveColor );
Q_PROPERTY( QColor focusColor READ focusColor WRITE setFocusColor );
Expand All @@ -56,6 +57,7 @@ class QcSlider : public QWidget, QcHelper, QcAbstractStepValue, QtCollider::Styl

double step() { return _step; }
void setStep( double d ) { _step = d; }
double pixelStep();

Qt::Orientation orientation() const { return _ort; }
void setOrientation( int );
Expand Down
5 changes: 1 addition & 4 deletions SCClassLibrary/QtCollider/QSlider.sc
Expand Up @@ -54,10 +54,7 @@ QSlider : QAbstractStepValue {
}
}

pixelStep {
// FIXME for now we are using step instead
^this.step;
}
pixelStep { ^this.getProperty(\pixelStep) }

orientation_ { arg aSymbol;
orientation = aSymbol;
Expand Down

0 comments on commit 0f24601

Please sign in to comment.