diff options
author | vng <viktor.govako@gmail.com> | 2011-06-12 12:39:49 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:19:26 +0300 |
commit | 1f90697f1af585087aea489cdb0045e05eca29c2 (patch) | |
tree | 2f821fa7e9c33ec1f36c3e57345cce92a3d46993 /qt/slider_ctrl.cpp | |
parent | c566cde6fcc3350738fee6108db26888a5fd4beb (diff) |
Make smooth scale control.
Diffstat (limited to 'qt/slider_ctrl.cpp')
-rw-r--r-- | qt/slider_ctrl.cpp | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/qt/slider_ctrl.cpp b/qt/slider_ctrl.cpp index 7113c94c52..12024a7676 100644 --- a/qt/slider_ctrl.cpp +++ b/qt/slider_ctrl.cpp @@ -3,13 +3,19 @@ #include "slider_ctrl.hpp" #include "proxystyle.hpp" +#include "../base/math.hpp" + #include "../base/start_mem_debug.hpp" namespace qt { - QClickSlider::QClickSlider(Qt::Orientation orient, QWidget * pParent) - : QSlider(orient, pParent) + /////////////////////////////////////////////////////////////////////////////////////////////// + // QClickSmoothSlider implementation + /////////////////////////////////////////////////////////////////////////////////////////////// + + QClickSmoothSlider::QClickSmoothSlider(Qt::Orientation orient, QWidget * pParent, int factor) + : base_t(orient, pParent), m_factor(factor) { // this style cause slider to set value exactly to the cursor position (not "page scroll") class MyProxyStyle : public ProxyStyle @@ -29,9 +35,46 @@ namespace qt setStyle(new MyProxyStyle(style())); } - QClickSlider::~QClickSlider() + QClickSmoothSlider::~QClickSmoothSlider() { QStyle * p = style(); delete p; } + + void QClickSmoothSlider::SetRange(int low, int up) + { + setRange(low * m_factor, up * m_factor); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // QScaleSlider implementation + /////////////////////////////////////////////////////////////////////////////////////////////// + + QScaleSlider::QScaleSlider(Qt::Orientation orient, QWidget * pParent, int factor) + : base_t(orient, pParent, factor) + { + } + + double QScaleSlider::GetScaleFactor() const + { + double const oldV = value(); + double const newV = sliderPosition(); + + if (oldV != newV) + { + double const f = pow(2, fabs(oldV - newV) / m_factor); + return (newV > oldV ? f : 1.0 / f); + } + else return 1.0; + } + + void QScaleSlider::SetPosWithBlockedSignals(double pos) + { + bool const b = signalsBlocked(); + blockSignals(true); + + setSliderPosition(my::rounds(pos * m_factor)); + + blockSignals(b); + } } |