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 int Trace::LabelHitPadding = 2;
34 Trace::Trace(pv::SigSession &session, QString name) :
41 QString Trace::get_name() const
46 void Trace::set_name(QString name)
51 QColor Trace::get_colour() const
56 void Trace::set_colour(QColor colour)
61 int Trace::get_v_offset() const
66 void Trace::set_v_offset(int v_offset)
71 void Trace::set_view(pv::view::View *view)
77 void Trace::paint_label(QPainter &p, int right, bool hover)
80 const int y = _v_offset - _view->v_offset();
87 const QColor colour = get_colour();
90 const QRectF label_rect = get_label_rect(right);
93 const QPointF points[] = {
95 label_rect.topRight(),
97 label_rect.bottomRight(),
98 label_rect.bottomLeft()
101 const QPointF highlight_points[] = {
102 QPointF(label_rect.left() + 1, label_rect.top() + 1),
103 QPointF(label_rect.right(), label_rect.top() + 1),
104 QPointF(right - 1, y),
105 QPointF(label_rect.right(), label_rect.bottom() - 1),
106 QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
110 p.setPen(highlight_pen());
111 p.setBrush(Qt::transparent);
112 p.drawPolygon(points, countof(points));
115 p.setPen(Qt::transparent);
116 p.setBrush(hover ? colour.lighter() : colour);
117 p.drawPolygon(points, countof(points));
119 p.setPen(colour.lighter());
120 p.setBrush(Qt::transparent);
121 p.drawPolygon(highlight_points, countof(highlight_points));
123 p.setPen(colour.darker());
124 p.setBrush(Qt::transparent);
125 p.drawPolygon(points, countof(points));
128 p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
129 p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
132 bool Trace::pt_in_label_rect(int left, int right, const QPoint &point)
136 const QRectF label = get_label_rect(right);
138 QPointF(label.left() - LabelHitPadding,
139 label.top() - LabelHitPadding),
140 QPointF(right, label.bottom() + LabelHitPadding)
144 void Trace::compute_text_size(QPainter &p)
147 p.boundingRect(QRectF(), 0, _name).width(),
148 p.boundingRect(QRectF(), 0, "Tg").height());
151 QRectF Trace::get_label_rect(int right)
153 using pv::view::View;
156 const int y = _v_offset - _view->v_offset();
158 const QSizeF label_size(
159 _text_size.width() + View::LabelPadding.width() * 2,
160 ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
161 const float label_arrow_length = label_size.height() / 2;
163 right - label_arrow_length - label_size.width() - 0.5,
164 y + 0.5f - label_size.height() / 2,
165 label_size.width(), label_size.height());