HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
wave_scrollbar.cpp
Go to the documentation of this file.
3 #include <math.h>
4 #include <QDebug>
5 
6 namespace hal {
8  : QScrollBar(parent), mTransform(trans), mVleft(0), mVmaxScroll(0), mVieportWidth(0), mHandleSliderChange(true)
9  {
10  setSingleStep(1);
11  }
12 
13  int WaveScrollbar::toUInt(double v)
14  {
15  if (v < 0) return 0;
16  return (int) floor(v+0.5);
17  }
18 
19  void WaveScrollbar::adjust(quint64 visibleWidth)
20  {
21  setMinimum(0);
22  mVieportWidth = visibleWidth;
23  quint64 vmax = mTransform->vMax();
24  if (vmax <= visibleWidth)
25  {
26  mVmaxScroll = 0;
27  setMaximum(0);
28  return;
29  }
30  mVmaxScroll = vmax - visibleWidth;
31  if (mVmaxScroll < 4096)
32  setMaximum(toUInt(mVmaxScroll));
33  else
34  setMaximum(4096);
35  }
36 
37  void WaveScrollbar::setVleftIntern(double v)
38  {
39  if (v > mVmaxScroll)
40  v = mVmaxScroll;
41  mVleft = v;
42  }
43 
44  void WaveScrollbar::updateScale(double deltaScale, double tEvent, quint64 visibleWidth)
45  {
46  double oldVleft = mVleft;
47  adjust(visibleWidth);
48  if (!mVmaxScroll) return;
49  double prod = deltaScale * (tEvent - mTransform->tMin());
50  double newVleft = prod + oldVleft;
51  setVleft(newVleft);
52  }
53 
54  void WaveScrollbar::setVleft(double v)
55  {
56  if (v < 0 || !maximum())
57  {
58  setValue(0);
59  setVleftIntern(0);
60  }
61  else
62  {
63  setVleftIntern(v);
64  mHandleSliderChange = false;
65  if (maximum() < 4096)
66  setValue(toUInt(mVleft));
67  else
68  setValue(toUInt(mVleft * 4096. / mVmaxScroll));
69  mHandleSliderChange = true;
70  }
71  }
72 
73  double WaveScrollbar::vLeft() const
74  {
75  return mVleft;
76  }
77 
79  {
80  if (change == SliderChange::SliderValueChange &&
81  (!mHandleSliderChange || value() == mLastValue)) return;
82  if (!maximum())
83  setVleftIntern(0);
84  else if (maximum() < 4096)
85  setVleftIntern(value());
86  else
87  {
88  int dx = mLastValue - value();
89  if (abs(dx)==1)
90  {
91  double v = mVleft - dx * mVieportWidth / 2;
92  if (v<0) v=0;
93  setVleftIntern(v);
94  setValue(toUInt(mVleft * 4096. / mVmaxScroll));
95  }
96  else
97  setVleftIntern(toUInt(value() * mVmaxScroll / 4096.));
98  }
99  mLastValue = value();
100  }
101 
102  double WaveScrollbar::xPosF(double t) const
103  {
104  return mTransform->vPos(t) - mVleft;
105  }
106 
107  int WaveScrollbar::xPosI(double t) const
108  {
109  double v = mTransform->vPos(t);
110  if (v < mVleft) return -1;
111  return toUInt(v - mVleft);
112  }
113 
114  double WaveScrollbar::tPosF(int x) const
115  {
116  return mTransform->tPos(vLeft() + x);
117  }
118 
119  quint64 WaveScrollbar::tPosI(int x) const
120  {
121  return floor(tPosF(x)+0.5);
122  }
123 
124  double WaveScrollbar::tLeftF() const
125  {
126  return mTransform->tPos(vLeft());
127  }
128 
129  quint64 WaveScrollbar::tLeftI() const
130  {
131  return floor(tLeftF()+0.5);
132  }
133 }
void adjust(quint64 visibleWidth)
double tLeftF() const
quint64 tPosI(int x) const
quint64 tLeftI() const
WaveScrollbar(const WaveTransform *trans, QWidget *parent=nullptr)
double tPosF(int x) const
int xPosI(double t) const
double vLeft() const
void setVleft(double v)
void updateScale(double deltaScale, double tEvent, quint64 visibleWidth)
double xPosF(double t) const
void sliderChange(SliderChange change) override
quint64 tMin() const
double tPos(quint64 v) const
double vPos(double t) const
double vMax() const
Definition: defines.h:45
void setMaximum(int)
void setMinimum(int)
void setSingleStep(int)
void setValue(int)