added Coordinate Lable in Scope

This commit is contained in:
Ryan Tang 2023-03-24 18:07:48 -04:00
parent b914e05097
commit 214e18812b
2 changed files with 22 additions and 3 deletions

View File

@ -275,8 +275,8 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
//------------- Key binding //------------- Key binding
rowID ++; rowID ++;
QLabel * lbhints = new QLabel("Type 'r' to restore view.", this); QLabel * lbhints = new QLabel("Type 'r' to restore view, '+/-' Zoom in/out, arrow key to pan.", this);
layout->addWidget(lbhints, rowID, 0, 1, 3); layout->addWidget(lbhints, rowID, 0, 1, 4);
QLabel * lbinfo = new QLabel("Trace update every " + QString::number(updateTraceThread->GetWaitTimeSec()) + " sec.", this); QLabel * lbinfo = new QLabel("Trace update every " + QString::number(updateTraceThread->GetWaitTimeSec()) + " sec.", this);
lbinfo->setAlignment(Qt::AlignRight); lbinfo->setAlignment(Qt::AlignRight);

19
scope.h
View File

@ -6,6 +6,7 @@
#include <QChart> #include <QChart>
#include <QChartView> #include <QChartView>
#include <QSpinBox> #include <QSpinBox>
#include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include <QLineEdit> #include <QLineEdit>
@ -59,6 +60,12 @@ public:
TraceView(QChart * chart, QWidget * parent = nullptr): QChartView(chart, parent){ TraceView(QChart * chart, QWidget * parent = nullptr): QChartView(chart, parent){
m_isTouching = false; m_isTouching = false;
this->setRubberBand(QChartView::RectangleRubberBand); 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: protected:
@ -74,14 +81,25 @@ protected:
QChartView::mousePressEvent(event); QChartView::mousePressEvent(event);
} }
void mouseMoveEvent(QMouseEvent *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; if (m_isTouching) return;
QChartView::mouseMoveEvent(event); QChartView::mouseMoveEvent(event);
} }
void mouseReleaseEvent(QMouseEvent *event){ void mouseReleaseEvent(QMouseEvent *event){
if (m_isTouching) m_isTouching = false; if (m_isTouching) m_isTouching = false;
chart()->setAnimationOptions(QChart::SeriesAnimations); chart()->setAnimationOptions(QChart::SeriesAnimations);
QChartView::mouseReleaseEvent(event); QChartView::mouseReleaseEvent(event);
} }
void leaveEvent(QEvent *event) override {
m_coordinateLabel->setVisible(false);
QChartView::leaveEvent(event);
}
void keyPressEvent(QKeyEvent *event){ void keyPressEvent(QKeyEvent *event){
switch (event->key()) { switch (event->key()) {
case Qt::Key_Plus: chart()->zoomIn(); break; case Qt::Key_Plus: chart()->zoomIn(); break;
@ -97,6 +115,7 @@ protected:
private: private:
bool m_isTouching; bool m_isTouching;
QLabel * m_coordinateLabel;
}; };
//^======================================= //^=======================================