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;
- }
-
- 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文件失败");
- }
-
- 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();
-
- 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);
-
- }
- 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);
-
- }
-
- 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());
- }
- void OneSettingItem::setCurrentChannel(const OscChnNum channel)
- {
-
- ui->comboBox->setCurrentIndex(static_cast<int>(channel));
-
-
-
-
-
- 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);
- }
- }
- 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()
- {
-
- 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)
- {
-
- if(ui->comboBox->currentData().toInt() == 0)
- {
- return;
- }
- emit signal_select_channel(static_cast<OscChnNum>(ui->comboBox->currentData().toInt()), ui->comboBox->currentText());
- }
|