From: Joel Holdsworth Date: Sun, 21 Dec 2014 15:47:01 +0000 (+0000) Subject: MarginWidget: Moved in mouseMoveEvent X-Git-Tag: pulseview-0.3.0~307 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2f7982367e8382e05c862de7afc71075ded5f606;p=pulseview.git MarginWidget: Moved in mouseMoveEvent --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index a42becaf..49a846e2 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -94,6 +94,39 @@ shared_ptr Header::get_mouse_over_item(const QPoint &pt) return shared_ptr(); } +bool Header::accept_drag() const +{ + // Check all the drag items share a common owner + RowItemOwner *item_owner = nullptr; + for (shared_ptr r : view_) + if (r->dragging()) { + if (!item_owner) + item_owner = r->owner(); + else if(item_owner != r->owner()) + return false; + } + + return item_owner; +} + +void Header::drag_items(const QPoint &delta) +{ + RowItemOwner *item_owner = nullptr; + for (std::shared_ptr r : view_) + if (r->dragging()) { + item_owner = r->owner(); + r->drag_by(delta); + + // Ensure the trace is selected + r->select(); + } + + item_owner->restack_items(); + for (const auto &r : *item_owner) + r->animate_to_layout_v_offset(); + signals_moved(); +} + void Header::paintEvent(QPaintEvent*) { // The trace labels are not drawn with the arrows exactly on the @@ -123,52 +156,6 @@ void Header::paintEvent(QPaintEvent*) painter.end(); } -void Header::mouseMoveEvent(QMouseEvent *event) -{ - assert(event); - mouse_point_ = event->pos(); - - if (!(event->buttons() & Qt::LeftButton)) - return; - - if ((event->pos() - mouse_down_point_).manhattanLength() < - QApplication::startDragDistance()) - return; - - // Check all the drag items share a common owner - RowItemOwner *item_owner = nullptr; - for (shared_ptr r : view_) - if (r->dragging()) { - if (!item_owner) - item_owner = r->owner(); - else if(item_owner != r->owner()) - return; - } - - if (!item_owner) - return; - - // Do the drag - dragging_ = true; - - const QPoint delta = event->pos() - mouse_down_point_; - - for (std::shared_ptr r : view_) - if (r->dragging()) { - r->drag_by(delta); - - // Ensure the trace is selected - r->select(); - } - - item_owner->restack_items(); - for (const auto &r : *item_owner) - r->animate_to_layout_v_offset(); - signals_moved(); - - update(); -} - void Header::contextMenuEvent(QContextMenuEvent *event) { const shared_ptr r = get_mouse_over_item(mouse_point_); diff --git a/pv/view/header.hpp b/pv/view/header.hpp index 758a702d..f12d23ca 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -74,12 +74,22 @@ private: std::shared_ptr get_mouse_over_item( const QPoint &pt); + /** + * Returns true if the selection of row items allows dragging. + * @return Returns true if the drag is acceptable. + */ + bool accept_drag() const; + + /** + * Drag the dragging items by the delta offset. + * @param delta the drag offset in pixels. + */ + void drag_items(const QPoint &delta); + private: void paintEvent(QPaintEvent *event); private: - void mouseMoveEvent(QMouseEvent *event); - void contextMenuEvent(QContextMenuEvent *event); void keyPressEvent(QKeyEvent *e); diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index d96d3aba..7582f4af 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -132,6 +132,28 @@ void MarginWidget::mouseReleaseEvent(QMouseEvent *event) mouse_down_item_ = nullptr; } +void MarginWidget::mouseMoveEvent(QMouseEvent *event) +{ + assert(event); + mouse_point_ = event->pos(); + + if (!(event->buttons() & Qt::LeftButton)) + return; + + if ((event->pos() - mouse_down_point_).manhattanLength() < + QApplication::startDragDistance()) + return; + + if (!accept_drag()) + return; + + // Do the drag + dragging_ = true; + drag_items(event->pos() - mouse_down_point_); + + update(); +} + void MarginWidget::leaveEvent(QEvent*) { mouse_point_ = QPoint(-1, -1); diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 35d557d1..54ace028 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -67,6 +67,18 @@ protected: */ void show_popup(const std::shared_ptr &item); + /** + * Returns true if the selection of row items allows dragging. + * @return Returns true if the drag is acceptable. + */ + virtual bool accept_drag() const = 0; + + /** + * Drag the dragging items by the delta offset. + * @param delta the drag offset in pixels. + */ + virtual void drag_items(const QPoint &delta) = 0; + /** * Handles left mouse button press events. * @param event the mouse event that triggered this handler. @@ -82,6 +94,7 @@ protected: protected: void mousePressEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); void leaveEvent(QEvent *event); diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 0d86efd8..a8cf6354 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -83,6 +83,19 @@ shared_ptr Ruler::get_mouse_over_item(const QPoint &pt) return nullptr; } +bool Ruler::accept_drag() const +{ + return true; +} + +void Ruler::drag_items(const QPoint &delta) +{ + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + if (i->dragging()) + i->drag_by(delta); +} + void Ruler::paintEvent(QPaintEvent*) { const int ValueMargin = 3; @@ -154,27 +167,6 @@ void Ruler::paintEvent(QPaintEvent*) } } -void Ruler::mouseMoveEvent(QMouseEvent *e) -{ - mouse_point_ = e->pos(); - - if (!(e->buttons() & Qt::LeftButton)) - return; - - if ((e->pos() - mouse_down_point_).manhattanLength() < - QApplication::startDragDistance()) - return; - - // Do the drag - dragging_ = true; - - const QPoint delta = e->pos() - mouse_down_point_; - const vector< shared_ptr > items(view_.time_items()); - for (auto &i : items) - if (i->dragging()) - i->drag_by(delta); -} - void Ruler::mouseDoubleClickEvent(QMouseEvent *e) { view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale()); diff --git a/pv/view/ruler.hpp b/pv/view/ruler.hpp index f29075c7..6559f6f0 100644 --- a/pv/view/ruler.hpp +++ b/pv/view/ruler.hpp @@ -73,11 +73,21 @@ private: std::shared_ptr get_mouse_over_item( const QPoint &pt); + /** + * Returns true if the selection of time items allows dragging. + * @return Returns true if the drag is acceptable. + */ + bool accept_drag() const; + + /** + * Drag the dragging items by the delta offset. + * @param delta the drag offset in pixels. + */ + void drag_items(const QPoint &delta); + private: void paintEvent(QPaintEvent *event); - void mouseMoveEvent(QMouseEvent *e); - void mouseDoubleClickEvent(QMouseEvent *e); private: