]> sigrok.org Git - pulseview.git/blob - pv/view/view.h
2fb9e7ff9ac646a7e7c012ae3dd9ae6ddf6dd25f
[pulseview.git] / pv / view / view.h
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         static bool compare_trace_v_offsets(
168                 const std::shared_ptr<pv::view::Trace> &a,
169                 const std::shared_ptr<pv::view::Trace> &b);
170
171 private:
172         bool eventFilter(QObject *object, QEvent *event);
173
174         bool viewportEvent(QEvent *e);
175
176         void resizeEvent(QResizeEvent *e);
177
178 private Q_SLOTS:
179
180         void h_scroll_value_changed(int value);
181         void v_scroll_value_changed(int value);
182
183         void signals_changed();
184         void data_updated();
185
186         void marker_time_changed();
187
188         void on_signals_moved();
189
190         void on_geometry_updated();
191
192 private:
193         SigSession &_session;
194
195         Viewport *_viewport;
196         Ruler *_ruler;
197         CursorHeader *_cursorheader;
198         Header *_header;
199
200         /// The view time scale in seconds per pixel.
201         double _scale;
202
203         /// The view time offset in seconds.
204         double _offset;
205
206         int _v_offset;
207         bool _updating_scroll;
208
209         bool _show_cursors;
210         CursorPair _cursors;
211
212         QPoint _hover_point;
213 };
214
215 } // namespace view
216 } // namespace pv
217
218 #endif // PULSEVIEW_PV_VIEW_VIEW_H