]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/view.h
Rename 'probe' to 'channel' (libsigrokdecode change).
[pulseview.git] / pv / view / view.h
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
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
21#ifndef PULSEVIEW_PV_VIEW_VIEW_H
22#define PULSEVIEW_PV_VIEW_VIEW_H
23
24#include <stdint.h>
25
26#include <set>
27#include <vector>
28
29#include <boost/shared_ptr.hpp>
30#include <boost/weak_ptr.hpp>
31
32#include <QAbstractScrollArea>
33#include <QSizeF>
34
35#include <pv/data/signaldata.h>
36
37#include "cursorpair.h"
38
39namespace pv {
40
41class SigSession;
42
43namespace view {
44
45class Header;
46class Ruler;
47class Trace;
48class Viewport;
49
50class View : public QAbstractScrollArea {
51 Q_OBJECT
52
53private:
54 static const double MaxScale;
55 static const double MinScale;
56
57 static const int MaxScrollValue;
58
59public:
60 static const int SignalHeight;
61 static const int SignalMargin;
62 static const int SignalSnapGridSize;
63
64 static const QColor CursorAreaColour;
65
66 static const QSizeF LabelPadding;
67
68public:
69 explicit View(SigSession &session, QWidget *parent = 0);
70
71 SigSession& session();
72 const SigSession& session() const;
73
74 /**
75 * Returns the view time scale in seconds per pixel.
76 */
77 double scale() const;
78
79 /**
80 * Returns the time offset of the left edge of the view in
81 * seconds.
82 */
83 double offset() const;
84 int v_offset() const;
85
86 void zoom(double steps);
87 void zoom(double steps, int offset);
88
89 void zoom_fit();
90
91 void zoom_one_to_one();
92
93 /**
94 * Sets the scale and offset.
95 * @param scale The new view scale in seconds per pixel.
96 * @param offset The view time offset in seconds.
97 */
98 void set_scale_offset(double scale, double offset);
99
100 std::vector< boost::shared_ptr<Trace> > get_traces() const;
101
102 std::list<boost::weak_ptr<SelectableItem> > selected_items() const;
103
104 std::set< boost::shared_ptr<pv::data::SignalData> >
105 get_visible_data() const;
106
107 std::pair<double, double> get_time_extents() const;
108
109 /**
110 * Returns true if cursors are displayed. false otherwise.
111 */
112 bool cursors_shown() const;
113
114 /**
115 * Shows or hides the cursors.
116 */
117 void show_cursors(bool show = true);
118
119 /**
120 * Moves the cursors to a convenient position in the view.
121 */
122 void centre_cursors();
123
124 /**
125 * Returns a reference to the pair of cursors.
126 */
127 CursorPair& cursors();
128
129 /**
130 * Returns a reference to the pair of cursors.
131 */
132 const CursorPair& cursors() const;
133
134 const QPoint& hover_point() const;
135
136 void normalize_layout();
137
138 void update_viewport();
139
140signals:
141 void hover_point_changed();
142
143 void signals_moved();
144
145 void selection_changed();
146
147 void scale_offset_changed();
148
149private:
150 void get_scroll_layout(double &length, double &offset) const;
151
152 /**
153 * Simultaneously sets the zoom and offset.
154 * @param scale The scale to set the view to in seconds per pixel. This
155 * value is clamped between MinScale and MaxScale.
156 * @param offset The offset of the left edge of the view in seconds.
157 */
158 void set_zoom(double scale, int offset);
159
160 void update_scroll();
161
162 void update_layout();
163
164 static bool compare_trace_v_offsets(
165 const boost::shared_ptr<pv::view::Trace> &a,
166 const boost::shared_ptr<pv::view::Trace> &b);
167
168private:
169 bool eventFilter(QObject *object, QEvent *event);
170
171 bool viewportEvent(QEvent *e);
172
173 void resizeEvent(QResizeEvent *e);
174
175private slots:
176
177 void h_scroll_value_changed(int value);
178 void v_scroll_value_changed(int value);
179
180 void signals_changed();
181 void data_updated();
182
183 void marker_time_changed();
184
185 void on_signals_moved();
186
187 void on_geometry_updated();
188
189private:
190 SigSession &_session;
191
192 Viewport *_viewport;
193 Ruler *_ruler;
194 Header *_header;
195
196 /// The view time scale in seconds per pixel.
197 double _scale;
198
199 /// The view time offset in seconds.
200 double _offset;
201
202 int _v_offset;
203 bool _updating_scroll;
204
205 bool _show_cursors;
206 CursorPair _cursors;
207
208 QPoint _hover_point;
209};
210
211} // namespace view
212} // namespace pv
213
214#endif // PULSEVIEW_PV_VIEW_VIEW_H