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