]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/viewwidget.hpp
MainWindow: Fix session error slot declaration
[pulseview.git] / pv / view / viewwidget.hpp
... / ...
CommitLineData
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_HPP
22#define PULSEVIEW_PV_VIEWWIDGET_HPP
23
24#include <memory>
25
26#include <QWidget>
27
28class QTouchEvent;
29
30namespace pv {
31namespace views {
32namespace TraceView {
33
34class View;
35class ViewItem;
36
37class ViewWidget : public QWidget
38{
39 Q_OBJECT
40
41protected:
42 ViewWidget(View &parent);
43
44 /**
45 * Indicates when a view item is being hovered over.
46 * @param item The item that is being hovered over, or @c nullptr
47 * if no view item is being hovered over.
48 * @remarks the default implementation does nothing.
49 */
50 virtual void item_hover(
51 const std::shared_ptr<ViewItem> &item);
52
53 /**
54 * Indicates the event an a view item has been clicked.
55 * @param item the view item that has been clicked.
56 * @remarks the default implementation does nothing.
57 */
58 virtual void item_clicked(
59 const std::shared_ptr<ViewItem> &item);
60
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
67 /**
68 * Returns true if the mouse button is down.
69 */
70 bool mouse_down() const;
71
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
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
95 /**
96 * Gets the items in the view widget.
97 */
98 virtual std::vector< std::shared_ptr<ViewItem> > items() = 0;
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 */
106 virtual std::shared_ptr<ViewItem> get_mouse_over_item(
107 const QPoint &pt) = 0;
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
121 /**
122 * Handles touch begin update and end events.
123 * @param e the event that triggered this handler.
124 */
125 virtual bool touch_event(QTouchEvent *event);
126
127protected:
128 bool event(QEvent *event);
129
130 void mousePressEvent(QMouseEvent *event);
131 void mouseReleaseEvent(QMouseEvent *event);
132 void mouseMoveEvent(QMouseEvent *event);
133
134 void leaveEvent(QEvent *event);
135
136public Q_SLOTS:
137 void clear_selection();
138
139Q_SIGNALS:
140 void selection_changed();
141
142protected:
143 pv::views::TraceView::View &view_;
144 QPoint mouse_point_;
145 QPoint mouse_down_point_;
146 std::shared_ptr<ViewItem> mouse_down_item_;
147 bool item_dragging_;
148};
149
150} // namespace TraceView
151} // namespace views
152} // namespace pv
153
154#endif // PULSEVIEW_PV_VIEWWIDGET_HPP