|
@@ -1,4 +1,4 @@
|
|
|
-#include "OneEyeMap.h"
|
|
|
+#include "OneEyeMap.h"
|
|
|
#include "ui_oneeyemap.h"
|
|
|
|
|
|
#include <QApplication>
|
|
@@ -10,10 +10,10 @@ OneEyeMap::OneEyeMap(QWidget *parent) :
|
|
|
ui(new Ui::OneEyeMap)
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
- m_logger = spdlog::get("OSC");
|
|
|
+ m_logger = spdlog::get("EyeMap");
|
|
|
if(m_logger == nullptr)
|
|
|
{
|
|
|
- SPDLOG_ERROR("获取 OSC logger 失败");
|
|
|
+ SPDLOG_ERROR("获取 EyeMap logger 失败");
|
|
|
return;
|
|
|
}
|
|
|
/* 初始化变量,加载qss */
|
|
@@ -32,29 +32,32 @@ OneEyeMap::OneEyeMap(QWidget *parent) :
|
|
|
/* 自定义大小 */
|
|
|
// setFixedSize(1600, 900);
|
|
|
|
|
|
+ /* 设置水平刻度和垂直刻度数目 */
|
|
|
+ m_hScaleNum = 6;
|
|
|
+ m_vScaleNum = 4;
|
|
|
+
|
|
|
/* 设置绘制区域 */
|
|
|
m_leftMargin = 70;
|
|
|
m_topMargin = 24;
|
|
|
m_rightMargin = 24;
|
|
|
m_bottomMargin = 24;
|
|
|
/* 设置刻度区域 */
|
|
|
- m_rectScaleValue = QRect(0, ui->widget_title->height(), this->width(), this->height() - ui->widget_title->height());
|
|
|
+ m_rectScaleValue.setX(0);
|
|
|
+ m_rectScaleValue.setY(ui->widget_title->height());
|
|
|
+ m_rectScaleValue.setWidth(this->width());
|
|
|
+ m_rectScaleValue.setHeight(this->height() - ui->widget_title->height());
|
|
|
/* 设置眼图区域 */
|
|
|
m_rectEyeMap.setX(m_leftMargin);
|
|
|
- m_rectEyeMap.setY(ui->widget_title->height() + m_topMargin);
|
|
|
- m_rectEyeMap.setWidth(m_rectScaleValue.width() - m_rightMargin);
|
|
|
- m_rectEyeMap.setHeight(m_rectScaleValue.height() - m_bottomMargin);
|
|
|
- // m_rectEyeMap.setLeft(m_leftMargin);
|
|
|
- // m_rectEyeMap.setTop(ui->widget_title->height() + m_topMargin);
|
|
|
- // m_rectEyeMap.setRight(m_rectScaleValue.width() - m_rightMargin);
|
|
|
- // m_rectEyeMap.setBottom(m_rectScaleValue.height() - m_bottomMargin);
|
|
|
+ m_rectEyeMap.setY(m_rectScaleValue.y() + m_topMargin);
|
|
|
+ m_rectEyeMap.setWidth(m_rectScaleValue.width() - m_leftMargin - m_rightMargin);
|
|
|
+ m_rectEyeMap.setHeight(m_rectScaleValue.height() - m_topMargin - m_bottomMargin);
|
|
|
|
|
|
/* 初始化全局数据 */
|
|
|
g_eyeMapMatrix.initEyeMapData(this->width(), this->height());
|
|
|
/* 设置定时器 */
|
|
|
m_timer.setTimerType(Qt::PreciseTimer);
|
|
|
m_timer.setSingleShot(false);
|
|
|
- m_timer.start(16); /* 16ms刷新一次,大约120帧 */
|
|
|
+ // m_timer.start(16); /* 16ms刷新一次,大约60帧 */
|
|
|
|
|
|
connect(this, &OneEyeMap::signal_update, this, &OneEyeMap::do_update);
|
|
|
connect(&m_timer, &QTimer::timeout, this, &OneEyeMap::do_update);
|
|
@@ -100,7 +103,9 @@ void OneEyeMap::paintEvent(QPaintEvent *event)
|
|
|
|
|
|
/******************** 绘制刻度网格 *********************/
|
|
|
drawScale(painter);
|
|
|
-
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "width = {}, height = {}", this->width(), this->height());
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "m_rectScaleValue: x = {}, y = {}, width = {}, height = {}", m_rectScaleValue.x(), m_rectScaleValue.y(), m_rectScaleValue.width(), m_rectScaleValue.height());
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "m_rectEyeMap: x = {}, y = {}, width = {}, height = {}", m_rectEyeMap.x(), m_rectEyeMap.y(), m_rectEyeMap.width(), m_rectEyeMap.height());
|
|
|
|
|
|
/* 绘制眼图,就是绘制 1000 * 256 个矩形 */
|
|
|
// painter.setPen(QPen(Qt::NoPen));
|
|
@@ -126,12 +131,18 @@ void OneEyeMap::paintEvent(QPaintEvent *event)
|
|
|
void OneEyeMap::resizeEvent(QResizeEvent *event)
|
|
|
{
|
|
|
/* 设置刻度区域 */
|
|
|
- m_rectScaleValue = QRect(0, ui->widget_title->height(), this->width(), this->height() - ui->widget_title->height());
|
|
|
+ m_rectScaleValue.setX(0);
|
|
|
+ m_rectScaleValue.setY(ui->widget_title->height());
|
|
|
+ m_rectScaleValue.setWidth(this->width());
|
|
|
+ m_rectScaleValue.setHeight(this->height() - ui->widget_title->height());
|
|
|
/* 设置眼图区域 */
|
|
|
- m_rectEyeMap.setLeft(m_leftMargin);
|
|
|
- m_rectEyeMap.setTop(ui->widget_title->height() + m_topMargin);
|
|
|
- m_rectEyeMap.setRight(m_rectScaleValue.width() - m_rightMargin);
|
|
|
- m_rectEyeMap.setBottom(m_rectScaleValue.height() - m_bottomMargin);
|
|
|
+ m_rectEyeMap.setX(m_leftMargin);
|
|
|
+ m_rectEyeMap.setY(m_rectScaleValue.y() + m_topMargin);
|
|
|
+ m_rectEyeMap.setWidth(m_rectScaleValue.width() - m_leftMargin - m_rightMargin);
|
|
|
+ m_rectEyeMap.setHeight(m_rectScaleValue.height() - m_topMargin - m_bottomMargin);
|
|
|
+
|
|
|
+ /* 刷新一下页面 */
|
|
|
+ update();
|
|
|
event->accept();
|
|
|
}
|
|
|
|
|
@@ -144,6 +155,31 @@ void OneEyeMap::drawScaleValue(QPainter &painter)
|
|
|
brush.setStyle(Qt::SolidPattern);
|
|
|
painter.setBrush(brush);
|
|
|
painter.drawRect(m_rectScaleValue);
|
|
|
+
|
|
|
+ /* 绘制刻度值 */
|
|
|
+
|
|
|
+ QRect rectText(0, 0, 50, 14);
|
|
|
+ QFont font;
|
|
|
+ font.setFamily("思源黑体R");
|
|
|
+ font.setPixelSize(14);
|
|
|
+ painter.setFont(font);
|
|
|
+ int oneScale = m_rectEyeMap.height() / m_vScaleNum;
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "oneScale = {}", oneScale);
|
|
|
+ /* 绘制电压值 */
|
|
|
+ for(int i = 0; i <= m_vScaleNum; i++)
|
|
|
+ {
|
|
|
+ /* 计算字体区域坐标 */
|
|
|
+ rectText.moveTo(10, m_rectEyeMap.y() + oneScale * i - 7);
|
|
|
+ painter.drawText(rectText, Qt::AlignRight | Qt::AlignVCenter, getVScaleValue(i));
|
|
|
+ }
|
|
|
+ /* 绘制时间刻度值 */
|
|
|
+ int oneTime = m_rectEyeMap.width() / m_hScaleNum;
|
|
|
+ for(int i = 0; i <= m_hScaleNum; i++)
|
|
|
+ {
|
|
|
+ rectText.moveTo(m_rectEyeMap.x() + oneTime * i - 25, m_rectEyeMap.y() + m_rectEyeMap.height() + 4);
|
|
|
+ painter.drawText(rectText, Qt::AlignCenter, getTimeValue(i));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/* 绘制刻度 */
|
|
@@ -157,7 +193,7 @@ void OneEyeMap::drawScale(QPainter &painter)
|
|
|
brush.setStyle(Qt::SolidPattern);
|
|
|
painter.setBrush(brush);
|
|
|
painter.drawRect(m_rectEyeMap);
|
|
|
- /* 绘制刻度值 */
|
|
|
+ /* 绘制刻度线 */
|
|
|
QPen pen;
|
|
|
pen.setWidth(1);
|
|
|
pen.setStyle(Qt::SolidLine);
|
|
@@ -172,16 +208,18 @@ void OneEyeMap::drawScale(QPainter &painter)
|
|
|
painter.drawLine(startX, startY + (height / 2), startX + width, startY + (height / 2)); /* 绘制水平中线 */
|
|
|
painter.drawLine(startX + (width / 2), startY, startX + (width / 2), startY + height); /* 绘制垂直中线 */
|
|
|
/* 绘制中线上的刻度 */
|
|
|
- double scaleW = width / 10.0;
|
|
|
- double scaleH = height / 5.0;
|
|
|
+ int hScale = m_hScaleNum * 5;
|
|
|
+ int vScale = m_vScaleNum * 5;
|
|
|
+ double scaleW = width * 1.0 / hScale;
|
|
|
+ double scaleH = height * 1.0 / vScale;
|
|
|
QVector<QLineF> wLines;
|
|
|
QVector<QLineF> hLines;
|
|
|
- for(int i = 0; i < 10; i++)
|
|
|
+ for(int i = 0; i < hScale; i++)
|
|
|
{
|
|
|
QLineF line1(startX + i * scaleW, startY + height / 2.0 - 4, startX + i * scaleW, startY + height / 2.0 + 4);
|
|
|
wLines.append(line1);
|
|
|
}
|
|
|
- for(int i = 0; i < 5; i++)
|
|
|
+ for(int i = 0; i < vScale; i++)
|
|
|
{
|
|
|
QLineF line2(startX + width / 2.0 - 4, startY + height - i * scaleH, startX + width / 2.0 + 4, startY + height - i * scaleH);
|
|
|
hLines.append(line2);
|
|
@@ -189,51 +227,72 @@ void OneEyeMap::drawScale(QPainter &painter)
|
|
|
painter.drawLines(wLines);
|
|
|
painter.drawLines(hLines);
|
|
|
|
|
|
- /* 绘制网格,网格点之间的间距是固定的 */
|
|
|
+ /* 绘制网格,这里是网格线 */
|
|
|
pen.setWidth(1);
|
|
|
+ pen.setColor(QColor(255, 255, 255, 0.15 * 255));
|
|
|
painter.setPen(pen);
|
|
|
- scaleW = width / 10.0;
|
|
|
- scaleH = height / 10.0;
|
|
|
- int x = 0;
|
|
|
- int y = 0;
|
|
|
- QVector<QLineF> wGridLines;
|
|
|
- QVector<QLineF> hGridLines;
|
|
|
- for(int i = 1; i < 10; i++)
|
|
|
- {
|
|
|
- y = i * scaleH;
|
|
|
- while(true)
|
|
|
- {
|
|
|
- x = x + 8;
|
|
|
- QLineF line1(x, y, x + 2, y);
|
|
|
- wGridLines.append(line1);
|
|
|
- if(x >= width)
|
|
|
- {
|
|
|
- x = 0;
|
|
|
- y = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ scaleH = height * 1.0 / m_vScaleNum;
|
|
|
+ scaleW = width * 1.0 / m_hScaleNum;
|
|
|
+
|
|
|
+ /* 水平线 */
|
|
|
+ for(int i = 1; i < m_vScaleNum; i++)
|
|
|
+ {
|
|
|
+ int y = startY + i * scaleH;
|
|
|
+ QLineF line1(startX, y, startX + width, y);
|
|
|
+ painter.drawLine(line1);
|
|
|
}
|
|
|
- x = 0;
|
|
|
- y = 0;
|
|
|
- for(int i = 1; i < 10; i++)
|
|
|
- {
|
|
|
- x = i * scaleW;
|
|
|
- while(true)
|
|
|
- {
|
|
|
- y = y + 8;
|
|
|
- QLineF line1(x, y, x, y + 2);
|
|
|
- hGridLines.append(line1);
|
|
|
- if(y >= height)
|
|
|
- {
|
|
|
- x = 0;
|
|
|
- y = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ /* 垂直线 */
|
|
|
+ for(int i = 1; i < m_hScaleNum; i++)
|
|
|
+ {
|
|
|
+ int x = startX + i * scaleW;
|
|
|
+ QLineF line1(x, startY, x, startY + height);
|
|
|
+ painter.drawLine(line1);
|
|
|
}
|
|
|
- painter.drawLines(wGridLines);
|
|
|
- painter.drawLines(hGridLines);
|
|
|
+
|
|
|
+ /* 绘制虚线 */
|
|
|
+ // painter.setPen(pen);
|
|
|
+ // scaleW = width / 10.0;
|
|
|
+ // scaleH = height / 10.0;
|
|
|
+ // int x = 0;
|
|
|
+ // int y = 0;
|
|
|
+ // QVector<QLineF> wGridLines;
|
|
|
+ // QVector<QLineF> hGridLines;
|
|
|
+ // for(int i = 1; i < 10; i++)
|
|
|
+ // {
|
|
|
+ // y = i * scaleH;
|
|
|
+ // while(true)
|
|
|
+ // {
|
|
|
+ // x = x + 8;
|
|
|
+ // QLineF line1(x, y, x + 2, y);
|
|
|
+ // wGridLines.append(line1);
|
|
|
+ // if(x >= width)
|
|
|
+ // {
|
|
|
+ // x = 0;
|
|
|
+ // y = 0;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // x = 0;
|
|
|
+ // y = 0;
|
|
|
+ // for(int i = 1; i < 10; i++)
|
|
|
+ // {
|
|
|
+ // x = i * scaleW;
|
|
|
+ // while(true)
|
|
|
+ // {
|
|
|
+ // y = y + 8;
|
|
|
+ // QLineF line1(x, y, x, y + 2);
|
|
|
+ // hGridLines.append(line1);
|
|
|
+ // if(y >= height)
|
|
|
+ // {
|
|
|
+ // x = 0;
|
|
|
+ // y = 0;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // painter.drawLines(wGridLines);
|
|
|
+ // painter.drawLines(hGridLines);
|
|
|
}
|
|
|
|
|
|
/* 绘制眼图区域 */
|
|
@@ -242,3 +301,80 @@ void OneEyeMap::drawEyeMap(QPainter &painter)
|
|
|
|
|
|
}
|
|
|
|
|
|
+/* 获取一个格子的电压值 */
|
|
|
+QString OneEyeMap::getVScaleValue(int index)
|
|
|
+{
|
|
|
+ index = 2 - index;
|
|
|
+ if(m_cRange == OscChannelRange::CR_100MV)
|
|
|
+ {
|
|
|
+ return QString::number(0.1 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_250MV)
|
|
|
+ {
|
|
|
+ return QString::number(0.25 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_500MV)
|
|
|
+ {
|
|
|
+ return QString::number(0.5 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_1V)
|
|
|
+ {
|
|
|
+ return QString::number(1.0 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_2V5)
|
|
|
+ {
|
|
|
+ return QString::number(2.5 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_5V)
|
|
|
+ {
|
|
|
+ return QString::number(5.0 * index) + "V";
|
|
|
+ } else if(m_cRange == OscChannelRange::CR_8V)
|
|
|
+ {
|
|
|
+ return QString::number(8.0 * index) + "V";
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ return QString::number(0.1 * index) + "V";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取一个时间值 */
|
|
|
+QString OneEyeMap::getTimeValue(int index)
|
|
|
+{
|
|
|
+ QString str;
|
|
|
+ switch (m_tGridValue)
|
|
|
+ {
|
|
|
+ case OscTimeGridValue::TGV_20NS:
|
|
|
+ str = QString::number(index * 20 / 1000.0) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_50NS:
|
|
|
+ str = QString::number(index * 50 / 1000.0) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_100NS:
|
|
|
+ str = QString::number(index * 100 / 1000.0) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_200NS:
|
|
|
+ str = QString::number(index * 200 / 1000.0) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_500NS:
|
|
|
+ str = QString::number(index * 500 / 1000.0) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_1US:
|
|
|
+ str = QString::number(index * 1) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_2US:
|
|
|
+ str = QString::number(index * 2) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_5US:
|
|
|
+ str = QString::number(index * 5) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_10US:
|
|
|
+ str = QString::number(index * 10) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_20US:
|
|
|
+ str = QString::number(index * 20) + "us";
|
|
|
+ break;
|
|
|
+ case OscTimeGridValue::TGV_100US:
|
|
|
+ str = QString::number(index * 100) + "us";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ str = "us";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+}
|
|
|
+
|