]> sigrok.org Git - pulseview.git/blame - pv/view/viewwidget.hpp
ViewWidget: Moved in event and touch_event
[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
21#ifndef PULSEVIEW_PV_VIEWWIDGET_H
22#define PULSEVIEW_PV_VIEWWIDGET_H
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
33class View;
e9e4e5e7 34class ViewItem;
40aca27e
JH
35
36class ViewWidget : public QWidget
37{
38 Q_OBJECT
39
40protected:
41 ViewWidget(View &parent);
42
e9e4e5e7
JH
43 /**
44 * Indicates the event an a view item has been clicked.
45 * @param item the view item that has been clicked.
46 * @remarks the default implementation does nothing.
47 */
48 virtual void item_clicked(
49 const std::shared_ptr<pv::view::ViewItem> &item);
50
b434cbaf
JH
51 /**
52 * Returns true if the selection of row items allows dragging.
53 * @return Returns true if the drag is acceptable.
54 */
55 bool accept_drag() const;
56
1f1edc09
JH
57 /**
58 * Returns true if the mouse button is down.
59 */
60 bool mouse_down() const;
61
1dffa582
JH
62 /**
63 * Drag the dragging items by the delta offset.
64 * @param delta the drag offset in pixels.
65 */
66 void drag_items(const QPoint &delta);
67
e9e4e5e7
JH
68 /**
69 * Gets the items in the view widget.
70 */
71 virtual std::vector< std::shared_ptr<pv::view::ViewItem> > items() = 0;
72
73 /**
74 * Gets the first view item which has a hit-box that contains @c pt .
75 * @param pt the point to search with.
76 * @return the view item that has been found, or and empty
77 * @c shared_ptr if no item was found.
78 */
79 virtual std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
80 const QPoint &pt) = 0;
81
82 /**
83 * Handles left mouse button press events.
84 * @param event the mouse event that triggered this handler.
85 */
86 void mouse_left_press_event(QMouseEvent *event);
87
88 /**
89 * Handles left mouse button release events.
90 * @param event the mouse event that triggered this handler.
91 */
92 void mouse_left_release_event(QMouseEvent *event);
93
c9743553
JH
94 /**
95 * Handles touch begin update and end events.
96 * @param e the event that triggered this handler.
97 */
98 virtual bool touch_event(QTouchEvent *e);
99
e9e4e5e7 100protected:
c9743553
JH
101 bool event(QEvent *event);
102
e9e4e5e7
JH
103 void mousePressEvent(QMouseEvent * event);
104 void mouseReleaseEvent(QMouseEvent *event);
105 void mouseMoveEvent(QMouseEvent *event);
106
107 void leaveEvent(QEvent *event);
108
109public Q_SLOTS:
110 void clear_selection();
111
112Q_SIGNALS:
113 void selection_changed();
114
40aca27e
JH
115protected:
116 pv::view::View &view_;
e9e4e5e7
JH
117 QPoint mouse_point_;
118 QPoint mouse_down_point_;
119 std::shared_ptr<ViewItem> mouse_down_item_;
803cdac4 120 bool item_dragging_;
40aca27e
JH
121};
122
123} // namespace view
124} // namespace pv
125
126#endif // PULSEVIEW_PV_VIEWWIDGET_H