]> sigrok.org Git - pulseview.git/commitdiff
MarginWidget: Moved in mousePressEvent
authorJoel Holdsworth <redacted>
Sun, 21 Dec 2014 13:51:20 +0000 (13:51 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 11:56:00 +0000 (11:56 +0000)
pv/view/header.cpp
pv/view/header.hpp
pv/view/marginwidget.cpp
pv/view/marginwidget.hpp
pv/view/ruler.cpp
pv/view/ruler.hpp

index 1cbe59cec4133711f9287d8c55de7a5caba1335d..2a732f25daa3f7f16590c8d8e39310e4acc4a295 100644 (file)
@@ -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<RowItem> 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<RowItem> 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);
index 34f851b67a26af234a85c956b47bcd8df0314a09..704c33451686330012c6a929588872d885210852 100644 (file)
@@ -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);
 
index 2ef262762cc0c13a7683b0aa7379099e3fca2502..e20e7b9f00afe664e72439969b73fe5894b6eca7 100644 (file)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <QApplication>
 #include <QMenu>
 #include <QMouseEvent>
 
@@ -49,6 +50,47 @@ void MarginWidget::show_popup(const shared_ptr<ViewItem> &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);
index 7df6c02d3fbebbcdf8ca5db4222e5a53c41e9713..77a10a22f5a1240a19d418cb8e297a07492811ad 100644 (file)
@@ -67,7 +67,15 @@ protected:
         */
        void show_popup(const std::shared_ptr<ViewItem> &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);
index fb40e117c8ccfc7850abab1d0756c00f512dcfd1..b847d2c82a5c25408f0cc561a9bc35cd20c0e9ea 100644 (file)
@@ -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;
index ce9cae30134c0af64fb14ed97ff6ae48c208eb0d..7fa58452fe76cd5fa7210d8b35a27420c6f00847 100644 (file)
@@ -77,7 +77,6 @@ private:
        void paintEvent(QPaintEvent *event);
 
        void mouseMoveEvent(QMouseEvent *e);
-       void mousePressEvent(QMouseEvent *e);
        void mouseReleaseEvent(QMouseEvent *);
 
        void mouseDoubleClickEvent(QMouseEvent *e);