diff --git a/app/twaintest/TwainTest_resource.qrc b/app/twaintest/TwainTest_resource.qrc new file mode 100644 index 00000000..d3b486d3 --- /dev/null +++ b/app/twaintest/TwainTest_resource.qrc @@ -0,0 +1,9 @@ + + + + TwainTest_zh_CN.qm + + + image_rsc/logo/logo.ico + + diff --git a/app/twaintest/TwainTest_zh_CN.qm b/app/twaintest/TwainTest_zh_CN.qm new file mode 100644 index 00000000..40fb282d Binary files /dev/null and b/app/twaintest/TwainTest_zh_CN.qm differ diff --git a/app/twaintest/TwainTest_zh_CN.ts b/app/twaintest/TwainTest_zh_CN.ts new file mode 100644 index 00000000..226d0b59 --- /dev/null +++ b/app/twaintest/TwainTest_zh_CN.ts @@ -0,0 +1,287 @@ + + + + + MainWindow + + + MainWindow + Twain测试工具 + + + + Set Capbility: + 选择测试项目: + + + + Scan + 扫描 + + + + Set Cap + 设置 + + + + Device Status: + 设备状态: + + + + Capbility Type: + 测试项目类型: + + + + Reset Capbility + 重置测试项目 + + + + Set cap Content: + 设置测试项目标值: + + + + Get Cap + 获取 + + + + Get cap Content: + 获取测试项当前值: + + + + menu_scan + act_scan + 扫描 + + + + act_selectDevice + 选择设备源... + + + + + No device connected + 当前无设备连接 + + + + Device %1 is open + 设备 %1 已连接 + + + + + + + Prompt + 提示 + + + + Device source not found! + 未找到设备源! + + + + Set successfully + 设置成功 + + + + Set failed + 设置失败 + + + + Get failed + 获取失败 + + + + (FillBackground) + (背景填充) + + + + (BackRotate180) + (背面旋转180度) + + + + (ScrewDetectEnable) + (歪斜检测) + + + + (EnhanceColor) + (颜色增强) + + + + (DARK_SAMPLE) + (深色样张) + + + + (FillHole) + (穿孔移除) + + + + (ScrewLevel) + (歪斜容忍度) + + + + (Sharpen) + (锐化与模糊) + + + + (HardwareVersion) + (硬件版本) + + + + (MultiOutputRed) + (多流输出除红) + + + + (EnFold) + (对折) + + + + (StableDetectEnable) + (装订检测) + + + + (DiscardBlankVince) + (跳过空白发票) + + + + (FillHoleRatio) + (穿孔搜索范围) + + + + (SwitchFrontBack) + (交换正反面) + + + + (HsvCorrect) + (答题卡除红) + + + + (DogEarDelection) + (折角检测) + + + + (FillBackgroundMode) + (背景填充方式) + + + + (CroporDesaskewIndent) + (边缘缩进) + + + + (CropNoise) + (背景抗噪等级) + + + + (CroporDesaskewThreshold) + (阈值) + + + + (DetachNoise) + (黑白图像噪点优化) + + + + (DetachNoiseValue) + (噪点优化尺寸) + + + + (SizeDetect) + (尺寸检测) + + + + (LowPowerMode) + (节能模式) + + + + (ENCODE) + (编码) + + + + (CropModel) + (裁切方式) + + + + (DogEarDistance) + (折角大小) + + + + (ImageSplit) + (图像拆分) + + + + (FadeBackground) + (是否除背景色) + + + + (FADE_BKG_VALUE) + (背景色范围) + + + + (TO_BE_SCAN) + (待纸扫描) + + + + (MULTI_OUT) + (是否开启多流输出) + + + + (MULTI_OUT_TYPE) + (多流输出类型) + + + + (SCAN_WITH_HOLE) + (是否开启带孔扫描) + + + + (IP) + (获取设备IP) + + + diff --git a/app/twaintest/image_rsc/logo/logo.ico b/app/twaintest/image_rsc/logo/logo.ico new file mode 100644 index 00000000..bb062276 Binary files /dev/null and b/app/twaintest/image_rsc/logo/logo.ico differ diff --git a/app/twaintest/main.cpp b/app/twaintest/main.cpp index fd3e5334..818279fb 100644 --- a/app/twaintest/main.cpp +++ b/app/twaintest/main.cpp @@ -1,10 +1,16 @@ #include "mainwindow.h" #include +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); + + QTranslator translator_app; + if (translator_app.load(":translation/TwainTest_zh_CN.qm")) + a.installTranslator(&translator_app); + MainWindow w; w.show(); return a.exec(); diff --git a/app/twaintest/mainwindow.cpp b/app/twaintest/mainwindow.cpp index 0d504eef..65acf1e8 100644 --- a/app/twaintest/mainwindow.cpp +++ b/app/twaintest/mainwindow.cpp @@ -16,17 +16,22 @@ MainWindow::MainWindow(QWidget *parent) , m_cacheUuid("") { ui->setupUi(this); + this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico")); HGChar cacheUuid[256] = { 0 }; HGBase_GetUuid(cacheUuid, 256); m_cacheUuid = cacheUuid; + updateUiEnable(false); + initCapbility(); + QStringList capTypes = { "TWTY_INT8", "TWTY_UINT8", "TWTY_INT16", "TWTY_UINT16", "TWTY_INT32", "TWTY_UINT32", "TWTY_BOOL","TWTY_FIX32", "TWTY_STR32", "TWTY_STR64", "TWTY_STR128", "TWTY_STR255" }; ui->comboBox_capType->addItems(capTypes); ui->comboBox_capType->setCurrentIndex(0); ui->comboBox_capType->setEditable(true); + ui->comboBox_setCap->setEditable(true); ui->label_deviceStatus->setText(tr("No device connected")); HGTwain_CreateDSM((HWND)this->winId(), &m_twainDSM); @@ -61,6 +66,7 @@ MainWindow::~MainWindow() void MainWindow::on_act_selectDevice_triggered() { ui->label_deviceStatus->setText(tr("No device connected")); + updateUiEnable(false); if (m_twainDS != nullptr) { @@ -77,6 +83,7 @@ void MainWindow::on_act_selectDevice_triggered() { HGTwain_LoginDS(m_twainDS, "user", "huagoscan"); ui->label_deviceStatus->setText(tr("Device %1 is open").arg(getDeviceName())); + updateUiEnable(true); } } else @@ -88,19 +95,13 @@ void MainWindow::on_act_selectDevice_triggered() } } -void MainWindow::on_pushButton_SetCap_clicked() +void MainWindow::on_pushButton_setCap_clicked() { - QString capCode = ui->lineEdit_setCap->text(); + QString capCode = ui->comboBox_setCap->currentText(); bool ok = false; - HGUShort cap = capCode.toInt(&ok, 16); + HGUShort cap = capCode.left(6).toInt(&ok, 16); - HGCapValue value; - QString capType = ui->comboBox_capType->currentText(); - if (capType == "TWTY_BOOL") - { - value.type = HGCAPVALUE_TYPE_BOOL; - value.valueBool = ui->lineEdit_setCapContent->text().toInt(); - } + HGCapValue value = getHGCapValue(); HGResult ret = HGTwain_SetCapbility(m_twainDS, cap, &value, ui->checkBox_resetCap->isChecked()); if (ret == HGBASE_ERR_OK) @@ -113,9 +114,76 @@ void MainWindow::on_pushButton_SetCap_clicked() } } +void MainWindow::on_pushButton_getCap_clicked() +{ + QString capCode = ui->comboBox_setCap->currentText(); + bool ok = false; + HGUShort cap = capCode.left(6).toInt(&ok, 16); + + HGCapValue value2; + HGTwain_GetCapbility(m_twainDS, 0x8803, &value2); + + HGCapValue value; + HGResult ret = HGTwain_GetCapbility(m_twainDS, cap, &value); + if (ret != HGBASE_ERR_OK) + { + QMessageBox::information(this, tr("Prompt"), tr("Get failed")); + return; + } + + if (value.type == HGCAPVALUE_TYPE_CHAR) + { + ui->lineEdit_getCapContent->setText(QString(value.valueChar)); + } + else if (value.type == HGCAPVALUE_TYPE_BYTE) + { + ui->lineEdit_getCapContent->setText(QString(value.valueByte)); + } + else if (value.type == HGCAPVALUE_TYPE_SHORT) + { + ui->lineEdit_getCapContent->setText(QString::number(value.valueShort)); + } + else if (value.type == HGCAPVALUE_TYPE_USHORT) + { + ui->lineEdit_getCapContent->setText(QString::number(value.valueUShort)); + } + else if (value.type == HGCAPVALUE_TYPE_INT) + { + ui->lineEdit_getCapContent->setText(QString::number(value.valueInt)); + } + else if (value.type == HGCAPVALUE_TYPE_UINT) + { + ui->lineEdit_getCapContent->setText(QString::number(value.valueUInt)); + } + else if (value.type == HGCAPVALUE_TYPE_BOOL) + { + ui->lineEdit_getCapContent->setText(value.valueBool ? QString("true") : QString("false")); + } + else if (value.type == HGCAPVALUE_TYPE_FLOAT) + { + ui->lineEdit_getCapContent->setText(QString::number(value.valueFloat, 'f', 4)); + } + else if (value.type == HGCAPVALUE_TYPE_STR32) + { + ui->lineEdit_getCapContent->setText(QString::fromLocal8Bit(value.valueStr32)); + } + else if (value.type == HGCAPVALUE_TYPE_STR64) + { + ui->lineEdit_getCapContent->setText(QString::fromLocal8Bit(value.valueStr64)); + } + else if (value.type == HGCAPVALUE_TYPE_STR128) + { + ui->lineEdit_getCapContent->setText(QString::fromLocal8Bit(value.valueStr128)); + } + else if (value.type == HGCAPVALUE_TYPE_STR255) + { + ui->lineEdit_getCapContent->setText(QString::fromLocal8Bit(value.valueStr255)); + } +} + void MainWindow::on_pushButton_scan_clicked() { - HGResult ret = HGTwain_EnableDS(m_twainDS, HGFALSE, (HWND)this->winId(), DSEventFunc, this, DSImageFunc, this); + HGTwain_EnableDS(m_twainDS, HGFALSE, (HWND)this->winId(), DSEventFunc, this, DSImageFunc, this); } void MainWindow::on_newImage(void *image) @@ -127,7 +195,7 @@ void MainWindow::on_newImage(void *image) info.jpegQuality = 100; info.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; info.tiffJpegQuality = 0; - HGResult ret = HGImgFmt_SaveImage((HGImage)image, 0, &info, getStdString(scanFileName).c_str()); + HGImgFmt_SaveImage((HGImage)image, 0, &info, getStdString(scanFileName).c_str()); } void MainWindow::on_clearRes() @@ -137,6 +205,7 @@ void MainWindow::on_clearRes() void MainWindow::DSEventFunc(HGTwainDS ds, HGUInt event, HGPointer param) { + (void)ds; MainWindow* p = (MainWindow*)param; if (HGTWAIN_EVENT_TYPE_SCANFINISHED == event || HGTWAIN_EVENT_TYPE_CLOSEDSREQ == event) { @@ -146,11 +215,139 @@ void MainWindow::DSEventFunc(HGTwainDS ds, HGUInt event, HGPointer param) HGUInt MainWindow::DSImageFunc(HGTwainDS ds, HGImage image, HGUInt type, HGPointer param) { + (void)ds; + (void)type; MainWindow* p = (MainWindow*)param; emit p->newImage(image); return HGBASE_ERR_OK; } +void MainWindow::initCapbility() +{ + QStringList cap = {}; + + cap.append(QString("0x8004") + tr("(FillBackground)")); + cap.append(QString("0x8005") + tr("(BackRotate180)")); + cap.append(QString("0x8006") + tr("(ScrewDetectEnable)")); + cap.append(QString("0x8007") + tr("(EnhanceColor)")); + cap.append(QString("0x8016") + tr("(DARK_SAMPLE)")); + cap.append(QString("0x8018") + tr("(FillHole)")); + cap.append(QString("0x8021") + tr("(ScrewLevel)")); + cap.append(QString("0x8022") + tr("(Sharpen)")); + cap.append(QString("0x8025") + tr("(HardwareVersion)")); + cap.append(QString("0x8026") + tr("(MultiOutputRed)")); + cap.append(QString("0x8037") + tr("(EnFold)")); + + cap.append(QString("0x8090") + tr("(StableDetectEnable)")); + cap.append(QString("0x8091") + tr("(DiscardBlankVince)")); + cap.append(QString("0x8092") + tr("(FillHoleRatio)")); + cap.append(QString("0x8094") + tr("(SwitchFrontBack)")); + cap.append(QString("0x8095") + tr("(HsvCorrect)")); + cap.append(QString("0x8096") + tr("(DogEarDelection)")); + cap.append(QString("0x8097") + tr("(FillBackgroundMode)")); + cap.append(QString("0x8098") + tr("(CroporDesaskewIndent)")); + cap.append(QString("0x8099") + tr("(CropNoise)")); + cap.append(QString("0x8100") + tr("(CroporDesaskewThreshold)")); + cap.append(QString("0x8101") + tr("(DetachNoise)")); + cap.append(QString("0x8102") + tr("(DetachNoiseValue)")); + cap.append(QString("0x8103") + tr("(SizeDetect)")); + cap.append(QString("0x8104") + tr("(LowPowerMode)")); + cap.append(QString("0x8105") + tr("(ENCODE)")); + cap.append(QString("0x8106") + tr("(CropModel)")); + cap.append(QString("0x8107") + tr("(DogEarDistance)")); + cap.append(QString("0x8108") + tr("(ImageSplit)")); + cap.append(QString("0x8109") + tr("(FadeBackground)")); + cap.append(QString("0x8110") + tr("(FADE_BKG_VALUE)")); + cap.append(QString("0x8111") + tr("(TO_BE_SCAN)")); + cap.append(QString("0x8112") + tr("(MULTI_OUT)")); + cap.append(QString("0x8113") + tr("(MULTI_OUT_TYPE)")); + cap.append(QString("0x8114") + tr("(SCAN_WITH_HOLE)")); + cap.append(QString("0x8200") + tr("(IP)")); + + //TODO 还需要添加剩余的twain测试项 + + ui->comboBox_setCap->addItems(cap); +} + +HGCapValue MainWindow::getHGCapValue() +{ + HGCapValue value; + QString capType = ui->comboBox_capType->currentText(); + if (capType == "TWTY_INT8") + { + value.type = HGCAPVALUE_TYPE_CHAR; + QString text = ui->lineEdit_setCapContent->text(); + if (!text.isEmpty()) + value.valueChar = text.at(0).toLatin1(); + } + else if (capType == "TWTY_UINT8") + { + value.type = HGCAPVALUE_TYPE_BYTE; + QString text = ui->lineEdit_setCapContent->text(); + if (!text.isEmpty()) + value.valueChar = text.at(0).toLatin1(); + } + else if (capType == "TWTY_UINT8") + { + value.type = HGCAPVALUE_TYPE_SHORT; + value.valueShort = ui->lineEdit_setCapContent->text().toShort(); + } + else if (capType == "TWTY_INT16") + { + value.type = HGCAPVALUE_TYPE_USHORT; + value.valueUShort = ui->lineEdit_setCapContent->text().toUShort(); + } + else if (capType == "TWTY_INT32") + { + value.type = HGCAPVALUE_TYPE_INT; + value.valueInt = ui->lineEdit_setCapContent->text().toInt(); + } + else if (capType == "TWTY_UINT32") + { + value.type = HGCAPVALUE_TYPE_UINT; + value.valueUInt = ui->lineEdit_setCapContent->text().toUInt(); + } + else if (capType == "TWTY_BOOL") + { + value.type = HGCAPVALUE_TYPE_BOOL; + value.valueBool = (HGBool)ui->lineEdit_setCapContent->text().toInt(); + } + else if (capType == "TWTY_FIX32") + { + value.type = HGCAPVALUE_TYPE_FLOAT; + value.valueFloat = ui->lineEdit_setCapContent->text().toFloat(); + } + else if (capType == "TWTY_STR32") + { + value.type = HGCAPVALUE_TYPE_BYTE; + strcpy(value.valueStr32, ui->lineEdit_setCapContent->text().toStdString().c_str()); + } + else if (capType == "TWTY_STR64") + { + value.type = HGCAPVALUE_TYPE_BYTE; + strcpy(value.valueStr64, ui->lineEdit_setCapContent->text().toStdString().c_str()); + } + else if (capType == "TWTY_STR128") + { + value.type = HGCAPVALUE_TYPE_BYTE; + strcpy(value.valueStr128, ui->lineEdit_setCapContent->text().toStdString().c_str()); + } + else if (capType == "TWTY_STR255") + { + value.type = HGCAPVALUE_TYPE_BYTE; + strcpy(value.valueStr255, ui->lineEdit_setCapContent->text().toStdString().c_str()); + } + + return value; +} + +void MainWindow::updateUiEnable(bool enable) +{ + ui->pushButton_setCap->setEnabled(enable); + ui->pushButton_getCap->setEnabled(enable); + ui->pushButton_scan->setEnabled(enable); +} + QString MainWindow::getDeviceName() { HGChar devName[256] = {0}; diff --git a/app/twaintest/mainwindow.h b/app/twaintest/mainwindow.h index de8eda19..5a9fc4cd 100644 --- a/app/twaintest/mainwindow.h +++ b/app/twaintest/mainwindow.h @@ -20,7 +20,9 @@ public: private slots: void on_act_selectDevice_triggered(); - void on_pushButton_SetCap_clicked(); + void on_pushButton_setCap_clicked(); + + void on_pushButton_getCap_clicked(); void on_pushButton_scan_clicked(); @@ -36,6 +38,10 @@ private: static void HGAPI DSEventFunc(HGTwainDS ds, HGUInt event, HGPointer param); static HGUInt HGAPI DSImageFunc(HGTwainDS ds, HGImage image, HGUInt type, HGPointer param); + void initCapbility(); + HGCapValue getHGCapValue(); + + void updateUiEnable(bool enable); QString getDeviceName(); QString getCachePath(); QString getCacheFileName(HGImage img); diff --git a/app/twaintest/mainwindow.ui b/app/twaintest/mainwindow.ui index 8f21ed2f..9967b621 100644 --- a/app/twaintest/mainwindow.ui +++ b/app/twaintest/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 800 - 600 + 706 + 506 @@ -17,7 +17,7 @@ - 30 + 60 80 91 16 @@ -27,21 +27,11 @@ Set Capbility: - - - - 130 - 70 - 161 - 31 - - - - 310 - 450 + 290 + 400 101 41 @@ -50,11 +40,11 @@ Scan - + - 240 - 200 + 430 + 210 111 41 @@ -66,9 +56,9 @@ - 30 + 60 30 - 331 + 361 16 @@ -79,9 +69,9 @@ - 130 - 130 - 161 + 160 + 140 + 231 31 @@ -89,8 +79,8 @@ - 20 - 130 + 50 + 140 101 16 @@ -102,8 +92,8 @@ - 370 - 210 + 560 + 220 121 16 @@ -115,89 +105,89 @@ - 410 - 70 + 160 + 210 231 - 31 + 41 - 330 - 80 - 71 + 40 + 220 + 111 16 - Content: + Set cap Content: - + - 20 - 320 - 91 - 16 - - - - Get Capbility: - - - - - - 130 - 310 - 161 - 31 - - - - - - - 330 - 320 - 71 - 16 - - - - Content: - - - - - - 410 - 310 + 160 + 70 231 31 + + + + 430 + 290 + 111 + 41 + + + + Get Cap + + + + + + 40 + 300 + 101 + 16 + + + + Get cap Content: + + + + + + 160 + 290 + 231 + 41 + + + 0 0 - 800 + 706 22 - + - act_scan + menu_scan - + diff --git a/build2/qt/HGTwainTest/HGTwainTest.pro b/build2/qt/HGTwainTest/HGTwainTest.pro index 28f7eae9..5045630e 100644 --- a/build2/qt/HGTwainTest/HGTwainTest.pro +++ b/build2/qt/HGTwainTest/HGTwainTest.pro @@ -106,3 +106,9 @@ HEADERS += \ FORMS += \ ../../../app/twaintest/mainwindow.ui + +RESOURCES += \ + ../../../app/twaintest/TwainTest_resource.qrc + +TRANSLATIONS += \ + ../../../app/twaintest/TwainTest_zh_CN.ts