]> sigrok.org Git - pulseview.git/commitdiff
MarginWidget: Moved in mouseMoveEvent
authorJoel Holdsworth <redacted>
Sun, 21 Dec 2014 15:47:01 +0000 (15:47 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 11:56:01 +0000 (11:56 +0000)
pv/view/header.cpp
pv/view/header.hpp
pv/view/marginwidget.cpp
pv/view/marginwidget.hpp
pv/view/ruler.cpp
pv/view/ruler.hpp

index a42becaf366695caeff75440fd4ffff6e6eee18c..49a846e286a594a76db1a74063595c1accdab13a 100644 (file)
@@ -94,6 +94,39 @@ shared_ptr<ViewItem> Header::get_mouse_over_item(const QPoint &pt)
        return shared_ptr<RowItem>();
 }
 
+bool Header::accept_drag() const
+{
+       // Check all the drag items share a common owner
+       RowItemOwner *item_owner = nullptr;
+       for (shared_ptr<RowItem> r : view_)
+               if (r->dragging()) {
+                       if (!item_owner)
+                               item_owner = r->owner();
+                       else if(item_owner != r->owner())
+                               return false;
+               }
+
+       return item_owner;
+}
+
+void Header::drag_items(const QPoint &delta)
+{
+       RowItemOwner *item_owner = nullptr;
+       for (std::shared_ptr<RowItem> r : view_)
+               if (r->dragging()) {
+                       item_owner = r->owner();
+                       r->drag_by(delta);
+
+                       // Ensure the trace is selected
+                       r->select();
+               }
+
+       item_owner->restack_items();
+       for (const auto &r : *item_owner)
+               r->animate_to_layout_v_offset();
+       signals_moved();
+}
+
 void Header::paintEvent(QPaintEvent*)
 {
        // The trace labels are not drawn with the arrows exactly on the
@@ -123,52 +156,6 @@ void Header::paintEvent(QPaintEvent*)
        painter.end();
 }
 
-void Header::mouseMoveEvent(QMouseEvent *event)
-{
-       assert(event);
-       mouse_point_ = event->pos();
-
-       if (!(event->buttons() & Qt::LeftButton))
-               return;
-
-       if ((event->pos() - mouse_down_point_).manhattanLength() <
-               QApplication::startDragDistance())
-               return;
-
-       // Check all the drag items share a common owner
-       RowItemOwner *item_owner = nullptr;
-       for (shared_ptr<RowItem> r : view_)
-               if (r->dragging()) {
-                       if (!item_owner)
-                               item_owner = r->owner();
-                       else if(item_owner != r->owner())
-                               return;
-               }
-
-       if (!item_owner)
-               return;
-
-       // Do the drag
-       dragging_ = true;
-
-       const QPoint delta = event->pos() - mouse_down_point_;
-
-       for (std::shared_ptr<RowItem> r : view_)
-               if (r->dragging()) {
-                       r->drag_by(delta);
-
-                       // Ensure the trace is selected
-                       r->select();
-               }
-
-       item_owner->restack_items();
-       for (const auto &r : *item_owner)
-               r->animate_to_layout_v_offset();
-       signals_moved();
-
-       update();
-}
-
 void Header::contextMenuEvent(QContextMenuEvent *event)
 {
        const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
index 758a702d78937d9abbe48b03955a827ec26cde3d..f12d23ca5852f40a1707301e38b2d4de22910fec 100644 (file)
@@ -74,12 +74,22 @@ private:
        std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
                const QPoint &pt);
 
+       /**
+        * Returns true if the selection of row items allows dragging.
+        * @return Returns true if the drag is acceptable.
+        */
+       bool accept_drag() const;
+
+       /**
+        * Drag the dragging items by the delta offset.
+        * @param delta the drag offset in pixels.
+        */
+       void drag_items(const QPoint &delta);
+
 private:
        void paintEvent(QPaintEvent *event);
 
 private:
