From: Joel Holdsworth Date: Sun, 21 Dec 2014 14:29:54 +0000 (+0000) Subject: MarginWidget: Moved in mouseReleaseEvent X-Git-Tag: pulseview-0.3.0~308 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e47b69882ca7299041123c664dbcc8b552c5db99;p=pulseview.git MarginWidget: Moved in mouseReleaseEvent --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 766347d5..a42becaf 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -123,46 +123,6 @@ void Header::paintEvent(QPaintEvent*) painter.end(); } -void Header::mouseLeftReleaseEvent(QMouseEvent *event) -{ - assert(event); - - const bool ctrl_pressed = - QApplication::keyboardModifiers() & Qt::ControlModifier; - - // Unselect everything if control is not pressed - const shared_ptr mouse_over = - get_mouse_over_item(event->pos()); - - for (auto &r : view_) - r->drag_release(); - - if (dragging_) - view_.restack_all_row_items(); - else - { - if (!ctrl_pressed) { - for (shared_ptr r : view_) - if (mouse_down_item_ != r) - r->select(false); - - if (mouse_down_item_) - show_popup(mouse_down_item_); - } - } - - dragging_ = false; -} - -void Header::mouseReleaseEvent(QMouseEvent *event) -{ - assert(event); - if (event->button() & Qt::LeftButton) - mouseLeftReleaseEvent(event); - - mouse_down_item_ = nullptr; -} - void Header::mouseMoveEvent(QMouseEvent *event) { assert(event); diff --git a/pv/view/header.hpp b/pv/view/header.hpp index 704c3345..758a702d 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -78,9 +78,6 @@ private: void paintEvent(QPaintEvent *event); private: - void mouseLeftReleaseEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); void contextMenuEvent(QContextMenuEvent *event); diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index 5a81c459..d96d3aba 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -80,6 +80,38 @@ void MarginWidget::mouse_left_press_event(QMouseEvent *event) update(); } +void MarginWidget::mouse_left_release_event(QMouseEvent *event) +{ + assert(event); + + auto items = this->items(); + const bool ctrl_pressed = + QApplication::keyboardModifiers() & Qt::ControlModifier; + + // Unselect everything if control is not pressed + const shared_ptr mouse_over = + get_mouse_over_item(event->pos()); + + for (auto &i : items) + i->drag_release(); + + if (dragging_) + view_.restack_all_row_items(); + else + { + if (!ctrl_pressed) { + for (shared_ptr i : items) + if (mouse_down_item_ != i) + i->select(false); + + if (mouse_down_item_) + show_popup(mouse_down_item_); + } + } + + dragging_ = false; +} + void MarginWidget::mousePressEvent(QMouseEvent *event) { assert(event); @@ -91,6 +123,15 @@ void MarginWidget::mousePressEvent(QMouseEvent *event) mouse_left_press_event(event); } +void MarginWidget::mouseReleaseEvent(QMouseEvent *event) +{ + assert(event); + if (event->button() & Qt::LeftButton) + mouse_left_release_event(event); + + mouse_down_item_ = nullptr; +} + void MarginWidget::leaveEvent(QEvent*) { mouse_point_ = QPoint(-1, -1); diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 11946965..35d557d1 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -73,8 +73,15 @@ protected: */ void mouse_left_press_event(QMouseEvent *event); + /** + * Handles left mouse button release events. + * @param event the mouse event that triggered this handler. + */ + void mouse_left_release_event(QMouseEvent *event); + protected: void mousePressEvent(QMouseEvent * event); + void mouseReleaseEvent(QMouseEvent *event); void leaveEvent(QEvent *event); diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index f4bffd4c..0d86efd8 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -175,21 +175,6 @@ void Ruler::mouseMoveEvent(QMouseEvent *e) i->drag_by(delta); } -void Ruler::mouseReleaseEvent(QMouseEvent *) -{ - using pv::widgets::Popup; - - if (!dragging_ && mouse_down_item_) - show_popup(mouse_down_item_); - - dragging_ = false; - mouse_down_item_.reset(); - - const vector< shared_ptr > items(view_.time_items()); - for (auto &i : items) - i->drag_release(); -} - 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 d13a31b8..f29075c7 100644 --- a/pv/view/ruler.hpp +++ b/pv/view/ruler.hpp @@ -77,7 +77,6 @@ private: void paintEvent(QPaintEvent *event); void mouseMoveEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *); void mouseDoubleClickEvent(QMouseEvent *e);