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