X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fcursorheader.cpp;h=981a958b8d0d94ec3d515fcfba3dce82844c8d76;hp=a9b709f2ecc30966a70e86350133d00bce340b4f;hb=2fae5107535c39adde322393d2f6d18098c0154e;hpb=4d95ef609546490c4f981d47e4a44d097079c628 diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index a9b709f2..981a958b 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -18,18 +18,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "cursorheader.h" +#include "cursorheader.hpp" -#include "ruler.h" -#include "view.h" +#include "ruler.hpp" +#include "view.hpp" #include #include #include -#include +#include using std::shared_ptr; +using std::vector; namespace pv { namespace view { @@ -46,22 +47,22 @@ int CursorHeader::calculateTextHeight() CursorHeader::CursorHeader(View &parent) : MarginWidget(parent), - _dragging(false), - _textHeight(calculateTextHeight()) + dragging_(false), + textHeight_(calculateTextHeight()) { setMouseTracking(true); } QSize CursorHeader::sizeHint() const { - return QSize(0, _textHeight + Padding + BaselineOffset); + return QSize(0, textHeight_ + Padding + BaselineOffset); } 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,17 +71,14 @@ void CursorHeader::paintEvent(QPaintEvent*) QPainter p(this); p.setRenderHint(QPainter::Antialiasing); - unsigned int prefix = pv::view::Ruler::calculate_tick_spacing( - p, _view.scale(), _view.offset()).second; + // 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, prefix); - } + if (view_.cursors_shown()) + view_.cursors()->paint_label(p, r); } void CursorHeader::mouseMoveEvent(QMouseEvent *e) @@ -88,38 +86,41 @@ void CursorHeader::mouseMoveEvent(QMouseEvent *e) if (!(e->buttons() & Qt::LeftButton)) return; - if ((e->pos() - _mouse_down_point).manhattanLength() < + if ((e->pos() - mouse_down_point_).manhattanLength() < QApplication::startDragDistance()) return; - _dragging = true; + // 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) { if (e->buttons() & Qt::LeftButton) { - _mouse_down_point = e->pos(); + 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(); } @@ -129,16 +130,22 @@ 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); + if (!dragging_ && mouse_down_item_) { + Popup *const p = mouse_down_item_->create_popup(&view_); + if (p) { + const QPoint arrpos(mouse_down_item_->get_x(), + height() - BaselineOffset); p->set_position(mapToGlobal(arrpos), Popup::Bottom); p->show(); } + } + + dragging_ = false; + mouse_down_item_.reset(); - _dragging = false; - _grabbed_marker.reset(); + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + i->drag_release(); } } // namespace view