-       void mouseMoveEvent(QMouseEvent *event);
-
        void contextMenuEvent(QContextMenuEvent *event);
 
        void keyPressEvent(QKeyEvent *e);
index d96d3aba66f315bf1483f7b4f3045ce96552a7f6..7582f4af187bfbfbc1dc7125c42378d6bd2fd387 100644 (file)
@@ -132,6 +132,28 @@ void MarginWidget::mouseReleaseEvent(QMouseEvent *event)
        mouse_down_item_ = nullptr;
 }
 
+void MarginWidget::mouseMoveEvent(QMouseEvent *event)
+{
+       assert(event);
+       mouse_point_ = event->pos();
+
+       if (!(event->buttons() & Qt::LeftButton))
+               return;
+
+       if ((event->pos() - mouse_down_point_).manhattanLength() <
+               QApplication::startDragDistance())
+               return;
+
+       if (!accept_drag())
+               return;
+
+       // Do the drag
+       dragging_ = true;
+       drag_items(event->pos() - mouse_down_point_);
+
+       update();
+}
+
 void MarginWidget::leaveEvent(QEvent*)
 {
        mouse_point_ = QPoint(-1, -1);
index 35d557d10ccab7dcae57f57f6c990bce7c85e9d6..54ace028fcda121bd79588c20a1b32d6af159c67 100644 (file)
@@ -67,6 +67,18 @@ protected:
         */
        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.
@@ -82,6 +94,7 @@ protected:
 protected:
        void mousePressEvent(QMouseEvent * event);
        void mouseReleaseEvent(QMouseEvent *event);
+       void mouseMoveEvent(QMouseEvent *event);
 
        void leaveEvent(QEvent *event);
 
index 0d86efd853202b0bf2753c91eff0344e5848478b..a8cf63540a0cb239645b1cb3e4e5131743caac1e 100644 (file)
@@ -83,6 +83,19 @@ shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
        return nullptr;
 }
 
+bool Ruler::accept_drag() const
+{
+       return true;
+}
+
+void Ruler::drag_items(const QPoint &delta)
+{
+       const vector< shared_ptr<TimeItem> > items(view_.time_items());
+       for (auto &i : items)
+               if (i->dragging())
+                       i->drag_by(delta);
+}
+
 void Ruler::paintEvent(QPaintEvent*)
 {
        const int ValueMargin = 3;
@@ -154,27 +167,6 @@ void Ruler::paintEvent(QPaintEvent*)
        }
 }
 
-void Ruler::mouseMoveEvent(QMouseEvent *e)
-{
-       mouse_point_ = e->pos();
-
-       if (!(e->buttons() & Qt::LeftButton))
-               return;
-
-       if ((e->pos() - mouse_down_point_).manhattanLength() <
-               QApplication::startDragDistance())
-               return;
-
-       // Do the drag
-       dragging_ = true;
-
-       const QPoint delta = e->pos() - mouse_down_point_;
-       const vector< shared_ptr<TimeItem> > items(view_.time_items());
-       for (auto &i : items)
-               if (i->dragging())
-                       i->drag_by(delta);
-}
-
 void Ruler::mouseDoubleClickEvent(QMouseEvent *e)
 {
        view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
index f29075c7868bc052b270135c31667f7b0aa72418..6559f6f09cd770d2c0060a2eb1273ea4112a6d39 100644 (file)
@@ -73,11 +73,21 @@ private:
        std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
                const QPoint &pt);
 
+       /**
+        * Returns true if the selection of time items allows dragging.
+        * @return Returns true if the drag is acceptable.
+        */
+       bool accept_drag() const;
+
+       /**
+        * Drag the dragging items by the delta offset.
+        * @param delta the drag offset in pixels.
+        */
+       void drag_items(const QPoint &delta);
+
 private:
        void paintEvent(QPaintEvent *event);
 
-       void mouseMoveEvent(QMouseEvent *e);
-
        void mouseDoubleClickEvent(QMouseEvent *e);
 
 private: