eyemapwidget.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #include "eyemapwidget.h"
  2. #include "ui_eyemapwidget.h"
  3. #include <QDebug>
  4. #include <QFile>
  5. #include <QDateTime>
  6. #include "settingnum.h"
  7. #include "OneEyeMap.h"
  8. #include "EyeMapInfo.h"
  9. #include "paramconfig.h"
  10. #include "warning.h"
  11. EyeMapWidget::EyeMapWidget(QWidget *parent) :
  12. QWidget(parent),
  13. ui(new Ui::EyeMapWidget)
  14. {
  15. ui->setupUi(this);
  16. m_logger = spdlog::get("EyeMap");
  17. if(m_logger == nullptr)
  18. {
  19. qDebug() << "获取 EyeMap logger 失败";
  20. return;
  21. }
  22. /* 设置无边框和自动全屏 */
  23. this->setWindowFlags(Qt::FramelessWindowHint);
  24. this->setWindowState(Qt::WindowFullScreen);
  25. /* 打印一些基础信息 */
  26. SPDLOG_LOGGER_INFO(m_logger, "屏幕分辨率:{}x{}", this->width(), this->height());
  27. /* 加载QSS文件 */
  28. QFile fileQss(":/qss/EyeMapWidget/EyeMapWidget.qss");
  29. if(fileQss.open(QFile::ReadOnly))
  30. {
  31. QString qss = fileQss.readAll();
  32. this->setStyleSheet(qss);
  33. fileQss.close();
  34. } else
  35. {
  36. SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败");
  37. }
  38. /* 获取日期和时间,启动时间定时器 */
  39. QDate date = QDate::currentDate();
  40. QString strDate = date.toString("yyyy-MM-dd");
  41. QString strWeek = date.toString("dddd");
  42. ui->label_date->setText(strDate + " " + strWeek);
  43. QDateTime time = QDateTime::currentDateTime();
  44. QString strTime = time.toString("hh:mm:ss");
  45. ui->label_time->setText(strTime);
  46. m_timerTime.setTimerType(Qt::PreciseTimer);
  47. m_timerTime.setSingleShot(false);
  48. initEyeMap();
  49. /* 连接信号和槽 */
  50. connect(ui->pBtn_exit, &QPushButton::clicked, this, &EyeMapWidget::do_exit);
  51. connect(&m_timerTime, &QTimer::timeout, this, &EyeMapWidget::do_timeWalk);
  52. connect(ui->pBtn_settingNum, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingNum);
  53. connect(ui->pBtn_settingScale, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingParam);
  54. m_timerTime.start(1000);
  55. }
  56. EyeMapWidget::~EyeMapWidget()
  57. {
  58. delete ui;
  59. }
  60. void EyeMapWidget::do_exit()
  61. {
  62. Warning warning;
  63. warning.setText("是否退出程序?");
  64. warning.exec();
  65. if(!warning.isOk())
  66. {
  67. return;
  68. }
  69. /* 更新GEyeMapInfo的初始化数据,防止这个类析构了一起把8个眼图模块都析构了,数据消失了 */
  70. GEyeMapInfo.updateInitEyeMapInfo();
  71. GEyeMapInfo.row = m_row;
  72. GEyeMapInfo.column = m_column;
  73. GEyeMapInfo.updateSaveFile();
  74. this->close();
  75. }
  76. /* 时间跳动槽函数 */
  77. void EyeMapWidget::do_timeWalk()
  78. {
  79. /* 获取时间 */
  80. QTime time = QTime::currentTime();
  81. QString strTime = time.toString("hh:mm:ss");
  82. ui->label_time->setText(strTime);
  83. }
  84. /* 设置眼图个数页面的槽函数 */
  85. void EyeMapWidget::do_pBtnSettingNum()
  86. {
  87. std::shared_ptr<SettingNum> settingNum = std::make_shared<SettingNum>();
  88. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  89. // {
  90. // SPDLOG_LOGGER_DEBUG(m_logger, "眼图序号: {}, 通道号:{} ", it->getNum(), it->getChannelInfo().channelName.toStdString());
  91. // }
  92. /* 这里不能设置父指针 */
  93. // settingNum->setParent(this);
  94. /* 设置模态窗口 */
  95. settingNum->setModal(true);
  96. /* 设置眼图显示的个数 */
  97. settingNum->setRowAndColumn(m_row, m_column);
  98. /* 设置每个项的信息 */
  99. settingNum->setEveryEyeMapInfo(GEyeMapInfo.getEyeMapInfo());
  100. /* 设置可选的通道信息 */
  101. settingNum->setChannelList(GEyeMapInfo.getChannelInfo());
  102. settingNum->exec();
  103. /* 判断是否点击的是ok,是则重新布局 */
  104. if(settingNum->isOk)
  105. {
  106. m_row = settingNum->row;
  107. m_column = settingNum->column;
  108. eyeMapLayout();
  109. }
  110. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  111. // {
  112. // SPDLOG_LOGGER_DEBUG(m_logger, "配置完成后的眼图序号: {}, 通道号:{} ", it->getNum(), it->getChannelInfo().channelName.toStdString());
  113. // }
  114. }
  115. /* 设置眼图参数的槽函数 */
  116. void EyeMapWidget::do_pBtnSettingParam()
  117. {
  118. std::shared_ptr<ParamConfig> paramConfig = std::make_shared<ParamConfig>();
  119. paramConfig->createItem(GEyeMapInfo.getEyeMapInfo());
  120. paramConfig->exec();
  121. /* 判断是否点击了确定按钮 */
  122. if(paramConfig->isOk)
  123. {
  124. }
  125. }
  126. /* 初始化眼图 */
  127. void EyeMapWidget::initEyeMap()
  128. {
  129. /* 创建8个眼图 */
  130. for(const auto &it : GEyeMapInfo.listInitEyeMapInfo)
  131. {
  132. OneEyeMap* oneEyeMap = new OneEyeMap(ui->widget_container);
  133. oneEyeMap->setNum(it.num);
  134. oneEyeMap->setTitle(it.title);
  135. oneEyeMap->setTitleBarColor(it.titleBarColor);
  136. oneEyeMap->setVoltageRange(it.voltageRange);
  137. oneEyeMap->setChannelInfo(it.channelInfo);
  138. oneEyeMap->setTimeGridValue(it.tGridValue);
  139. oneEyeMap->hide();
  140. GEyeMapInfo.addEyeMapPtr(oneEyeMap);
  141. }
  142. m_row = GEyeMapInfo.row;
  143. m_column = GEyeMapInfo.column;
  144. eyeMapLayout();
  145. }
  146. /* 排列眼图布局 */
  147. void EyeMapWidget::eyeMapLayout()
  148. {
  149. // SPDLOG_LOGGER_DEBUG(m_logger, "眼图显示区域总大小: width = {}, height = {}", ui->widget_container->width(), ui->widget_container->height());
  150. /* 计算每个模块的大小 */
  151. int oneWidth = 0;
  152. int oneHeight = 0;
  153. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  154. // {
  155. // if(it->isVisible())
  156. // {
  157. // m_showNum++;
  158. // }
  159. // }
  160. int num = m_row * m_column;
  161. if(num == 0)
  162. {
  163. return;
  164. }
  165. /* 只有1个 */
  166. else if (num == 1)
  167. {
  168. oneWidth = ui->widget_container->width() - m_marginLeft - m_marginRight;
  169. oneHeight = ui->widget_container->height() - m_marginTop - m_marginBottom;
  170. }
  171. /* 两个 */
  172. else if(num == 2)
  173. {
  174. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight);
  175. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - m_spacing ) / 2;
  176. }
  177. /* 4、6、8个 */
  178. else if(num == 4 || num == 6 || num == 8)
  179. {
  180. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight - m_spacing) / 2;
  181. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - (m_spacing * (num / 2 - 1)) ) / (num / 2);
  182. }
  183. /* 重新设置每个模块的大小 */
  184. for(const auto &it : GEyeMapInfo.getEyeMapList())
  185. {
  186. it->resize(oneWidth, oneHeight);
  187. // SPDLOG_LOGGER_DEBUG(m_logger, "oneWidth = {}, oneHeight = {}, OneEyeMap.width = {}, OneEyeMap.height = {}", oneWidth, oneHeight, it->width(), it->height());
  188. }
  189. /* 排列位置 */
  190. for(const auto &it : GEyeMapInfo.getEyeMapList())
  191. {
  192. if(num == 1)
  193. {
  194. it->move(m_marginLeft, m_marginTop);
  195. break;
  196. }
  197. else if(num == 2)
  198. {
  199. int row = it->getNum() % 2 == 1 ? 0 : 1;
  200. int dx = m_marginLeft;
  201. int dy = m_marginTop + row * (oneHeight + m_spacing);
  202. it->move(dx, dy);
  203. if(it->getNum() == 2)
  204. {
  205. break;
  206. }
  207. }
  208. else
  209. {
  210. /* 奇数放左边,偶数放右边 */
  211. int row = ( it->getNum() - 1) / 2;
  212. int column = ( it->getNum() % 2 == 1 ) ? 0 : 1;
  213. int dx = m_marginLeft + column * (oneWidth + m_spacing);
  214. int dy = m_marginTop + row * (oneHeight + m_spacing);
  215. it->move(dx, dy);
  216. if(it->getNum() == num)
  217. {
  218. break;
  219. }
  220. }
  221. }
  222. /* 设置显示或隐藏 */
  223. for(const auto &it : GEyeMapInfo.getEyeMapList())
  224. {
  225. if(it->getNum() <= num)
  226. {
  227. it->setShow(true);
  228. } else
  229. {
  230. it->setShow(false);
  231. }
  232. }
  233. }