2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 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
26 #include <QApplication>
34 const int Signal::LabelHitPadding = 2;
35 const int Signal::LabelHighlightRadius = 6;
37 const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64));
39 Signal::Signal(const sr_probe *const probe) :
47 QString Signal::get_name() const
52 void Signal::set_name(QString name)
57 QColor Signal::get_colour() const
62 void Signal::set_colour(QColor colour)
67 int Signal::get_v_offset() const
72 void Signal::set_v_offset(int v_offset)
77 void Signal::paint_label(QPainter &p, int y, int right, bool hover)
84 const QColor colour = get_colour();
87 const QRectF label_rect = get_label_rect(y, right);
90 const QPointF points[] = {
92 label_rect.topRight(),
94 label_rect.bottomRight(),
95 label_rect.bottomLeft()
98 const QPointF highlight_points[] = {
99 QPointF(label_rect.left() + 1, label_rect.top() + 1),
100 QPointF(label_rect.right(), label_rect.top() + 1),
101 QPointF(right - 1, y),
102 QPointF(label_rect.right(), label_rect.bottom() - 1),
103 QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
107 p.setPen(QPen(QApplication::palette().brush(
108 QPalette::Highlight), LabelHighlightRadius,
109 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
110 p.setBrush(Qt::transparent);
111 p.drawPolygon(points, countof(points));
114 p.setPen(Qt::transparent);
115 p.setBrush(hover ? colour.lighter() : colour);
116 p.drawPolygon(points, countof(points));
118 p.setPen(colour.lighter());
119 p.setBrush(Qt::transparent);
120 p.drawPolygon(highlight_points, countof(highlight_points));
122 p.setPen(colour.darker());
123 p.setBrush(Qt::transparent);
124 p.drawPolygon(points, countof(points));
127 p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
128 p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
131 bool Signal::pt_in_label_rect(int y, int left, int right,
136 const QRectF label = get_label_rect(y, right);
138 QPointF(label.left() - LabelHitPadding,
139 label.top() - LabelHitPadding),
140 QPointF(right, label.bottom() + LabelHitPadding)
144 void Signal::paint_axis(QPainter &p, int y, int left, int right)
146 p.setPen(SignalAxisPen);
147 p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
150 void Signal::compute_text_size(QPainter &p)
153 p.boundingRect(QRectF(), 0, _name).width(),
154 p.boundingRect(QRectF(), 0, "Tg").height());
157 QRectF Signal::get_label_rect(int y, int right)
159 using pv::view::View;
161 const QSizeF label_size(
162 _text_size.width() + View::LabelPadding.width() * 2,
163 ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
164 const float label_arrow_length = label_size.height() / 2;
166 right - label_arrow_length - label_size.width() - 0.5,
167 y + 0.5f - label_size.height() / 2,
168 label_size.width(), label_size.height());