Welcome to mirror list, hosted at ThFree Co, Russian Federation.

slider_ctrl.cpp « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bda73f4c0feb7983af6c52d7e8b0f1dc8c5415d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "base/SRC_FIRST.hpp"

#include "qt/slider_ctrl.hpp"
#include "qt/proxystyle.hpp"

#include "base/math.hpp"


namespace qt
{
  ///////////////////////////////////////////////////////////////////////////////////////////////
  // 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")
    /// @todo Do investigate this stuff with Qt5.
    class MyProxyStyle : public ProxyStyle
    {
    public:
      MyProxyStyle(QStyle * p) : ProxyStyle(p) {}

      virtual int styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
      {
        if (hint == SH_Slider_AbsoluteSetButtons)
          return Qt::LeftButton;
        else
          return ProxyStyle::styleHint(hint, option, widget, returnData);
      }
    };

    setStyle(new MyProxyStyle(style()));
  }

  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);
  }
}