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