]> sigrok.org Git - pulseview.git/blob - pv/view/view.h
62157eed76a5613e552571aa0a0e322be3a23c3a
[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 <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
39 namespace pv {
40
41 class SigSession;
42
43 namespace view {
44
45 class Header;
46 class Ruler;
47 class Trace;
48 class Viewport;
49
50 class View : public QAbstractScrollArea {
51         Q_OBJECT
52
53 private:
54         static const double MaxScale;
55         static const double MinScale;
56
57         static const int MaxScrollValue;
58
59 public:
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
68 public:
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
140 signals:
141         void hover_point_changed();
142
143         void signals_moved();
144
145         void selection_changed();
146
147         void scale_offset_changed();
148
149 private:
150         void get_scroll_layout(double &length, double &offset) const;
151         
152         void set_zoom(double scale, int offset);
153
154         void update_scroll();
155
156         void update_layout();
157
158         static bool compare_trace_v_offsets(
159                 const boost::shared_ptr<pv::view::Trace> &a,
160                 const boost::shared_ptr<pv::view::Trace> &b);
161
162 private:
163         bool eventFilter(QObject *object, QEvent *event);
164
165         bool viewportEvent(QEvent *e);
166
167         void resizeEvent(QResizeEvent *e);
168
169 private slots:
170
171         void h_scroll_value_changed(int value);
172         void v_scroll_value_changed(int value);
173
174         void signals_changed();
175         void data_updated();
176
177         void marker_time_changed();
178
179         void on_signals_moved();
180
181         void on_geometry_updated();
182
183 private:
184         SigSession &_session;
185
186         Viewport *_viewport;
187         Ruler *_ruler;
188         Header *_header;
189
190         /// The view time scale in seconds per pixel.
191         double _scale;
192
193         /// The view time offset in seconds.
194         double _offset;
195
196         int _v_offset;
197         bool _updating_scroll;
198
199         bool _show_cursors;
200         CursorPair _cursors;
201
202         QPoint _hover_point;
203 };
204
205 } // namespace view
206 } // namespace pv
207
208 #endif // PULSEVIEW_PV_VIEW_VIEW_H