]> sigrok.org Git - pulseview.git/blame - pv/view/trace.h
Moved text colour calculation into Trace::get_text_colour
[pulseview.git] / pv / view / trace.h
CommitLineData
931f20b0
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 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
21#ifndef PULSEVIEW_PV_TRACE_H
22#define PULSEVIEW_PV_TRACE_H
23
24#include <QColor>
25#include <QPainter>
fe08b6e8 26#include <QPen>
931f20b0
JH
27#include <QRect>
28#include <QString>
29
30#include <stdint.h>
31
32#include "selectableitem.h"
33
34namespace pv {
35
36class SigSession;
37
38namespace view {
39
01fd3263
JH
40class View;
41
931f20b0
JH
42class Trace : public SelectableItem
43{
44 Q_OBJECT
45
46private:
fe08b6e8 47 static const QPen AxisPen;
931f20b0
JH
48 static const int LabelHitPadding;
49
50protected:
51 Trace(SigSession &session, QString name);
52
53public:
54 /**
55 * Gets the name of this signal.
56 */
57 QString get_name() const;
58
59 /**
60 * Sets the name of the signal.
61 */
62 virtual void set_name(QString name);
63
64 /**
65 * Get the colour of the signal.
66 */
67 QColor get_colour() const;
68
69 /**
70 * Set the colour of the signal.
71 */
72 void set_colour(QColor colour);
73
74 /**
75 * Gets the vertical layout offset of this signal.
76 */
77 int get_v_offset() const;
78
79 /**
80 * Sets the vertical layout offset of this signal.
81 */
82 void set_v_offset(int v_offset);
83
84 /**
85 * Returns true if the trace is visible and enabled.
86 */
87 virtual bool enabled() const = 0;
88
e0fc5810 89 virtual void set_view(pv::view::View *view);
01fd3263 90
931f20b0 91 /**
fe08b6e8 92 * Paints the background layer of the trace with a QPainter
931f20b0 93 * @param p the QPainter to paint into.
931f20b0
JH
94 * @param left the x-coordinate of the left edge of the signal
95 * @param right the x-coordinate of the right edge of the signal
931f20b0 96 **/
fe08b6e8
JH
97 virtual void paint_back(QPainter &p, int left, int right);
98
99 /**
100 * Paints the mid-layer of the trace with a QPainter
101 * @param p the QPainter to paint into.
102 * @param left the x-coordinate of the left edge of the signal
103 * @param right the x-coordinate of the right edge of the signal
104 **/
105 virtual void paint_mid(QPainter &p, int left, int right);
106
107 /**
108 * Paints the foreground layer of the trace with a QPainter
109 * @param p the QPainter to paint into.
110 * @param left the x-coordinate of the left edge of the signal
111 * @param right the x-coordinate of the right edge of the signal
112 **/
113 virtual void paint_fore(QPainter &p, int left, int right);
931f20b0
JH
114
115 /**
116 * Paints the signal label into a QGLWidget.
117 * @param p the QPainter to paint into.
931f20b0
JH
118 * @param right the x-coordinate of the right edge of the header
119 * area.
120 * @param hover true if the label is being hovered over by the mouse.
121 */
01fd3263 122 virtual void paint_label(QPainter &p, int right, bool hover);
931f20b0
JH
123
124 /**
125 * Determines if a point is in the header label rect.
931f20b0
JH
126 * @param left the x-coordinate of the left edge of the header
127 * area.
128 * @param right the x-coordinate of the right edge of the header
129 * area.
130 * @param point the point to test.
131 */
01fd3263 132 bool pt_in_label_rect(int left, int right, const QPoint &point);
931f20b0 133
fe08b6e8
JH
134protected:
135 /**
136 * Gets the y-offset of the axis.
137 */
138 int get_y() const;
139
410f9c81
JH
140 /**
141 * Gets the text colour.
142 * @remarks This colour is computed by comparing the lightness
143 * of the trace colour against a threshold to determine whether
144 * white or black would be more visible.
145 */
146 QColor get_text_colour() const;
147
fe08b6e8
JH
148 /**
149 * Paints a zero axis across the viewport.
150 * @param p the QPainter to paint into.
151 * @param y the y-offset of the axis.
152 * @param left the x-coordinate of the left edge of the view.
153 * @param right the x-coordinate of the right edge of the view.
154 */
155 void paint_axis(QPainter &p, int y, int left, int right);
156
931f20b0
JH
157private:
158
159 /**
160 * Computes an caches the size of the label text.
161 */
162 void compute_text_size(QPainter &p);
163
164 /**
165 * Computes the outline rectangle of a label.
166 * @param p the QPainter to lay out text with.
931f20b0
JH
167 * @param right the x-coordinate of the right edge of the header
168 * area.
169 * @return Returns the rectangle of the signal label.
170 */
01fd3263 171 QRectF get_label_rect(int right);
931f20b0
JH
172
173signals:
174 void text_changed();
175
176protected:
177 pv::SigSession &_session;
01fd3263 178 pv::view::View *_view;
931f20b0
JH
179
180 QString _name;
181 QColor _colour;
182 int _v_offset;
183
184 QSizeF _text_size;
185};
186
187} // namespace view
188} // namespace pv
189
190#endif // PULSEVIEW_PV_TRACEL_H