From: Joel Holdsworth Date: Sat, 20 Dec 2014 18:34:03 +0000 (+0000) Subject: Ruler: Factored out get_mouse_over_item X-Git-Tag: pulseview-0.3.0~325 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=25a0d47cfb287d16f72116e8c198d0e5867f8c20;p=pulseview.git Ruler: Factored out get_mouse_over_item --- diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index f671c95e..160f1acb 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -76,6 +76,15 @@ QSize Ruler::extended_size_hint() const ViewItem::HighlightRadius); } +shared_ptr Ruler::get_mouse_over_item(const QPoint &pt) +{ + const vector< shared_ptr > items(view_.time_items()); + for (auto i = items.rbegin(); i != items.rend(); i++) + if ((*i)->enabled() && (*i)->label_rect(rect()).contains(pt)) + return *i; + return nullptr; +} + void Ruler::paintEvent(QPaintEvent*) { const int ValueMargin = 3; @@ -174,18 +183,10 @@ void Ruler::mousePressEvent(QMouseEvent *e) { if (e->buttons() & Qt::LeftButton) { mouse_down_point_ = e->pos(); - - mouse_down_item_.reset(); + mouse_down_item_ = get_mouse_over_item(e->pos()); clear_selection(); - const vector< shared_ptr > items(view_.time_items()); - for (auto i = items.rbegin(); i != items.rend(); i++) - if ((*i)->label_rect(rect()).contains(e->pos())) { - mouse_down_item_ = (*i); - break; - } - if (mouse_down_item_) { mouse_down_item_->select(); mouse_down_item_->drag(); diff --git a/pv/view/ruler.hpp b/pv/view/ruler.hpp index f6ce3446..7054268d 100644 --- a/pv/view/ruler.hpp +++ b/pv/view/ruler.hpp @@ -60,6 +60,10 @@ public: */ QSize extended_size_hint() const; +private: + std::shared_ptr get_mouse_over_item( + const QPoint &pt); + private: void paintEvent(QPaintEvent *event);