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