#include "onesettingitem.h" #include "ui_onesettingitem.h" #include #include #include #include "colordialogapi.h" OneSettingItem::OneSettingItem(QWidget *parent) : QWidget(parent), ui(new Ui::OneSettingItem) { ui->setupUi(this); m_logger = spdlog::get("EyeMap"); if(m_logger == nullptr) { qDebug() << "获取 EyeMap logger 失败"; return; } /* 加载QSS */ QFile fileQss(":/qss/SettingNum/OneItem/OneSettingItem.qss"); if(fileQss.open(QFile::ReadOnly)) { QString qss = fileQss.readAll(); this->setStyleSheet(qss); fileQss.close(); } else { SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败"); } /* 禁止comboBox滚轮滚动 */ ui->comboBox->installEventFilter(this); /* 链接信号和槽 */ connect(ui->pBtn_background, &QPushButton::clicked, this, &OneSettingItem::do_pBtn_background); connect(ui->comboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &OneSettingItem::do_select_channel); } OneSettingItem::~OneSettingItem() { delete ui; } /* 设置序号 */ void OneSettingItem::setNum(int num) { eyeMapInfo.num = num; ui->label_num->setText(QString::number(num)); } /* 设置颜色 */ void OneSettingItem::setColor(const QColor& color) { eyeMapInfo.titleBarColor = color; QString qss = QString("background-color: %1").arg(color.name()); ui->pBtn_background->setStyleSheet(qss); } /* 获取所有信息 */ OneEyeMapInfo& OneSettingItem::getEyeMapInfo() { /* 更新所有的信息并返回 */ eyeMapInfo.title = ui->lineEdit->text(); eyeMapInfo.channelInfo = getCurrentChannel(); return eyeMapInfo; } /* 设置项信息 */ void OneSettingItem::setItemInfo(const OneEyeMapInfo& info) { eyeMapInfo = info; setNum(info.num); ui->label_num->setText(QString::number(info.num)); ui->lineEdit->setText(info.title); setColor(info.titleBarColor); setCurrentChannel(info.channelInfo.channelName); // SPDLOG_LOGGER_DEBUG(m_logger, "当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString()); } /* 设置可选通道列表 */ void OneSettingItem::setChannelList(const QList& list) { ui->comboBox->clear(); ui->comboBox->addItem(GEyeMapInfo.getChannelName(OscChnNum::Osc_None), 0); for(const auto &it : list) { ui->comboBox->addItem(it.channelName, static_cast(it.channel)); } /* 设置当前选项 */ ui->comboBox->setCurrentText(eyeMapInfo.channelInfo.channelName); // SPDLOG_LOGGER_DEBUG(m_logger, "---当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString()); } /* 设置当前通道名 */ void OneSettingItem::setCurrentChannel(const QString& channelName) { ui->comboBox->setCurrentText(channelName); } /* 获取当前通道号 */ OneChannelInfo OneSettingItem::getCurrentChannel() { OneChannelInfo info; info.channel = static_cast(ui->comboBox->currentData().toInt()); info.channelName = ui->comboBox->currentText(); return info; } /* 滚轮事件,禁止选择栏滚动 */ // void OneSettingItem::wheelEvent(QWheelEvent *event) // { // event->ignore(); // } /* 事件过滤器 */ bool OneSettingItem::eventFilter(QObject *watched, QEvent *event) { if(watched == ui->comboBox) { if(event->type() == QEvent::Wheel) { return true; } } return QWidget::eventFilter(watched, event); } /* 设置颜色 */ void OneSettingItem::do_pBtn_background() { // SPDLOG_LOGGER_DEBUG(m_logger, "序号{}点击了背景颜色按钮", eyeMapInfo.num); QColor color = getColor(nullptr, ColorDlgSkin::DARK); if(color.isValid()) { QString qss = QString("background-color: %1").arg(color.name()); ui->pBtn_background->setStyleSheet(qss); } eyeMapInfo.titleBarColor = color; } /* 选择了通道号,发送信号主要是给外面判断通道号是否冲突 */ void OneSettingItem::do_select_channel(int index) { // SPDLOG_LOGGER_DEBUG(m_logger, "序号{}选择了 {}, 通道号: {}", eyeMapInfo.num, ui->comboBox->currentText().toStdString(), ui->comboBox->currentData().toInt()); if(ui->comboBox->currentData().toInt() == 0) { return; } emit signal_select_channel(static_cast(ui->comboBox->currentData().toInt()), ui->comboBox->currentText()); }