HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
wave_timescale.cpp
Go to the documentation of this file.
4 #include <QPainter>
5 #include <math.h>
6 #include <QPaintEvent>
7 
8 namespace hal {
9 
10  WaveTimescale::WaveTimescale(const WaveTransform *trans, const WaveScrollbar *scroll, QWidget *parent)
11  : QWidget(parent), mTransform(trans), mScrollbar(scroll)
12  {
13  setFixedHeight(28);
16  move(0,0);
17  }
18 
20  {
21  Q_UNUSED(event);
22  QPainter painter(this);
23  painter.setBrush(QColor::fromRgb(0xE0,0xE0,0xE0));
24  painter.drawRect(rect());
25 
26  if (mTransform->scale() <= 0) return;
27  WaveLogicTimescale wlts(mTransform->scale());
28 
29  // scale
30  for (quint64 tMinor = ceil(mScrollbar->tLeftI() / wlts.minorInterval()) * wlts.minorInterval();
31  tMinor<=mTransform->tMax(); tMinor += wlts.minorInterval())
32  {
33  float x = mScrollbar->xPosF(tMinor);
34  if (x > event->rect().width()) break;
35  if (tMinor%wlts.majorInterval() == 0)
36  {
37  // major tick
38  painter.setPen(QPen(QColor("#707070"),0));
39  painter.drawLine(QLineF(x,0,x,tMinor%wlts.labelInterval() == 0 ? 24 : 12));
40  }
41  else
42  {
43  // minor tick
44  painter.setPen(QPen(QColor("#a0a0a0"),0));
45  painter.drawLine(QLineF(x,0,x,10));
46  }
47  if (tMinor%wlts.labelInterval() == 0)
48  {
49  // label
50  painter.setPen(QPen(Qt::black,0));
51  painter.drawText(x+1,24,QString::number(tMinor));
52  }
53  }
54  }
55 
56  void WaveTimescale::setScale(int viewportWidth)
57  {
58  if (viewportWidth > 1) setFixedWidth(viewportWidth);
59  move(0,0);
60  update();
61  }
62 
64  {
65  int z = floor((2.-log(scale) / log(10)) * 3);
66  int exp = z<3? 1 : z/3;
67  quint64 base = floor(pow(10,exp)+0.5);
68  switch (z%3)
69  {
70  case 0:
71  mTlabel = z<3 ? base/2 : 2*base;
72  mTmajor = base;
73  mTminor = base/10;
74  break;
75  case 1:
76  mTlabel = z<3 ? base : 5*base;
77  mTmajor = base;
78  mTminor = base/5;
79  break;
80  case 2:
81  mTlabel = z<3 ? 2*base : 10*base;
82  mTmajor = 10*base;
83  mTminor = base;
84  break;
85  }
86  }
87 }
WaveLogicTimescale(double scale)
quint64 minorInterval() const
quint64 majorInterval() const
quint64 labelInterval() const
quint64 tLeftI() const
double xPosF(double t) const
void paintEvent(QPaintEvent *event) override
void setScale(int viewportWidth)
WaveTimescale(const WaveTransform *trans, const WaveScrollbar *scroll, QWidget *parent=nullptr)
double scale() const
Definition: defines.h:45
QColor fromRgb(QRgb rgb)
void drawLine(const QLineF &line)
void drawRect(const QRectF &rectangle)
void drawText(const QPointF &position, const QString &text)
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
QString number(int n, int base)
WA_TransparentForMouseEvents
virtual bool event(QEvent *event) override
void move(int x, int y)
void setAttribute(Qt::WidgetAttribute attribute, bool on)
void setFixedHeight(int h)
void setFixedWidth(int w)
void setSizePolicy(QSizePolicy)
void update()