Skip to content

Commit

Permalink
GUI: QcRangeSlider: fix stretch behaviour (supercollider#5595)
Browse files Browse the repository at this point in the history
* GUI: QcRangeSlider: fix stretch behaviour

Fixes issue supercollider#3696. The proposed change makes it possible to
adjust the height / width of a RangeSlider by using stretch
factors. The behaviour of RangeSlider will then match the behaviour
of Slider.

* Refactoring QcRangeSlider::setOrientation

Preventing the undefined behaviour of static_cast

* Format with clang-format

* QcRangeSlider: fix build errors

* RangeSlider: setOrientation call without cast
  • Loading branch information
miriamvoth authored and dyfer committed Nov 28, 2021
1 parent e5686af commit 1ad0dcb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions QtCollider/widgets/QcRangeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ QcRangeSlider::QcRangeSlider(): QtCollider::Style::Client(this), _lo(0.0), _hi(1
setAttribute(Qt::WA_AcceptTouchEvents);
}

void QcRangeSlider::setOrientation(Qt::Orientation o) {
_ort = o;
void QcRangeSlider::setOrientation(int orientation) {
_ort = asOrientationWithDefault(orientation, Qt::Vertical);

if (_ort == Qt::Horizontal) {
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
} else {
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
}

updateGeometry();
Expand Down Expand Up @@ -389,3 +389,10 @@ void QcRangeSlider::paintEvent(QPaintEvent* e) {
p.drawRect(valRect.adjusted(2, 1, -2, -1));
}
}

Qt::Orientation QcRangeSlider::asOrientationWithDefault(int orientationValue, Qt::Orientation defaultOrientation) {
if (orientationValue == Qt::Horizontal || orientationValue == Qt::Vertical)
return static_cast<Qt::Orientation>(orientationValue);

return defaultOrientation;
}
3 changes: 2 additions & 1 deletion QtCollider/widgets/QcRangeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class QcRangeSlider : public QWidget, QcHelper, QcAbstractStepValue, QtCollider:

QcRangeSlider();
Qt::Orientation orientation() const { return _ort; }
void setOrientation(Qt::Orientation o);
void setOrientation(int);
double loValue() const { return _lo; }
void setLoValue(double);
double hiValue() const { return _hi; }
Expand Down Expand Up @@ -82,6 +82,7 @@ public Q_SLOTS:
void mouseReleaseEvent(QMouseEvent*);
void keyPressEvent(QKeyEvent*);
void paintEvent(QPaintEvent*);
Qt::Orientation asOrientationWithDefault(int, Qt::Orientation);

Qt::Orientation _ort;
double _lo;
Expand Down

0 comments on commit 1ad0dcb

Please sign in to comment.