X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fcursorheader.cpp;h=22c1259f99622fb94d53d74ab41098f0ff265ac7;hp=3e2944e09269304a823db91b49fe6ecaef06f2da;hb=e95fb8e943bd24e18ba5d237f259a76e705f3914;hpb=361c560ed9ef67278916e086ed0b0649ae01b583 diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index 3e2944e0..22c1259f 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -30,6 +30,7 @@ #include using std::shared_ptr; +using std::vector; namespace pv { namespace view { @@ -59,9 +60,9 @@ QSize CursorHeader::sizeHint() const void CursorHeader::clear_selection() { - CursorPair &cursors = view_.cursors(); - cursors.first()->select(false); - cursors.second()->select(false); + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + i->select(false); update(); } @@ -70,14 +71,14 @@ void CursorHeader::paintEvent(QPaintEvent*) QPainter p(this); p.setRenderHint(QPainter::Antialiasing); + // The cursor labels are not drawn with the arrows exactly on the + // bottom line of the widget, because then the selection shadow + // would be clipped away. + const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset); + // Draw the cursors - if (view_.cursors_shown()) { - // The cursor labels are not drawn with the arrows exactly on the - // bottom line of the widget, because then the selection shadow - // would be clipped away. - const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset); - view_.cursors().draw_markers(p, r); - } + if (view_.cursors_shown()) + view_.cursors()->draw_markers(p, r); } void CursorHeader::mouseMoveEvent(QMouseEvent *e) @@ -89,11 +90,15 @@ void CursorHeader::mouseMoveEvent(QMouseEvent *e) QApplication::startDragDistance()) return; + // Do the drag dragging_ = true; - if (shared_ptr m = grabbed_marker_.lock()) - m->set_time(view_.offset() + - ((double)e->x() + 0.5) * view_.scale()); + const int delta = e->pos().x() - mouse_down_point_.x(); + 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) * view_.scale()); } void CursorHeader::mousePressEvent(QMouseEvent *e) @@ -101,22 +106,21 @@ void CursorHeader::mousePressEvent(QMouseEvent *e) if (e->buttons() & Qt::LeftButton) { mouse_down_point_ = e->pos(); - grabbed_marker_.reset(); + mouse_down_item_.reset(); clear_selection(); - if (view_.cursors_shown()) { - CursorPair &cursors = view_.cursors(); - if (cursors.first()->get_label_rect( - rect()).contains(e->pos())) - grabbed_marker_ = cursors.first(); - else if (cursors.second()->get_label_rect( - rect()).contains(e->pos())) - grabbed_marker_ = cursors.second(); - } + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + if (i && i->label_rect(rect()).contains(e->pos())) { + mouse_down_item_ = i; + break; + } - if (shared_ptr m = grabbed_marker_.lock()) - m->select(); + if (mouse_down_item_) { + mouse_down_item_->select(); + mouse_down_item_->drag(); + } selection_changed(); } @@ -126,16 +130,20 @@ void CursorHeader::mouseReleaseEvent(QMouseEvent *) { using pv::widgets::Popup; - if (!dragging_) - if (shared_ptr m = grabbed_marker_.lock()) { - Popup *const p = m->create_popup(&view_); - const QPoint arrpos(m->get_x(), height() - BaselineOffset); - p->set_position(mapToGlobal(arrpos), Popup::Bottom); - p->show(); - } + if (!dragging_ && mouse_down_item_) { + Popup *const p = mouse_down_item_->create_popup(&view_); + const QPoint arrpos(mouse_down_item_->get_x(), + height() - BaselineOffset); + p->set_position(mapToGlobal(arrpos), Popup::Bottom); + p->show(); + } dragging_ = false; - grabbed_marker_.reset(); + mouse_down_item_.reset(); + + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + i->drag_release(); } } // namespace view