]> sigrok.org Git - pulseview.git/commitdiff
Ruler: Factored out get_mouse_over_item
authorJoel Holdsworth <redacted>
Sat, 20 Dec 2014 18:34:03 +0000 (18:34 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 11:56:00 +0000 (11:56 +0000)
pv/view/ruler.cpp
pv/view/ruler.hpp

index f671c95e0c9bd529d67111237ea8fc45c73da0c5..160f1acbd9ce63babf15e337616502d6a28d7631 100644 (file)
@@ -76,6 +76,15 @@ QSize Ruler::extended_size_hint() const
                ViewItem::HighlightRadius);
 }
 
+shared_ptr<TimeItem> Ruler::get_mouse_over_item(const QPoint &pt)
+{
+       const vector< shared_ptr<TimeItem> > 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<TimeItem> > 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();
index f6ce3446daaa8395ad36bf29b4ce175666aaf65a..7054268d586c4c6d20fd542f1503a0fa564d0925 100644 (file)
@@ -60,6 +60,10 @@ public:
         */
        QSize extended_size_hint() const;
 
+private:
+       std::shared_ptr<pv::view::TimeItem> get_mouse_over_item(
+               const QPoint &pt);
+
 private:
        void paintEvent(QPaintEvent *event);