]>
Commit | Line | Data |
---|---|---|
28a4c9c5 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
28a4c9c5 JH |
3 | * |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
cef18fc6 | 21 | #include <extdef.h> |
28a4c9c5 | 22 | |
cef18fc6 | 23 | #include "signal.h" |
3e46726a | 24 | |
51e77110 JH |
25 | namespace pv { |
26 | ||
3e46726a | 27 | const QSizeF Signal::LabelPadding(4, 0); |
28a4c9c5 | 28 | |
2858b391 JH |
29 | Signal::Signal(QString name) : |
30 | _name(name) | |
28a4c9c5 JH |
31 | { |
32 | } | |
33 | ||
34 | QString Signal::get_name() const | |
35 | { | |
36 | return _name; | |
37 | } | |
3e46726a | 38 | |
3b258424 | 39 | QRectF Signal::get_label_rect(QPainter &p, const QRect &rect) |
3e46726a | 40 | { |
3e46726a | 41 | const QSizeF text_size = p.boundingRect( |
3b258424 | 42 | QRectF(0, 0, rect.width(), 0), 0, _name).size(); |
3e46726a JH |
43 | |
44 | const float nominal_offset = get_nominal_offset(rect); | |
45 | const QSizeF label_size( | |
46 | text_size.width() + LabelPadding.width() * 2, | |
47 | text_size.height() + LabelPadding.height() * 2); | |
48 | const float label_arrow_length = label_size.height() / 2; | |
3b258424 | 49 | return QRectF( |
3e46726a JH |
50 | rect.right() - label_arrow_length - label_size.width(), |
51 | nominal_offset - label_size.height() / 2, | |
52 | label_size.width(), label_size.height()); | |
3b258424 JH |
53 | } |
54 | ||
55 | void Signal::paint_label(QPainter &p, const QRect &rect) | |
56 | { | |
57 | p.setBrush(get_colour()); | |
58 | ||
59 | const QColor colour = get_colour(); | |
60 | const float nominal_offset = get_nominal_offset(rect); | |
61 | const QRectF label_rect = get_label_rect(p, rect); | |
3e46726a JH |
62 | |
63 | // Paint the label | |
64 | const QPointF points[] = { | |
65 | label_rect.topLeft(), | |
66 | label_rect.topRight(), | |
67 | QPointF(rect.right(), nominal_offset), | |
68 | label_rect.bottomRight(), | |
69 | label_rect.bottomLeft() | |
70 | }; | |
71 | ||
c9b6acc1 JH |
72 | const QPointF highlight_points[] = { |
73 | QPointF(label_rect.left() + 1, label_rect.top() + 1), | |
74 | QPointF(label_rect.right(), label_rect.top() + 1), | |
75 | QPointF(rect.right() - 1, nominal_offset), | |
76 | QPointF(label_rect.right(), label_rect.bottom() - 1), | |
77 | QPointF(label_rect.left() + 1, label_rect.bottom() - 1) | |
78 | }; | |
79 | ||
80 | p.setPen(Qt::transparent); | |
3e46726a JH |
81 | p.setBrush(colour); |
82 | p.drawPolygon(points, countof(points)); | |
83 | ||
c9b6acc1 JH |
84 | p.setPen(colour.lighter()); |
85 | p.setBrush(Qt::transparent); | |
86 | p.drawPolygon(highlight_points, countof(highlight_points)); | |
87 | ||
88 | p.setPen(colour.darker()); | |
89 | p.setBrush(Qt::transparent); | |
90 | p.drawPolygon(points, countof(points)); | |
91 | ||
3e46726a JH |
92 | // Paint the text |
93 | p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white); | |
3b258424 | 94 | p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); |
3e46726a | 95 | } |
51e77110 JH |
96 | |
97 | } // namespace pv |