HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
wave_form_primitive.cpp
Go to the documentation of this file.
5 #include <QPainter>
6 #include <QFontMetrics>
7 #include <QDebug>
8 #include <math.h>
9 
10 namespace hal {
11  void WaveFormPrimitiveHline::paint(int y0, QPainter& painter)
12  {
13  int y = 14 * (1-mValue) + y0;
14  painter.drawLine(QLineF(mX0,y,mX1,y));
15  }
16 
18  {
19  painter.drawLine(QLineF(mX0,y0,mX0,y0+14));
20  }
21 
23  {
24  QBrush saveBrush = painter.brush();
25  painter.setBrush(painter.pen().color());
26  painter.drawLine(QLineF(mX0,y0+2,mX0,y0+10));
27  QPoint pts[5];
28  const int px[5] = { 0, 3, 0, -3, 0 } ;
29  const int py[5] = { 3, 6, 0, 6, 3 } ;
30  for (int i=0; i<5; i++)
31  {
32  pts[i] = QPoint(px[i]+mX0, py[i]+y0+2);
33  }
34  painter.drawPolygon(pts,5);
35  painter.setBrush(saveBrush);
36  }
37 
38 
40  {
41  float y = 14 * 0.5 + y0;
42  QPen savePen = painter.pen();
44  dashPen.setStyle(Qt::DotLine);
45  painter.setPen(dashPen);
46  painter.drawLine(QLineF(mX0,y,mX1,y));
47  painter.setPen(savePen);
48  }
49 
51  : WaveFormPrimitive(x0,x1)
52  {
53  memset(mAccumTime, 0, sizeof(mAccumTime));
54  if (0 <= val && val <= 1)
55  mAccumTime[val] = x1-x0;
56  }
57 
59  {
60  for (int i=0; i<2; i++)
61  mAccumTime[i] += other.mAccumTime[i];
62  }
63 
65  {
66  QBrush saveBrush = painter.brush();
67  QColor fillCol = painter.pen().color();
68  double sum = mAccumTime[0] + mAccumTime[1];
69  if (sum > 0)
70  {
71  if (mAccumTime[1] > mAccumTime[0])
72  {
73  painter.drawLine(QLineF(mX0,0,mX1,0));
74  fillCol.setAlpha(floor(55 + 400 * mAccumTime[0] / sum));
75  }
76  else
77  {
78  painter.drawLine(QLineF(mX0,14,mX1,14));
79  fillCol.setAlpha(floor(55 + 400 * mAccumTime[1] / sum));
80  }
81  }
82  painter.setBrush(QBrush(fillCol));
83  painter.drawRect(QRectF(mX0,y0,mX1-mX0,14));
84  painter.setBrush(saveBrush);
85  }
86 
87  WaveFormPrimitiveValue::WaveFormPrimitiveValue(float x0, float x1, int val, int bits, int base)
88  : WaveFormPrimitive(x0,x1), mValue(val), mBits(bits), mBase(base)
89  {
90  QVector<QPointF> pts;
91  pts.append(QPointF(x0,7));
92  if (mX1-mX0 > 8)
93  {
94  pts.append(QPointF(x0+4,14));
95  pts.append(QPointF(x1-4,14));
96  }
97  else
98  {
99  pts.append(QPointF((x0+x1)/2.,14));
100  }
101  pts.append(QPointF(x1,7));
102  if (mX1-mX0 > 8)
103  {
104  pts.append(QPointF(x1-4,0));
105  pts.append(QPointF(x0+4,0));
106  }
107  else
108  {
109  pts.append(QPointF((x0+x1)/2.,0));
110  }
111  mPolygon = QPolygonF(pts);
112  }
113 
115  {
116  painter.drawPolygon(mPolygon.translated(0,y0));
117  QFont font = painter.font();
118  font.setPixelSize(8);
119  font.setBold(true);
120  QString txt = WaveData::stringValue(mValue,mBits,mBase);
121  QFontMetrics fm(font);
122  QRectF r = fm.boundingRect(txt);
123  r.setWidth(r.width()+4*txt.size());
124  float wMax = mX0 < 0 ? mX1 : mX1 - mX0;
125  if (r.width()+6 > wMax) return;
126  r.setHeight(14);
127  float xText = mX0 + (wMax - r.width())/2.;
128  if (xText<0) xText = 0;
129  r.moveTo(xText, y0-1);
130  painter.drawText(r,txt);
131  }
132 }
static QString stringValue(int val, int bits, int base)
Definition: wave_data.cpp:489
WaveFormPrimitiveFilled(float x0, float x1, int val)
void add(const WaveFormPrimitiveFilled &other)
void paint(int y0, QPainter &painter)
void paint(int y0, QPainter &painter)
void paint(int y0, QPainter &painter)
void paint(int y0, QPainter &painter)
void paint(int y0, QPainter &painter)
WaveFormPrimitiveValue(float x0, float x1, int val, int bits, int base)
void paint(int y0, QPainter &painter)
Definition: defines.h:45
void setAlpha(int alpha)
void setBold(bool enable)
void setPixelSize(int pixelSize)
QRect boundingRect(QChar ch) const const
const QBrush & brush() const const
void drawLine(const QLineF &line)
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawRect(const QRectF &rectangle)
void drawText(const QPointF &position, const QString &text)
const QFont & font() const const
const QPen & pen() const const
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
QColor color() const const
void setStyle(Qt::PenStyle style)
QPolygonF translated(qreal dx, qreal dy) const const
void moveTo(qreal x, qreal y)
void setHeight(qreal height)
void setWidth(qreal width)
qreal width() const const
int size() const const
void append(const T &value)