2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 const QPen Trace::AxisPen(QColor(128, 128, 128, 64));
33 const int Trace::LabelHitPadding = 2;
35 Trace::Trace(pv::SigSession &session, QString name) :
42 QString Trace::get_name() const
47 void Trace::set_name(QString name)
52 QColor Trace::get_colour() const
57 void Trace::set_colour(QColor colour)
62 int Trace::get_v_offset() const
67 void Trace::set_v_offset(int v_offset)
72 void Trace::set_view(pv::view::View *view)
78 void Trace::paint_back(QPainter &p, int left, int right)
85 void Trace::paint_mid(QPainter &p, int left, int right)
92 void Trace::paint_fore(QPainter &p, int left, int right)
99 void Trace::paint_label(QPainter &p, int right, bool hover)
102 const int y = _v_offset - _view->v_offset();
109 const QColor colour = get_colour();
111 compute_text_size(p);
112 const QRectF label_rect = get_label_rect(right);
115 const QPointF points[] = {
116 label_rect.topLeft(),
117 label_rect.topRight(),
119 label_rect.bottomRight(),
120 label_rect.bottomLeft()
123 const QPointF highlight_points[] = {
124 QPointF(label_rect.left() + 1, label_rect.top() + 1),
125 QPointF(label_rect.right(), label_rect.top() + 1),
126 QPointF(right - 1, y),
127 QPointF(label_rect.right(), label_rect.bottom() - 1),
128 QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
132 p.setPen(highlight_pen());
133 p.setBrush(Qt::transparent);
134 p.drawPolygon(points, countof(points));
137 p.setPen(Qt::transparent);
138 p.setBrush(hover ? colour.lighter() : colour);
139 p.drawPolygon(points, countof(points));
141 p.setPen(colour.lighter());
142 p.setBrush(Qt::transparent);
143 p.drawPolygon(highlight_points, countof(highlight_points));
145 p.setPen(colour.darker());
146 p.setBrush(Qt::transparent);
147 p.drawPolygon(points, countof(points));
150 p.setPen(get_text_colour());
151 p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
154 bool Trace::pt_in_label_rect(int left, int right, const QPoint &point)
158 const QRectF label = get_label_rect(right);
160 QPointF(label.left() - LabelHitPadding,
161 label.top() - LabelHitPadding),
162 QPointF(right, label.bottom() + LabelHitPadding)
166 int Trace::get_y() const
168 return _v_offset - _view->v_offset();
171 QColor Trace::get_text_colour() const
173 return (_colour.lightness() > 64) ? Qt::black : Qt::white;
176 void Trace::paint_axis(QPainter &p, int y, int left, int right)
179 p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
182 void Trace::compute_text_size(QPainter &p)
185 p.boundingRect(QRectF(), 0, _name).width(),
186 p.boundingRect(QRectF(), 0, "Tg").height());
189 QRectF Trace::get_label_rect(int right)
191 using pv::view::View;
194 const int y = _v_offset - _view->v_offset();
196 const QSizeF label_size(
197 _text_size.width() + View::LabelPadding.width() * 2,
198 ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
199 const float label_arrow_length = label_size.height() / 2;
201 right - label_arrow_length - label_size.width() - 0.5,
202 y + 0.5f - label_size.height() / 2,
203 label_size.width(), label_size.height());