]> sigrok.org Git - pulseview.git/commitdiff
Viewport: Implemented item hover cursors
authorJoel Holdsworth <redacted>
Mon, 29 Dec 2014 11:18:37 +0000 (11:18 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 12:24:23 +0000 (12:24 +0000)
pv/view/viewport.cpp
pv/view/viewport.hpp
pv/view/viewwidget.cpp
pv/view/viewwidget.hpp

index 2772c7764ead3a45b2c76733be6b0fe98d252c05..2dfdddc1448bddecd8653918c63204ca63dd266c 100644 (file)
@@ -35,6 +35,7 @@
 using std::abs;
 using std::back_inserter;
 using std::copy;
+using std::dynamic_pointer_cast;
 using std::max;
 using std::min;
 using std::none_of;
@@ -65,6 +66,15 @@ shared_ptr<ViewItem> Viewport::get_mouse_over_item(const QPoint &pt)
        return nullptr;
 }
 
+void Viewport::item_hover(const shared_ptr<ViewItem> &item)
+{
+       if (item)
+               setCursor(dynamic_pointer_cast<RowItem>(item) ?
+                       Qt::SizeVerCursor : Qt::SizeHorCursor);
+       else
+               unsetCursor();
+}
+
 void Viewport::drag()
 {
        drag_offset_ = view_.offset();
index f43177d2d3f611d9ea00abe87b6eadfbe02ce92e..78dfbb24bbfd485f7f12ae1f211145af06d8e933 100644 (file)
@@ -43,6 +43,13 @@ public:
        explicit Viewport(View &parent);
 
 private:
+       /**
+        * Indicates when a view item is being hovered over.
+        * @param item The item that is being hovered over, or @c nullptr
+        * if no view item is being hovered over.
+        */
+       void item_hover(const std::shared_ptr<pv::view::ViewItem> &item);
+
        /**
         * Gets the first view item which has a hit-box that contains @c pt .
         * @param pt the point to search with.
index cf7376646586f2a88d9eb5d9680808fd407635af..e364d6385f61eb9768b5b0afc9995adda4840bee 100644 (file)
@@ -51,6 +51,11 @@ void ViewWidget::clear_selection()
        update();
 }
 
+void ViewWidget::item_hover(const shared_ptr<ViewItem> &item)
+{
+       (void)item;
+}
+
 void ViewWidget::item_clicked(const shared_ptr<ViewItem> &item)
 {
        (void)item;
@@ -256,30 +261,32 @@ void ViewWidget::mouseReleaseEvent(QMouseEvent *event)
        mouse_down_item_ = nullptr;
 }
 
-void ViewWidget::mouseMoveEvent(QMouseEvent *event)
+void ViewWidget::mouseMoveEvent(QMouseEvent *e)
 {
-       assert(event);
-       mouse_point_ = event->pos();
+       assert(e);
+       mouse_point_ = e->pos();
 
-       if (!(event->buttons() & Qt::LeftButton))
-               return;
-
-       if (!item_dragging_)
+       if (!e->buttons())
+               item_hover(get_mouse_over_item(e->pos()));
+       else if (e->buttons() & Qt::LeftButton)
        {
-               if ((event->pos() - mouse_down_point_).manhattanLength() <
-                       QApplication::startDragDistance())
-                       return;
+               if (!item_dragging_)
+               {
+                       if ((e->pos() - mouse_down_point_).manhattanLength() <
+                               QApplication::startDragDistance())
+                               return;
 
-               if (!accept_drag())
-                       return;
+                       if (!accept_drag())
+                               return;
 
-               item_dragging_ = true;
-       }
+                       item_dragging_ = true;
+               }
 
-       // Do the drag
-       drag_items(event->pos() - mouse_down_point_);
+               // Do the drag
+               drag_items(e->pos() - mouse_down_point_);
 
-       update();
+               update();
+       }
 }
 
 void ViewWidget::leaveEvent(QEvent*)
index 6fd1ecefd1f853a2403fc880cacb36c1c699a108..003c0eeda09b57f31d9f26e31b54244045876ac6 100644 (file)
@@ -40,6 +40,15 @@ class ViewWidget : public QWidget
 protected:
        ViewWidget(View &parent);
 
+       /**
+        * Indicates when a view item is being hovered over.
+        * @param item The item that is being hovered over, or @c nullptr
+        * if no view item is being hovered over.
+        * @remarks the default implementation does nothing.
+        */
+       virtual void item_hover(
+               const std::shared_ptr<pv::view::ViewItem> &item);
+
        /**
         * Indicates the event an a view item has been clicked.
         * @param item the view item that has been clicked.