mirror of http://192.168.1.51:8099/lmh188/twain3
1324 lines
44 KiB
C++
1324 lines
44 KiB
C++
|
#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={{"A3","A3"},
|
|||
|
{"A4","A4"},
|
|||
|
{"A4 Transverse","A4横向"},
|
|||
|
{"A5","A5"},
|
|||
|
{"A5 Transverse","A5横向"},
|
|||
|
{"A6","A6"},
|
|||
|
{"A6 Transverse","A6横向"},
|
|||
|
{"B4","B4"},
|
|||
|
{"B5","B5"},
|
|||
|
{"B5 Transverse","B5横向"},
|
|||
|
{"B6","B6"},
|
|||
|
{"B6 Transverse","B6横向"},
|
|||
|
{"Legal","Legal"},
|
|||
|
{"Double Letter","双倍信封"},
|
|||
|
{"Letter","信封"},
|
|||
|
{"Letter Transverse","信封横向"},
|
|||
|
{"Matches the original size","匹配原始尺寸"},
|
|||
|
{"Max Size Auto Crop","最大尺寸自动裁切"},
|
|||
|
{"Max Size","最大尺寸"}};
|
|||
|
|
|||
|
ScanSettingDialog::ScanSettingDialog(Func twG, int uiMode,std::string model, QWidget *parent) :
|
|||
|
QDialog(parent),
|
|||
|
ui(new Ui::ScanSettingDialog),
|
|||
|
m_twG(twG),
|
|||
|
Model(model),
|
|||
|
UImode(uiMode)
|
|||
|
{
|
|||
|
Qt::WindowFlags flags = Qt::Dialog;
|
|||
|
flags |= Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint;
|
|||
|
setWindowFlags(flags);
|
|||
|
ui->setupUi(this);
|
|||
|
QFile file(":/huagao.json");
|
|||
|
if(file.open(QIODevice::OpenModeFlag::ReadOnly))
|
|||
|
{
|
|||
|
defaultjson=json::parse(file.readAll().toStdString());
|
|||
|
file.close();
|
|||
|
}
|
|||
|
#if defined (HGVERSION)
|
|||
|
setWindowIcon(QIcon(":/ImageResource/huagoscan_LOGO_icon.png"));
|
|||
|
#else
|
|||
|
setWindowIcon(QIcon(":/ImageResource/Lanxum_logo.ico"));
|
|||
|
#endif
|
|||
|
QString modeText;
|
|||
|
if (UImode == showUI)
|
|||
|
modeText = tr(std::string("扫描").c_str());
|
|||
|
else if (UImode == UIonly)
|
|||
|
modeText = tr(std::string("确认").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();
|
|||
|
//ui->listWidget->setCurrentRow(0);
|
|||
|
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) 界面互斥
|
|||
|
|
|||
|
|
|||
|
void ScanSettingDialog::on_cbox_colorMode_currentIndexChanged(int index)
|
|||
|
{
|
|||
|
ui->cbtn_colorLineSwitch->setEnabled(index != 2); //色调曲线
|
|||
|
ui->tbtn_colorCurve->setEnabled((index != 2)&&(ui->cbtn_colorLineSwitch->isChecked())); //色调曲线
|
|||
|
ui->label_deColor->setEnabled(index != 0); //除色
|
|||
|
ui->cbox_deColor->setEnabled(index != 0);//除色
|
|||
|
ui->cbtn_colorAdjust->setEnabled(index != 2);//色彩修正
|
|||
|
ui->cbtn_deMoire->setEnabled(index != 2);//去摩尔纹
|
|||
|
ui->cbtn_setBWDot->setEnabled(index == 2);//错误扩散
|
|||
|
ui->cbtn_noise->setEnabled(index == 2);//噪点优化
|
|||
|
ui->cbtn_texRmv->setEnabled(index != 2);//去网纹
|
|||
|
ui->gbox_sharAndBlur->setEnabled(index != 2);//锐化
|
|||
|
ui->cbtn_specialMulti->setEnabled(index == 0);//多流输出除红
|
|||
|
ui->cbtn_deRed_asheet->setEnabled(index==0);//答题卡除红
|
|||
|
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)//匹配原始尺寸和最大尺寸自动裁切
|
|||
|
{
|
|||
|
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("非常难检测").c_str());
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
sk = tr(std::string("难以检测").c_str());
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
sk = tr(std::string("正常").c_str());
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
sk = tr(std::string("容易检测").c_str());
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
sk = tr(std::string("非常容易检测").c_str());
|
|||
|
break;
|
|||
|
default:
|
|||
|
sk = tr(std::string("正常").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("警告").c_str()), tr(std::string("未找到说明文档!").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("关于 HuaGoScan"),
|
|||
|
tr("<p>HuaGoScan Driver" \
|
|||
|
"<br>版本号: 2.2.2.0" \
|
|||
|
"<br>Copyright © 2019,HUAGOSCAN CO.,LTD. All Rights Reserved.</p>" \
|
|||
|
"<p>扫描仪系列: %1" \
|
|||
|
"<br>固件版本: %2" \
|
|||
|
"<br>序列号: %3</p>" \
|
|||
|
"<p>制造商: %4" \
|
|||
|
"<br>联系地址: %5" \
|
|||
|
"<br>网址: <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("关于 LanXumScan"),
|
|||
|
tr("<p>LANXUMSCAN Driver" \
|
|||
|
"<br>版本号: 2.2.2.0" \
|
|||
|
"<p>扫描仪系列: %1" \
|
|||
|
"<br>固件版本: %2" \
|
|||
|
"<br>序列号: %3</p>" \
|
|||
|
"<p>制造商: %4" \
|
|||
|
"<br>联系地址: %5" \
|
|||
|
"<br>网址: <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(param[Model][USER].dump());
|
|||
|
else
|
|||
|
m_twG.IconfirmFunction(param[Model][USER].dump());
|
|||
|
close();
|
|||
|
}
|
|||
|
|
|||
|
void ScanSettingDialog::on_pbtn_cancel_clicked()
|
|||
|
{
|
|||
|
m_twG.IcancelFunction();
|
|||
|
close();
|
|||
|
}
|
|||
|
|
|||
|
//usr_settings functions(12)
|
|||
|
#define MAX_SETTINGS_NUM 10
|
|||
|
|
|||
|
void ScanSettingDialog::on_pBtn_usrSetting_app_clicked()
|
|||
|
{
|
|||
|
if( QMessageBox::question(this,
|
|||
|
tr(std::string("提示").c_str()),
|
|||
|
tr(std::string("确认应用配置?").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("新增配置").c_str()));
|
|||
|
d.setLabelText(tr(std::string("请为新配置命名!").c_str()));
|
|||
|
if (d.exec())
|
|||
|
{
|
|||
|
QString name = d.textValue();
|
|||
|
if(name.contains('/'))
|
|||
|
{
|
|||
|
QMessageBox::information(this,tr(std::string("警告").c_str()),tr(std::string("非法文件名!").c_str()),QMessageBox::Yes);
|
|||
|
return;
|
|||
|
}
|
|||
|
//增加列表项
|
|||
|
add_usrSetting(name);
|
|||
|
//新增配置文件
|
|||
|
getParam_fromUI();
|
|||
|
save_json(QString::fromStdString(Global::getSettingPath()) + name + ".json");
|
|||
|
//save_jsonList(name + ".json", ¶ms);
|
|||
|
//列表最大数量限制
|
|||
|
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("提示").c_str()),
|
|||
|
tr(std::string("确认删除选择的配置吗?").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("提示").c_str()),
|
|||
|
tr(std::string("确认删除所有配置文件?").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("选择导入文件").c_str()), "", "(*.json)");
|
|||
|
if (list.isEmpty()) return;
|
|||
|
//检测导入配置文件后,首选项列表个数是否超过最大数量限制
|
|||
|
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("警告").c_str()), tr(std::string("配置文件个数已经超过最大支持数量!").c_str()));
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
//添加配置文件到首选项列表
|
|||
|
for (int i = 0; i < list.size(); i++) {
|
|||
|
QFileInfo fileinfo(list.at(i));
|
|||
|
QString name = fileinfo.baseName();
|
|||
|
add_usrSetting(name);
|
|||
|
}
|
|||
|
//达到最大数量限制UI逻辑
|
|||
|
if (ui->listWidget->count() >= MAX_SETTINGS_NUM)
|
|||
|
{
|
|||
|
ui->pBtn_usrSetting_add->setEnabled(false);
|
|||
|
ui->pBtn_usrSetting_inp->setEnabled(false);
|
|||
|
}
|
|||
|
//将导入的文件备份到标准首选项配置目录
|
|||
|
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("导出配置").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("警告").c_str()),
|
|||
|
// tr(std::string("非法文件名").c_str()),
|
|||
|
// QMessageBox::Yes ,
|
|||
|
// QMessageBox::Yes);
|
|||
|
// return ;
|
|||
|
// }
|
|||
|
if (!filename.endsWith(".json"))
|
|||
|
{
|
|||
|
filename += ".json";
|
|||
|
}
|
|||
|
QFile file(filename);
|
|||
|
if(!file.open(QIODevice::WriteOnly)){
|
|||
|
if(QFile::exists(filename))
|
|||
|
QFile::remove(filename);
|
|||
|
QMessageBox::question(this,tr(std::string("警告").c_str()), tr(std::string("非法文件名").c_str()),
|
|||
|
QMessageBox::Yes , QMessageBox::Yes);
|
|||
|
return ;
|
|||
|
}
|
|||
|
file.close();
|
|||
|
//TODO:实现选中列表中的配置导出,而非导出当前UI配置
|
|||
|
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("提示").c_str()),
|
|||
|
tr(std::string("确认覆盖保存?").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("提示").c_str()),
|
|||
|
tr(std::string("已经存在相同文件 '%1'. 确认覆盖?").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)
|
|||
|
{
|
|||
|
//获取dirPath文件夹下的json文件列表
|
|||
|
QDir dir(dirPath);
|
|||
|
QStringList filter;
|
|||
|
filter << "*.json";
|
|||
|
QFileInfoList json_list;
|
|||
|
json_list = dir.entryInfoList(filter, QDir::Files);
|
|||
|
//获取当前首选项列表已加载的配置列表
|
|||
|
QStringList name_list;
|
|||
|
for (int i = 0; i < ui->listWidget->count(); i++)
|
|||
|
{
|
|||
|
name_list.append(ui->listWidget->item(i)->text());
|
|||
|
}
|
|||
|
//剔除已加载配置
|
|||
|
foreach(QFileInfo jsonName, json_list)
|
|||
|
{
|
|||
|
foreach(QString name, name_list)
|
|||
|
{
|
|||
|
if (name == jsonName.baseName())
|
|||
|
json_list.removeOne(jsonName);
|
|||
|
}
|
|||
|
}
|
|||
|
//生成返回列表
|
|||
|
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("warning"), tr("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("warning"), tr("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)
|
|||
|
{
|
|||
|
//基本选项卡参数
|
|||
|
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>());
|
|||
|
//亮度对比度选项卡参数
|
|||
|
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]);
|
|||
|
|
|||
|
//图像处理选项卡参数
|
|||
|
ui->cbtn_deBlack->setChecked(param[Model][defaultoruser][FILLBLACK].get<bool>());
|
|||
|
ui->cbtn_fillcolor->setChecked(ui->cbtn_deBlack->isChecked()&¶m[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>());
|
|||
|
|
|||
|
//送纸部分选项卡参数
|
|||
|
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()
|
|||
|
{
|
|||
|
//基本选项卡参数
|
|||
|
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("横向").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();
|
|||
|
|
|||
|
//亮度对比度选项卡参数
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
//图像处理选项卡参数
|
|||
|
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][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);
|
|||
|
}
|
|||
|
}
|