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