From: Joel Holdsworth Date: Mon, 29 Dec 2014 11:18:37 +0000 (+0000) Subject: Viewport: Implemented item hover cursors X-Git-Tag: pulseview-0.3.0~294 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e8b969a9ae4e0a683eabddc8ded7babaf03844fd;p=pulseview.git Viewport: Implemented item hover cursors --- diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 2772c776..2dfdddc1 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -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 Viewport::get_mouse_over_item(const QPoint &pt) return nullptr; } +void Viewport::item_hover(const shared_ptr &item) +{ + if (item) + setCursor(dynamic_pointer_cast(item) ? + Qt::SizeVerCursor : Qt::SizeHorCursor); + else + unsetCursor(); +} + void Viewport::drag() { drag_offset_ = view_.offset(); diff --git a/pv/view/viewport.hpp b/pv/view/viewport.hpp index f43177d2..78dfbb24 100644 --- a/pv/view/viewport.hpp +++ b/pv/view/viewport.hpp @@ -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 &item); + /** * Gets the first view item which has a hit-box that contains @c pt . * @param pt the point to search with. diff --git a/pv/view/viewwidget.cpp b/pv/view/viewwidget.cpp index cf737664..e364d638 100644 --- a/pv/view/viewwidget.cpp +++ b/pv/view/viewwidget.cpp @@ -51,6 +51,11 @@ void ViewWidget::clear_selection() update(); } +void ViewWidget::item_hover(const shared_ptr &item) +{ + (void)item; +} + void ViewWidget::item_clicked(const shared_ptr &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*) diff --git a/pv/view/viewwidget.hpp b/pv/view/viewwidget.hpp index 6fd1ecef..003c0eed 100644 --- a/pv/view/viewwidget.hpp +++ b/pv/view/viewwidget.hpp @@ -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 &item); + /** * Indicates the event an a view item has been clicked. * @param item the view item that has been clicked.