#include "rm_settings_window_base.h" #if (USE_DEVICE_SETTINGS && !USE_DEVICE_SETTINGS_JSON) #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 "../core/fm_strings.h" #include "rm_settings_cfg.h" #include #include #include #if (SETTINGS_WINDOW_SCROLL) #include #include #include "../ui/fm_colors.h" #endif #if (DETECT_SETTING_USB_EJECT && !DETECT_USB_CHANGE) #include "../core/rm_usb.h" #include "../rm_application.h" #endif // 문자열 처리 UTF // https://www.branah.com/unicode-converter //bool RMSettingsWindowBase::loaded = false; QString RMSettingsWindowBase::lastSettingDisk = ""; //const int gComboBoxWidth = 200; //const int gTitleWidth = 50; #if (RM_MODEL_EMT_KR) static const QStringList gOnOff = QStringList() << "ON" << "OFF"; #else // RM_MODEL_EMT_KR static const QStringList gOnOff = QStringList() << MKU8("\xe3\x82\xaa\xe3\x83\xb3") << MKU8("\xe3\x82\xaa\xe3\x83\x95"); #endif // RM_MODEL_EMT_KR static const QStringList gEOnOff = QStringList() << "ON" << "OFF"; #if (RM_MODEL_EMT_KR) RMSettingsWindowBase::RMSettingsWindowBase(QWidget *parent) : RMPopup(parent,FMS::txt("settings"),"") #else RMSettingsWindowBase::RMSettingsWindowBase(QWidget *parent) : RMPopup(parent,"","title_settings.png") #endif { // 이미 로딩됨 #if !(RM_MODEL_EMT_KR) QString path = QDir::cleanPath(lastSettingDisk + SETTINGS_FILE_NAME); // 모델 디스크가 아닐 경우 #if (MULTI_MODEL_VIEWER) if(RMApp::isModelDisk(lastSettingDisk,NULL) == false) #else // MULTI_MODEL_VIEWER if(RMApp::isModelDisk(lastSettingDisk) == false) #endif // MULTI_MODEL_VIEWER { CFG::setDefault(); #if !(DO_NOT_MAKE_CFG) CFG::save(path); #endif } else { CFG::load(path); } #endif // #if !(RM_MODEL_EMT_KR) #if (SETTINGS_WINDOW_SCROLL) this->setFixedSize(SETTINGS_WINDOW_WIDTH,SETTINGS_WiNDOW_SCROLL_HEIGHT); #else this->setFixedSize(SETTINGS_WINDOW_WIDTH,SETTINGS_WiNDOW_HEIGHT); #endif //_contentWidget->setObjectName("bg_dark_widget"); layout = new QHBoxLayout(_contentWidget); layout->setMargin(8); layout->setSpacing(8); QWidget* bwLeft = new QWidget(_buttonWidget); _buttonLayout->addWidget(bwLeft); QWidget* bwRight = new QWidget(_buttonWidget); _buttonLayout->addWidget(bwRight); QHBoxLayout* blLeft = new QHBoxLayout(bwLeft); blLeft->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); QHBoxLayout* blRight = new QHBoxLayout(bwRight); blRight->setAlignment(Qt::AlignRight|Qt::AlignVCenter); #if (LIVE_LANGUAGE2) RMButton* defaultButton = RMButton::create2(bwRight,blRight,"button","default",QSize(120,30)); defaultButton->setText(FMS::txt("default")); connect(defaultButton,SIGNAL(clicked()),SLOT(onDefault())); RMButton* okButton = RMButton::create2(bwRight,blRight,"button","ok",QSize(120,30)); okButton->setText(FMS::txt("ok")); connect(okButton,SIGNAL(clicked()),this,SLOT(onSaveAnAccept())); RMButton* cancelButton = RMButton::create2(bwRight,blRight,"button","cancel",QSize(120,30)); cancelButton->setText(FMS::txt("cancel")); connect(cancelButton,SIGNAL(clicked()),this,SLOT(onCancel())); #else // LIVE_LANGUAGE2 // 初期値 QString title = MKU8("\xe5\x88\x9d\xe6\x9c\x9f\xe5\x80\xa4"); #if (LIVE_LANGUAGE_CHANGE) if(RMLanguage::isJP() == false) { title = "Reset"; } #endif RMButton* defaultButton = RMButton::create(bwRight,blRight,"button",FMS::txt("default"),QSize(120,30)); //RMButton* defaultButton = RMButton::create(bwLeft,blLeft,"popup_button",title,QSize(120,30)); defaultButton->setText(FMS::txt("default")); connect(defaultButton,SIGNAL(clicked()),SLOT(onDefault())); // 適用 title = MKU8("\xe9\x81\xa9\xe7\x94\xa8"); #if (LIVE_LANGUAGE_CHANGE) if(RMLanguage::isJP() == false) { title = "Save";} #endif //#if !(MODEL_WATEX) // RMButton* applyButton = RMButton::create(bwRight,blRight,"popup_button",title,QSize(120,30)); // applyButton->setText(title); // connect(applyButton,SIGNAL(clicked()),this,SLOT(onSave())); //#endif RMButton* okButton = RMButton::create(bwRight,blRight,"button",FMS::txt("ok"),QSize(120,30)); //RMButton* okButton = RMButton::create(bwRight,blRight,"popup_button",QString("OK"),QSize(120,30)); okButton->setText(FMS::txt("ok")); connect(okButton,SIGNAL(clicked()),this,SLOT(onSaveAnAccept())); #if (MODEL_WATEX) title = MKU8("\xe3\x82\xad\xe3\x83\xa3\xe3\x83\xb3\xe3\x82\xbb\xe3\x83\xab"); // キャンセル #else title = MKU8("\xe9\x96\x89\xe3\x81\x98\xe3\x82\x8b"); // 閉じる #endif #if (LIVE_LANGUAGE_CHANGE) if(RMLanguage::isJP() == false) { title = "Cancel";} #endif RMButton* cancelButton = RMButton::create(bwRight,blRight,"button",FMS::txt("cancel"),QSize(120,30)); cancelButton->setText(FMS::txt("cancel")); // connect(okButton,SIGNAL(clicked()),this,SLOT(onOK())); // RMButton* cancelButton = RMButton::create(bwRight,blRight,"popup_button",title,QSize(120,30)); // cancelButton->setText(title); connect(cancelButton,SIGNAL(clicked()),this,SLOT(onCancel())); /* 모델명 사용하지 않음 QLabel* modelName = new QLabel(_title->_toolBar); modelName->setText(QString((const char*)CFG::data) + " "); modelName->setObjectName("title_label"); _title->_toolBarLayout->insertWidget(0,modelName); */ #endif // #else // LIVE_LANGUAGE2 #if (DETECT_SETTING_USB_EJECT && !DETECT_USB_CHANGE) _usb = new rm_usb(this); _usb->registerEvent(this); RMApplication::instance()->installNativeEventFilter(_usb); connect(_usb,SIGNAL(usbChanged(bool,QString&)),SLOT(onUSBChange(bool,QString&))); #endif // @DETECT_SETTING_USB_EJECT #if (SETTINGS_WINDOW_SCROLL) layout->setMargin(0); layout->setSpacing(0); // 스크롤 영역 생성 _contentScrollArea = new QScrollArea(_contentWidget); _contentScrollArea->setStyleSheet("QScrollArea { background: transparent; }"); _contentScrollArea->setWidgetResizable( true ); layout->addWidget(_contentScrollArea); _contentScrollWidget = new QWidget(); // _contentScrollArea //_contentScrollWidget->setStyleSheet("QWidget { background: #FF0000;}"); _contentScrollLayout = new QHBoxLayout(_contentScrollWidget); //ZERO_LAYOUT(_contentScrollLayout); //_contentScrollLayout->setMargin(8); _contentScrollLayout->setSpacing(8); _contentScrollLayout->setContentsMargins(8,10,8,10); // 상하단 마진 _contentScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); _contentScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // 자동 설정 //_contentScrollWidget->setFixedHeight(SETTINGS_WiNDOW_HEIGHT); _contentScrollWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); _contentScrollArea->setFrameShape(QFrame::NoFrame); _contentScrollWidget->setObjectName("scroll2"); _contentScrollWidget->setStyleSheet("QWidget#scroll2 { background: transparent; }"); //_contentScrollWidget->setFixedHeight(SETTINGS_WiNDOW_HEIGHT); _contentScrollArea->setWidget(_contentScrollWidget); QString scrollStyle = "QScrollBar:vertical\ {\ border-width: 0px;\ border-style: solid;\ background: #3B3B3B;\ width: 10px;\ margin: 0px 0 0px 0;\ }\ QScrollBar::handle:vertical:disabled{background: #3B3B3B;}\ QScrollBar::handle:vertical\ {\ background: $HANDLE_COLOR$;\ min-height: 25px;\ margin: 2px 1px 2px 1px;\ }\ QScrollBar::add-line:vertical\ {\ border: none;\ background: none;\ height: 0px;\ width: 0px;\ subcontrol-position: bottom;\ subcontrol-origin: margin;\ }\ QScrollBar::sub-line:vertical\ {\ border: none;\ background: none;\ height: 0px;\ width: 0px;\ subcontrol-position: top;\ subcontrol-origin: margin;\ }\ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\ {\ background: #3A3A3A;\ }\ QScrollBar::up-arrow:vertical\ {\ border: none;\ background: #3A3A3A;\ }\ QScrollBar::down-arrow:vertical\ {\ border: none;\ background: #5A5A5A;\ }"; _contentScrollArea->verticalScrollBar()->setStyleSheet(scrollStyle.replace("$HANDLE_COLOR$",QString().sprintf("#%06X",FM_SILDER_COLOR))); #endif // SCROLL } #if (DETECT_SETTING_USB_EJECT && !DETECT_USB_CHANGE) void RMSettingsWindowBase::onUSBChange(bool inserted, QString& drive) { // qInfo() << __FUNCTION__; if(inserted == false && RMSettingsWindowBase::lastSettingDisk.contains(drive,Qt::CaseInsensitive)) { reject(); } } #elif (DETECT_USB_CHANGE) void RMSettingsWindowBase::onUsbRemoved() { reject(); } #endif // @DETECT_SETTING_USB_EJECT #if (USE_JSON_SETTINGS) #else // #if (USE_JSON_SETTINGS) RMGroupRadioButtons* RMSettingsWindowBase::_MGR_ONOFF(QWidget* parent,QString title,QLayout* layout,int type) { #if (LIVE_LANGUAGE_CHANGE && !RM_MODEL_EMT_KR) if(RMLanguage::isJP() == false) { return _MGR(parent,title,layout,gEOnOff,type); } #endif return _MGR(parent,title,layout,gOnOff,type); } RMRadioButtons* RMSettingsWindowBase::_MR_ONOFF(QWidget* parent,QString title,QLayout* layout,int type,QLabel** titleLabel) { #if (LIVE_LANGUAGE_CHANGE && !RM_MODEL_EMT_KR) if(RMLanguage::isJP() == false) { return _MR(parent,title,layout,gEOnOff,type,QList(),titleLabel); } #endif return _MR(parent,title,layout,gOnOff,type,QList(),titleLabel); } RMGroupRadioButtons* RMSettingsWindowBase::_MGR(QWidget *parent,QString title,QLayout* layout,QStringList items,int type,QList indexMap) { RMGroupRadioButtons* gr = new RMGroupRadioButtons(parent,title,items,&CFG::data[type],indexMap); layout->addWidget(gr); return gr; } RMGroupRadioButtons* RMSettingsWindowBase::_MGRR(QWidget *parent,QString title,QLayout* layout,QStringList items,int type,QList indexMap) { RMGroupRadioButtons* gr = new RMGroupRadioButtons(parent,title,items,&CFG::data[type],true,indexMap); layout->addWidget(gr); return gr; } RMRadioButtons* RMSettingsWindowBase::_MR(QWidget *parent,QString title,QLayout* layout,QStringList items,int type,QList indexMap,QLabel** titleLabel) { RMRadioButtons* gr = NULL; if(strcmp(layout->metaObject()->className(),"QGridLayout") == 0) { // (qobject_cast) QGridLayout* gl = (QGridLayout*)layout; int row = ceil((double)layout->count() / 2.0); QLabel* tl = new QLabel(this); tl->setObjectName("text_normal_label"); tl->setText(title); gl->addWidget(tl,row,0,Qt::AlignLeft); // qInfo() << title << "MR row:" << row; gr = new RMRadioButtons(parent,"",items,&CFG::data[type],indexMap); gl->addWidget(gr,row,1,Qt::AlignLeft); if(titleLabel != NULL) { *titleLabel = tl; } } else { gr = new RMRadioButtons(parent,title,items,&CFG::data[type],indexMap); layout->addWidget(gr); } return gr; } void RMSettingsWindowBase::_MGT(QWidget *parent,QString title,QLayout* layout, QString text,QLabel** titleLabel) { if(strcmp(layout->metaObject()->className(),"QGridLayout") == 0) { QGridLayout* gl = (QGridLayout*)layout; int row = ceil(((double)layout->count()) / 2.0); int column = 0; int columnSpan = 2; if(title.length() > 0) { QLabel* tl = new QLabel(this); tl->setObjectName("text_normal_label"); tl->setText(title); gl->addWidget(tl,row,0,Qt::AlignLeft); column = 1; columnSpan = 1; if(titleLabel != NULL) { *titleLabel = tl; } } if(text.length() > 0) { QLabel* textLabel = new QLabel(parent); textLabel->setObjectName("text_normal_label"); textLabel->setText(text); gl->addWidget(textLabel,row,column,1,columnSpan,Qt::AlignLeft); } } else { QLabel* textLabel = new QLabel(parent); textLabel->setObjectName("text_normal_label"); textLabel->setText(text); layout->addWidget(textLabel); }; } RMComboBox* RMSettingsWindowBase::_MC(QWidget *parent,QString title,QLayout* layout, QStringList items,int type,QList indexMap,QLabel** titleLabel) { RMComboBox* c = NULL; if(strcmp(layout->metaObject()->className(),"QGridLayout") == 0) { QGridLayout* gl = (QGridLayout*)layout; int row = ceil(((double)layout->count()) / 2.0); int column = 0; int columnSpan = 2; if(title.length() > 0) { QLabel* tl = new QLabel(this); tl->setObjectName("text_normal_label"); tl->setText(title); gl->addWidget(tl,row,0,Qt::AlignLeft); column = 1; columnSpan = 1; if(titleLabel != NULL) { *titleLabel = tl; } } //qInfo() << "row" << row << " column:" << column; c = new RMComboBox(parent,"",items,&CFG::data[type],indexMap); gl->addWidget(c,row,column,1,columnSpan,Qt::AlignLeft); } else { c = new RMComboBox(parent,title,items,&CFG::data[type],indexMap); layout->addWidget(c); } return c; } RMGroupComboBox* RMSettingsWindowBase::_MGC(QWidget *parent,QString title,QLayout* layout,QStringList items,int type,QList indexMap) { RMGroupComboBox* c = new RMGroupComboBox(parent,title,items,&CFG::data[type],indexMap); layout->addWidget(c); return c; } #endif // #else // #if (USE_JSON_SETTINGS) void RMSettingsWindowBase::onSaveAnAccept() { #if (RM_MODEL_EMT_KR) QString path = CFG::cfgPath; #else // RM_MODEL_EMT_KR QString path = QDir::cleanPath(lastSettingDisk + SETTINGS_FILE_NAME); #endif // RM_MODEL_EMT_KR if(validateData()) { CFG::save(path); afterSave(); accept(); } } RMSettingsWindowBase::~RMSettingsWindowBase() { } void RMSettingsWindowBase::onSave() { QString path = QDir::cleanPath(lastSettingDisk + SETTINGS_FILE_NAME); if(validateData()) { CFG::save(path); afterSave(); } } void RMSettingsWindowBase::onCancel() { CFG::restore(); reject(); } void RMSettingsWindowBase::onDefault() { CFG::setDefault(); emit RMValueUpdater::instance()->updateByValues(); // 레코드 세팅 문제로 (Combo box event 발생하면 default 값이 save 됨) CFG::setDefault(); } #endif // #if (USE_DEVICE_SETTINGS)