diff --git a/scope.cpp b/scope.cpp index b889cc5..9306c56 100644 --- a/scope.cpp +++ b/scope.cpp @@ -275,8 +275,8 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat //------------- Key binding rowID ++; - QLabel * lbhints = new QLabel("Type 'r' to restore view.", this); - layout->addWidget(lbhints, rowID, 0, 1, 3); + QLabel * lbhints = new QLabel("Type 'r' to restore view, '+/-' Zoom in/out, arrow key to pan.", this); + layout->addWidget(lbhints, rowID, 0, 1, 4); QLabel * lbinfo = new QLabel("Trace update every " + QString::number(updateTraceThread->GetWaitTimeSec()) + " sec.", this); lbinfo->setAlignment(Qt::AlignRight); diff --git a/scope.h b/scope.h index b3f2ccb..1eb07b4 100644 --- a/scope.h +++ b/scope.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,12 @@ public: TraceView(QChart * chart, QWidget * parent = nullptr): QChartView(chart, parent){ m_isTouching = false; this->setRubberBand(QChartView::RectangleRubberBand); + + m_coordinateLabel = new QLabel(this); + m_coordinateLabel->setStyleSheet("QLabel { color : black; }"); + m_coordinateLabel->setVisible(false); + m_coordinateLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft); + setMouseTracking(true); } protected: @@ -74,14 +81,25 @@ protected: QChartView::mousePressEvent(event); } void mouseMoveEvent(QMouseEvent *event){ + + QPointF chartPoint = this->chart()->mapToValue(event->pos()); + QString coordinateText = QString("x: %1, y: %2").arg(QString::number(chartPoint.x(), 'f', 0)).arg(QString::number(chartPoint.y(), 'f', 0)); + m_coordinateLabel->setText(coordinateText); + m_coordinateLabel->move(event->pos() + QPoint(10, -10)); + m_coordinateLabel->setVisible(true); if (m_isTouching) return; QChartView::mouseMoveEvent(event); + } void mouseReleaseEvent(QMouseEvent *event){ if (m_isTouching) m_isTouching = false; chart()->setAnimationOptions(QChart::SeriesAnimations); QChartView::mouseReleaseEvent(event); } + void leaveEvent(QEvent *event) override { + m_coordinateLabel->setVisible(false); + QChartView::leaveEvent(event); + } void keyPressEvent(QKeyEvent *event){ switch (event->key()) { case Qt::Key_Plus: chart()->zoomIn(); break; @@ -94,9 +112,10 @@ protected: default: QGraphicsView::keyPressEvent(event); break; } } - + private: bool m_isTouching; + QLabel * m_coordinateLabel; }; //^=======================================