]> sigrok.org Git - pulseview.git/blame - pv/views/trace/trace.hpp
Move trace view files
[pulseview.git] / pv / views / trace / trace.hpp
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
931f20b0
JH
18 */
19
f4e57597
SA
20#ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_TRACE_HPP
21#define PULSEVIEW_PV_VIEWS_TRACEVIEW_TRACE_HPP
931f20b0
JH
22
23#include <QColor>
24#include <QPainter>
fe08b6e8 25#include <QPen>
931f20b0
JH
26#include <QRect>
27#include <QString>
28
cafe470e 29#include <cstdint>
931f20b0 30
af503b10 31#include "tracetreeitem.hpp"
931f20b0 32
bf0edd2b
SA
33#include "pv/data/signalbase.hpp"
34
6f925ba9
UH
35using std::shared_ptr;
36
b213ef09
JH
37class QFormLayout;
38
931f20b0 39namespace pv {
931f20b0 40
5ed05b69
SA
41namespace data {
42class SignalBase;
43}
44
23935421
JH
45namespace widgets {
46class Popup;
47}
48
f4e57597 49namespace views {
1573bf16 50namespace trace {
01fd3263 51
af503b10 52class Trace : public TraceTreeItem
931f20b0
JH
53{
54 Q_OBJECT
55
56private:
fe08b6e8 57 static const QPen AxisPen;
931f20b0
JH
58 static const int LabelHitPadding;
59
d55923a6
SA
60 static const QColor BrightGrayBGColour;
61 static const QColor DarkGrayBGColour;
ac0708fb 62
931f20b0 63protected:
6f925ba9 64 Trace(shared_ptr<data::SignalBase> channel);
931f20b0
JH
65
66public:
5ed05b69
SA
67 /**
68 * Returns the underlying SignalBase instance.
69 */
70 shared_ptr<data::SignalBase> base() const;
71
931f20b0
JH
72 /**
73 * Sets the name of the signal.
74 */
75 virtual void set_name(QString name);
76
931f20b0
JH
77 /**
78 * Set the colour of the signal.
79 */
bf0edd2b 80 virtual void set_colour(QColor colour);
931f20b0 81
931f20b0 82 /**
7db87de3 83 * Paints the signal label.
931f20b0 84 * @param p the QPainter to paint into.
b3f44329 85 * @param rect the rectangle of the header area.
931f20b0
JH
86 * @param hover true if the label is being hovered over by the mouse.
87 */
b3f44329 88 virtual void paint_label(QPainter &p, const QRect &rect, bool hover);
931f20b0 89
9b6378f1
JH
90 virtual QMenu* create_context_menu(QWidget *parent);
91
569d1e41
JH
92 pv::widgets::Popup* create_popup(QWidget *parent);
93
d7c0ca4a
JH
94 /**
95 * Computes the outline rectangle of a label.
b3f44329 96 * @param rect the rectangle of the header area.
d7c0ca4a
JH
97 * @return Returns the rectangle of the signal label.
98 */
b3f44329 99 QRectF label_rect(const QRectF &rect) const;
d7c0ca4a 100
569d1e41 101protected:
99af6802 102 /**
5d738861
UH
103 * Paints the background layer of the signal with a QPainter.
104 * @param p The QPainter to paint into.
105 * @param pp The painting parameters object to paint with.
99af6802 106 */
60938e04 107 virtual void paint_back(QPainter &p, ViewItemPaintParams &pp);
99af6802 108
fe08b6e8
JH
109 /**
110 * Paints a zero axis across the viewport.
111 * @param p the QPainter to paint into.
97904bf7 112 * @param pp the painting parameters object to paint with.
fe08b6e8 113 * @param y the y-offset of the axis.
fe08b6e8 114 */
60938e04 115 void paint_axis(QPainter &p, ViewItemPaintParams &pp, int y);
fe08b6e8 116
91e8bf08
JH
117 void add_colour_option(QWidget *parent, QFormLayout *form);
118
37fd11b1
JH
119 void create_popup_form();
120
569d1e41
JH
121 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
122
bf0edd2b
SA
123protected Q_SLOTS:
124 virtual void on_name_changed(const QString &text);
68456dab 125
bf0edd2b 126 virtual void on_colour_changed(const QColor &colour);
91e8bf08 127
20eaae39
JH
128 void on_popup_closed();
129
bf0edd2b
SA
130private Q_SLOTS:
131 void on_nameedit_changed(const QString &name);
132
133 void on_colouredit_changed(const QColor &colour);
134
931f20b0 135protected:
6f925ba9 136 shared_ptr<data::SignalBase> base_;
931f20b0 137
37fd11b1 138private:
8dbbc7f0
JH
139 pv::widgets::Popup *popup_;
140 QFormLayout *popup_form_;
931f20b0
JH
141};
142
1573bf16 143} // namespace trace
f4e57597 144} // namespace views
931f20b0
JH
145} // namespace pv
146
f4e57597 147#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_TRACE_HPP