From: Joel Holdsworth Date: Sun, 21 Dec 2014 13:51:20 +0000 (+0000) Subject: MarginWidget: Moved in mousePressEvent X-Git-Tag: pulseview-0.3.0~310 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6a2cc8dd37f6d128ad7e16b9a7a78bb44d5a5aa5;p=pulseview.git MarginWidget: Moved in mousePressEvent --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 1cbe59ce..2a732f25 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -123,47 +123,6 @@ void Header::paintEvent(QPaintEvent*) painter.end(); } -void Header::mouseLeftPressEvent(QMouseEvent *event) -{ - (void)event; - - const bool ctrl_pressed = - QApplication::keyboardModifiers() & Qt::ControlModifier; - - // Clear selection if control is not pressed and this item is unselected - if ((!mouse_down_item_ || !mouse_down_item_->selected()) && - !ctrl_pressed) - for (shared_ptr r : view_) - r->select(false); - - // Set the signal selection state if the item has been clicked - if (mouse_down_item_) { - if (ctrl_pressed) - mouse_down_item_->select(!mouse_down_item_->selected()); - else - mouse_down_item_->select(true); - } - - // Save the offsets of any signals which will be dragged - for (const shared_ptr r : view_) - if (r->selected()) - r->drag(); - - selection_changed(); - update(); -} - -void Header::mousePressEvent(QMouseEvent *event) -{ - assert(event); - - mouse_down_point_ = event->pos(); - mouse_down_item_ = get_mouse_over_item(event->pos()); - - if (event->button() & Qt::LeftButton) - mouseLeftPressEvent(event); -} - void Header::mouseLeftReleaseEvent(QMouseEvent *event) { assert(event); diff --git a/pv/view/header.hpp b/pv/view/header.hpp index 34f851b6..704c3345 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -78,9 +78,6 @@ private: void paintEvent(QPaintEvent *event); private: - void mouseLeftPressEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent * event); - void mouseLeftReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index 2ef26276..e20e7b9f 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include @@ -49,6 +50,47 @@ void MarginWidget::show_popup(const shared_ptr &item) p->show(); } +void MarginWidget::mouse_left_press_event(QMouseEvent *event) +{ + (void)event; + + const bool ctrl_pressed = + QApplication::keyboardModifiers() & Qt::ControlModifier; + + // Clear selection if control is not pressed and this item is unselected + if ((!mouse_down_item_ || !mouse_down_item_->selected()) && + !ctrl_pressed) + clear_selection(); + + // Set the signal selection state if the item has been clicked + if (mouse_down_item_) { + if (ctrl_pressed) + mouse_down_item_->select(!mouse_down_item_->selected()); + else + mouse_down_item_->select(true); + } + + // Save the offsets of any signals which will be dragged + const auto items = this->items(); + for (auto &i : items) + if (i->selected()) + i->drag(); + + selection_changed(); + update(); +} + +void MarginWidget::mousePressEvent(QMouseEvent *event) +{ + assert(event); + + mouse_down_point_ = event->pos(); + mouse_down_item_ = get_mouse_over_item(event->pos()); + + if (event->button() & Qt::LeftButton) + mouse_left_press_event(event); +} + void MarginWidget::leaveEvent(QEvent*) { mouse_point_ = QPoint(-1, -1); diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 7df6c02d..77a10a22 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -67,7 +67,15 @@ protected: */ void show_popup(const std::shared_ptr &item); + /** + * Handles left mouse button press events. + * @param event the mouse event that triggered this handler. + */ + void mouse_left_press_event(QMouseEvent *event); + private: + void mousePressEvent(QMouseEvent * event); + void leaveEvent(QEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event); diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index fb40e117..b847d2c8 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -175,23 +175,6 @@ void Ruler::mouseMoveEvent(QMouseEvent *e) i->drag_by(delta); } -void Ruler::mousePressEvent(QMouseEvent *e) -{ - if (e->buttons() & Qt::LeftButton) { - mouse_down_point_ = e->pos(); - mouse_down_item_ = get_mouse_over_item(e->pos()); - - clear_selection(); - - if (mouse_down_item_) { - mouse_down_item_->select(); - mouse_down_item_->drag(); - } - - selection_changed(); - } -} - void Ruler::mouseReleaseEvent(QMouseEvent *) { using pv::widgets::Popup; diff --git a/pv/view/ruler.hpp b/pv/view/ruler.hpp index ce9cae30..7fa58452 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 mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *); void mouseDoubleClickEvent(QMouseEvent *e);