X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fcursorheader.cpp;h=2683e9e6b20c8fc10c9d81f5bfd10dadb14f95fa;hp=3f25e2123b5aa87043d53285ebcffde4353a130d;hb=8914fe790fb677c56194a3ae4da06ba671fca78a;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index 3f25e212..2683e9e6 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,7 +47,6 @@ int CursorHeader::calculateTextHeight() CursorHeader::CursorHeader(View &parent) : MarginWidget(parent), - dragging_(false), textHeight_(calculateTextHeight()) { setMouseTracking(true); @@ -59,9 +59,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,21 +70,21 @@ 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); - } + // Draw the items + const vector< shared_ptr > items(view_.time_items()); + for (auto &m : items) + m->paint_label(p, r); } void CursorHeader::mouseMoveEvent(QMouseEvent *e) { + mouse_point_ = e->pos(); + if (!(e->buttons() & Qt::LeftButton)) return; @@ -92,11 +92,16 @@ 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 - 0.5) * + view_.scale()); } void CursorHeader::mousePressEvent(QMouseEvent *e) @@ -104,22 +109,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(); } @@ -129,16 +133,33 @@ 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; - grabbed_marker_.reset(); + mouse_down_item_.reset(); + + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + i->drag_release(); +} + +void CursorHeader::leaveEvent(QEvent*) +{ + mouse_point_ = QPoint(-1, -1); + update(); +} + +void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e) +{ + view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale()); } } // namespace view