123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #include "onesettingitem.h"
- #include "ui_onesettingitem.h"
- #include <QDebug>
- #include <QFile>
- #include <QEvent>
- #include "colordialogapi.h"
- #include "ColorDelegate.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);
- /* 限制自定义名称的字数 */
- ui->lineEdit->setMaxLength(10);
- /* 链接信号和槽 */
- connect(ui->pBtn_background, &QPushButton::clicked, this, &OneSettingItem::do_pBtn_background);
- connect(ui->comboBox, QOverload<int>::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();
- // SPDLOG_LOGGER_DEBUG(m_logger, "当前通道号: {}", eyeMapInfo.channelInfo.channelName.toStdString());
- 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<OneChannelInfo>& 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<int>(it.channel));
- }
- /* 设置自定义委托 */
- ui->comboBox->setItemDelegate(new ColorDelegate(ui->comboBox));
- /* 设置当前选项 */
- 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);
- eyeMapInfo.channelInfo.channelName = channelName;
- eyeMapInfo.channelInfo.channel = static_cast<OscChnNum>(ui->comboBox->currentData().toInt());
- }
- /* 获取当前通道号 */
- OneChannelInfo OneSettingItem::getCurrentChannel()
- {
- OneChannelInfo info;
- info.channel = static_cast<OscChnNum>(ui->comboBox->currentData().toInt());
- info.channelName = ui->comboBox->currentText();
- return info;
- }
- /* 设置自定义的通道名称栏报警 */
- void OneSettingItem::setChannelNameAlarm(bool isAlarm)
- {
- if(isAlarm)
- {
- ui->lineEdit->setProperty("Warn", true);
- ui->lineEdit->style()->unpolish(ui->lineEdit);
- ui->lineEdit->style()->polish(ui->lineEdit);
- }else {
- ui->lineEdit->setProperty("Warn", false);
- ui->lineEdit->style()->unpolish(ui->lineEdit);
- ui->lineEdit->style()->polish(ui->lineEdit);
- }
- }
- /* 设置通道选择栏报警 */
- void OneSettingItem::setChannelSelectAlarm(bool isAlarm)
- {
- if(isAlarm)
- {
- ui->comboBox->setProperty("Warn", true);
- ui->comboBox->style()->unpolish(ui->comboBox);
- ui->comboBox->style()->polish(ui->comboBox);
- }else {
- ui->comboBox->setProperty("Warn", false);
- ui->comboBox->style()->unpolish(ui->comboBox);
- ui->comboBox->style()->polish(ui->comboBox);
- }
- }
- /* 滚轮事件,禁止选择栏滚动 */
- // 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<OscChnNum>(ui->comboBox->currentData().toInt()), ui->comboBox->currentText());
- }
|