twain3/ui/scansettingdialog.cpp

1331 lines
43 KiB
C++
Raw Normal View History

#include "scansettingdialog.h"
#include "ui_scansettingdialog.h"
#include "cutpapertool.h"
#include "setpicclrtool.h"
#include "Global.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QJsonValue>
#include <QString>
#include <QDebug>
#include <QFile>
#include <QDateTime>
#include <QDir>
#include <QMessageBox>
#include <QDesktopServices>
#include <QUrl>
#include <QInputDialog>
#include <QFileDialog>
#include <QButtonGroup>
std::map<std::string,std::string> papersizename={{u8"A3",u8"A3"},
{u8"A4",u8"A4"},
{u8"A4 Transverse",u8"A4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"A5",u8"A5"},
{u8"A5 Transverse",u8"A5<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"A6",u8"A6"},
{u8"A6 Transverse",u8"A6<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"B4",u8"B4"},
{u8"B5",u8"B5"},
{u8"B5 Transverse",u8"B5<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"B6",u8"B6"},
{u8"B6 Transverse",u8"B6<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"Legal",u8"Legal"},
{u8"Double Letter",u8"˫<EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD>"},
{u8"Letter",u8"<EFBFBD>ŷ<EFBFBD>"},
{u8"Letter Transverse",u8"<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"Matches the original size",u8"ƥ<EFBFBD><EFBFBD>ԭʼ<EFBFBD>ߴ<EFBFBD>"},
{u8"Max Size Auto Crop",u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
{u8"Max Size",u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD>"}};
ScanSettingDialog::ScanSettingDialog(Func twG, int uiMode,std::string model, QWidget *parent) :
QDialog(parent),
ui(new Ui::ScanSettingDialog),
m_twG(twG),
Model(model),
UImode(uiMode)
{
#ifdef _WIN32
Q_INIT_RESOURCE(images);
#endif // _WIN32
Qt::WindowFlags flags = Qt::Dialog;
flags |= Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint;
setWindowFlags(flags);
ui->setupUi(this);
QFile file(u8":/huagao.json");
if(file.open(QIODevice::OpenModeFlag::ReadOnly))
{
defaultjson=json::parse(file.readAll().toStdString());
file.close();
}
#if defined (HGVERSION)
setWindowIcon(QIcon(u8":/ImageResource/huagoscan_LOGO_icon.png"));
#else
setWindowIcon(QIcon(u8":/ImageResource/Lanxum_logo.ico"));
#endif
QString modeText;
if (UImode == showUI)
modeText = tr(std::string(u8"ɨ<EFBFBD><EFBFBD>").c_str());
else if (UImode == UIonly)
modeText = tr(std::string(u8"ȷ<EFBFBD><EFBFBD>").c_str());
if (!modeText.isEmpty())
ui->pbtn_ok->setText(modeText);
ui->cbtn_exchangeFB->setVisible(false);
}
ScanSettingDialog::~ScanSettingDialog()
{
if (enableparent)
enableparent();
delete ui;
}
int ScanSettingDialog::getScanCount()
{
if (ui->spin_pageNum->isEnabled())
{
return ui->spin_pageNum->value();
}
return -1;// -1 means continually scanning
}
void ScanSettingDialog::init_globalLogic()
{
QButtonGroup* bg1 = new QButtonGroup(this);
bg1->addButton(ui->rbtn_maxPage, 0);
bg1->addButton(ui->rbtn_pageNum, 1);
QButtonGroup* bg2 = new QButtonGroup(this);
bg2->addButton(ui->rbtn_sharpening1, 0);
bg2->addButton(ui->rbtn_sharpening2, 1);
bg2->addButton(ui->rbtn_blur1, 2);
bg2->addButton(ui->rbtn_blur2, 3);
QButtonGroup* bg3 = new QButtonGroup(this);
bg3->addButton(ui->rbtn_ocrPDF, 0);
bg3->addButton(ui->rbtn_ocrTxt, 1);
bg3->addButton(ui->rbtn_ocrPDF_txt, 2);
connect(ui->tbtn_colorCurve, SIGNAL(clicked()), this, SLOT(showColorLineSetDialog()), Qt::UniqueConnection);
connect(ui->tbtn_sizeArea, SIGNAL(clicked()), this, SLOT(showCutDialog()), Qt::UniqueConnection);
//init user settings btn
ui->pBtn_usrSetting_del->setEnabled(false);
ui->pBtn_usrSetting_clr->setEnabled(false);
ui->pBtn_usrSetting_app->setEnabled(false);
ui->pBtn_usrSetting_save->setEnabled(false);
ui->pBtn_usrSetting_exp->setEnabled(false);
//init UI exclusion logic
on_cbox_colorMode_currentIndexChanged(ui->cbox_colorMode->currentIndex());
on_cbox_scanPage_currentIndexChanged(ui->cbox_scanPage->currentIndex());
on_cbtn_deHole_stateChanged(ui->cbtn_deHole->isChecked());
on_rbtn_pageNum_toggled(ui->rbtn_pageNum->isChecked());
on_cbox_pageDirection_currentIndexChanged(ui->cbox_pageDirection->currentIndex());
on_cbtn_skewCheck_stateChanged(ui->cbtn_skewCheck->isChecked());
ui->rbtn_sharpening1->setChecked(true);
//ui->pbtn_help->setVisible(false);
}
void ScanSettingDialog::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
if(QFile::exists(tmppath))
{
QFile file(tmppath);
file.open(QIODevice::OpenModeFlag::ReadOnly);
std::string itemname=file.readAll().data();
param = loadjson((Global::getSettingPath() + itemname + ".json").c_str());
file.close();
}
else
param = loadjson(userJsonName.c_str());
if (!param.is_object())
param = defaultjson;
param[Model][SYSTEM][SPAPERSIZE].get_to(support_paper);
ui->cbox_paperSize->clear();
for (auto& paper : support_paper)
ui->cbox_paperSize->addItem(std::string(papersizename[paper.first.c_str()]).c_str());
std::vector<int> dpi;
param[Model][SYSTEM][DPI].get_to(dpi);
ui->cbox_resolution->clear();
for(auto item=0;item<dpi.size(); item++)
{
ui->cbox_resolution->insertItem(item,QString::number(dpi[item]));
}
init_globalLogic();
configUI_fromConfigParam(USER);
load_userSettingList();
init_funcVisible();
if(!m_map.isEmpty())
m_map.clear();
m_map.insert(QVector<int>() << ui->cbox_paperSize->currentIndex() << ui->cbox_resolution->currentIndex(), sizeAreaRect);
}
void ScanSettingDialog::closeEvent(QCloseEvent* e)
{
// attempt to close by window close button
// the dialog must never close itself, the request must go through TWPP
e->ignore();
m_twG.IcancelFunction();
QFile::remove(tmppath);
if(ui->listWidget->count()>0){
QFile file(tmppath);
file.open(QIODevice::OpenModeFlag::ReadOnly|QIODevice::OpenModeFlag::WriteOnly);
file.write(ui->listWidget->currentItem()->text().toStdString().c_str());
file.close();
}
QDialog::closeEvent(e);
}
void ScanSettingDialog::keyPressEvent(QKeyEvent* e) {
// Qt dialogs can be closed by ESC button, we dont like that
if (e->key() == Qt::Key_Escape) {
e->ignore();
}
else {
QDialog::keyPressEvent(e);
}
}
void ScanSettingDialog::init_funcVisible()
{
//basic functions disable
ui->cbtn_multiStream->setVisible(true);
ui->cbox_multiStream->setVisible(true);
ui->cbtn_sizeAreaSwitch->setVisible(true);
ui->tbtn_sizeArea->setVisible(true);
//brightness functions disable
ui->cbtn_colorLineSwitch->setVisible(true);
ui->tbtn_colorCurve->setVisible(true);
//image process functions disable
ui->cbtn_antiInfi->setVisible(true);
ui->cbtn_colorAdjust->setVisible(false);
ui->cbtn_deMoire->setVisible(true);
ui->cbtn_setBWDot->setVisible(true);
ui->cbtn_noise->setVisible(true);
ui->cbtn_texRmv->setVisible(true);
ui->tabWidget->setCurrentIndex(0);
ui->cbtn_sizeAreaSwitch->setVisible(true);
ui->tbtn_sizeArea->setVisible(true);
ui->cbtn_colorLineSwitch->setVisible(false);
ui->tbtn_colorCurve->setVisible(false);
ui->cbtn_bgremoval->setVisible(false);
//other function page disable
ui->tabWidget->removeTab(4);
if (Model == "G300" || Model == "G400"){
ui->cbtn_stapleCheck->setVisible(false);
ui->cbtn_skewCheck->setVisible(false);
ui->Slider_skewCheck->setVisible(false);
ui->label_skewCheck->setVisible(false);
}
}
void ScanSettingDialog::load_userSettingList()
{
std::string itemname;
int index=0;
if(QFile::exists(tmppath))
{
QFile file(tmppath);
file.open(QIODevice::OpenModeFlag::ReadOnly);
itemname=file.readAll().data();
file.close();
}
ui->listWidget->clear();
QStringList list = check_json(QString::fromStdString(Global::getSettingPath()));
for (int i = 0; i < list.size(); i++)
{
add_usrSetting(list.at(i));
if(list.at(i)==itemname.c_str())
index=i;
}
if(ui->listWidget->count()>0)
{
ui->listWidget->setCurrentRow(index);
ui->pBtn_usrSetting_app->setEnabled(true);
ui->pBtn_usrSetting_clr->setEnabled(true);
ui->pBtn_usrSetting_del->setEnabled(true);
ui->pBtn_usrSetting_exp->setEnabled(true);
ui->pBtn_usrSetting_save->setEnabled(true);
}
}
//UI logic functions(23) <20><><EFBFBD><EFBFBD><E6BBA5>
void ScanSettingDialog::on_cbox_colorMode_currentIndexChanged(int index)
{
ui->cbtn_colorLineSwitch->setEnabled(index != 2); //ɫ<><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ui->tbtn_colorCurve->setEnabled((index != 2)&&(ui->cbtn_colorLineSwitch->isChecked())); //ɫ<><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ui->label_deColor->setEnabled(index != 0); //<2F><>ɫ
ui->cbox_deColor->setEnabled(index != 0);//<2F><>ɫ
ui->cbtn_colorAdjust->setEnabled(index != 2);//ɫ<><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ui->cbtn_deMoire->setEnabled(index != 2);//ȥĦ<C8A5><C4A6><EFBFBD><EFBFBD>
ui->cbtn_setBWDot->setEnabled(index == 2);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɢ
ui->cbtn_noise->setEnabled(index == 2);//<2F><><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>
ui->cbtn_texRmv->setEnabled(index != 2);//ȥ<><C8A5><EFBFBD><EFBFBD>
ui->gbox_sharAndBlur->setEnabled(index != 2);//<2F><><EFBFBD><EFBFBD>
ui->cbtn_specialMulti->setEnabled(index == 0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ui->cbtn_deRed_asheet->setEnabled(index==0);//<2F><><EFBFBD><EFBFBD><E2BFA8><EFBFBD><EFBFBD>
ui->cbox_multiStream->setEnabled(index!=3 && ui->cbtn_multiStream->isChecked());
ui->cbtn_multiStream->setEnabled(index!=3);
if (index == 0)
ui->cbox_deColor->setCurrentIndex(3);
if (index != 0)
{
ui->cbtn_specialMulti->setChecked(false);
ui->cbtn_deRed_asheet->setChecked(false);
}
if (index == 2) {
ui->cbtn_colorLineSwitch->setChecked(false);
ui->cbtn_colorAdjust->setChecked(false);
ui->cbtn_deMoire->setChecked(false);
ui->cbtn_texRmv->setChecked(false);
ui->gbox_sharAndBlur->setChecked(false);
}
if (index != 2) {
ui->cbtn_setBWDot->setChecked(false);
ui->cbtn_noise->setChecked(false);
}
if(index ==3 )
{
ui->cbtn_colorAdjust->setEnabled(false);
ui->cbtn_colorLineSwitch->setEnabled(false);
ui->tbtn_colorCurve->setEnabled(false);
ui->label_deColor->setEnabled(false);
ui->cbox_deColor->setEnabled(false);
ui->cbtn_deMoire->setEnabled(false);
ui->cbtn_texRmv->setEnabled(false);
ui->cbtn_specialMulti->setEnabled(false);
ui->cbtn_deRed_asheet->setEnabled(false);
ui->cbox_multiStream->setEnabled(false);
ui->cbtn_multiStream->setEnabled(false);
ui->gbox_sharAndBlur->setEnabled(false);
}
}
void ScanSettingDialog::on_cbtn_multiStream_stateChanged(int arg1)
{
ui->label_colorMode->setEnabled(arg1 == 0);
ui->cbox_colorMode->setEnabled(arg1 == 0);
ui->cbox_multiStream->setEnabled(arg1 != 0);
ui->cbtn_colorLineSwitch->setEnabled(arg1 == 0);
ui->tbtn_colorCurve->setEnabled(arg1 == 0);
ui->gbox_filter->setEnabled(arg1 == 0);
int color_mode = ui->cbox_colorMode->currentIndex();
ui->cbox_deColor->setEnabled(arg1 == 0 && color_mode != 0);
ui->label_deColor->setEnabled(arg1 == 0 && color_mode != 0);
ui->cbtn_colorAdjust->setEnabled(arg1 == 0 && color_mode != 2);
ui->cbtn_deMoire->setEnabled(arg1 == 0 && color_mode != 2);
ui->cbtn_setBWDot->setEnabled(arg1 == 0 && color_mode == 2);
ui->cbtn_noise->setEnabled(arg1 == 0 && color_mode == 2);
ui->cbtn_texRmv->setEnabled(arg1 == 0 && color_mode != 2);
ui->gbox_sharAndBlur->setEnabled(arg1 == 0 && color_mode != 2);
ui->gbox_specialImgProc->setEnabled(arg1 == 0);
ui->cbtn_specialMulti->setEnabled(arg1 == 0 && color_mode == 0);
ui->cbtn_deRed_asheet->setEnabled(arg1 == 0 && color_mode == 0);
if (arg1 != 0) {
ui->cbox_colorMode->setCurrentIndex(ui->cbox_multiStream->currentIndex() == 3 ? 1 : 0);
ui->cbtn_colorLineSwitch->setChecked(false);
ui->cbox_deColor->setCurrentIndex(3);
ui->cbtn_colorAdjust->setChecked(false);
ui->cbtn_deMoire->setChecked(false);
ui->cbtn_setBWDot->setChecked(false);
ui->cbtn_noise->setChecked(false);
ui->cbtn_texRmv->setChecked(false);
ui->gbox_sharAndBlur->setChecked(false);
ui->cbtn_specialMulti->setChecked(false);
ui->cbtn_deRed_asheet->setChecked(false);
}
}
void ScanSettingDialog::on_cbox_multiStream_currentIndexChanged(int index)
{
ui->cbox_colorMode->setCurrentIndex(index != 3 ? 0 : 1);
}
void ScanSettingDialog::on_cbox_paperSize_currentIndexChanged(int index)
{
std::string papername;
if(std::find_if(papersizename.begin(),papersizename.end(),[&](const std::map<std::string, std::string>::value_type item)
{
if(item.second == ui->cbox_paperSize->currentText().toStdString())
{
papername=item.first;
return true;
}
return false;
})==papersizename.end())
papername="A4";
if(support_paper[papername]==0||support_paper[papername]==52||support_paper[papername]==54)
{
ui->cbtn_sizeCheck->setChecked(false);
ui->cbtn_sizeCheck->setEnabled(false);
}
else {
ui->cbtn_sizeCheck->setEnabled(true);
}
bool ret = support_paper[papername]==0||support_paper[papername]==52||support_paper[papername]==54;
ui->cbtn_sizeAreaSwitch->setEnabled(!ret);
if(ret)//ƥ<><C6A5>ԭʼ<D4AD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD><DFB4>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
{
ui->cbtn_sizeAreaSwitch->setChecked(false);
return;
}
QVector<int> v;
v << index << ui->cbox_resolution->currentIndex();
if(m_map.contains(v))
sizeAreaRect = m_map.value(v);
else
{
sizeAreaRect = QRectF(0,0,0,0);
m_map.insert(v, sizeAreaRect);
}
}
void ScanSettingDialog::on_cbtn_sizeAreaSwitch_stateChanged(int arg1)
{
ui->tbtn_sizeArea->setEnabled(arg1 != 0);
}
void ScanSettingDialog::on_cbox_scanPage_currentIndexChanged(int index)
{
ui->cbtn_backRotate_180->setEnabled(index > 0 && index < 4);
ui->cbtn_adjust->setEnabled(index != 4);
if (index == 4)
{
ui->cbtn_adjust->setChecked(true);
ui->cbtn_imgSplit->setChecked(false);
ui->cbtn_imgSplit->setEnabled(false);
}
else
ui->cbtn_imgSplit->setEnabled(true);
}
void ScanSettingDialog::on_cbtn_imgSplit_clicked()
{
param[Model][USER][SPLITIMAGE]=ui->cbtn_imgSplit->isChecked();
}
void ScanSettingDialog::on_cbox_resolution_currentIndexChanged(int index)
{
QVector<int> v;
v << ui->cbox_paperSize->currentIndex() << index;
if(m_map.contains(v))
sizeAreaRect = m_map.value(v);
else
{
sizeAreaRect = QRectF(0,0,0,0);
m_map.insert(v, sizeAreaRect);
}
}
void ScanSettingDialog::on_cbtn_colorLineSwitch_stateChanged(int arg1)
{
ui->tbtn_colorCurve->setEnabled(arg1 != 0);
ui->Slider_brightness->setEnabled(arg1 == 0);
ui->Slider_contrast->setEnabled(arg1 == 0);
ui->Slider_gamma->setEnabled(arg1 == 0);
ui->spin_brightness->setEnabled(arg1 == 0);
ui->spin_contrast->setEnabled(arg1 == 0);
ui->dSpin_gamma->setEnabled(arg1 == 0);
}
void ScanSettingDialog::on_cbtn_deHole_stateChanged(int arg1)
{
ui->label_deHole->setEnabled(arg1 != 0);
ui->Slider_deHole->setEnabled(arg1 != 0);
ui->label_deHolePara->setEnabled(arg1 != 0);
if (arg1 == 0)
ui->Slider_deHole->setValue(0);
}
void ScanSettingDialog::on_cbtn_sharAndBlur_stateChanged(int arg1)
{
}
void ScanSettingDialog::on_rbtn_pageNum_toggled(bool checked)
{
ui->spin_pageNum->setEnabled(checked);
if (checked == false)
ui->spin_pageNum->setValue(1);
}
void ScanSettingDialog::on_cbox_pageDirection_currentIndexChanged(int index)
{
if (index == 4)
{
ui->cbtn_backRotate_180->setChecked(false);
ui->cbtn_backRotate_180->setEnabled(false);
}
else if (ui->cbox_scanPage->currentIndex() != 0)
{
ui->cbtn_backRotate_180->setEnabled(true);
}
if(index==1)
ui->cbtn_backRotate_180->setChecked(true);
else {
ui->cbtn_backRotate_180->setChecked(false);
}
}
void ScanSettingDialog::on_cbtn_skewCheck_stateChanged(int arg1)
{
ui->label_skewCheck->setEnabled(arg1 != 0);
ui->Slider_skewCheck->setEnabled(arg1 != 0);
if (arg1 == 0)
ui->Slider_skewCheck->setValue(3);
}
void ScanSettingDialog::on_cbtn_jpgPercent_stateChanged(int arg1)
{
ui->label_jpgPercent->setEnabled(arg1 != 0);
ui->Slider_jpgPercent->setEnabled(arg1 != 0);
ui->label_jpgPercentPara->setEnabled(arg1 != 0);
}
void ScanSettingDialog::on_gbox_ocr_toggled(bool arg1)
{
ui->cbox_pageDirection->setEnabled(!arg1);
ui->cbtn_backRotate_180->setEnabled(!arg1);
if (arg1) {
ui->cbox_pageDirection->setCurrentIndex(4);
ui->cbtn_backRotate_180->setChecked(false);
}
}
void ScanSettingDialog::on_Slider_brightness_valueChanged(int value)
{
ui->spin_brightness->setValue(value);
}
void ScanSettingDialog::on_spin_brightness_valueChanged(int arg1)
{
ui->Slider_brightness->setValue(arg1);
}
void ScanSettingDialog::on_Slider_contrast_valueChanged(int value)
{
ui->spin_contrast->setValue(value);
}
void ScanSettingDialog::on_spin_contrast_valueChanged(int arg1)
{
ui->Slider_contrast->setValue(arg1);
}
void ScanSettingDialog::on_Slider_gamma_valueChanged(int value)
{
ui->dSpin_gamma->setValue(double(value) / 10);
}
void ScanSettingDialog::on_dSpin_gamma_valueChanged(double arg1)
{
ui->Slider_gamma->setValue(int(arg1 * 10));
}
void ScanSettingDialog::on_Slider_deHole_valueChanged(int value)
{
ui->label_deHolePara->setText(QString::number(5 + 5 * value) + "%");
}
void ScanSettingDialog::on_Slider_skewCheck_valueChanged(int value)
{
QString sk = "";
switch (value)
{
case 1:
sk = tr(std::string(u8"<EFBFBD>dz<EFBFBD><EFBFBD>Ѽ<EFBFBD><EFBFBD><EFBFBD>").c_str());
break;
case 2:
sk = tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>").c_str());
break;
case 3:
sk = tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str());
break;
case 4:
sk = tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>").c_str());
break;
case 5:
sk = tr(std::string(u8"<EFBFBD>dz<EFBFBD><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>").c_str());
break;
default:
sk = tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str());
}
ui->label_skewCheck->setText(sk);
}
void ScanSettingDialog::on_Slider_jpgPercent_valueChanged(int value)
{
ui->label_jpgPercentPara->setText(QString::number(10 * value) + "%");
}
void ScanSettingDialog::EnableID_OKorID_Cancel(bool enable)
{
ui->pbtn_default->setEnabled(enable);
ui->pbtn_cancel->setEnabled(enable);
ui->pbtn_ok->setEnabled(enable);
}
void ScanSettingDialog::showColorLineSetDialog()
{
setPicClrTool d(this);
int colormode=ui->cbox_colorMode->currentIndex()==3?0:ui->cbox_colorMode->currentIndex();
d.setColorMode(colormode);
if (colormode == 0)
{
if (rgbKeyPoint.size() > 0)
d.setRGBKeyTable(rgbKeyPoint);
}
else {
if (grayKeyPoint.size() > 0)
d.setGrayKeyTable(grayKeyPoint);
}
d.exec();
if (colormode == 0)
{
d.getRGBTable(RGBLineTable);
rgbKeyPoint = d.getRGBKeyTable();
param[Model][USER][GAMMATABLE] = RGBLineTable;
param[Model][USER][GAMMATABLELENGHT] = 768;
}
else
{
d.getGrayTable(greyLineTable);
grayKeyPoint = d.getGrayKeyTable();
param[Model][USER][GAMMATABLE] = greyLineTable;
param[Model][USER][GAMMATABLELENGHT] = 256;
}
}
void ScanSettingDialog::showCutDialog()
{
QList<int> list;
list << 100 << 150 << 200 << 240 << 300 << 600;
int dpi = list[ui->cbox_resolution->currentIndex()];
QString size = ui->cbox_paperSize->currentText();
CutPaperTool d(this);
d.setPaperType(dpi, size, 300);
d.setSizeInit(sizeAreaRect);
if(d.exec())
{
sizeAreaRect = d.getCutRectPixel();
m_map.insert(QVector<int>() << ui->cbox_paperSize->currentIndex() << ui->cbox_resolution->currentIndex(), sizeAreaRect);
}
}
//global btn slots(4)
void ScanSettingDialog::on_pbtn_help_clicked()
{
QString helpPath = QString::fromStdString(Global::getSettingPath()) + "/";
#if defined (HGVERSION)
QFile file(helpPath + "HuaGoScan SANE_Cs.pdf");
#else
QFile file(helpPath + "LanXumScan SANE_Cs.pdf");
#endif
if (!QFileInfo(file).exists())
QMessageBox::warning(this, tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()), tr(std::string(u8"δ<EFBFBD>ҵ<EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>").c_str()));
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(file).absoluteFilePath()));
}
void ScanSettingDialog::on_pbtn_about_clicked()
{
//const QString device_serial = "G200";//TODO:read from hardware memory
QString web_site = QString::fromStdString(website);
QMessageBox::about(this,
#if defined (HGVERSION)
QStringLiteral("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> HuaGoScan"),
tr(u8"<p>HuaGoScan Driver" \
"<br><3E><EFBFBD><E6B1BE>: 2.2.2.0" \
"<br>Copyright ? 2019,HUAGOSCAN CO.,LTD. All Rights Reserved.</p>" \
"<p>ɨ<><C9A8><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>: %1" \
"<br><3E>̼<EFBFBD><CCBC>汾: %2" \
"<br><3E><><EFBFBD>к<EFBFBD>: %3</p>" \
"<p><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %4" \
"<br><3E><>ϵ<EFBFBD><CFB5>ַ: %5" \
"<br><3E><>ַ: <a href='http://%6'>%6</a></p>")
.arg(QString::fromStdString(Model)).arg(QString::fromStdString(m_twG.Igetfw())).arg(QString::fromStdString(m_twG.Igetser()))
.arg(QString::fromStdString(manufacturer)).arg(QString::fromStdString(contact_address)).arg(web_site)
);
#else
QStringLiteral("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> LanXumScan"),
tr(u8"<p>LANXUMSCAN Driver" \
"<br><3E><EFBFBD><E6B1BE>: 2.2.2.0" \
"<p>ɨ<><C9A8><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>: %1" \
"<br><3E>̼<EFBFBD><CCBC>汾: %2" \
"<br><3E><><EFBFBD>к<EFBFBD>: %3</p>" \
"<p><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %4" \
"<br><3E><>ϵ<EFBFBD><CFB5>ַ: %5" \
"<br><3E><>ַ: <a href='http://%6'>%6</a></p>")
.arg(QString::fromStdString(Model)).arg(QString::fromStdString(m_twG.Igetfw())).arg(QString::fromStdString(m_twG.Igetser()))
.arg(QString::fromStdString(manufacturer)).arg(QString::fromStdString(contact_address)).arg(web_site)
);
#endif
}
void ScanSettingDialog::on_pbtn_default_clicked()
{
configUI_fromConfigParam(DEFAULT);
}
void ScanSettingDialog::on_pbtn_ok_clicked()
{
getParam_fromUI();
try
{
if(ui->listWidget->currentRow()!=-1){
save_json(Global::getSettingPath().c_str()+ui->listWidget->currentItem()->text()+".json");
if(QFile::exists(tmppath))
{
QFile::remove(tmppath);
}
QFile file(tmppath);
if(file.open(QIODevice::ReadWrite))
{
file.write(ui->listWidget->currentItem()->text().toStdString().c_str());
file.close();
}
}
else
throw std::exception();
}
catch(std::exception)
{
save_json(QString::fromStdString(userJsonName));
}
if (UImode == showUI)
m_twG.IscanFunction(jsonToGscan(param,USER,Model));
else
m_twG.IconfirmFunction(jsonToGscan(param, USER, Model));
#ifndef _WIN32
close();
#endif // _WIN32
}
void ScanSettingDialog::on_pbtn_cancel_clicked()
{
m_twG.IcancelFunction();
#ifndef _WIN32
close();
#endif // _WIN32
}
//usr_settings functions(12)
#define MAX_SETTINGS_NUM 10
void ScanSettingDialog::on_pBtn_usrSetting_app_clicked()
{
if( QMessageBox::question(this,
tr(std::string(u8"<EFBFBD><EFBFBD>ʾ").c_str()),
tr(std::string(u8"ȷ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>").c_str()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes)
== QMessageBox::Yes)
{
QString name =QString(Global::getSettingPath().c_str())+ui->listWidget->currentItem()->text();
//load_jsonList(name + ".json");
json p;
try{
p = loadjson(name + ".json");
if (!p.is_object())
throw std::exception();
param = p;
}
catch(...)
{
}
configUI_fromConfigParam(USER);
}
}
void ScanSettingDialog::on_pBtn_usrSetting_add_clicked()
{
QInputDialog d(this);
d.setWindowTitle(tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()));
d.setLabelText(tr(std::string(u8"<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()));
if (d.exec())
{
QString name = d.textValue();
if(name.contains('/'))
{
QMessageBox::information(this,tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()),tr(std::string(u8"<EFBFBD>Ƿ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()),QMessageBox::Yes);
return;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
add_usrSetting(name);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
getParam_fromUI();
save_json(QString::fromStdString(Global::getSettingPath()) + name + ".json");
//save_jsonList(name + ".json", &params);
//<2F>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ui->listWidget->count() >= MAX_SETTINGS_NUM)
{
ui->pBtn_usrSetting_add->setEnabled(false);
ui->pBtn_usrSetting_inp->setEnabled(false);
}
}
}
void ScanSettingDialog::on_pBtn_usrSetting_del_clicked()
{
int a = QMessageBox::question(this,
tr(std::string(u8"<EFBFBD><EFBFBD>ʾ").c_str()),
tr(std::string(u8"ȷ<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (a == QMessageBox::Yes)
{
QString name = ui->listWidget->currentItem()->text();
delete_json(name);
ui->listWidget->takeItem(ui->listWidget->currentRow());
ui->pBtn_usrSetting_add->setEnabled(true);
ui->pBtn_usrSetting_inp->setEnabled(true);
}
}
void ScanSettingDialog::on_pBtn_usrSetting_clr_clicked()
{
int a = QMessageBox::question(this,
tr(std::string(u8"<EFBFBD><EFBFBD>ʾ").c_str()),
tr(std::string(u8"ȷ<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>?").c_str()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (a == QMessageBox::Yes)
{
for (int i = 0; i < ui->listWidget->count(); i++)
{
QString name = ui->listWidget->item(i)->text();
delete_json(name);
}
ui->listWidget->clear();
ui->pBtn_usrSetting_add->setEnabled(true);
ui->pBtn_usrSetting_inp->setEnabled(true);
}
}
void ScanSettingDialog::on_pBtn_usrSetting_inp_clicked()
{
QStringList list = QFileDialog::getOpenFileNames(this, tr(std::string(u8"ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>").c_str()), "", "(*.json)");
if (list.isEmpty()) return;
//<2F><><EFBFBD><EFBFBD><E2B5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ񳬹<C7B7><F1B3ACB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while ((list.count() + ui->listWidget->count()) > MAX_SETTINGS_NUM) {
list.removeLast();
if ((list.count() + ui->listWidget->count()) <= MAX_SETTINGS_NUM) {
QMessageBox::warning(this, tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()), tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()));
break;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>б<EFBFBD>
for (int i = 0; i < list.size(); i++) {
QFileInfo fileinfo(list.at(i));
QString name = fileinfo.baseName();
add_usrSetting(name);
}
//<2F><EFBFBD><EFB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI<55>߼<EFBFBD>
if (ui->listWidget->count() >= MAX_SETTINGS_NUM)
{
ui->pBtn_usrSetting_add->setEnabled(false);
ui->pBtn_usrSetting_inp->setEnabled(false);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>׼<EFBFBD><D7BC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
for (int i = 0; i < list.size(); i++) {
QFile file(list.at(i));
file.copy(QString::fromStdString(Global::getSettingPath()) + QFileInfo(file).fileName());
}
}
void ScanSettingDialog::on_pBtn_usrSetting_exp_clicked()
{
QString filename = QFileDialog::getSaveFileName(this,
tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()),
"",
"(*.json)");
if (filename.isEmpty()) return;
// auto fi = QFileInfo(filename);
// if(fi.fileName().contains('/')||fi.fileName().size()<1)
// {
// QMessageBox::question(this,
// tr(std::string(u8"<22><><EFBFBD><EFBFBD>").c_str()),
// tr(std::string(u8"<22>Ƿ<EFBFBD><C7B7>ļ<EFBFBD><C4BC><EFBFBD>").c_str()),
// QMessageBox::Yes ,
// QMessageBox::Yes);
// return ;
// }
if (!filename.endsWith(u8".json"))
{
filename += ".json";
}
QFile file(filename);
if(!file.open(QIODevice::WriteOnly)){
if(QFile::exists(filename))
QFile::remove(filename);
QMessageBox::question(this,tr(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str()), tr(std::string(u8"<EFBFBD>Ƿ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>").c_str()),
QMessageBox::Yes , QMessageBox::Yes);
return ;
}
file.close();
//TODO:ʵ<><CAB5>ѡ<EFBFBD><D1A1><EFBFBD>б<EFBFBD><D0B1>е<EFBFBD><D0B5><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD>ǰUI<55><49><EFBFBD><EFBFBD>
getParam_fromUI();
save_json(filename);
//JsonConfig json;
//json.WriteToJson(&cfg_param, filename.toStdString());
}
void ScanSettingDialog::on_pBtn_usrSetting_save_clicked()
{
int a = QMessageBox::question(this,
tr(std::string(u8"<EFBFBD><EFBFBD>ʾ").c_str()),
tr(std::string(u8"ȷ<EFBFBD>ϸ<EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD>").c_str()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (a == QMessageBox::Yes)
{
QString name = ui->listWidget->currentItem()->text();
getParam_fromUI();
save_json(QString::fromStdString(Global::getSettingPath()) + name + ".json");
//save_jsonList(name + ".json", &cfg_param);
}
}
void ScanSettingDialog::on_listWidget_itemSelectionChanged()
{
bool n_empty = !ui->listWidget->selectedItems().isEmpty();
ui->pBtn_usrSetting_del->setEnabled(n_empty);
ui->pBtn_usrSetting_exp->setEnabled(n_empty);
}
void ScanSettingDialog::on_listWidget_currentRowChanged(int currentRow)
{
bool currRow = currentRow != -1;
ui->pBtn_usrSetting_clr->setEnabled(currRow);
ui->pBtn_usrSetting_app->setEnabled(currRow);
ui->pBtn_usrSetting_save->setEnabled(currRow);
//on_pBtn_usrSetting_app_clicked();
}
void ScanSettingDialog::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
ui->listWidget->setCurrentItem(item);
on_pBtn_usrSetting_app_clicked();
}
void ScanSettingDialog::add_usrSetting(QString name)
{
QList<QListWidgetItem*> list(ui->listWidget->findItems(name, Qt::MatchExactly));
if (list.isEmpty())
{
int index = ui->listWidget->currentRow();
if (index == ui->listWidget->count() - 1)
ui->listWidget->addItem(name);
else
ui->listWidget->insertItem(index + 1, name);
ui->listWidget->setCurrentRow(index + 1);
}
else
{
int a = QMessageBox::question(this,
tr(std::string(u8"<EFBFBD><EFBFBD>ʾ").c_str()),
tr(std::string(u8"<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ļ<EFBFBD> '%1'. ȷ<>ϸ<EFBFBD><CFB8><EFBFBD>?").c_str()).arg(name),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (a == QMessageBox::Yes)
{
QListWidgetItem* item = new QListWidgetItem;
item = list.at(0);
int index = ui->listWidget->row(item);
ui->listWidget->takeItem(index);
ui->listWidget->insertItem(index, name);
ui->listWidget->setCurrentRow(index);
delete item;
}
}
}
//json functions (4)
QStringList ScanSettingDialog::check_json(QString dirPath)
{
//<2F><>ȡdirPath<74>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>µ<EFBFBD>json<6F>ļ<EFBFBD><C4BC>б<EFBFBD>
QDir dir(dirPath);
QStringList filter;
filter << "*.json";
QFileInfoList json_list;
json_list = dir.entryInfoList(filter, QDir::Files);
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0>ѡ<EFBFBD><D1A1><EFBFBD>б<EFBFBD><D0B1>Ѽ<EFBFBD><D1BC>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
QStringList name_list;
for (int i = 0; i < ui->listWidget->count(); i++)
{
name_list.append(ui->listWidget->item(i)->text());
}
//<2F>޳<EFBFBD><DEB3>Ѽ<EFBFBD><D1BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach(QFileInfo jsonName, json_list)
{
foreach(QString name, name_list)
{
if (name == jsonName.baseName())
json_list.removeOne(jsonName);
}
}
//<2F><><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>б<EFBFBD>
QStringList reList;
foreach(QFileInfo iniName, json_list)
{
reList.append(iniName.baseName());
}
return reList;
}
void ScanSettingDialog::delete_json(QString name)
{
QFileInfo file(QString::fromStdString(Global::getSettingPath()) + name + ".json");
if (!file.exists()) return;
QFile::setPermissions(file.absoluteFilePath(),QFile::ReadOther | QFile::WriteOther);
QFile filename(file.absoluteFilePath());
filename.open(QIODevice::WriteOnly|QIODevice::WriteOnly);
filename.setPermissions(file.absoluteFilePath(),QFile::ReadOther | QFile::WriteOther);
filename.remove();
auto er= filename.error();
//file.dir().remove(file.fileName());
}
GScanCap ScanSettingDialog::load_settingjson()
{
QFile* file;
JsonConfig json;
file = new QFile(QString::fromStdString(Global::getSettingPath()) + QString(appJsonName.c_str()));
if (!file->open(QIODevice::ReadOnly))
{
return json.ReadDefaultConfig();
}
GScanCap cap;
memset(&cap, 0, sizeof(cap));
cap = json.ReadJsonFromFile(QFileInfo(*file).absoluteFilePath().toStdString());
file->close();
delete file;
return cap;
}
json ScanSettingDialog::loadjson(QString filename)
{
if (QFile::exists(filename))
{
QFile file(filename);
file.open(QIODevice::OpenModeFlag::ReadOnly);
//replace(str.begin(), str.end(), (char)34, ' ');
QByteArray str= file.readAll();
json js = json::parse(str);
file.close();
return js;
}
return json();
}
void ScanSettingDialog::load_jsonList(QString filename)
{
QFile* file;
QString JsonName = QString::fromStdString(appJsonName);
file = new QFile(QString::fromStdString(Global::getSettingPath()) + filename);
JsonConfig json;
if (!file->open(QIODevice::ReadOnly))
{
QMessageBox::warning(this, tr(u8"warning"), tr(u8"Load setting file failed. File would be damaged or deleted."));
configUI_fromConfigParam(DEFAULT);
return;
}
qDebug() << "read open userSettings.json OK:" << endl;
configUI_fromConfigParam(USER);
file->close();
delete file;
}
void ScanSettingDialog::save_jsonList(QString filename, GScanCap* param_ptr)
{
QFile* file;
QString JsonName = QString::fromStdString(appJsonName);
file = new QFile(QString::fromStdString(Global::getSettingPath()) + filename);
if (!file->open(QIODevice::WriteOnly))
{
QMessageBox::warning(this, tr(u8"warning"), tr(u8"Save setting file failed."));
return;
}
qDebug() << "write open userSettings.json OK:" << endl;
JsonConfig json;
json.WriteToJson(param_ptr, QFileInfo(*file).absoluteFilePath().toStdString());
file->close();
delete file;
}
//ui params functions(2)
void ScanSettingDialog::configUI_fromConfigParam(std::string defaultoruser)
{
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
if(param[Model][defaultoruser][AUTOMATICCOLOR].get<bool>())
ui->cbox_colorMode->setCurrentIndex(3);
else
ui->cbox_colorMode->setCurrentIndex(std::abs(param[Model][defaultoruser][PIXTYPE].get<int>() - 2));
int index = 1;
for (int i = 0; i<ui->cbox_paperSize->count(); i++)
{
if (ui->cbox_paperSize->itemText(i).toStdString() == papersizename[param[Model][defaultoruser][PAPERSIZENAME].get<std::string>()])
{index = i;
break;}
}
//int x=(param[Model][defaultoruser][PAPERSIZE].get<int>() == TwSS::MaxSize ||
// param[Model][defaultoruser][AUTOCROP].get<bool>() == 0) ? index : 0;
ui->cbox_paperSize->setCurrentIndex(index);
index = param[Model][defaultoruser][DUPLEX].get<int>();
if (param[Model][defaultoruser][DISCARBLANK].get<bool>())
index = 2;
else if (param[Model][defaultoruser][DISCARBLANKVINCE].get<bool>())
index = 3;
else if (param[Model][defaultoruser][FOLD].get<bool>())
index = 4;
ui->cbox_scanPage->setCurrentIndex(index);
ui->cbtn_exchangeFB->setChecked(param[Model][defaultoruser][EXCHANGEFB].get<bool>());
index = param[Model][defaultoruser][RESOLUTION].get<float>() == 100 ? 0 : 2;
if (param[Model][defaultoruser][RESOLUTION].get<float>() == 150)
index = 1;
else if (param[Model][defaultoruser][RESOLUTION].get<float>() == 240)
index = 3;
else if (param[Model][defaultoruser][RESOLUTION].get<float>() == 300)
index = 4;
else if (param[Model][defaultoruser][RESOLUTION].get<float>() == 600)
index = 5;
ui->cbox_resolution->setCurrentIndex(index);
ui->cbtn_multiStream->setChecked(param[Model][defaultoruser][MULTIOUTPUT].get<int>() != MultiOutput::Unused);
ui->cbox_multiStream->setEnabled(ui->cbtn_multiStream->isChecked());
ui->tbtn_sizeArea->setEnabled(param[Model][defaultoruser][CROPRECT_ENABLE].get<bool>());
ui->cbtn_sizeAreaSwitch->setChecked(param[Model][defaultoruser][CROPRECT_ENABLE].get<bool>());
sizeAreaRect.setX(param[Model][USER][CROPRECT_X].get<int>());
sizeAreaRect.setY(param[Model][USER][CROPRECT_Y].get<int>());
sizeAreaRect.setHeight(param[Model][USER][CROPRECT_H].get<int>());
sizeAreaRect.setWidth(param[Model][USER][CROPRECT_W].get<int>());
//<2F><><EFBFBD>ȶԱȶ<D4B1>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
ui->spin_brightness->setValue(param[Model][defaultoruser][BRIGHTNESS].get<int>());
ui->spin_contrast->setValue(param[Model][defaultoruser][CONTRAST].get<int>());
ui->dSpin_gamma->setValue(param[Model][defaultoruser][GAMMA].get<float>());
ui->cbtn_colorLineSwitch->setChecked(param[Model][defaultoruser][CUSTOMGAMMA]);
ui->tbtn_colorCurve->setEnabled(param[Model][defaultoruser][CUSTOMGAMMA]);
//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
ui->cbtn_deBlack->setChecked(param[Model][defaultoruser][FILLBLACK].get<bool>());
ui->cbtn_fillcolor->setChecked(ui->cbtn_deBlack->isChecked()&&param[Model][defaultoruser][FILLCOLOR].get<bool>());
ui->cbtn_adjust->setChecked(param[Model][defaultoruser][AUTODESCREW].get<bool>());
ui->cbtn_deHole->setChecked(param[Model][defaultoruser][OUTHOLE].get<bool>());
ui->Slider_deHole->setValue(param[Model][defaultoruser][OUTHOLERATIO].get<int>() / 5 - 1);
int decolorindex=param[Model][defaultoruser][FILTERTYPE].get<int>();
ui->cbox_deColor->setCurrentIndex(decolorindex);
index = param[Model][defaultoruser][SHARPENTYPE].get<int>();
ui->gbox_sharAndBlur->setChecked(index != 0);
if (index == 1)
ui->rbtn_sharpening1->setChecked(true);
else if (index == 2)
ui->rbtn_sharpening2->setChecked(true);
else if (index == 3)
ui->rbtn_blur1->setChecked(true);
else if (index == 4)
ui->rbtn_blur2->setChecked(true);
ui->cbtn_specialMulti->setChecked(param[Model][defaultoruser][MULTIOUTPUTR].get<bool>());
ui->cbtn_deRed_asheet->setChecked(param[Model][defaultoruser][ANSWERSHEETR].get<bool>());
ui->cbtn_imgSplit->setChecked(param[Model][defaultoruser][SPLITIMAGE].get<bool>()&&(ui->cbox_scanPage->currentIndex()!=4));
int setBwdot= param[Model][defaultoruser][ERROREXTENTION].get<int>();
ui->cbtn_setBWDot->setChecked(setBwdot);
bool en;
param[Model][defaultoruser][TEXTUREREMOVE].get_to(en);
ui->cbtn_texRmv->setChecked(en);
//param[Model][defaultoruser][REFUSEINFLOW].get_to(en);
ui->cbtn_antiInfi->setChecked(en);
param[Model][defaultoruser][REMOVEMORR].get_to(en);
ui->cbtn_deMoire->setChecked(en);
int in;
param[Model][defaultoruser][NOISEDETACH].get_to(in);
ui->cbtn_noise->setChecked(in);
ui->cbtn_bgremoval->setChecked(param[Model][defaultoruser][BACKGROUNDREMOVAL].get<bool>());
ui->cbtn_fillcolor->setChecked(param[Model][defaultoruser][FILLCOLOR].get<bool>());
//<2F><>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
param[Model][defaultoruser][SCANCOUNT].get<int>() == 65536 ? ui->rbtn_maxPage->setChecked(true) : ui->rbtn_pageNum->setChecked(true);
ui->cbox_pageDirection->setCurrentIndex(param[Model][defaultoruser][DOCORIENTATION].get<int>());
ui->cbtn_backRotate_180->setChecked(param[Model][defaultoruser][BACKROTATE180].get<bool>());
ui->cbtn_doubleCheck->setChecked(param[Model][defaultoruser][DOUBLEFOODD].get<bool>());
ui->cbtn_stapleCheck->setChecked(param[Model][defaultoruser][BINDINGDETECT].get<bool>());
ui->cbtn_skewCheck->setChecked(param[Model][defaultoruser][SKEWDENABLE].get<bool>());
ui->Slider_skewCheck->setValue(param[Model][defaultoruser][SKEWLEVEL].get<int>());
ui->cbtn_sizeCheck->setChecked((param[Model][defaultoruser][SIZEDETECT].get<bool>()));
}
void ScanSettingDialog::getParam_fromUI()
{
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
if(ui->cbox_colorMode->currentIndex()==3){
param[Model][USER][AUTOMATICCOLOR]=true;
param[Model][USER][PIXTYPE] = 2;
}
else{
param[Model][USER][PIXTYPE] = static_cast<ColorMode>(std::abs(ui->cbox_colorMode->currentIndex() - 2));
param[Model][USER][AUTOMATICCOLOR]=false;
}
param[Model][USER][MULTIOUTPUT] = ui->cbtn_multiStream->isChecked()? ui->cbox_multiStream->currentIndex():MultiOutput::Unused;
TwSS paperSizeIndex = TwSS::A3;
int index = 0;
PaperAlign paperAlignIndex = ui->cbox_paperSize->currentText().contains(std::string(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>").c_str())?PaperAlign::Rot270:PaperAlign::Rot0;
std::string papername;
if(std::find_if(papersizename.begin(),papersizename.end(),[&](const std::map<std::string, std::string>::value_type item)
{
if(item.second == ui->cbox_paperSize->currentText().toStdString())
{
papername=item.first;
return true;
}
return false;
})==papersizename.end())
param[Model][USER][PAPERSIZENAME]="A4";
else
param[Model][USER][PAPERSIZENAME] =papername;//ui->cbox_paperSize->currentText().toStdString();
paperSizeIndex = (TwSS)support_paper[papername];
param[Model][USER][PAPERSIZE] = paperSizeIndex;
param[Model][USER][PAPERALIGN] = paperAlignIndex;
param[Model][USER][AUTOCROP] = support_paper[papername] == 0;
QList<int> lst;
lst << 100 << 150 << 200 << 240 << 300<<600;
param[Model][USER][RESOLUTION] = lst.at(ui->cbox_resolution->currentIndex());
param[Model][USER][DUPLEX] = ui->cbox_scanPage->currentIndex() != 0;
param[Model][USER][DISCARBLANK] = ui->cbox_scanPage->currentIndex() == 2;
param[Model][USER][DISCARBLANKVINCE] = ui->cbox_scanPage->currentIndex() == 3;
param[Model][USER][FOLD] = (ui->cbox_scanPage->currentIndex() == 4);
param[Model][USER][EXCHANGEFB] = ui->cbtn_exchangeFB->isChecked();
param[Model][USER][CROPRECT_ENABLE] = ui->cbtn_sizeAreaSwitch->isChecked();
param[Model][USER][CROPRECT_H] = sizeAreaRect.height();
param[Model][USER][CROPRECT_W] = sizeAreaRect.width();
param[Model][USER][CROPRECT_X] = sizeAreaRect.x();
param[Model][USER][CROPRECT_Y] = sizeAreaRect.y();
//<2F><><EFBFBD>ȶԱȶ<D4B1>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
param[Model][USER][BRIGHTNESS] = ui->spin_brightness->value();
param[Model][USER][CONTRAST] = ui->spin_contrast->value();
param[Model][USER][GAMMA] = ui->dSpin_gamma->value();
param[Model][USER][CUSTOMGAMMA] = ui->cbtn_colorLineSwitch->isChecked();
try {
if (param[Model][USER][GAMMATABLELENGHT] == 256)
{
uchar table[256];
param[Model][USER][GAMMATABLE].get_to(table);
}
else if (param[Model][USER][GAMMATABLELENGHT] == 786)
{
uchar table[786];
param[Model][USER][GAMMATABLE].get_to(table);
}
else
{
throw "error";
}
}
catch(...){
uchar table[786];
for (int i = 0; i < 786; i += 3)
table[i] = table[i + 1] = table[i + 2] = i / 3;
param[Model][USER][GAMMATABLE] = table;
param[Model][USER][GAMMATABLELENGHT] = 786;
}
//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
param[Model][USER][FILLBLACK] = ui->cbtn_deBlack->isChecked();
param[Model][USER][FILLCOLOR]=ui->cbtn_fillcolor->isChecked();
param[Model][USER][AUTODESCREW] = ui->cbtn_adjust->isChecked();
param[Model][USER][OUTHOLE] = ui->cbtn_deHole->isChecked();
param[Model][USER][OUTHOLERATIO] = ui->Slider_deHole->value() * 5 + 5;
param[Model][USER][FILTERTYPE] = ui->cbox_deColor->currentIndex();
index = 1;
if (ui->rbtn_sharpening2->isChecked())
index = 2;
else if (ui->rbtn_blur1->isChecked())
index = 3;
else if (ui->rbtn_blur2->isChecked())
index = 4;
auto ty=ui->gbox_sharAndBlur->isChecked() ? index : 0;
param[Model][USER][SHARPENTYPE] = static_cast<SharpenType>(ui->gbox_sharAndBlur->isChecked() ? index : 0);
param[Model][USER][MULTIOUTPUTR] = ui->cbtn_specialMulti->isChecked();
param[Model][USER][ANSWERSHEETR] = ui->cbtn_deRed_asheet->isChecked();
param[Model][USER][SPLITIMAGE]=ui->cbtn_imgSplit->isChecked();
param[Model][USER][ERROREXTENTION]=ui->cbtn_setBWDot->isChecked()==true?1:0;
param[Model][USER][TEXTUREREMOVE] = ui->cbtn_texRmv->isChecked();
param[Model][USER][REFUSEINFLOW] = ui->cbtn_antiInfi->isChecked();
param[Model][USER][REMOVEMORR] = ui->cbtn_deMoire->isChecked();
param[Model][USER][NOISEDETACH] = ui->cbtn_noise->isChecked();
param[Model][USER][BACKGROUNDREMOVAL]=ui->cbtn_bgremoval->isChecked();
param[Model][USER][FILLCOLOR] = ui->cbtn_fillcolor->isChecked();
//<2F><>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>
param[Model][USER][SCANCOUNT] = ui->rbtn_maxPage->isChecked() ? 65536 : ui->spin_pageNum->value();
param[Model][USER][DOCORIENTATION] = ui->cbox_pageDirection->currentIndex();
param[Model][USER][BACKROTATE180] = ui->cbtn_backRotate_180->isChecked();
param[Model][USER][DOUBLEFOODD] = ui->cbtn_doubleCheck->isChecked();
param[Model][USER][BINDINGDETECT] = ui->cbtn_stapleCheck->isChecked();
param[Model][USER][SKEWDENABLE] = ui->cbtn_skewCheck->isChecked();
param[Model][USER][SKEWLEVEL] = ui->Slider_skewCheck->value();
param[Model][USER][SIZEDETECT] = ui->cbtn_sizeCheck->isChecked();
}
void ScanSettingDialog::save_json(QString path)
{
if(!QDir().exists(QString::fromStdString(Global::getSettingPath())))
{
QDir().mkpath(QString::fromStdString(Global::getSettingPath()));
}
QFile file(path);
if (file.open(QIODevice::WriteOnly| QIODevice::Text))
{
file.write(param.dump().c_str());
file.close();
}
}
void ScanSettingDialog::on_cbtn_deBlack_clicked(bool checked)
{
if(checked)
ui->cbtn_fillcolor->setEnabled(true);
else {
ui->cbtn_fillcolor->setChecked(false);
ui->cbtn_fillcolor->setEnabled(false);
}
}