2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
20 #ifndef PULSEVIEW_PV_VIEWS_TRACE_VIEWWIDGET_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACE_VIEWWIDGET_HPP
28 #include <pv/util.hpp>
30 using std::shared_ptr;
42 class ViewWidget : public QWidget
47 ViewWidget(View &parent);
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.
55 virtual void item_hover(const shared_ptr<ViewItem> &item, QPoint pos);
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.
62 virtual void item_clicked(const shared_ptr<ViewItem> &item);
65 * Returns true if the selection of row items allows dragging.
66 * @return Returns true if the drag is acceptable.
68 bool accept_drag() const;
71 * Returns true if the mouse button is down.
73 bool mouse_down() const;
76 * Drag the dragging items by the delta offset.
77 * @param delta the drag offset in pixels.
79 void drag_items(const QPoint &delta);
82 * Sets this item into the dragged state.
87 * Drag the background by the delta offset.
88 * @param delta the drag offset in pixels.
89 * @remarks The default implementation does nothing.
91 virtual void drag_by(const QPoint &delta);
94 * Sets this item into the un-dragged state.
96 virtual void drag_release();
99 * Gets the items in the view widget.
101 virtual vector< shared_ptr<ViewItem> > items() = 0;
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.
109 virtual shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) = 0;
112 * Handles left mouse button press events.
113 * @param event the mouse event that triggered this handler.
115 void mouse_left_press_event(QMouseEvent *event);
118 * Handles left mouse button release events.
119 * @param event the mouse event that triggered this handler.
121 void mouse_left_release_event(QMouseEvent *event);
124 * Handles touch begin update and end events.
125 * @param e the event that triggered this handler.
127 virtual bool touch_event(QTouchEvent *event);
130 bool event(QEvent *event);
132 void mousePressEvent(QMouseEvent *event);
133 void mouseReleaseEvent(QMouseEvent *event);
134 void mouseMoveEvent(QMouseEvent *event);
136 void keyPressEvent(QKeyEvent *event);
137 void keyReleaseEvent(QKeyEvent *event);
139 void leaveEvent(QEvent *event);
142 void clear_selection();
145 void selection_changed();
148 pv::views::trace::View &view_;
150 QPoint mouse_down_point_;
151 pv::util::Timestamp mouse_down_offset_;
152 shared_ptr<ViewItem> mouse_down_item_;
154 /// Keyboard modifiers that were active when mouse was last moved or clicked
155 Qt::KeyboardModifiers mouse_modifiers_;
164 #endif // PULSEVIEW_PV_VIEWS_TRACE_VIEWWIDGET_HPP