From ed12742a94d83bd19c37681bb9010ae5156812a0 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Tue, 7 May 2024 15:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=8B=B1=E6=96=87=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=EF=BC=8C=E9=A2=9C=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8E=E8=89=B2=E8=B0=83=E6=9B=B2=E7=BA=BF=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=9B=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/twainui/hg_settingdialog.cpp | 740 +-------------------------- modules/twainui/hg_settingdialog.h | 13 +- 2 files changed, 10 insertions(+), 743 deletions(-) diff --git a/modules/twainui/hg_settingdialog.cpp b/modules/twainui/hg_settingdialog.cpp index 84e14855..d105ec39 100644 --- a/modules/twainui/hg_settingdialog.cpp +++ b/modules/twainui/hg_settingdialog.cpp @@ -67,6 +67,7 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const m_colorModeId = -1; m_colorModeValue.clear(); + m_multiColorValue.clear(); memset(&m_gammaData, 0, sizeof(m_gammaData)); for(int i = 0; i < sizeof(m_gammaData.table) / sizeof(m_gammaData.table[0]); ++i) m_gammaData.table[i] = i & 0x0ff; @@ -1121,7 +1122,7 @@ void hg_settingdialog::refresh_control_value(int op_id) comb->setCurrentText(strValue); if (m_isMultiOutMode && 0 == strcmp(opt->name, SANE_STD_OPT_NAME_MULTI_OUT_TYPE)) { - m_colorModeValue = strValue; + m_multiColorValue = strValue; } else if (!m_isMultiOutMode && 0 == strcmp(opt->name, SANE_STD_OPT_NAME_COLOR_MODE)) { @@ -1331,7 +1332,7 @@ void hg_settingdialog::slot_string_list_comboBoxClicked() if (m_isMultiOutMode) { - m_colorModeValue = comboBoxcurrentItem.c_str(); + m_multiColorValue = comboBoxcurrentItem.c_str(); qDebug("colorMode=%s", comboBoxcurrentItem.c_str()); } @@ -1476,9 +1477,11 @@ void hg_settingdialog::slot_cutButtonClicked() void hg_settingdialog::slot_gammaButtonClicked() { + bool ok = false; int colorMode = 0; // 0-彩色, 1-灰度 - if (m_colorModeValue.toStdString() == OPTION_VALUE_YSMS_256JHD - || m_colorModeValue.toStdString() == OPTION_VALUE_YSMS_HB || m_colorModeValue.toStdString() == OPTION_VALUE_DLSCLX_HD_HB) + if (0 == strcmp(to_default_language(m_colorModeValue.toStdString().c_str(), &ok), OPTION_VALUE_YSMS_256JHD) || + 0 == strcmp(to_default_language(m_colorModeValue.toStdString().c_str(), &ok), OPTION_VALUE_YSMS_HB) || + 0 == strcmp(to_default_language(m_multiColorValue.toStdString().c_str(), &ok), OPTION_VALUE_DLSCLX_HD_HB)) { colorMode = 1; } @@ -2016,7 +2019,6 @@ void hg_settingdialog::slot_buttonAboutClicked() void hg_settingdialog::slot_buttonScanClicked() { - //save_scheme(); m_closeButton = closeButtonScan; if (!quit_) m_callback(UI_RESULT_START_SCAN); @@ -2099,20 +2101,6 @@ const void* hg_settingdialog::find_option_description(const std::string& title, void hg_settingdialog::closeEvent(QCloseEvent* e) { - //if(e->type() == QEvent::Close) // consider as cancel ... - //{ - // //if(save_) - // // save_scheme(); - // //else - // // cancel_setting(); - //} - - //HGChar cfgPath[512]; - //GetConfigPath(cfgPath, 512); - //QString oldFile = QString::fromStdString(cfgPath) + "olddefault.ini"; - //QString newFile = QString::fromStdString(cfgPath) + "default.ini"; - - // 配置方案策略更改后的业务保存逻辑: // // 1、用户模板方案,显示的点击buttonSave时才保存; @@ -2201,190 +2189,6 @@ bool hg_settingdialog::eventFilter(QObject *target, QEvent *event) return QDialog::eventFilter(target, event); } -bool hg_settingdialog::createMsgBoxUi(bool add, std::string &name) -{ - QString text(tr("Please select to overwrite the original configuration:")); - text += QString::fromStdString(name); - text += tr(",or add a new configuration"); - - QDialog *dlg = new QDialog(this); - dlg->setWindowTitle(tr("save the configuration")); - QLabel *label_question = new QLabel; - label_question->setText(text); - - QRadioButton *radioButtonCover = new QRadioButton; - radioButtonCover->setText(tr("cover original configuration:") + QString::fromStdString(name)); - radioButtonCover->setChecked(true); - add = false; - QRadioButton *radioButtonNew = new QRadioButton; - radioButtonNew->setText(tr("add new configuration")); - - QHBoxLayout *hLayoutName = new QHBoxLayout; - QLabel *label_name = new QLabel; - label_name->setText(tr("rename:")); - m_lineEdit_name = new QLineEdit; - std::string name2; - m_lineEdit_name->setText(QString::fromStdString(getCurUiShemeName(name2))); - - QSpacerItem *spacer1 = new QSpacerItem(20, 20, QSizePolicy::Expanding); - hLayoutName->addWidget(label_name); - hLayoutName->addWidget(m_lineEdit_name); - hLayoutName->addSpacerItem(spacer1); - label_name->setVisible(false); - m_lineEdit_name->setVisible(false); - - bool cover = true; - connect(radioButtonCover, &QRadioButton::clicked, this, [=, &add, &cover](){ - cover = true; - add = false; - label_name->setVisible(false); - m_lineEdit_name->setVisible(false); - }); - connect(radioButtonNew, &QRadioButton::clicked, this, [=, &add, &cover](){ - cover = false; - add = true; - label_name->setVisible(true); - m_lineEdit_name->setVisible(true); - - m_lineEdit_name->setFocus(); - QTimer::singleShot(0, m_lineEdit_name, &QLineEdit::selectAll); - }); - - QSpacerItem *spacer2 = new QSpacerItem(20, 20, QSizePolicy::Expanding); - QPushButton *pbtnOk = new QPushButton; - pbtnOk->setText(tr("ok")); - connect(pbtnOk, &QPushButton::clicked, this, [=, &name, &cover](){ - - QString text = m_lineEdit_name->text(); - static QRegularExpression re("\\s"); - text.remove(re);//Remove space - - name = text.toStdString(); - - if(name.empty()) - { - QMessageBox::information(this, tr("tips"), tr("scheme name cannot be empty")); - m_lineEdit_name->setText(QString::fromStdString(getCurUiShemeName(name))); - return; - } - - if (!cover) - { - std::vector now; - cur_cfg_->get_all_schemes(now); - for(auto& v: now) - { - if(v == name) - { - - QMessageBox::information(this, tr("tips"), tr("scheme name: ") + QString::fromStdString(name) + tr(" already exists")); - m_lineEdit_name->setText(QString::fromStdString(getCurUiShemeName(name))); - return; - } - } - } - - dlg->close(); - }); - - QHBoxLayout *hLayout_pbtnOk = new QHBoxLayout; - hLayout_pbtnOk->addSpacerItem(spacer2); - hLayout_pbtnOk->addWidget(pbtnOk); - - QVBoxLayout *vLayout = new QVBoxLayout; - vLayout->addWidget(label_question); - vLayout->addWidget(radioButtonCover); - vLayout->addWidget(radioButtonNew); - vLayout->addLayout(hLayoutName); - vLayout->addLayout(hLayout_pbtnOk); - dlg->setLayout(vLayout); - - dlg->exec(); - - return add; -} - -std::string hg_settingdialog::getCurUiShemeName(std::string name) -{ - std::string k(""), val(""); - int id = 0; - const SANE_Option_Descriptor* opt = nullptr; - - if (cur_scheme_->first_config(k, val)) - { - int count = 0; - do - { - id = cur_scheme_->id_from_name(k.c_str()); - opt = id == -1 ? nullptr : m_saneAPI.sane_get_option_descriptor_api(m_devHandle, id); - if (opt) - { - if (count++) - name += " + "; - - if (opt->type == SANE_TYPE_STRING) - name += from_default_language(val.c_str(), nullptr); - else - { - name += opt->title; - if (opt->type == SANE_TYPE_BOOL) - { - name += std::string("("); - if (*(SANE_Bool*)&val[0] == SANE_TRUE) - name += "true)"; - else - name += "false)"; - } - else if (opt->type == SANE_TYPE_INT) - { - char buf[128] = { 0 }; - sprintf(buf, "(%d)", *(int*)&val[0]); - name += buf; - } - else if (opt->type == SANE_TYPE_FIXED) - { - char buf[128] = { 0 }; - sprintf(buf, "(%.4f)", SANE_UNFIX(*(SANE_Fixed*)&val[0])); - name += buf; - } - } - } - } while (count < 3 && cur_scheme_->next_config(k, val)); - } - return name; -} - -void hg_settingdialog::save_scheme(void) -{ - if (comb_->currentIndex() == 0) - return; - - this->cur_scheme_ = this->cur_cfg_->get_scheme(comb_->currentText().toStdString().c_str()); - cur_scheme_->end_setting(true); - cur_scheme_->begin_setting(); - updateSchemeFromUi(); - cur_scheme_->end_setting(false); - cur_cfg_->save(); - cur_cfg_->select_scheme(cur_scheme_->get_scheme_name().c_str()); -} -void hg_settingdialog::cancel_setting(void) -{ - // restore changed value ... - cur_scheme_->end_setting(true); - //dev_que::apply_scheme(&m_saneAPI, m_devHandle, cur_scheme_); -} - -std::string hg_settingdialog::getAppVersion() -{ - char v[256] = {0}; - m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x884A, SANE_ACTION_GET_VALUE, v, NULL); - return v; -} -void hg_settingdialog::apply_current_scheme(void) -{ - dev_que::apply_scheme(&m_saneAPI, m_devHandle, cur_scheme_); -} - void hg_settingdialog::setIcon() { this->setWindowIcon(QIcon(":logo/image_rsc/logo/logo.ico")); @@ -2405,391 +2209,6 @@ void hg_settingdialog::setIcon() #endif } -void hg_settingdialog::applyDeviceScheme() -{ - update_opt_value_from_driver(); - - SANE_Int dev_options = 0; - m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); - for (int id = 1, optons = dev_options; id < optons; id++) - { - QVector ctrls = find_control(id); - - if (ctrls.empty()) - continue; - - const SANE_Option_Descriptor* opt = (const SANE_Option_Descriptor*)m_list_defaultOptions.at(id - 1).first; - if (opt->type == SANE_TYPE_BOOL) - { - for (size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QCheckBox* cb = qobject_cast(ctrls[i]); - if (cb) - { - SANE_Bool value = false; - SANE_Int method = 0; - - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method); - disconnect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); - cb->setCheckState(value ? Qt::Checked : Qt::Unchecked); - if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr) - { - btn_gamma_->setEnabled(value); - } - connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); - break; - } - } - } - else if (opt->type == SANE_TYPE_INT) - { - for (size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QSlider* slider = qobject_cast(ctrls[i]); - if (slider) - { - SANE_Int value = 0; - SANE_Int method = 0; - disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method); - slider->setValue(value); - connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - else - { - QSpinBox* spin = qobject_cast(ctrls[i]); - if (spin) - { - SANE_Int value = 0; - SANE_Int method = 0; - disconnect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method); - spin->setValue(value); - connect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); - } - } - } - } - else if (opt->type == SANE_TYPE_FIXED) - { - QSlider* slider = NULL; - QDoubleSpinBox* spin = NULL; - for (size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - if (!slider) - { - slider = qobject_cast(ctrls[i]); - if (slider) - disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - else if (!spin) - { - spin = qobject_cast(ctrls[i]); - if (spin) - disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); - } - } - if (slider) - { - SANE_Fixed value = 0; - SANE_Int method = 0; - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method); - double value2 = SANE_UNFIX(value); - slider->setValue(value2 * 100); - connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - - if (spin) - { - SANE_Fixed value = 0; - SANE_Int method = 0; - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method); - double value2 = SANE_UNFIX(value); - spin->setValue(value2); - connect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); - } - } - else if (opt->type == SANE_TYPE_STRING) - { - for (size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QComboBox* comb = qobject_cast(ctrls[i]); - if (comb) - { - char* value = (char*)malloc(opt->size * 2 + 4); - SANE_Int method = 0; - disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); - m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, value, &method); - QString value2 = QString(value); - comb->setCurrentText(QString(value2)); - connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); - free(value); - } - else - { - QLineEdit* edit = qobject_cast(ctrls[i]); - if (edit) - { - disconnect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); - edit->setText(m_list_defaultOptions.at(id - 1).second.toString()); - connect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); - } - } - } - } - } -} - -void hg_settingdialog::updateDefaultScheme() -{ - update_opt_value_from_driver(); - - m_isRefreshUi = true; - SANE_Int dev_options = 0; - m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); - for(int id = 1, optons = dev_options; id < optons; id++) - { - QVector ctrls = find_control(id); - - if(ctrls.empty()) - continue; - - const SANE_Option_Descriptor* opt = (const SANE_Option_Descriptor*)m_list_defaultOptions.at(id - 1).first; - if(opt->type == SANE_TYPE_BOOL) - { - for(size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QCheckBox* cb = qobject_cast(ctrls[i]); - if(cb) - { - //disconnect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); - - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - bool check = getDefaultCfgValue("default", opt->name, false); - cb->setCheckState(check ? Qt::Checked : Qt::Unchecked); - if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr) - { - btn_gamma_->setEnabled(check); - } - } - } - //connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); - break; - } - } - } - else if(opt->type == SANE_TYPE_INT) - { - for(size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QSlider* slider = qobject_cast(ctrls[i]); - if(slider) - { - //disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - int value = getDefaultCfgValue("default", opt->name, 0); - slider->setValue(value); - } - } - //connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - else - { - QSpinBox* spin = qobject_cast(ctrls[i]); - if(spin) - { - //disconnect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); - - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - int value = getDefaultCfgValue("default", opt->name, 0); - spin->setValue(value); - } - } - //connect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); - } - } - } - } - else if(opt->type == SANE_TYPE_FIXED) - { - QSlider *slider = NULL; - QDoubleSpinBox* spin = NULL; - for(size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - if (!slider) - { - slider = qobject_cast(ctrls[i]); - //if (slider) - //disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - else if (!spin) - { - spin = qobject_cast(ctrls[i]); - //if (spin) - //disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); - } - } - if (slider) - { - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - float value = getDefaultCfgValue("default", opt->name, QString("")).toFloat(); - slider->setValue(value * 100); - } - //connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); - } - - if (spin) - { - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - float value = getDefaultCfgValue("default", opt->name, QString("")).toFloat(); - spin->setValue(value); - } - //connect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); - } - } - } - } - else if(opt->type == SANE_TYPE_STRING) - { - for(size_t i = 0; i < (size_t)ctrls.size(); ++i) - { - QComboBox* comb = qobject_cast(ctrls[i]); - if(comb) - { - //disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); - - if (comb_->currentIndex() == 0) - { - if (searchKeyName("default", opt->name)) - { - QString value = getDefaultCfgValue("default", opt->name, QString("")); - comb->setCurrentText(value); - } - //connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); - } - else - { - QLineEdit* edit = qobject_cast(ctrls[i]); - if(edit) - { - //disconnect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); - edit->setText(m_list_defaultOptions.at(id - 1).second.toString()); - //connect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); - } - } - } - } - } - if (comb_->currentIndex() == 0) - { - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) - { - double value = getDefaultCfgValue("default", "cutLeftvalue", QString("")).toDouble(); - m_cutLeftValue = value; - } - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) - { - double value = getDefaultCfgValue("default", "cutTopValue", QString("")).toDouble(); - m_cutTopValue = value; - } - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT) && searchKeyName("default", "cutLeftvalue")) - { - double value = getDefaultCfgValue("default", "cutRightvalue", QString("")).toDouble(); - m_cutRightValue = value; - } - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) - { - double value = getDefaultCfgValue("default", "cutBottomvalue", QString("")).toDouble(); - m_cutBottomValue = value; - } - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) && searchKeyName("default", "curves")) - { - QString value = getDefaultCfgValue("default", "curves", QString("")); - if (!value.isEmpty()) - { - HGSize length = 0; - std::string base64Data = value.toStdString(); - HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), NULL, &length); - - if (length == sizeof(SANE_Gamma)) - { - HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), (HGByte*)&m_gammaData, &length); - } - } - } - } - } -} - -void hg_settingdialog::saveOriginDeviceScheme() -{ - m_list_originDeviceScheme.clear(); - - SANE_Int dev_options = 0; - m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); - for (int i = 1, j = dev_options; i < j; i++) - { - const SANE_Option_Descriptor* opt = m_saneAPI.sane_get_option_descriptor_api(m_devHandle, i); - SANE_Int method = 0; - if (opt == nullptr) - { - m_list_originDeviceScheme.append(QPair(opt, QVariant(0))); - } - else - { - if (opt->type == SANE_TYPE_INT) - { - SANE_Int init = 0; - - m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method); - m_list_originDeviceScheme.append(QPair(opt, QVariant(init))); - } - else if (opt->type == SANE_TYPE_FIXED) - { - SANE_Fixed init = 0; - - m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method); - m_list_originDeviceScheme.append(QPair(opt, QVariant(init))); - } - else if (opt->type == SANE_TYPE_BOOL) - { - SANE_Bool init = 0; - m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method); - m_list_originDeviceScheme.append(QPair(opt, QVariant(init))); - } - else if (opt->type == SANE_TYPE_STRING) - { - char* init = (char*)malloc(opt->size * 2 + 4); - - m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, init, &method); - m_list_originDeviceScheme.append(QPair(opt, QVariant(QString::fromStdString(init)))); - - free(init); - } - else - { - m_list_originDeviceScheme.append(QPair(opt, QVariant(0))); - } - } - } -} - void hg_settingdialog::cancelScheme() { SANE_Int none = 0; @@ -2830,51 +2249,6 @@ void hg_settingdialog::cancelScheme() } } -void hg_settingdialog::restoreDeviceScheme() -{ - SANE_Int dev_options = 0; - m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); - for (int i = 1; i < dev_options; ++i) - { - const SANE_Option_Descriptor* opt = m_saneAPI.sane_get_option_descriptor_api(m_devHandle, i); - if (!opt) - continue; - - if (0 == strcmp(SANE_STD_OPT_NAME_RESTORE, opt->name)) - { - m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_SET_VALUE, NULL, NULL); - break; - } - } -} - -void hg_settingdialog::processIniFile() -{ - HGChar cfgPath[512]; - GetConfigPath(cfgPath, 512); - QString oldFile = QString::fromStdString(cfgPath) + "olddefault.ini"; - QString newFile = QString::fromStdString(cfgPath) + "default.ini"; - - QFile::remove(oldFile); - QFile::copy(newFile, oldFile); -} - -void hg_settingdialog::initGammaData() -{ - QString value = getDefaultCfgValue("default", "curves", QString("")); - if (!value.isEmpty()) - { - HGSize length = 0; - std::string base64Data = value.toStdString(); - HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), NULL, &length); - - if (length == sizeof(SANE_Gamma)) - { - HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), (HGByte*)&m_gammaData, &length); - } - } -} - void hg_settingdialog::updateSchemeFromUi(gb::sane_config_schm* schm) { SANE_Int dev_options = 0; @@ -3018,6 +2392,7 @@ std::string sane_val_to_string(const char* val, SANE_Value_Type type) return ret; } + void hg_settingdialog::on_current_scheme_changed() { updateSchemeManagerUi(); @@ -3030,91 +2405,8 @@ void hg_settingdialog::on_current_scheme_changed() hg_settingdialog::apply_scheme(m_devHandle, &m_saneAPI, cur_scheme_); updateUIStatus(); updateRestorePushButton(); - - //if (comb_->currentIndex() == 0) - //{ - // restoreDeviceScheme(); - // applyDeviceScheme(); - // - // HGChar cfgPath[512]; - // GetConfigPath(cfgPath, 512); - // QString oldFile = QString::fromStdString(cfgPath) + "olddefault.ini"; - // QString newFile = QString::fromStdString(cfgPath) + "default.ini"; - // QFile::remove(newFile); - // QFile file(oldFile); - // file.rename(newFile); - // QFile::copy(newFile, oldFile); - // - // updateDefaultScheme(); - // - // return; - //} - // - //QString text(find_current_scheme_menu()); - //gb::sane_config_schm *cur = nullptr; - // - //cur_cfg_->select_scheme(text.toStdString().c_str()); - //cur = cur_cfg_->get_scheme(); - //if(!cur) - // cur = new gb::sane_config_schm(); - //cur->copy_default_value(cur_scheme_); - //cur_scheme_->end_setting(true); - //cur_scheme_->release(); - //cur_scheme_ = cur; - //cur_scheme_->begin_setting(); - // - //apply_current_scheme(); - //updateUIStatus(); - //changed_count_++; - // - //QString scheme(comb_->currentText()); - //bool enabled = false; - //gb::sane_config_schm *schm = cur_cfg_->get_scheme(scheme.toStdString().c_str()); - // - //if(schm) - // enabled = true; - // - //memset(&m_gammaData, 0, sizeof(m_gammaData)); - //for(int i = 0; i < sizeof(m_gammaData.table) / sizeof(m_gammaData.table[0]); ++i) - // m_gammaData.table[i] = i & 0x0ff; - // - //QString info(tr("")); - //std::string name(""), val(""); - //if(schm && schm->first_config(name, val)) - //{ - // do - // { - // QString title; - // SANE_Value_Type type = SANE_TYPE_STRING; - // for (int ii = 0; ii < m_list_defaultOptions.size(); ii++) - // { - // const SANE_Option_Descriptor* opt = reinterpret_cast(m_list_defaultOptions.at(ii).first); - // if(strcmp(opt->name, name.c_str()) == 0) - // { - // title = QString::fromStdString(opt->title); - // type = opt->type; - // if(type == SANE_TYPE_STRING) - // val = from_default_language(val.c_str(), nullptr); - // break; - // } - // } - // - // if(title.length()) - // { - // info += tr("
") + title + tr(":
"); - // info += tr("

") + QString::fromStdString(sane_val_to_string(val.c_str(), type)) + tr("

"); - // } - // else { - // if(val.length() == sizeof(SANE_Gamma)) - // memcpy(&m_gammaData, val.c_str(), sizeof(SANE_Gamma)); - // } - // }while(schm->next_config(name, val)); - //} - //if(schm) - // schm->release(); - // - //sketch_->setHtml(info); } + void hg_settingdialog::slot_pushButton_scheme_management(void) { QPushButton* btn = qobject_cast(sender()); @@ -3179,10 +2471,6 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) cur_cfg_->save(); schm->release(); updateRestorePushButton(); - //if (comb_->currentIndex() == 0) - // processIniFile(); - //else - // save_scheme(); } else if(btn == m_deleteCur) { @@ -3247,16 +2535,6 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) } void hg_settingdialog::restore_2_default_settings(void) { - //cur_scheme_->end_setting(true); - //->select_scheme(nullptr); - //dev_que_.apply_scheme(&m_saneAPI, nullptr); - //cur_cfg_->save(); - hg_settingdialog::apply_scheme(m_devHandle, &m_saneAPI, nullptr); updateRestorePushButton(); - //gb::sane_config_schm *s = new gb::sane_config_schm(); - //s->copy_default_value(cur_scheme_); - //cur_scheme_->release(); - //cur_scheme_ = s; - //cur_scheme_->begin_setting(); } diff --git a/modules/twainui/hg_settingdialog.h b/modules/twainui/hg_settingdialog.h index 4b3efa8f..3552c2fa 100644 --- a/modules/twainui/hg_settingdialog.h +++ b/modules/twainui/hg_settingdialog.h @@ -109,20 +109,8 @@ private: virtual bool eventFilter(QObject *target, QEvent *event) override; void save_to_default_if_ui_not_equal_scheme(gb::sane_config_schm* cur, bool save); - bool createMsgBoxUi(bool add, std::string &name); - std::string getCurUiShemeName(std::string name); - void save_scheme(void); - void cancel_setting(void); - std::string getAppVersion(); - void apply_current_scheme(void); void setIcon(); - void applyDeviceScheme(); - void updateDefaultScheme(); - void saveOriginDeviceScheme(); void cancelScheme(); - void restoreDeviceScheme(); - void processIniFile(); - void initGammaData(); void updateSchemeFromUi(gb::sane_config_schm* schm = nullptr); void updateSchemeManagerUi(); void updateRestorePushButton(); @@ -179,6 +167,7 @@ private: int m_colorModeId; QString m_colorModeValue; + QString m_multiColorValue; SANE_Gamma m_gammaData; SANE_Gamma m_originGammaData; QComboBox *comb_;