]> sigrok.org Git - pulseview.git/blame - pv/views/trace/viewwidget.hpp
Fix compiler warnings
[pulseview.git] / pv / views / trace / viewwidget.hpp
CommitLineData
40aca27e
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
40aca27e
JH
18 */
19
7a01bd36
JH
20#ifndef PULSEVIEW_PV_VIEWWIDGET_HPP
21#define PULSEVIEW_PV_VIEWWIDGET_HPP
40aca27e 22
e9e4e5e7
JH
23#include <memory>
24
119c5c23 25#include <QPoint>
40aca27e
JH
26#include <QWidget>
27
4eba9990 28#include <pv/util.hpp>
29
6f925ba9
UH
30using std::shared_ptr;
31using std::vector;
32
c9743553
JH
33class QTouchEvent;
34
40aca27e 35namespace pv {
f4e57597 36namespace views {
1573bf16 37namespace trace {
219b3ab9 38
40aca27e 39class View;
e9e4e5e7 40class ViewItem;
40aca27e
JH
41
42class ViewWidget : public QWidget
43{
44 Q_OBJECT
45
46protected:
47 ViewWidget(View &parent);
48
e8b969a9
JH
49 /**
50 * Indicates when a view item is being hovered over.
51 * @param item The item that is being hovered over, or @c nullptr
52 * if no view item is being hovered over.
53 * @remarks the default implementation does nothing.
54 */
119c5c23 55 virtual void item_hover(const shared_ptr<ViewItem> &item, QPoint pos);
e8b969a9 56
e9e4e5e7
JH
57 /**
58 * Indicates the event an a view item has been clicked.
59 * @param item the view item that has been clicked.
60 * @remarks the default implementation does nothing.
61 */
6f925ba9 62 virtual void item_clicked(const shared_ptr<ViewItem> &item);
e9e4e5e7 63
b434cbaf
JH
64 /**
65 * Returns true if the selection of row items allows dragging.
66 * @return Returns true if the drag is acceptable.
67 */
68 bool accept_drag() const;
69
1f1edc09
JH
70 /**
71 * Returns true if the mouse button is down.
72 */
73 bool mouse_down() const;
74
1dffa582
JH
75 /**
76 * Drag the dragging items by the delta offset.
77 * @param delta the drag offset in pixels.
78 */
79 void drag_items(const QPoint &delta);
80
28290534
JH
81 /**
82 * Sets this item into the dragged state.
83 */
84 virtual void drag();
85
86 /**
87 * Drag the background by the delta offset.
88 * @param delta the drag offset in pixels.
89 * @remarks The default implementation does nothing.
90 */
91 virtual void drag_by(const QPoint &delta);
92
93 /**
94 * Sets this item into the un-dragged state.
95 */
96 virtual void drag_release();
97
e9e4e5e7
JH
98 /**
99 * Gets the items in the view widget.
100 */
6f925ba9 101 virtual vector< shared_ptr<ViewItem> > items() = 0;
e9e4e5e7
JH
102
103 /**
104 * Gets the first view item which has a hit-box that contains @c pt .
105 * @param pt the point to search with.
106 * @return the view item that has been found, or and empty
107 * @c shared_ptr if no item was found.
108 */
6f925ba9 109 virtual shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) = 0;
e9e4e5e7
JH
110
111 /**
112 * Handles left mouse button press events.
113 * @param event the mouse event that triggered this handler.
114 */
115 void mouse_left_press_event(QMouseEvent *event);
116
117 /**
118 * Handles left mouse button release events.
119 * @param event the mouse event that triggered this handler.
120 */
121 void mouse_left_release_event(QMouseEvent *event);
122
c9743553
JH
123 /**
124 * Handles touch begin update and end events.
125 * @param e the event that triggered this handler.
126 */
d9ea9628 127 virtual bool touch_event(QTouchEvent *event);
c9743553 128
e9e4e5e7 129protected:
c9743553
JH
130 bool event(QEvent *event);
131
d9ea9628 132 void mousePressEvent(QMouseEvent *event);
e9e4e5e7 133 void mouseReleaseEvent(QMouseEvent *event);
d9ea9628 134 void mouseMoveEvent(QMouseEvent *event);
e9e4e5e7 135
710c2a18 136 void keyPressEvent(QKeyEvent *event);
137 void keyReleaseEvent(QKeyEvent *event);
138
e9e4e5e7
JH
139 void leaveEvent(QEvent *event);
140
141public Q_SLOTS:
142 void clear_selection();
143
144Q_SIGNALS:
145 void selection_changed();
146
40aca27e 147protected:
1573bf16 148 pv::views::trace::View &view_;
e9e4e5e7
JH
149 QPoint mouse_point_;
150 QPoint mouse_down_point_;
4eba9990 151 pv::util::Timestamp mouse_down_offset_;
6f925ba9 152 shared_ptr<ViewItem> mouse_down_item_;
9f094349
SA
153
154 /// Keyboard modifiers that were active when mouse was last moved or clicked
155 Qt::KeyboardModifiers mouse_modifiers_;
156
803cdac4 157 bool item_dragging_;
40aca27e
JH
158};
159
1573bf16 160} // namespace trace
f4e57597 161} // namespace views
40aca27e
JH
162} // namespace pv
163
7a01bd36 164#endif // PULSEVIEW_PV_VIEWWIDGET_HPP