|
@@ -0,0 +1,244 @@
|
|
|
|
+#include "OneEyeMap.h"
|
|
|
|
+#include "ui_oneeyemap.h"
|
|
|
|
+
|
|
|
|
+#include <QApplication>
|
|
|
|
+#include <QPainter>
|
|
|
|
+#include <QPaintEvent>
|
|
|
|
+
|
|
|
|
+OneEyeMap::OneEyeMap(QWidget *parent) :
|
|
|
|
+ QWidget(parent),
|
|
|
|
+ ui(new Ui::OneEyeMap)
|
|
|
|
+{
|
|
|
|
+ ui->setupUi(this);
|
|
|
|
+ m_logger = spdlog::get("OSC");
|
|
|
|
+ if(m_logger == nullptr)
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_ERROR("获取 OSC logger 失败");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ /* 初始化变量,加载qss */
|
|
|
|
+ // QFile fileQss(":/qss/OneEyeMap/OneEyeMap.qss");
|
|
|
|
+ QFile fileQss(":/qss/OneEyeMap/OneEyeMap.qss");
|
|
|
|
+ if(fileQss.open(QFile::ReadOnly))
|
|
|
|
+ {
|
|
|
|
+ QString qss = fileQss.readAll();
|
|
|
|
+ this->setStyleSheet(qss);
|
|
|
|
+ fileQss.close();
|
|
|
|
+ } else
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "加载qss文件失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* 自定义大小 */
|
|
|
|
+ // setFixedSize(1600, 900);
|
|
|
|
+
|
|
|
|
+ /* 设置绘制区域 */
|
|
|
|
+ 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_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);
|
|
|
|
+
|
|
|
|
+ /* 初始化全局数据 */
|
|
|
|
+ g_eyeMapMatrix.initEyeMapData(this->width(), this->height());
|
|
|
|
+ /* 设置定时器 */
|
|
|
|
+ m_timer.setTimerType(Qt::PreciseTimer);
|
|
|
|
+ m_timer.setSingleShot(false);
|
|
|
|
+ m_timer.start(16); /* 16ms刷新一次,大约120帧 */
|
|
|
|
+
|
|
|
|
+ connect(this, &OneEyeMap::signal_update, this, &OneEyeMap::do_update);
|
|
|
|
+ connect(&m_timer, &QTimer::timeout, this, &OneEyeMap::do_update);
|
|
|
|
+
|
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "OneEyeMap 初始化成功");
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+OneEyeMap::~OneEyeMap()
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ delete ui;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 刷新页面 */
|
|
|
|
+void OneEyeMap::do_update()
|
|
|
|
+{
|
|
|
|
+ update();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @brief 绘制图形
|
|
|
|
+ *
|
|
|
|
+ * @param event
|
|
|
|
+ */
|
|
|
|
+void OneEyeMap::paintEvent(QPaintEvent *event)
|
|
|
|
+{
|
|
|
|
+ g_eyeMapMatrix.mutexEyeData.lock();
|
|
|
|
+ QPainter painter(this);
|
|
|
|
+
|
|
|
|
+ painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
+
|
|
|
|
+ /******************** 绘制标题背景 ********************/
|
|
|
|
+ QBrush brush;
|
|
|
|
+ brush.setStyle(Qt::SolidPattern);
|
|
|
|
+ brush.setColor("#000000");
|
|
|
|
+ painter.setBrush(brush);
|
|
|
|
+ painter.drawRect(ui->widget_title->geometry());
|
|
|
|
+
|
|
|
|
+ /******************** 绘制刻度值 ********************/
|
|
|
|
+ drawScaleValue(painter);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /******************** 绘制刻度网格 *********************/
|
|
|
|
+ drawScale(painter);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /* 绘制眼图,就是绘制 1000 * 256 个矩形 */
|
|
|
|
+ // painter.setPen(QPen(Qt::NoPen));
|
|
|
|
+ // for(int i = 0; i < 1000; i++)
|
|
|
|
+ // {
|
|
|
|
+ // for(int j = 0; j < 256; j++)
|
|
|
|
+ // {
|
|
|
|
+ // if(g_eyeMapMatrix.dataMatrix[i][j].isDraw == false)
|
|
|
|
+ // {
|
|
|
|
+ // continue;
|
|
|
|
+ // }
|
|
|
|
+ // // painter.setBrush(QBrush(g_eyeMapMatrix.dataMatrix[i][j].color));
|
|
|
|
+ // painter.setBrush(g_eyeMapMatrix.dataMatrix[i][j].brush);
|
|
|
|
+ // painter.drawRect(g_eyeMapMatrix.dataMatrix[i][j].rect);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ g_eyeMapMatrix.mutexEyeData.unlock();
|
|
|
|
+
|
|
|
|
+ event->accept();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 缩放事件 */
|
|
|
|
+void OneEyeMap::resizeEvent(QResizeEvent *event)
|
|
|
|
+{
|
|
|
|
+ /* 设置刻度区域 */
|
|
|
|
+ m_rectScaleValue = QRect(0, ui->widget_title->height(), this->width(), 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);
|
|
|
|
+ event->accept();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 绘制刻度区域 */
|
|
|
|
+void OneEyeMap::drawScaleValue(QPainter &painter)
|
|
|
|
+{
|
|
|
|
+ /* 绘制背景颜色 */
|
|
|
|
+ QBrush brush;
|
|
|
|
+ brush.setColor("#1E1E1E");
|
|
|
|
+ brush.setStyle(Qt::SolidPattern);
|
|
|
|
+ painter.setBrush(brush);
|
|
|
|
+ painter.drawRect(m_rectScaleValue);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 绘制刻度 */
|
|
|
|
+void OneEyeMap::drawScale(QPainter &painter)
|
|
|
|
+{
|
|
|
|
+ /* 限制操作区域,不过坐标零点依旧是widget的(0,0) */
|
|
|
|
+ painter.setClipRect(m_rectEyeMap);
|
|
|
|
+ /* 绘制背景颜色 */
|
|
|
|
+ QBrush brush;
|
|
|
|
+ brush.setColor(QColor(0, 0, 0, 0.8 * 255));
|
|
|
|
+ brush.setStyle(Qt::SolidPattern);
|
|
|
|
+ painter.setBrush(brush);
|
|
|
|
+ painter.drawRect(m_rectEyeMap);
|
|
|
|
+ /* 绘制刻度值 */
|
|
|
|
+ QPen pen;
|
|
|
|
+ pen.setWidth(1);
|
|
|
|
+ pen.setStyle(Qt::SolidLine);
|
|
|
|
+ /* 绘制中线 */
|
|
|
|
+ int startX = m_rectEyeMap.x();
|
|
|
|
+ int startY = m_rectEyeMap.y();
|
|
|
|
+ int width = m_rectEyeMap.width();
|
|
|
|
+ int height = m_rectEyeMap.height();
|
|
|
|
+ pen.setColor(QColor(255, 255, 255, 0.35 * 255));
|
|
|
|
+ pen.setWidth(2);
|
|
|
|
+ painter.setPen(pen);
|
|
|
|
+ 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;
|
|
|
|
+ QVector<QLineF> wLines;
|
|
|
|
+ QVector<QLineF> hLines;
|
|
|
|
+ for(int i = 0; i < 10; 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++)
|
|
|
|
+ {
|
|
|
|
+ QLineF line2(startX + width / 2.0 - 4, startY + height - i * scaleH, startX + width / 2.0 + 4, startY + height - i * scaleH);
|
|
|
|
+ hLines.append(line2);
|
|
|
|
+ }
|
|
|
|
+ painter.drawLines(wLines);
|
|
|
|
+ painter.drawLines(hLines);
|
|
|
|
+
|
|
|
|
+ /* 绘制网格,网格点之间的间距是固定的 */
|
|
|
|
+ pen.setWidth(1);
|
|
|
|
+ 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);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 绘制眼图区域 */
|
|
|
|
+void OneEyeMap::drawEyeMap(QPainter &painter)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|