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