onesettingitem.cpp 4.3 KB

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