onesettingitem.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "onesettingitem.h"
  2. #include "ui_onesettingitem.h"
  3. #include <QDebug>
  4. #include <QFile>
  5. #include <QEvent>
  6. #include "colordialogapi.h"
  7. #include "ColorDelegate.h"
  8. OneSettingItem::OneSettingItem(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::OneSettingItem)
  11. {
  12. ui->setupUi(this);
  13. m_logger = spdlog::get("EyeMap");
  14. if(m_logger == nullptr)
  15. {
  16. qDebug() << "获取 EyeMap logger 失败";
  17. return;
  18. }
  19. /* 加载QSS */
  20. QFile fileQss(":/qss/SettingNum/OneItem/OneSettingItem.qss");
  21. if(fileQss.open(QFile::ReadOnly))
  22. {
  23. QString qss = fileQss.readAll();
  24. this->setStyleSheet(qss);
  25. fileQss.close();
  26. } else
  27. {
  28. SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败");
  29. }
  30. /* 禁止comboBox滚轮滚动 */
  31. ui->comboBox->installEventFilter(this);
  32. /* 限制自定义名称的字数 */
  33. ui->lineEdit->setMaxLength(10);
  34. /* 链接信号和槽 */
  35. connect(ui->pBtn_background, &QPushButton::clicked, this, &OneSettingItem::do_pBtn_background);
  36. connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &OneSettingItem::do_select_channel);
  37. }
  38. OneSettingItem::~OneSettingItem()
  39. {
  40. delete ui;
  41. }
  42. /* 设置序号 */
  43. void OneSettingItem::setNum(int num)
  44. {
  45. eyeMapInfo.num = num;
  46. ui->label_num->setText(QString::number(num));
  47. }
  48. /* 设置颜色 */
  49. void OneSettingItem::setColor(const QColor& color)
  50. {
  51. eyeMapInfo.titleBarColor = color;
  52. QString qss = QString("background-color: %1").arg(color.name());
  53. ui->pBtn_background->setStyleSheet(qss);
  54. }
  55. /* 获取所有信息 */
  56. OneEyeMapInfo& OneSettingItem::getEyeMapInfo()
  57. {
  58. /* 更新所有的信息并返回 */
  59. eyeMapInfo.title = ui->lineEdit->text();
  60. eyeMapInfo.channelInfo = getCurrentChannel();
  61. // SPDLOG_LOGGER_DEBUG(m_logger, "当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString());
  62. return eyeMapInfo;
  63. }
  64. /* 设置项信息 */
  65. void OneSettingItem::setItemInfo(const OneEyeMapInfo& info)
  66. {
  67. eyeMapInfo = info;
  68. setNum(info.num);
  69. ui->label_num->setText(QString::number(info.num));
  70. ui->lineEdit->setText(info.title);
  71. setColor(info.titleBarColor);
  72. setCurrentChannel(info.channelInfo.channelName);
  73. // SPDLOG_LOGGER_DEBUG(m_logger, "当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString());
  74. }
  75. /* 设置可选通道列表 */
  76. void OneSettingItem::setChannelList(const QList<OneChannelInfo>& list)
  77. {
  78. ui->comboBox->clear();
  79. ui->comboBox->addItem(GEyeMapInfo.getChannelName(OscChnNum::Osc_None), 0);
  80. for(const auto &it : list)
  81. {
  82. ui->comboBox->addItem(it.channelName, static_cast<int>(it.channel));
  83. }
  84. /* 设置自定义委托 */
  85. ui->comboBox->setItemDelegate(new ColorDelegate(ui->comboBox));
  86. /* 设置当前选项 */
  87. ui->comboBox->setCurrentText(eyeMapInfo.channelInfo.channelName);
  88. // SPDLOG_LOGGER_DEBUG(m_logger, "---当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString());
  89. }
  90. /* 设置当前通道名 */
  91. void OneSettingItem::setCurrentChannel(const QString& channelName)
  92. {
  93. ui->comboBox->setCurrentText(channelName);
  94. eyeMapInfo.channelInfo.channelName = channelName;
  95. eyeMapInfo.channelInfo.channel = static_cast<OscChnNum>(ui->comboBox->currentData().toInt());
  96. }
  97. /* 获取当前通道号 */
  98. OneChannelInfo OneSettingItem::getCurrentChannel()
  99. {
  100. OneChannelInfo info;
  101. info.channel = static_cast<OscChnNum>(ui->comboBox->currentData().toInt());
  102. info.channelName = ui->comboBox->currentText();
  103. return info;
  104. }
  105. /* 设置自定义的通道名称栏报警 */
  106. void OneSettingItem::setChannelNameAlarm(bool isAlarm)
  107. {
  108. if(isAlarm)
  109. {
  110. ui->lineEdit->setProperty("Warn", true);
  111. ui->lineEdit->style()->unpolish(ui->lineEdit);
  112. ui->lineEdit->style()->polish(ui->lineEdit);
  113. }else {
  114. ui->lineEdit->setProperty("Warn", false);
  115. ui->lineEdit->style()->unpolish(ui->lineEdit);
  116. ui->lineEdit->style()->polish(ui->lineEdit);
  117. }
  118. }
  119. /* 设置通道选择栏报警 */
  120. void OneSettingItem::setChannelSelectAlarm(bool isAlarm)
  121. {
  122. if(isAlarm)
  123. {
  124. ui->comboBox->setProperty("Warn", true);
  125. ui->comboBox->style()->unpolish(ui->comboBox);
  126. ui->comboBox->style()->polish(ui->comboBox);
  127. }else {
  128. ui->comboBox->setProperty("Warn", false);
  129. ui->comboBox->style()->unpolish(ui->comboBox);
  130. ui->comboBox->style()->polish(ui->comboBox);
  131. }
  132. }
  133. /* 滚轮事件,禁止选择栏滚动 */
  134. // void OneSettingItem::wheelEvent(QWheelEvent *event)
  135. // {
  136. // event->ignore();
  137. // }
  138. /* 事件过滤器 */
  139. bool OneSettingItem::eventFilter(QObject *watched, QEvent *event)
  140. {
  141. if(watched == ui->comboBox)
  142. {
  143. if(event->type() == QEvent::Wheel)
  144. {
  145. return true;
  146. }
  147. }
  148. return QWidget::eventFilter(watched, event);
  149. }
  150. /* 设置颜色 */
  151. void OneSettingItem::do_pBtn_background()
  152. {
  153. // SPDLOG_LOGGER_DEBUG(m_logger, "序号{}点击了背景颜色按钮", eyeMapInfo.num);
  154. QColor color = getColor(nullptr, ColorDlgSkin::DARK);
  155. if(color.isValid())
  156. {
  157. QString qss = QString("background-color: %1").arg(color.name());
  158. ui->pBtn_background->setStyleSheet(qss);
  159. }
  160. eyeMapInfo.titleBarColor = color;
  161. }
  162. /* 选择了通道号,发送信号主要是给外面判断通道号是否冲突 */
  163. void OneSettingItem::do_select_channel(int index)
  164. {
  165. // SPDLOG_LOGGER_DEBUG(m_logger, "序号{}选择了 {}, 通道号: {}", eyeMapInfo.num, ui->comboBox->currentText().toStdString(), ui->comboBox->currentData().toInt());
  166. if(ui->comboBox->currentData().toInt() == 0)
  167. {
  168. return;
  169. }
  170. emit signal_select_channel(static_cast<OscChnNum>(ui->comboBox->currentData().toInt()), ui->comboBox->currentText());
  171. }