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
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);

21
scope.h
View File

@ -6,6 +6,7 @@
#include <QChart>
#include <QChartView>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QLineEdit>
@ -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;
};
//^=======================================