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