]>
Commit | Line | Data |
---|---|---|
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 | ||
37 | namespace pv { | |
38 | ||
39 | class SigSession; | |
40 | ||
41 | namespace view { | |
42 | ||
43 | class CursorHeader; | |
44 | class Header; | |
45 | class Ruler; | |
46 | class Trace; | |
47 | class Viewport; | |
48 | ||
49 | class View : public QAbstractScrollArea { | |
50 | Q_OBJECT | |
51 | ||
52 | private: | |
53 | static const double MaxScale; | |
54 | static const double MinScale; | |
55 | ||
56 | static const int MaxScrollValue; | |
57 | ||
58 | public: | |
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 | ||
67 | public: | |
68 | explicit View(SigSession &session, QWidget *parent = 0); | |
69 | ||
70 | SigSession& session(); | |
71 | const SigSession& session() const; | |
72 | ||
73 | Viewport* viewport(); | |
74 | ||
75 | const Viewport* viewport() const; | |
76 | ||
77 | /** | |
78 | * Returns the view time scale in seconds per pixel. | |
79 | */ | |
80 | double scale() const; | |
81 | ||
82 | /** | |
83 | * Returns the time offset of the left edge of the view in | |
84 | * seconds. | |
85 | */ | |
86 | double offset() const; | |
87 | int v_offset() const; | |
88 | ||
89 | void zoom(double steps); | |
90 | void zoom(double steps, int offset); | |
91 | ||
92 | void zoom_fit(); | |
93 | ||
94 | void zoom_one_to_one(); | |
95 | ||
96 | /** | |
97 | * Sets the scale and offset. | |
98 | * @param scale The new view scale in seconds per pixel. | |
99 | * @param offset The view time offset in seconds. | |
100 | */ | |
101 | void set_scale_offset(double scale, double offset); | |
102 | ||
103 | std::vector< std::shared_ptr<Trace> > get_traces() const; | |
104 | ||
105 | std::list<std::weak_ptr<SelectableItem> > selected_items() const; | |
106 | ||
107 | std::set< std::shared_ptr<pv::data::SignalData> > | |
108 | get_visible_data() const; | |
109 | ||
110 | std::pair<double, double> get_time_extents() const; | |
111 | ||
112 | /** | |
113 | * Returns true if cursors are displayed. false otherwise. | |
114 | */ | |
115 | bool cursors_shown() const; | |
116 | ||
117 | /** | |
118 | * Shows or hides the cursors. | |
119 | */ | |
120 | void show_cursors(bool show = true); | |
121 | ||
122 | /** | |
123 | * Moves the cursors to a convenient position in the view. | |
124 | */ | |
125 | void centre_cursors(); | |
126 | ||
127 | /** | |
128 | * Returns a reference to the pair of cursors. | |
129 | */ | |
130 | CursorPair& cursors(); | |
131 | ||
132 | /** | |
133 | * Returns a reference to the pair of cursors. | |
134 | */ | |
135 | const CursorPair& cursors() const; | |
136 | ||
137 | const QPoint& hover_point() const; | |
138 | ||
139 | void normalize_layout(); | |
140 | ||
141 | void update_viewport(); | |
142 | ||
143 | Q_SIGNALS: | |
144 | void hover_point_changed(); | |
145 | ||
146 | void signals_moved(); | |
147 | ||
148 | void selection_changed(); | |
149 | ||
150 | void scale_offset_changed(); | |
151 | ||
152 | private: | |
153 | void get_scroll_layout(double &length, double &offset) const; | |
154 | ||
155 | /** | |
156 | * Simultaneously sets the zoom and offset. | |
157 | * @param scale The scale to set the view to in seconds per pixel. This | |
158 | * value is clamped between MinScale and MaxScale. | |
159 | * @param offset The offset of the left edge of the view in seconds. | |
160 | */ | |
161 | void set_zoom(double scale, int offset); | |
162 | ||
163 | void update_scroll(); | |
164 | ||
165 | void update_layout(); | |
166 | ||
167 | private: | |
168 | bool eventFilter(QObject *object, QEvent *event); | |
169 | ||
170 | bool viewportEvent(QEvent *e); | |
171 | ||
172 | void resizeEvent(QResizeEvent *e); | |
173 | ||
174 | private 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 | ||
188 | void on_hover_point_changed(); | |
189 | ||
190 | private: | |
191 | SigSession &_session; | |
192 | ||
193 | Viewport *_viewport; | |
194 | Ruler *_ruler; | |
195 | CursorHeader *_cursorheader; | |
196 | Header *_header; | |
197 | ||
198 | /// The view time scale in seconds per pixel. | |
199 | double _scale; | |
200 | ||
201 | /// The view time offset in seconds. | |
202 | double _offset; | |
203 | ||
204 | int _v_offset; | |
205 | bool _updating_scroll; | |
206 | ||
207 | bool _show_cursors; | |
208 | CursorPair _cursors; | |
209 | ||
210 | QPoint _hover_point; | |
211 | }; | |
212 | ||
213 | } // namespace view | |
214 | } // namespace pv | |
215 | ||
216 | #endif // PULSEVIEW_PV_VIEW_VIEW_H |