]>
Commit | Line | Data |
---|---|---|
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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #ifndef PULSEVIEW_PV_VIEWWIDGET_HPP | |
21 | #define PULSEVIEW_PV_VIEWWIDGET_HPP | |
22 | ||
23 | #include <memory> | |
24 | ||
25 | #include <QPoint> | |
26 | #include <QWidget> | |
27 | ||
28 | #include <pv/util.hpp> | |
29 | ||
30 | using std::shared_ptr; | |
31 | using std::vector; | |
32 | ||
33 | class QTouchEvent; | |
34 | ||
35 | namespace pv { | |
36 | namespace views { | |
37 | namespace trace { | |
38 | ||
39 | class View; | |
40 | class ViewItem; | |
41 | ||
42 | class ViewWidget : public QWidget | |
43 | { | |
44 | Q_OBJECT | |
45 | ||
46 | protected: | |
47 | ViewWidget(View &parent); | |
48 | ||
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 | */ | |
55 | virtual void item_hover(const shared_ptr<ViewItem> &item, QPoint pos); | |
56 | ||
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(const shared_ptr<ViewItem> &item); | |
63 | ||
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 | ||
70 | /** | |
71 | * Returns true if the mouse button is down. | |
72 | */ | |
73 | bool mouse_down() const; | |
74 | ||
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 | ||
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 | ||
98 | /** | |
99 | * Gets the items in the view widget. | |
100 | */ | |
101 | virtual vector< shared_ptr<ViewItem> > items() = 0; | |
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 | */ | |
109 | virtual shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) = 0; | |
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 | ||
123 | /** | |
124 | * Handles touch begin update and end events. | |
125 | * @param e the event that triggered this handler. | |
126 | */ | |
127 | virtual bool touch_event(QTouchEvent *event); | |
128 | ||
129 | protected: | |
130 | bool event(QEvent *event); | |
131 | ||
132 | void mousePressEvent(QMouseEvent *event); | |
133 | void mouseReleaseEvent(QMouseEvent *event); | |
134 | void mouseMoveEvent(QMouseEvent *event); | |
135 | ||
136 | void leaveEvent(QEvent *event); | |
137 | ||
138 | public Q_SLOTS: | |
139 | void clear_selection(); | |
140 | ||
141 | Q_SIGNALS: | |
142 | void selection_changed(); | |
143 | ||
144 | protected: | |
145 | pv::views::trace::View &view_; | |
146 | QPoint mouse_point_; | |
147 | QPoint mouse_down_point_; | |
148 | pv::util::Timestamp mouse_down_offset_; | |
149 | shared_ptr<ViewItem> mouse_down_item_; | |
150 | bool item_dragging_; | |
151 | }; | |
152 | ||
153 | } // namespace trace | |
154 | } // namespace views | |
155 | } // namespace pv | |
156 | ||
157 | #endif // PULSEVIEW_PV_VIEWWIDGET_HPP |