]> sigrok.org Git - pulseview.git/blobdiff - pv/view/marginwidget.hpp
Added ViewWidget as a common ancestor of all view widgets
[pulseview.git] / pv / view / marginwidget.hpp
index 5b6631af724f3177e5c643bda1f0674e0ad5ccad..308d9348d12a0341aa6a203cd1b214a8c74839cf 100644 (file)
 #include <memory>
 
 #include <QPoint>
-#include <QWidget>
+
+#include "viewwidget.hpp"
 
 namespace pv {
 namespace view {
 
-class View;
 class ViewItem;
 
-class MarginWidget : public QWidget
+class MarginWidget : public ViewWidget
 {
        Q_OBJECT
 
@@ -47,22 +47,71 @@ public:
        virtual QSize extended_size_hint() const = 0;
 
 protected:
+       /**
+        * Gets the items in the margin widget.
+        */
+       virtual std::vector< std::shared_ptr<pv::view::ViewItem> > items() = 0;
+
+       /**
+        * Gets the first view item which has a label 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<pv::view::ViewItem> get_mouse_over_item(
+               const QPoint &pt) = 0;
+
        /**
         * Shows the popup of a the specified @c ViewItem .
         * @param item The item to show the popup for.
         */
        void show_popup(const std::shared_ptr<ViewItem> &item);
 
+       /**
+        * Returns true if the selection of row items allows dragging.
+        * @return Returns true if the drag is acceptable.
+        */
+       virtual bool accept_drag() const = 0;
+
+       /**
+        * Drag the dragging items by the delta offset.
+        * @param delta the drag offset in pixels.
+        */
+       virtual void drag_items(const QPoint &delta) = 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);
+
+protected:
+       void mousePressEvent(QMouseEvent * event);
+       void mouseReleaseEvent(QMouseEvent *event);
+       void mouseMoveEvent(QMouseEvent *event);
+
+       void leaveEvent(QEvent *event);
+
+       virtual void contextMenuEvent(QContextMenuEvent *event);
+
+       virtual void keyPressEvent(QKeyEvent *e);
+
 public Q_SLOTS:
-       virtual void clear_selection();
+       void clear_selection();
 
 Q_SIGNALS:
        void selection_changed();
 
 protected:
-       pv::view::View &view_;
        QPoint mouse_point_;
        QPoint mouse_down_point_;
+       std::shared_ptr<ViewItem> mouse_down_item_;
        bool dragging_;
 };