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