421 lines
14 KiB
C++
421 lines
14 KiB
C++
#include "window_settings_emt_kr.h"
|
|
#if (USE_DEVICE_SETTINGS && !USE_DEVICE_SETTINGS_JSON && RM_MODEL_EMT_KR)
|
|
|
|
#include "../fm_dimensions.h"
|
|
#include "../ui/title_widget.h"
|
|
#include "rm_combo_box.h"
|
|
#include "rm_radio_buttons.h"
|
|
#include "rm_group_combo_box.h"
|
|
#include "rm_group_radio_buttons.h"
|
|
#include "rm_text_edit.h"
|
|
|
|
//#include "rm_setting_time.h"
|
|
#include <QComboBox>
|
|
#include <QGridLayout>
|
|
#include <QDir>
|
|
#include <QMessageBox>
|
|
#include <QJsonObject>
|
|
#include "rm_settings_cfg_emt_kr.h"
|
|
|
|
#if (DETECT_SETTING_USB_EJECT)
|
|
#include "../core/rm_usb.h"
|
|
#include "../rm_application.h"
|
|
#endif
|
|
|
|
|
|
// 문자열 처리 UTF
|
|
// https://www.branah.com/unicode-converter
|
|
|
|
const int gComboBoxWidth = 200;
|
|
const int gTitleWidth = 50;
|
|
const int defaultHeight = 55;
|
|
const int subHeight = 30;
|
|
|
|
WindowSettings::WindowSettings(QWidget *parent) : RMSettingsWindowBase(parent)
|
|
{
|
|
QWidget* row = NULL;
|
|
QVBoxLayout* rowLayout = _createRow(&row);
|
|
_createRowS(row,rowLayout,CFG::items,0,200);
|
|
_refresh(CFG::items,0);
|
|
}
|
|
void WindowSettings::afterSave()
|
|
{
|
|
|
|
}
|
|
bool WindowSettings::validateData()
|
|
{
|
|
return true;
|
|
}
|
|
QStringList WindowSettings::_valueStrings(QJsonObject& object,const char* key)
|
|
{
|
|
QStringList ret = QStringList();
|
|
if(object.contains(key)) {
|
|
QJsonArray array = object.value(key).toArray();
|
|
for(int i=0;i<array.size();i++) {
|
|
ret.append(array.at(i).toString());
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
QList<int> WindowSettings::_valueIndices(QJsonObject& object,const char* key)
|
|
{
|
|
QList<int> ret = QList<int>();
|
|
if(object.contains(key)) {
|
|
QJsonArray array = object.value(key).toArray();
|
|
for(int i=0;i<array.size();i++) {
|
|
ret.append(array.at(i).toInt());
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
int WindowSettings::_getObjectIndex(QString& id)
|
|
{
|
|
QObject* obj = _controlByNames.value(id);
|
|
RMComboBox* combo = qobject_cast<RMComboBox*>(obj);
|
|
if(combo != NULL) {
|
|
return combo->comboBox->currentIndex();
|
|
}
|
|
else {
|
|
RMRadioButtons* radios = qobject_cast<RMRadioButtons*>(obj);
|
|
if(radios != NULL) {
|
|
return radios->currentIndex();
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
void WindowSettings::_refresh(QJsonArray items,int depth)
|
|
{
|
|
for(int i=0;i<items.size();i++) {
|
|
QJsonObject obj = items.at(i).toObject();
|
|
|
|
// sub group
|
|
if(obj.contains("group")) {
|
|
_refresh(obj.value("items").toArray(),depth+1);
|
|
}
|
|
|
|
if(obj.contains("events")) {
|
|
//qInfo() << obj << __FUNCTION__;
|
|
QStringList eventList = _valueStrings(obj,"events");
|
|
|
|
QString keyString = obj.value("key").toString();
|
|
int index = _getObjectIndex(keyString);
|
|
//qInfo() << index << __FUNCTION__;
|
|
_processEvent(keyString,eventList,index);
|
|
}
|
|
}
|
|
}
|
|
void WindowSettings::_createRowS(QWidget* parent, QLayout* playout, QJsonArray items, int depth, int value_column_width)
|
|
{
|
|
|
|
for(int i=0;i<items.size();i++) {
|
|
QJsonObject obj = items.at(i).toObject();
|
|
|
|
if(obj.contains("hidden")) {
|
|
continue;
|
|
}
|
|
|
|
// 열 변환
|
|
if(obj.contains("column_break")) {
|
|
QWidget* row = NULL;
|
|
QVBoxLayout* rowLayout = _createRow(&row);
|
|
|
|
parent = row;
|
|
playout = rowLayout;
|
|
}
|
|
if(!obj.contains("key")) {
|
|
qInfo() << "ERROR:" << obj << __FUNCTION__;
|
|
continue;
|
|
}
|
|
QString key = obj.value("key").toString();
|
|
|
|
QString title = "";
|
|
if(obj.contains("title")) {
|
|
title = obj.value("title").toString();
|
|
}
|
|
|
|
QObject* keyObject = NULL;
|
|
|
|
// 그룹 타입의 경우
|
|
if(obj.contains("group")) {
|
|
QGroupBox* g = new QGroupBox(parent);
|
|
keyObject = g;
|
|
//g->setFixedHeight(160);
|
|
g->setObjectName("settings");
|
|
playout->addWidget(g);
|
|
g->setTitle(title);
|
|
QLayout *gg = NULL;
|
|
if(!obj.contains("no_grid")) {
|
|
QGridLayout* gl = new QGridLayout(g);
|
|
gl->setMargin(8);
|
|
gl->setSpacing(4);
|
|
gg = gl;
|
|
} else {
|
|
QVBoxLayout* gl = new QVBoxLayout(g);
|
|
gl->setMargin(8);
|
|
gl->setSpacing(4);
|
|
gg = gl;
|
|
}
|
|
int vcw = value_column_width;
|
|
if(obj.contains("value_column_width")) {
|
|
vcw = obj.value("value_column_width").toInt(value_column_width);
|
|
}
|
|
_createRowS(g,gg,obj.value("items").toArray(),depth+1,vcw);
|
|
}
|
|
else if(obj.contains("control")) {
|
|
QString ctype = obj.value("control").toString();
|
|
if(ctype == "radio" || ctype == "combo") {
|
|
|
|
if (!obj.contains("value_strings") || !obj.contains("offset")) {
|
|
qInfo() << "ERROR ITEM:" << obj << __FUNCTION__;
|
|
continue;
|
|
}
|
|
QStringList items = _valueStrings(obj,"value_strings"); // .value("value_strings").toArray()
|
|
int offset = obj.value("offset").toInt();
|
|
QList<int> indexMap = QList<int>();
|
|
if(obj.contains("values")) {
|
|
indexMap = _valueIndices(obj,"values");
|
|
}
|
|
QLabel* titleLabel = NULL;
|
|
if(ctype == "radio") {
|
|
RMRadioButtons* rrb = NULL;
|
|
if(depth == 0 || obj.contains("group_box")) {
|
|
RMGroupRadioButtons* rb = _MGR(parent,title,playout,items,offset,indexMap);
|
|
rb->setFixedHeight(defaultHeight);
|
|
rrb = rb->radioButtons;
|
|
} else {
|
|
rrb = _MR(parent,title,playout,items,offset,indexMap,&titleLabel);
|
|
rrb->setFixedHeight(subHeight);
|
|
rrb->setFixedWidth(value_column_width);
|
|
//titleLabel->setFixedWidth(100);
|
|
}
|
|
keyObject = rrb;
|
|
if(obj.contains("events")) {
|
|
connect(rrb,SIGNAL(selected(int)),SLOT(onSelected(int)));
|
|
}
|
|
if(obj.contains("disabled")) {
|
|
rrb->setEnabled(false);
|
|
}
|
|
} else {
|
|
RMComboBox* ccb = NULL;
|
|
if(depth == 0 || obj.contains("group_box")) {
|
|
RMGroupComboBox* cb = _MGC(parent,title,playout,items,offset,indexMap);
|
|
cb->comboBox->setFixedWidth(gComboBoxWidth);
|
|
cb->setFixedHeight(defaultHeight);
|
|
ccb = cb->comboBox;
|
|
} else {
|
|
ccb = _MC(parent,title,playout,items,offset,indexMap,&titleLabel);
|
|
ccb->setFixedHeight(subHeight);
|
|
ccb->setFixedWidth(value_column_width);
|
|
//titleLabel->setFixedWidth(100);
|
|
}
|
|
keyObject = ccb;
|
|
if(obj.contains("events")) {
|
|
connect(ccb,SIGNAL(selected(int)),SLOT(onSelected(int)));
|
|
}
|
|
if(obj.contains("disabled")) {
|
|
//qInfo() << "disabled" << title << __FUNCTION__;
|
|
ccb->setEnabled(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
if(keyObject != NULL) {
|
|
_controlByNames.insert(key,keyObject);
|
|
_controlByObjects.insert(keyObject,key);
|
|
|
|
// 이벤트 추가
|
|
if(obj.contains("events")) {
|
|
|
|
QStringList eventList = _valueStrings(obj,"events");
|
|
// QJsonArray events = obj.value("events").toArray();
|
|
// QStringList eventList = QStringList();
|
|
// for(int e=0;e<events.size();e++) {
|
|
// eventList.append(events.at(e).toString());
|
|
// }
|
|
_controlEvents.insert(keyObject,eventList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void WindowSettings::_processEvent(QString& key, QStringList& eventStrings, int index)
|
|
{
|
|
for(int e=0;e<eventStrings.size();e++) {
|
|
QString event = eventStrings.at(e);
|
|
if(event.startsWith("UPDATEVALUES")) {
|
|
_processUpdateEvent(key,event,index);
|
|
}
|
|
else if(event.startsWith("ENABLED")) {
|
|
_processEnableEvent(key,event,index);
|
|
}
|
|
else if (event.startsWith("UPDATE_OTHER_BY_EVENTS")) {
|
|
_processUpdateOtherEvent(key,event,index);
|
|
}
|
|
}
|
|
}
|
|
void WindowSettings::_setObjectIndex(QObject* sender, int index)
|
|
{
|
|
RMComboBox* combo = qobject_cast<RMComboBox*>(sender);
|
|
if(combo != NULL) {
|
|
combo->comboBox->setCurrentIndex(index);
|
|
}
|
|
else {
|
|
RMRadioButtons* radios = qobject_cast<RMRadioButtons*>(sender);
|
|
if(radios != NULL) {
|
|
radios->setCurrentIndex(index);
|
|
}
|
|
}
|
|
}
|
|
void WindowSettings::_setObjectEnable(QObject* sender, bool enabled)
|
|
{
|
|
RMComboBox* combo = qobject_cast<RMComboBox*>(sender);
|
|
if(combo != NULL) {
|
|
combo->setEnabled(enabled);
|
|
}
|
|
else {
|
|
RMRadioButtons* radios = qobject_cast<RMRadioButtons*>(sender);
|
|
if(radios != NULL) {
|
|
radios->setEnabled(enabled);
|
|
}
|
|
}
|
|
}
|
|
void WindowSettings::_processUpdateOtherEvent(QString& key, QString& event, int index)
|
|
{
|
|
Q_UNUSED(index)
|
|
Q_UNUSED(key)
|
|
|
|
QStringList args = event.split(",");
|
|
if(args.size() < 2) {
|
|
return;
|
|
}
|
|
//qInfo() << "key:" << key << __FUNCTION__;
|
|
// SD_OMAKASE의 항목을 확인하여
|
|
QString target = args.at(1); // = SD_OMAKASE
|
|
QObject* tt = _controlByNames.value(target); // 프리셋 컨트롤
|
|
|
|
// "UPDATEVALUES,0,SD_DRIVERECMODE=0,SD_PARKINGRECMODE=4,SD_VIDEOQUALITY=1,SD_VIDEOFRAME=1",
|
|
// "UPDATEVALUES,1,SD_DRIVERECMODE=0,SD_PARKINGRECMODE=1,SD_VIDEOQUALITY=2,SD_VIDEOFRAME=1",
|
|
// "UPDATEVALUES,2,SD_DRIVERECMODE=0,SD_PARKINGRECMODE=3,SD_VIDEOQUALITY=0,SD_VIDEOFRAME=0"
|
|
QStringList targetEvents = _controlEvents.value(tt);
|
|
for(int e=0;e<targetEvents.size();e++) {
|
|
// "UPDATEVALUES,0,SD_DRIVERECMODE=0,SD_PARKINGRECMODE=4,SD_VIDEOQUALITY=1,SD_VIDEOFRAME=1",
|
|
|
|
QStringList eargs = targetEvents.at(e).split(",");
|
|
|
|
// UPDATEVALUES 항목이 아닌 경우 무시
|
|
if(eargs.at(0) != "UPDATEVALUES") {
|
|
//qInfo() << eargs.at(0) << __FUNCTION__;
|
|
continue;
|
|
}
|
|
|
|
// 각 KEY=VALUE 확인 모든 조합이 일치하면
|
|
bool bAllEqual = true;
|
|
for(int a=2;a<eargs.size();a++) {
|
|
QString etarget = eargs[a]; // SD_DRIVERECMODE=0
|
|
QStringList etargetList = etarget.split("=");
|
|
QString etargetKey = etargetList.at(0); // SD_DRIVERECMODE
|
|
int etargetValue = etargetList.at(1).toInt(); // 0
|
|
int eidx = _getObjectIndex(etargetKey); // 현재 컨트롤 값
|
|
//QObject* ct = _controlByNames.value(etargetKey); // 컨트롤 값 확인
|
|
// 조합이 틀린경우 다음 UPDATEVALUES 로 이동
|
|
if(eidx != etargetValue) {
|
|
bAllEqual = false;
|
|
break;
|
|
}
|
|
}
|
|
// 모든 항목이 일치하는 조합이 발생하면 해당 컨트롤 업데이트 후 종료
|
|
if(bAllEqual) {
|
|
int foundIndex = eargs.at(1).toInt(); // UPDATEVALUES,0 -> 0
|
|
_setObjectIndex(tt,foundIndex);
|
|
return;
|
|
}
|
|
}
|
|
// 발견된 조합이 없을 경우 NOT_FOUND 확인 (VERIFYVALUES_BY,SD_OMAKASE,NOT_FOUND=4)
|
|
if(args.size() >= 3) {
|
|
QString nf = args.at(2);
|
|
if(nf.startsWith("NOT_FOUND")) {
|
|
int idx = nf.split("=").at(1).toInt();
|
|
//QObject* tt = _controlByNames.value(target);
|
|
_setObjectIndex(tt,idx);
|
|
}
|
|
}
|
|
//qInfo() << args << __FUNCTION__;
|
|
}
|
|
void WindowSettings::_processUpdateEvent(QString& key, QString& event, int index)
|
|
{
|
|
Q_UNUSED(key)
|
|
|
|
QStringList args = event.split(",");
|
|
// 업데이트 명령일 경우
|
|
if(args[1].toInt() != index) {
|
|
return;
|
|
}
|
|
|
|
// 각 업데이트 확인
|
|
for(int a=2;a<args.size();a++) {
|
|
QString target = args[a];
|
|
QStringList taget = target.split("=");
|
|
QString targetKey = taget.at(0);
|
|
int targetValue = taget.at(1).toInt();
|
|
QObject* tt = _controlByNames.value(targetKey);
|
|
_setObjectIndex(tt,targetValue);
|
|
}
|
|
}
|
|
void WindowSettings::_processEnableEvent(QString& key, QString& event, int index)
|
|
{
|
|
Q_UNUSED(key)
|
|
// SHOWHIDE,1,SD_PARKING_CUTOFF_NORMAL=1,SD_PARKING_CUTOFF_HYBRID=0,SD_PARKING_CUTOFF_ELECTRIC=0
|
|
QStringList args = event.split(",");
|
|
|
|
// 선택된 인덱스의 항목이 아닐 경우
|
|
if(args[1].toInt() != index) {
|
|
return;
|
|
}
|
|
// 각 업데이트 확인
|
|
for(int a=2;a<args.size();a++) {
|
|
QString target = args[a];
|
|
QStringList taget = target.split("=");
|
|
QString targetKey = taget.at(0);
|
|
int targetValue = taget.at(1).toInt();
|
|
QObject* tt = _controlByNames.value(targetKey);
|
|
//qInfo() << tt << taget << targetValue << __FUNCTION__;
|
|
_setObjectEnable(tt,targetValue == 1);
|
|
}
|
|
|
|
}
|
|
|
|
void WindowSettings::onSelected(int index)
|
|
{
|
|
QObject* s = sender();
|
|
// 정보 존재
|
|
if(_controlEvents.contains(s)) {
|
|
|
|
QStringList eventStrings = _controlEvents.value(s);
|
|
QString key = _controlByObjects[s];
|
|
_processEvent(key,eventStrings,index);
|
|
}
|
|
}
|
|
|
|
QVBoxLayout* WindowSettings::_createRow(QWidget** rw)
|
|
{
|
|
const int width = SETTINGS_WINDOW_WIDTH - _contentScrollLayout->contentsMargins().left() - _contentScrollLayout->contentsMargins().right() - _contentScrollLayout->spacing() - 20;
|
|
*rw = new QWidget(_contentScrollWidget);
|
|
(*rw)->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
|
|
(*rw)->setFixedWidth(width / 2);
|
|
_contentScrollLayout->addWidget(*rw);
|
|
_contentScrollLayout->setAlignment(Qt::AlignTop);
|
|
|
|
QVBoxLayout* l = new QVBoxLayout(*rw);
|
|
l->setMargin(0);
|
|
l->setSpacing(10);
|
|
l->setAlignment(Qt::AlignTop);
|
|
return l;
|
|
}
|
|
WindowSettings::~WindowSettings()
|
|
{
|
|
|
|
}
|
|
#endif // #if (USE_DEVICE_SETTINGS)
|
|
//#endif // #if (RM_MODEL == RM_MODEL_TYPE_CS_32FH)
|
|
|