diff --git a/cursor.cpp b/cursor.cpp index cf32067..da3bd61 100644 --- a/cursor.cpp +++ b/cursor.cpp @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -#include +#include #include "cursor.h" -Cursor::Cursor(Qt::Orientation orientation, QObject * parent) : QObject::QObject(parent), orientation(orientation) +Cursor::Cursor(Qt::Orientation orientation, Qt::CursorShape mouseCursorShape, QObject * parent) : QObject::QObject(parent), orientation(orientation), cursorShape(mouseCursorShape) { } @@ -39,6 +39,18 @@ bool Cursor::pointOverCursor(QPoint point) bool Cursor::mouseEvent(QEvent::Type type, QMouseEvent event) { + // If the mouse pointer moves over a cursor, display a resize pointer + if (pointOverCursor(event.pos()) && type != QEvent::Leave) { + if (!cursorOverrided) { + cursorOverrided = true; + QApplication::setOverrideCursor(QCursor(cursorShape)); + } + // Restore pointer if it moves off the cursor, or leaves the widget + } else if (cursorOverrided) { + cursorOverrided = false; + QApplication::restoreOverrideCursor(); + } + // Start dragging on left mouse button press, if over a cursor if (type == QEvent::MouseButtonPress) { if (event.button() == Qt::LeftButton) { diff --git a/cursor.h b/cursor.h index 2ecef70..aceb608 100644 --- a/cursor.h +++ b/cursor.h @@ -29,19 +29,21 @@ class Cursor : public QObject Q_OBJECT public: - Cursor(Qt::Orientation orientation, QObject * parent); + Cursor(Qt::Orientation orientation, Qt::CursorShape mouseCursorShape, QObject * parent); int pos(); void setPos(int newPos); - bool mouseEvent(QEvent::Type type, QMouseEvent event); + bool mouseEvent(QEvent::Type type, QMouseEvent event); signals: - void posChanged(); + void posChanged(); private: - int fromPoint(QPoint point); - bool pointOverCursor(QPoint point); + int fromPoint(QPoint point); + bool pointOverCursor(QPoint point); - Qt::Orientation orientation; - bool dragging = false; - int cursorPosition = 0; + Qt::Orientation orientation; + Qt::CursorShape cursorShape; + bool dragging = false; + bool cursorOverrided = false; + int cursorPosition = 0; }; diff --git a/cursors.cpp b/cursors.cpp index 4d838e2..15ed35b 100644 --- a/cursors.cpp +++ b/cursors.cpp @@ -22,8 +22,8 @@ Cursors::Cursors(QObject * parent) : QObject::QObject(parent) { - minCursor = new Cursor(Qt::Vertical, this); - maxCursor = new Cursor(Qt::Vertical, this); + minCursor = new Cursor(Qt::Vertical, Qt::SizeHorCursor, this); + maxCursor = new Cursor(Qt::Vertical, Qt::SizeHorCursor, this); connect(minCursor, &Cursor::posChanged, this, &Cursors::cursorMoved); connect(maxCursor, &Cursor::posChanged, this, &Cursors::cursorMoved); } diff --git a/plotview.cpp b/plotview.cpp index 76cfbea..5888c81 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -30,6 +30,7 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) { mainSampleSource = input; setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + setMouseTracking(true); enableCursors(false); enableTimeScale(true); connect(&cursors, SIGNAL(cursorsMoved()), this, SLOT(cursorsMoved())); @@ -131,7 +132,8 @@ bool PlotView::eventFilter(QObject * obj, QEvent *event) // Pass mouse events to individual plot objects if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseMove || - event->type() == QEvent::MouseButtonRelease) { + event->type() == QEvent::MouseButtonRelease || + event->type() == QEvent::Leave) { QMouseEvent *mouseEvent = static_cast(event); diff --git a/tuner.cpp b/tuner.cpp index 258e630..90880e2 100644 --- a/tuner.cpp +++ b/tuner.cpp @@ -22,9 +22,9 @@ Tuner::Tuner(QObject * parent) : QObject::QObject(parent) { - minCursor = new Cursor(Qt::Horizontal, this); - cfCursor = new Cursor(Qt::Horizontal, this); - maxCursor = new Cursor(Qt::Horizontal, this); + minCursor = new Cursor(Qt::Horizontal, Qt::SizeVerCursor, this); + cfCursor = new Cursor(Qt::Horizontal, Qt::SizeAllCursor, this); + maxCursor = new Cursor(Qt::Horizontal, Qt::SizeVerCursor, this); connect(minCursor, &Cursor::posChanged, this, &Tuner::cursorMoved); connect(cfCursor, &Cursor::posChanged, this, &Tuner::cursorMoved); connect(maxCursor, &Cursor::posChanged, this, &Tuner::cursorMoved);