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