From: Joel Holdsworth Date: Sun, 28 Dec 2014 18:33:51 +0000 (+0000) Subject: ViewItem: Use drag_point() with drag_by() X-Git-Tag: pulseview-0.3.0~320 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=23e75650eba0491b2636de3cef87f893e38ae6f3;p=pulseview.git ViewItem: Use drag_point() with drag_by() --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index c19d1088..77ac1aa8 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -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 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(); diff --git a/pv/view/rowitem.cpp b/pv/view/rowitem.cpp index 861d4adf..2e693dd9 100644 --- a/pv/view/rowitem.cpp +++ b/pv/view/rowitem.cpp @@ -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()); diff --git a/pv/view/rowitem.hpp b/pv/view/rowitem.hpp index 3f2afbc3..023e2c38 100644 --- a/pv/view/rowitem.hpp +++ b/pv/view/rowitem.hpp @@ -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. diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index bcf6a528..47da23a8 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -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 > 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) diff --git a/pv/view/timeitem.cpp b/pv/view/timeitem.cpp index dabdd5f1..ec8dd1a4 100644 --- a/pv/view/timeitem.cpp +++ b/pv/view/timeitem.cpp @@ -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 diff --git a/pv/view/timeitem.hpp b/pv/view/timeitem.hpp index f9884884..ba4ce8b6 100644 --- a/pv/view/timeitem.hpp +++ b/pv/view/timeitem.hpp @@ -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_; }; diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp index 6917190a..02a9c6a2 100644 --- a/pv/view/viewitem.cpp +++ b/pv/view/viewitem.cpp @@ -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()); diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index 11efbc0c..eb0823e4 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -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