]> sigrok.org Git - pulseview.git/commitdiff
ViewItem: Use drag_point() with drag_by()
authorJoel Holdsworth <redacted>
Sun, 28 Dec 2014 18:33:51 +0000 (18:33 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 11:56:00 +0000 (11:56 +0000)
pv/view/header.cpp
pv/view/rowitem.cpp
pv/view/rowitem.hpp
pv/view/ruler.cpp
pv/view/timeitem.cpp
pv/view/timeitem.hpp
pv/view/viewitem.cpp
pv/view/viewitem.hpp

index c19d10883af7fed3c77e3ee60d0f497faadb2958..77ac1aa88c343498bfcaf57939b4f0995862b54a 100644 (file)
@@ -247,11 +247,11 @@ void Header::mouseMoveEvent(QMouseEvent *event)
        // Do the drag
        dragging_ = true;
 
-       const int delta = event->pos().y() - mouse_down_point_.y();
+       const QPoint delta = event->pos() - mouse_down_point_;
 
        for (std::shared_ptr<RowItem> r : view_)
                if (r->dragging()) {
-                       r->force_to_v_offset(r->drag_point().y() + delta);
+                       r->drag_by(delta);
 
                        // Ensure the trace is selected
                        r->select();
index 861d4adf05d28763640c12a2dac1a27d4f308f4c..2e693dd97ade70706e18bd90e2156b34787f9766 100644 (file)
@@ -115,6 +115,12 @@ int RowItem::get_visual_y() const
        return visual_v_offset_ + owner_->owner_visual_v_offset();
 }
 
+void RowItem::drag_by(const QPoint &delta)
+{
+       force_to_v_offset(drag_point_.y() + delta.y() -
+               owner_->owner_visual_v_offset());
+}
+
 QPoint RowItem::point(const QRect &rect) const
 {
        return QPoint(rect.right(), get_visual_y());
index 3f2afbc3821c9598b04f3d8bf5dbc04e81d72143..023e2c3807b2c2d4e61bc6dd78e96591d9607cec 100644 (file)
@@ -93,6 +93,12 @@ public:
         */
        int get_visual_y() const;
 
+       /**
+        * Drags the item to a delta relative to the drag point.
+        * @param delta the offset from the drag point.
+        */
+       void drag_by(const QPoint &delta);
+
        /**
         * Gets the arrow-tip point of the row item marker.
         * @param rect the rectangle of the header area.
index bcf6a5281d494195b97bfc6c152dfc59227453f1..47da23a8b78e21a9e5f7725ca533f64d472897ad 100644 (file)
@@ -171,13 +171,11 @@ void Ruler::mouseMoveEvent(QMouseEvent *e)
        // Do the drag
        dragging_ = true;
 
-       const int delta = e->pos().x() - mouse_down_point_.x();
+       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->set_time(view_.offset() +
-                               (i->drag_point().x() + delta - 0.5) *
-                               view_.scale());
+                       i->drag_by(delta);
 }
 
 void Ruler::mousePressEvent(QMouseEvent *e)
index dabdd5f137fc45c39e204d354e831554afcc421a..ec8dd1a49f5c0abc81d68e5e4845f873e3fa4b5a 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include "timeitem.hpp"
+#include "view.hpp"
 
 namespace pv {
 namespace view {
@@ -27,5 +28,11 @@ TimeItem::TimeItem(View &view) :
        view_(view) {
 }
 
+void TimeItem::drag_by(const QPoint &delta)
+{
+       set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) *
+               view_.scale());
+}
+
 } // namespace view
 } // namespace pv
index f988488409c18426aebab42b720dab2d54731987..ba4ce8b6d69799a8d1b828461c738435e5b0e988 100644 (file)
@@ -48,6 +48,12 @@ public:
 
        virtual float get_x() const = 0;
 
+       /**
+        * Drags the item to a delta relative to the drag point.
+        * @param delta the offset from the drag point.
+        */
+       void drag_by(const QPoint &delta);
+
 protected:
        View &view_;
 };
index 6917190a46dbd8e60554cc241219a2fc62de4743..02a9c6a2f39d8deb9dcb0e0c4d3f11e1b1f16a93 100644 (file)
@@ -34,8 +34,8 @@ const int ViewItem::HighlightRadius = 3;
 
 ViewItem::ViewItem() :
        context_parent_(NULL),
-       selected_(false),
-       drag_point_(INT_MIN, INT_MIN)
+       drag_point_(INT_MIN, INT_MIN),
+       selected_(false)
 {
 }
 
@@ -54,11 +54,6 @@ bool ViewItem::dragging() const
        return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN;
 }
 
-QPoint ViewItem::drag_point() const
-{
-       return drag_point_;
-}
-
 void ViewItem::drag()
 {
        drag_point_ = point(QRect());
index 11efbc0cdd1f7bd79855b7fe4c77cc67583f8922..eb0823e47e8f1b55b897597a0c8bf14a0b960742 100644 (file)
@@ -71,11 +71,6 @@ public:
         */
        bool dragging() const;
 
-       /**
-        * Retunrns the current drag point.
-        */
-       QPoint drag_point() const;
-
        /**
         * Sets this item into the dragged state.
         */
@@ -86,6 +81,12 @@ public:
         */
        void drag_release();
 
+       /**
+        * Drags the item to a delta relative to the drag point.
+        * @param delta the offset from the drag point.
+        */
+       virtual void drag_by(const QPoint &delta) = 0;
+
        /**
         * Get the drag point.
         * @param rect the rectangle of the widget area.
@@ -149,10 +150,10 @@ protected:
 
 protected:
        QWidget *context_parent_;
+       QPoint drag_point_;
 
 private:
        bool selected_;
-       QPoint drag_point_;
 };
 
 } // namespace view