329 lines
10 KiB
C++
329 lines
10 KiB
C++
|
|
#include "monitorDisplaySettingDlg.h"
|
||
|
|
#include "ui_monitorDisplaySettingDlg.h"
|
||
|
|
#include "monitorPanel.h"
|
||
|
|
#include <QColorDialog>
|
||
|
|
#include <QSvgRenderer>
|
||
|
|
#include <QPainter>
|
||
|
|
#include "projectModelManager.h"
|
||
|
|
#include "projectIconSelectionDlg.h"
|
||
|
|
|
||
|
|
MonitorDisplaySettingDlg::MonitorDisplaySettingDlg(QWidget *parent)
|
||
|
|
: QDialog(parent)
|
||
|
|
, ui(new Ui::monitorDisplaySettingDlg)
|
||
|
|
{
|
||
|
|
ui->setupUi(this);
|
||
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||
|
|
_parent = dynamic_cast<MonitorPanel*>(parent);
|
||
|
|
initial();
|
||
|
|
}
|
||
|
|
|
||
|
|
MonitorDisplaySettingDlg::~MonitorDisplaySettingDlg()
|
||
|
|
{
|
||
|
|
delete ui;
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::initial()
|
||
|
|
{
|
||
|
|
connect(ui->btn_save,&QPushButton::clicked,this,&MonitorDisplaySettingDlg::onSaveClicked);
|
||
|
|
connect(ui->btn_cancel,&QPushButton::clicked,this,&MonitorDisplaySettingDlg::onCancelClicked);
|
||
|
|
|
||
|
|
connect(ui->cb_type,&QComboBox::currentTextChanged,this,&MonitorDisplaySettingDlg::onTypeChanged);
|
||
|
|
connect(ui->cb_state,&QComboBox::currentTextChanged,this,&MonitorDisplaySettingDlg::onStateChanged);
|
||
|
|
|
||
|
|
connect(ui->btn_selectColor, &QPushButton::clicked, this, [this]() {
|
||
|
|
QColor newColor = QColorDialog::getColor(_curColor, this, "选择颜色");
|
||
|
|
if (newColor.isValid()) { // 用户点击了OK
|
||
|
|
_curColor = newColor;
|
||
|
|
// 更新按钮显示
|
||
|
|
QPixmap pixmap(16, 16);
|
||
|
|
pixmap.fill(newColor);
|
||
|
|
ui->btn_selectColor->setIcon(QIcon(pixmap));
|
||
|
|
ui->btn_selectColor->setText(newColor.name());
|
||
|
|
// 触发预览更新
|
||
|
|
|
||
|
|
if(_curType.notEmpty() && _curState.notEmpty()){
|
||
|
|
_tempSetting[_curType][_curState].sColor = _curColor.name();
|
||
|
|
ui->content->setColors(_curColor);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
connect(ui->checkBox_custom, &QCheckBox::toggled, this,&MonitorDisplaySettingDlg::onCheckboxToggled);
|
||
|
|
connect(ui->btn_selectIcon, &QPushButton::clicked, this,&MonitorDisplaySettingDlg::onIconSelectClicked);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::showDlg()
|
||
|
|
{
|
||
|
|
show();
|
||
|
|
_tempSetting = _parent->getModelController()->getMonitorDisplaySetting();
|
||
|
|
ui->cb_type->clear();
|
||
|
|
ui->cb_state->clear();
|
||
|
|
|
||
|
|
for(auto iter = _tempSetting.begin();iter != _tempSetting.end();++iter){
|
||
|
|
ui->cb_type->addItem(iter.key().sName,iter.key().sTag);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onSaveClicked()
|
||
|
|
{
|
||
|
|
saveSetting(_curType,_curState);
|
||
|
|
_parent->getModelController()->getMonitorDisplaySetting() = _tempSetting;
|
||
|
|
hide();
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onCancelClicked()
|
||
|
|
{
|
||
|
|
hide();
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onCheckboxToggled(bool val)
|
||
|
|
{
|
||
|
|
if(val){
|
||
|
|
ui->btn_selectColor->setEnabled(true);
|
||
|
|
ui->btn_selectIcon->setEnabled(true);
|
||
|
|
ui->sb_width->setEnabled(true);
|
||
|
|
ui->sb_height->setEnabled(true);
|
||
|
|
ui->cb_effect->setEnabled(true);
|
||
|
|
}
|
||
|
|
else{
|
||
|
|
ui->btn_selectColor->setEnabled(false);
|
||
|
|
ui->btn_selectIcon->setEnabled(false);
|
||
|
|
ui->sb_width->setEnabled(false);
|
||
|
|
ui->sb_height->setEnabled(false);
|
||
|
|
ui->cb_effect->setEnabled(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onIconSelectClicked()
|
||
|
|
{
|
||
|
|
if(!_curMeta.isEmpty() && !_curModel.isEmpty()){
|
||
|
|
auto mapAllSvg = ProjectModelManager::instance().getData()[_curMeta][_curModel].modelSetting.mapSvg;
|
||
|
|
ProjectIconSelectionDlg dialog(mapAllSvg, this);
|
||
|
|
if (dialog.exec() == QDialog::Accepted) {
|
||
|
|
QByteArray selectedSVG = dialog.selectedSVG();
|
||
|
|
if (!selectedSVG.isEmpty()) {
|
||
|
|
QSvgRenderer renderer(selectedSVG);
|
||
|
|
QPixmap pixmap(32, 32);
|
||
|
|
pixmap.fill(Qt::transparent);
|
||
|
|
QPainter painter(&pixmap);
|
||
|
|
renderer.render(&painter);
|
||
|
|
|
||
|
|
ui->btn_selectIcon->setIcon(QIcon(pixmap));
|
||
|
|
ui->content->setSvgFile(selectedSVG);
|
||
|
|
|
||
|
|
if(_curType.notEmpty() && _curState.notEmpty()){
|
||
|
|
_tempSetting[_curType][_curState].bytPicture = selectedSVG;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onTypeChanged(const QString& str)
|
||
|
|
{
|
||
|
|
/*saveSetting(_curType,_curState);
|
||
|
|
ui->cb_state->clear();
|
||
|
|
monitorItemTypeStruct keyType;
|
||
|
|
keyType.sTag = ui->cb_type->currentData().toString();
|
||
|
|
keyType.sName = str;
|
||
|
|
QMap<monitorItemStateStruct,monitorItemDisplayInfo> mapInfo = _tempSetting.value(keyType);
|
||
|
|
for(auto iter = mapInfo.begin();iter != mapInfo.end();++iter){
|
||
|
|
ui->cb_state->addItem(iter.key().sState,int(iter.key().eState));
|
||
|
|
if(_curMeta != iter->sMeta){
|
||
|
|
_curMeta = iter->sMeta;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_curType = keyType;
|
||
|
|
onStateChanged(ui->cb_state->currentText());*/
|
||
|
|
|
||
|
|
//monitorItemStateStruct keyState;
|
||
|
|
//keyState.sState = ui->cb_state->currentText();
|
||
|
|
//loadSetting(_curType,ui->cb_state->currentText());
|
||
|
|
// 1. 保存当前设备类型的设置
|
||
|
|
saveSetting(_curType, _curState);
|
||
|
|
|
||
|
|
// 2. 清空状态下拉框
|
||
|
|
ui->cb_state->clear();
|
||
|
|
|
||
|
|
// 3. 构建新的设备类型键值
|
||
|
|
monitorItemTypeStruct keyType;
|
||
|
|
keyType.sTag = ui->cb_type->currentData().toString();
|
||
|
|
keyType.sName = str;
|
||
|
|
|
||
|
|
// 4. 获取新设备类型对应的状态列表
|
||
|
|
QMap<monitorItemStateStruct, monitorItemDisplayInfo> mapInfo = _tempSetting.value(keyType);
|
||
|
|
|
||
|
|
// 5. 如果新设备类型没有状态数据,直接返回
|
||
|
|
if (mapInfo.isEmpty()) {
|
||
|
|
_curType = keyType;
|
||
|
|
// 清空当前状态相关显示
|
||
|
|
clearStateDisplay();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 6. 填充状态下拉框
|
||
|
|
QString firstState; // 记录第一个状态,用于后续加载
|
||
|
|
for (auto iter = mapInfo.begin(); iter != mapInfo.end(); ++iter) {
|
||
|
|
QString stateName = iter.key().sState;
|
||
|
|
int stateValue = static_cast<int>(iter.key().eState);
|
||
|
|
|
||
|
|
ui->cb_state->addItem(stateName, stateValue);
|
||
|
|
|
||
|
|
// 记录第一个状态
|
||
|
|
if (firstState.isEmpty()) {
|
||
|
|
firstState = stateName;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新元数据(如果有变化)
|
||
|
|
if (_curMeta != iter->sMeta) {
|
||
|
|
_curMeta = iter->sMeta;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 7. 更新当前设备类型
|
||
|
|
_curType = keyType;
|
||
|
|
|
||
|
|
// 8. 加载第一个状态的设置
|
||
|
|
if (!firstState.isEmpty()) {
|
||
|
|
// 设置下拉框当前项为第一个状态
|
||
|
|
ui->cb_state->setCurrentIndex(0);
|
||
|
|
// 触发状态变化处理
|
||
|
|
onStateChanged(firstState);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::onStateChanged(const QString& str)
|
||
|
|
{
|
||
|
|
/*if(_tempSetting.contains(_curType)){
|
||
|
|
monitorItemStateStruct keyState;
|
||
|
|
keyState.sState = str;
|
||
|
|
keyState.eState = monitorItemState(ui->cb_state->currentData().toInt());
|
||
|
|
if(_tempSetting[_curType].contains(keyState)){
|
||
|
|
saveSetting(_curType,_curState);
|
||
|
|
auto info = _tempSetting[_curType][keyState];
|
||
|
|
ui->checkBox_custom->setChecked(info.bEnable);
|
||
|
|
if(_curModel != info.sModel){
|
||
|
|
_curModel = info.sModel;
|
||
|
|
}
|
||
|
|
_curState = keyState;
|
||
|
|
loadSetting(_curType,_curState);
|
||
|
|
}
|
||
|
|
}*/
|
||
|
|
// 1. 检查当前设备类型是否存在
|
||
|
|
if (!_tempSetting.contains(_curType)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. 检查状态是否为空
|
||
|
|
if (str.isEmpty()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. 构建状态键值
|
||
|
|
monitorItemStateStruct keyState;
|
||
|
|
keyState.sState = str;
|
||
|
|
|
||
|
|
// 4. 从下拉框获取状态枚举值(添加安全检查)
|
||
|
|
QVariant stateData = ui->cb_state->currentData();
|
||
|
|
if (!stateData.isValid()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool ok = false;
|
||
|
|
int stateValue = stateData.toInt(&ok);
|
||
|
|
if (!ok) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
keyState.eState = monitorItemState(stateValue);
|
||
|
|
|
||
|
|
// 5. 检查状态是否存在
|
||
|
|
auto& typeSettings = _tempSetting[_curType];
|
||
|
|
if (!typeSettings.contains(keyState)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 6. 保存当前设置
|
||
|
|
saveSetting(_curType, _curState);
|
||
|
|
|
||
|
|
// 7. 获取新状态信息
|
||
|
|
auto& info = typeSettings[keyState];
|
||
|
|
|
||
|
|
// 8. 更新界面控件
|
||
|
|
ui->checkBox_custom->setChecked(info.bEnable);
|
||
|
|
|
||
|
|
// 9. 更新模型信息(仅在变化时)
|
||
|
|
if (_curModel != info.sModel) {
|
||
|
|
_curModel = info.sModel;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 10. 更新当前状态并加载新设置
|
||
|
|
_curState = keyState;
|
||
|
|
loadSetting(_curType, _curState);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::loadSetting(monitorItemTypeStruct type,monitorItemStateStruct state)
|
||
|
|
{
|
||
|
|
auto setting = _tempSetting[type][state];
|
||
|
|
ui->checkBox_custom->setChecked(setting.bEnable);
|
||
|
|
if(setting.bEnable){
|
||
|
|
ui->btn_selectColor->setEnabled(true);
|
||
|
|
ui->btn_selectIcon->setEnabled(true);
|
||
|
|
ui->sb_width->setEnabled(true);
|
||
|
|
ui->sb_height->setEnabled(true);
|
||
|
|
ui->cb_effect->setEnabled(true);
|
||
|
|
}
|
||
|
|
else{
|
||
|
|
ui->btn_selectColor->setEnabled(false);
|
||
|
|
ui->btn_selectIcon->setEnabled(false);
|
||
|
|
ui->sb_width->setEnabled(false);
|
||
|
|
ui->sb_height->setEnabled(false);
|
||
|
|
ui->cb_effect->setEnabled(false);
|
||
|
|
}
|
||
|
|
_curColor = QColor(setting.sColor);
|
||
|
|
// 更新按钮显示
|
||
|
|
QPixmap pixmap(16, 16);
|
||
|
|
pixmap.fill(_curColor);
|
||
|
|
ui->btn_selectColor->setIcon(QIcon(pixmap));
|
||
|
|
ui->btn_selectColor->setText(_curColor.name());
|
||
|
|
|
||
|
|
QSvgRenderer renderer(setting.bytPicture);
|
||
|
|
QPixmap pixSvg(32, 32);
|
||
|
|
pixmap.fill(Qt::transparent);
|
||
|
|
QPainter painter(&pixSvg);
|
||
|
|
renderer.render(&painter);
|
||
|
|
|
||
|
|
ui->btn_selectIcon->setIcon(QIcon(pixSvg));
|
||
|
|
ui->content->setSvgFile(setting.bytPicture);
|
||
|
|
ui->content->setColors(_curColor);
|
||
|
|
|
||
|
|
ui->sb_width->setValue(setting.nWidth);
|
||
|
|
ui->sb_height->setValue(setting.nHeight);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::saveSetting(monitorItemTypeStruct type,monitorItemStateStruct state)
|
||
|
|
{
|
||
|
|
if(type.notEmpty() && state.notEmpty()){
|
||
|
|
auto& setting = _tempSetting[type][state];
|
||
|
|
setting.bEnable = ui->checkBox_custom->isChecked();
|
||
|
|
setting.sColor = _curColor.name();
|
||
|
|
setting.bytPicture = ui->content->getCurSvg();
|
||
|
|
setting.nWidth = ui->sb_width->value();
|
||
|
|
setting.nHeight = ui->sb_height->value();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::updatePreview()
|
||
|
|
{
|
||
|
|
ui->content->update();
|
||
|
|
}
|
||
|
|
|
||
|
|
void MonitorDisplaySettingDlg::clearStateDisplay()
|
||
|
|
{
|
||
|
|
ui->checkBox_custom->setChecked(false);
|
||
|
|
// 可以添加其他需要清空的UI元素
|
||
|
|
_curState = monitorItemStateStruct(); // 清空当前状态
|
||
|
|
_curModel = QString(); // 清空当前模型
|
||
|
|
_curMeta = QString(); // 清空元数据
|
||
|
|
}
|