X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fviewwidget.hpp;h=fade3d289ab1e687ce511afd9c960337b9e75ef3;hp=5c8889e3be4cde76d2b91bc6724dd848d7bcb19a;hb=d9ea96280ab1128427143660ae375c30b19aa0cb;hpb=40aca27ed83559f7f79873e353f64d2c36a18fce diff --git a/pv/view/viewwidget.hpp b/pv/view/viewwidget.hpp index 5c8889e3..fade3d28 100644 --- a/pv/view/viewwidget.hpp +++ b/pv/view/viewwidget.hpp @@ -18,15 +18,20 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PULSEVIEW_PV_VIEWWIDGET_H -#define PULSEVIEW_PV_VIEWWIDGET_H +#ifndef PULSEVIEW_PV_VIEWWIDGET_HPP +#define PULSEVIEW_PV_VIEWWIDGET_HPP + +#include #include +class QTouchEvent; + namespace pv { namespace view { class View; +class ViewItem; class ViewWidget : public QWidget { @@ -35,11 +40,113 @@ class ViewWidget : public QWidget protected: ViewWidget(View &parent); + /** + * Indicates when a view item is being hovered over. + * @param item The item that is being hovered over, or @c nullptr + * if no view item is being hovered over. + * @remarks the default implementation does nothing. + */ + virtual void item_hover( + const std::shared_ptr &item); + + /** + * Indicates the event an a view item has been clicked. + * @param item the view item that has been clicked. + * @remarks the default implementation does nothing. + */ + virtual void item_clicked( + const std::shared_ptr &item); + + /** + * Returns true if the selection of row items allows dragging. + * @return Returns true if the drag is acceptable. + */ + bool accept_drag() const; + + /** + * Returns true if the mouse button is down. + */ + bool mouse_down() const; + + /** + * Drag the dragging items by the delta offset. + * @param delta the drag offset in pixels. + */ + void drag_items(const QPoint &delta); + + /** + * Sets this item into the dragged state. + */ + virtual void drag(); + + /** + * Drag the background by the delta offset. + * @param delta the drag offset in pixels. + * @remarks The default implementation does nothing. + */ + virtual void drag_by(const QPoint &delta); + + /** + * Sets this item into the un-dragged state. + */ + virtual void drag_release(); + + /** + * Gets the items in the view widget. + */ + virtual std::vector< std::shared_ptr > items() = 0; + + /** + * Gets the first view item which has a hit-box that contains @c pt . + * @param pt the point to search with. + * @return the view item that has been found, or and empty + * @c shared_ptr if no item was found. + */ + virtual std::shared_ptr get_mouse_over_item( + const QPoint &pt) = 0; + + /** + * Handles left mouse button press events. + * @param event the mouse event that triggered this handler. + */ + void mouse_left_press_event(QMouseEvent *event); + + /** + * Handles left mouse button release events. + * @param event the mouse event that triggered this handler. + */ + void mouse_left_release_event(QMouseEvent *event); + + /** + * Handles touch begin update and end events. + * @param e the event that triggered this handler. + */ + virtual bool touch_event(QTouchEvent *event); + +protected: + bool event(QEvent *event); + + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + + void leaveEvent(QEvent *event); + +public Q_SLOTS: + void clear_selection(); + +Q_SIGNALS: + void selection_changed(); + protected: pv::view::View &view_; + QPoint mouse_point_; + QPoint mouse_down_point_; + std::shared_ptr mouse_down_item_; + bool item_dragging_; }; } // namespace view } // namespace pv -#endif // PULSEVIEW_PV_VIEWWIDGET_H +#endif // PULSEVIEW_PV_VIEWWIDGET_HPP