123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #include "onesettingitem.h"
- #include "spdlog.h"
- #include "ui_onesettingitem.h"
- #include <QDebug>
- #include <QFile>
- #include <QEvent>
- #include <qnamespace.h>
- #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.channel);
- // 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, true), 0);
- ui->comboBox->setItemData(ui->comboBox->count() - 1, true, Qt::UserRole + 1);
- for(const auto &it : list)
- {
- /* 设置可选项,用户数据设置为通道号 */
- ui->comboBox->addItem(it.channelName, static_cast<int>(it.channel));
- ui->comboBox->setItemData(ui->comboBox->count() - 1, it.isConnected, Qt::UserRole + 1);
- // SPDLOG_LOGGER_DEBUG(m_logger, "通道号: {}, 通道名: {}", static_cast<int>(it.channel), it.channelName.toStdString());
- }
- /* 设置自定义委托 */
- ui->comboBox->setItemDelegate(new ColorDelegate(ui->comboBox));
- }
- /* 设置当前通道名 */
- void OneSettingItem::setCurrentChannel(const QString& channelName)
- {
- ui->comboBox->setCurrentText(channelName);
- eyeMapInfo.channelInfo.channelName = channelName;
- eyeMapInfo.channelInfo.channel = static_cast<OscChnNum>(ui->comboBox->currentData().toInt());
- }
- /**
- * @brief 使用通道号设置当前通道,这里的通道号和下拉列表的index一一对应
- *
- * @param channel
- */
- void OneSettingItem::setCurrentChannel(const OscChnNum channel)
- {
- // SPDLOG_LOGGER_DEBUG(m_logger, "设置通道号: {}", static_cast<int>(channel));
- ui->comboBox->setCurrentIndex(static_cast<int>(channel));
- // SPDLOG_LOGGER_DEBUG(m_logger, "当前index: {}", ui->comboBox->currentIndex());
- // for(int i = 0; i < ui->comboBox->count(); i++)
- // {
- // SPDLOG_LOGGER_WARN(m_logger, "通道号: {}, 通道名: {}", ui->comboBox->itemData(i).toInt(), ui->comboBox->itemText(i).toStdString());
- // }
- eyeMapInfo.channelInfo.channelName = ui->comboBox->currentText();
- eyeMapInfo.channelInfo.channel = channel;
- }
- /* 获取当前通道号 */
- 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());
- }
|