]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/view.h
Added cursors
[pulseview.git] / pv / view / view.h
... / ...
CommitLineData
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
32namespace pv {
33
34class SigSession;
35
36namespace view {
37
38class Header;
39class Ruler;
40class Viewport;
41
42class View : public QAbstractScrollArea {
43 Q_OBJECT
44
45private:
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
54public:
55 static const int SignalHeight;
56
57 static const QColor CursorAreaColour;
58
59public:
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
103signals:
104 void hover_point_changed();
105
106private:
107 void get_scroll_layout(double &length, double &offset) const;
108
109 void update_scroll();
110
111private:
112 bool eventFilter(QObject *object, QEvent *event);
113
114 bool viewportEvent(QEvent *e);
115
116 void resizeEvent(QResizeEvent *e);
117
118private slots:
119
120 void h_scroll_value_changed(int value);
121 void v_scroll_value_changed(int value);
122
123 void data_updated();
124
125private:
126 SigSession &_session;
127
128 Viewport *_viewport;
129 Ruler *_ruler;
130 Header *_header;
131
132 uint64_t _data_length;
133
134 /// The view time scale in seconds per pixel.
135 double _scale;
136
137 /// The view time offset in seconds.
138 double _offset;
139
140 int _v_offset;
141
142 bool _show_cursors;
143 std::pair<Cursor, Cursor> _cursors;
144
145 QPoint _hover_point;
146};
147
148} // namespace view
149} // namespace pv
150
151#endif // PULSEVIEW_PV_VIEW_VIEW_H