HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
comment_speech_bubble.cpp
Go to the documentation of this file.
3 
4 #include <QRectF>
5 #include <QPainter>
6 #include <QPainterPath>
7 #include <QFontMetrics>
8 #include <QDebug>
9 
10 namespace hal {
12  : mHover(false), mBubble(QRectF(-50,-15,sBubbleWidth,35)), mText(txt), mNode(nd), mContext(ctx)
13  {
15  }
16 
18  {
19  QRectF bb(mBubble);
20  bb.setRight(bb.right()+sBubbleWidthExtension);
21  return bb;
22  }
23 
25  {
26  QPainterPath retval;
27  retval.addRect(mBubble);
28  return retval;
29  }
30 
32  {
33  Q_UNUSED(event);
34  mHover = true;
35  update();
36  }
37 
39  {
40  Q_UNUSED(event);
41  mHover = false;
42  update();
43  }
44 
46  {
47  Q_UNUSED(event);
48  if (!mContext) return;
49  mContext->showComments(mNode);
50  }
51 
52  void CommentSpeechBubble::paintText(QPainter *painter, int maxWidth)
53  {
54  QFontMetrics fm(painter->font());
55  QString txt = mText;
56  int n = mText.size();
57  while ((fm.horizontalAdvance(txt) + 2 * sTextMargin) > maxWidth && n > 1)
58  {
59  --n;
60  txt = mText.left(n) + "…";
61  }
62  QRectF rText = mBubble;
63  rText.setWidth(maxWidth);
64  rText.setLeft(rText.left()+sTextMargin);
65  rText.setRight(rText.right()-sTextMargin);
66  rText.setHeight(sTextHeight);
67  painter->drawText(rText,Qt::AlignLeft|Qt::AlignVCenter,txt);
68  }
69 
71  {
72  Q_UNUSED(option);
73  Q_UNUSED(widget);
74  painter->setPen(QPen(Qt::black,0)); // border color
75  QRectF rBubble=mBubble;
76  rBubble.setHeight(sTextHeight);
77  int txtWidth = rBubble.width();
78  QColor bgColor("#F0E0C0"); // background color
79  if (mHover)
80  {
81  QFontMetrics fm(painter->font());
82  int w = fm.horizontalAdvance(mText);
83  txtWidth = w+8>boundingRect().width() ? boundingRect().width() : w+8;
84  rBubble.setWidth(txtWidth);
85  }
86  else
87  {
88  bgColor.setAlpha(80);
89  }
90  painter->setBrush(bgColor);
91  painter->drawRoundedRect(rBubble,8,4);
92  QVector<QPointF> pts;
93  pts.append(QPointF(-50,20));
94  pts.append(QPointF(-30,11));
95  pts.append(QPointF(-10,12));
96  painter->setPen(Qt::NoPen);
97  painter->drawPolygon(QPolygonF(pts));
98  pts.append(QPointF(-50,20));
99  painter->setPen(QPen(Qt::black,0)); // text color
100  painter->drawLines(pts);
101  paintText(painter,txtWidth);
102  }
103 
104 }
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
CommentSpeechBubble(const QString &txt, const Node &nd, GraphContext *ctx)
QPainterPath shape() const override
QRectF boundingRect() const override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
void showComments(const Node &nd)
The Node class object represents a module or a gate.
Definition: gui_def.h:61
Definition: defines.h:45
void setAlpha(int alpha)
int horizontalAdvance(const QString &text, int len) const const
void setAcceptHoverEvents(bool enabled)
void update(const QRectF &rect)
void drawLines(const QLineF *lines, int lineCount)
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
void drawText(const QPointF &position, const QString &text)
const QFont & font() const const
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
void addRect(const QRectF &rectangle)
qreal left() const const
qreal right() const const
void setHeight(qreal height)
void setLeft(qreal x)
void setRight(qreal x)
void setWidth(qreal width)
qreal width() const const
QString left(int n) const const
int size() const const
AlignLeft
void append(const T &value)