From a009d21992db132679e27030736ed614522245ea Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sat, 7 Nov 2015 15:31:08 +0100 Subject: [PATCH] Add a mechanism to make ViewItem classes immovable. This adds a new method ViewItem::is_draggable(), which returns true iff the view item is supposed to be draggable/movable. Also, ViewItem::drag() is turned into a nop if the item is not draggable. --- pv/view/viewitem.cpp | 8 +++++++- pv/view/viewitem.hpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp index a63d4d38..e9602f87 100644 --- a/pv/view/viewitem.cpp +++ b/pv/view/viewitem.cpp @@ -49,6 +49,11 @@ void ViewItem::select(bool select) selected_ = select; } +bool ViewItem::is_draggable() const +{ + return true; +} + bool ViewItem::dragging() const { return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN; @@ -56,7 +61,8 @@ bool ViewItem::dragging() const void ViewItem::drag() { - drag_point_ = point(QRect()); + if (is_draggable()) + drag_point_ = point(QRect()); } void ViewItem::drag_release() diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index 648be84e..16b34cb0 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -68,6 +68,11 @@ public: */ virtual void select(bool select = true); + /** + Returns true if the item may be dragged/moved. + */ + virtual bool is_draggable() const; + /** * Returns true if the item is being dragged. */ -- 2.30.2