HGGitLab

Commit a6381f50 authored by luoliangyi's avatar luoliangyi

1.集成twain功能

2.增加登录和登出功能
parent 6ff349b2
......@@ -19,7 +19,7 @@ RC_ICONS = image_rsc/logo/logo.ico
win32 {
contains(QT_ARCH, i386) {
LIBS += -L../../../release/lib/windows/x86/ -lHGBase -lHGImgFmt -lHGImgProc
LIBS += -L../../../release/lib/windows/x86/ -lHGBase -lHGImgFmt -lHGImgProc -lHGTwainUser
CONFIG(release, debug|release) {
DESTDIR = ../../../release/bin/windows/x86/
}
......@@ -27,7 +27,7 @@ contains(QT_ARCH, i386) {
}
} else {
LIBS += -L../../../release/lib/windows/x64/ -lHGBase -lHGImgFmt -lHGImgProc
LIBS += -L../../../release/lib/windows/x64/ -lHGBase -lHGImgFmt -lHGImgProc -lHGTwainUser
CONFIG(release, debug|release) {
DESTDIR = ../../../release/bin/windows/x64/
}
......@@ -52,6 +52,7 @@ INCLUDEPATH += $$PWD/../../../release/include/
SOURCES += \
../../../ui/HGUIGlobal.cpp \
dialog_admin.cpp \
dialog_export.cpp \
dialog_exportimagefile.cpp \
dialog_fullscreen.cpp \
......@@ -61,6 +62,7 @@ SOURCES += \
dialog_multirotate.cpp \
dialog_multirotateimagefile.cpp \
dialog_openimageindex.cpp \
dialog_passwordchange.cpp \
dialog_saveas.cpp \
dialog_savequality.cpp \
main.cpp \
......@@ -72,6 +74,7 @@ SOURCES += \
HEADERS += \
../../../ui/HGUIGlobal.h \
dialog_admin.h \
dialog_export.h \
dialog_exportimagefile.h \
dialog_fullscreen.h \
......@@ -81,6 +84,7 @@ HEADERS += \
dialog_multirotate.h \
dialog_multirotateimagefile.h \
dialog_openimageindex.h \
dialog_passwordchange.h \
dialog_saveas.h \
dialog_savequality.h \
mainwindow.h \
......@@ -90,6 +94,7 @@ HEADERS += \
widget_statusbar.h
FORMS += \
dialog_admin.ui \
dialog_export.ui \
dialog_exportimagefile.ui \
dialog_fullscreen.ui \
......@@ -99,6 +104,7 @@ FORMS += \
dialog_multirotate.ui \
dialog_multirotateimagefile.ui \
dialog_openimageindex.ui \
dialog_passwordchange.ui \
dialog_saveas.ui \
dialog_savequality.ui \
mainwindow.ui \
......
#include "dialog_admin.h"
#include "ui_dialog_admin.h"
#include <QMessageBox>
Dialog_Admin::Dialog_Admin(const QString& password, QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog_Admin)
{
ui->setupUi(this);
ui->lineEdit->setPlaceholderText(tr("Type password"));
ui->lineEdit->setEchoMode(QLineEdit::Password);
ui->lineEdit->setMaxLength(20);
m_password = password;
}
Dialog_Admin::~Dialog_Admin()
{
delete ui;
}
void Dialog_Admin::on_btn_signIn_clicked()
{
if (ui->lineEdit->text() == m_password)
done(1);
else
QMessageBox::warning(this,
tr("Warning"),
tr("Password incorrect. Please try again."));
}
void Dialog_Admin::on_btn_cancel_clicked()
{
done(0);
}
void Dialog_Admin::on_cbtn_showPassword_toggled(bool checked)
{
ui->lineEdit->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
}
void Dialog_Admin::on_lineEdit_textChanged(const QString &arg1)
{
ui->btn_signIn->setEnabled(!arg1.isEmpty());
}
#ifndef DIALOG_ADMIN_H
#define DIALOG_ADMIN_H
#include <QDialog>
namespace Ui {
class Dialog_Admin;
}
class Dialog_Admin : public QDialog
{
Q_OBJECT
public:
explicit Dialog_Admin(const QString &password, QWidget *parent = nullptr);
~Dialog_Admin();
private slots:
void on_btn_signIn_clicked();
void on_btn_cancel_clicked();
void on_cbtn_showPassword_toggled(bool checked);
void on_lineEdit_textChanged(const QString &arg1);
private:
Ui::Dialog_Admin *ui;
QString m_password;
};
#endif // DIALOG_ADMIN_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_Admin</class>
<widget class="QDialog" name="Dialog_Admin">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>119</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>130</height>
</size>
</property>
<property name="windowTitle">
<string>Account sign in</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="lab_account">
<property name="minimumSize">
<size>
<width>54</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Account:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_adminIcon">
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/images/statusbar/image_rsc/statusbar/statusBar_admin.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lab_accountName">
<property name="text">
<string>Administrator</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
<item>
<widget class="QLabel" name="lab_password">
<property name="text">
<string>password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbtn_showPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_signIn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Sign In</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "dialog_passwordchange.h"
#include "ui_dialog_passwordchange.h"
#include <QMessageBox>
#include <QPushButton>
#include <QRegExpValidator>
#include <QToolTip>
Dialog_PasswordChange::Dialog_PasswordChange(const QString &old_password, QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_PasswordChange),
m_old_password(old_password),
m_new_password("")
{
ui->setupUi(this);
QRegExp rx("[a-zA-Z0-9!@#%^&*()_]+$"); //创建一个正则表达式对象rx
qReg = new QRegExpValidator(rx, this); //创建一个过滤器对象
m_lineEditList<<ui->lineEdit_oldPassword<<ui->lineEdit_newPassword<<ui->lineEdit_confirmPassword;
foreach(QLineEdit* item, m_lineEditList)
{
item->setEchoMode(QLineEdit::Password);
item->setMaxLength(20);
item->setValidator(qReg);
}
m_lineEditList[0]->setPlaceholderText(tr("Type old password"));
m_lineEditList[1]->setPlaceholderText(tr("Type new password"));
m_lineEditList[2]->setPlaceholderText(tr("Retype new password"));
}
Dialog_PasswordChange::~Dialog_PasswordChange()
{
delete qReg;
delete ui;
}
QString Dialog_PasswordChange::getNewPassword()
{
return m_new_password;
}
void Dialog_PasswordChange::on_cbtn_showPassword_toggled(bool checked)
{
foreach(QLineEdit* item, m_lineEditList)
item->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::PasswordEchoOnEdit);
}
void Dialog_PasswordChange::on_lineEdit_oldPassword_textChanged(const QString &arg1)
{
ui->btn_ok->setEnabled(arg1.length() >= 8 && ui->lineEdit_newPassword->text().length() >= 8 && ui->lineEdit_confirmPassword->text().length() >= 8);
}
void Dialog_PasswordChange::on_lineEdit_newPassword_textChanged(const QString &arg1)
{
ui->btn_ok->setEnabled(arg1.length() >= 8 && ui->lineEdit_newPassword->text().length() >= 8 && ui->lineEdit_confirmPassword->text().length() >= 8);
}
void Dialog_PasswordChange::on_lineEdit_confirmPassword_textChanged(const QString &arg1)
{
ui->btn_ok->setEnabled(arg1.length() >= 8 && ui->lineEdit_newPassword->text().length() >= 8 && ui->lineEdit_confirmPassword->text().length() >= 8);
}
void Dialog_PasswordChange::on_btn_ok_clicked()
{
if(ui->lineEdit_oldPassword->text() != m_old_password)
QMessageBox::warning(this,
tr("Warning"),
tr("Old password incorrect.\n"
"Please try again."));
else if(ui->lineEdit_newPassword->text() != ui->lineEdit_confirmPassword->text())
QMessageBox::warning(this,
tr("Warning"),
tr("New password and confirm password are not matched.\n"
"Please make sure the two passwords are the same."));
else
{
m_new_password = ui->lineEdit_newPassword->text();
done(1);
}
}
void Dialog_PasswordChange::on_btn_cancel_clicked()
{
done(0);
}
void Dialog_PasswordChange::on_lineEdit_oldPassword_inputRejected()
{
QToolTip::showText(mapToGlobal(ui->lineEdit_oldPassword->pos()),
tr("Password only allowed to use numbers, English and special characters."));
}
void Dialog_PasswordChange::on_lineEdit_newPassword_inputRejected()
{
QToolTip::showText(mapToGlobal(ui->lineEdit_newPassword->pos()),
tr("Password only allowed to use numbers, English and special characters."));
}
void Dialog_PasswordChange::on_lineEdit_confirmPassword_inputRejected()
{
QToolTip::showText(mapToGlobal(ui->lineEdit_confirmPassword->pos()),
tr("Password only allowed to use numbers, English and special characters."));
}
#ifndef DIALOG_PASSWORDCHANGE_H
#define DIALOG_PASSWORDCHANGE_H
#include <QDialog>
class QLineEdit;
class QRegExpValidator;
namespace Ui {
class Dialog_PasswordChange;
}
class Dialog_PasswordChange : public QDialog
{
Q_OBJECT
public:
explicit Dialog_PasswordChange(const QString &old_password, QWidget *parent = nullptr);
~Dialog_PasswordChange();
QString getNewPassword();
private slots:
void on_cbtn_showPassword_toggled(bool checked);
void on_lineEdit_oldPassword_textChanged(const QString &arg1);
void on_lineEdit_newPassword_textChanged(const QString &arg1);
void on_lineEdit_confirmPassword_textChanged(const QString &arg1);
void on_btn_ok_clicked();
void on_btn_cancel_clicked();
void on_lineEdit_oldPassword_inputRejected();
void on_lineEdit_newPassword_inputRejected();
void on_lineEdit_confirmPassword_inputRejected();
private:
Ui::Dialog_PasswordChange *ui;
QString m_old_password,m_new_password;
QList<QLineEdit*> m_lineEditList;
QRegExpValidator *qReg;
};
#endif // DIALOG_PASSWORDCHANGE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_PasswordChange</class>
<widget class="QDialog" name="Dialog_PasswordChange">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>190</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>440</width>
<height>190</height>
</size>
</property>
<property name="windowTitle">
<string>Change password</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lab_oldPassword">
<property name="minimumSize">
<size>
<width>130</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Old password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_oldPassword"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="lab_newPassword">
<property name="minimumSize">
<size>
<width>130</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>New password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_newPassword"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="lab_confirmPassword">
<property name="minimumSize">
<size>
<width>130</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Confirm new password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_confirmPassword"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbtn_showPassword">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Password only allowed to use numbers, English and special characters.
Password length should between 8-20 charactors.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_ok">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -6,6 +6,7 @@
#include <QDateTime>
#include <QLineEdit>
#include <QRegExpValidator>
#include <QStandardPaths>
#include "widget_statusbar.h"
#include "dialog_openimageindex.h"
#include "dialog_saveas.h"
......@@ -17,14 +18,19 @@
#include "dialog_multirotate.h"
#include "dialog_multirotateimagefile.h"
#include "dialog_imgproc_autocrop.h"
#include "dialog_admin.h"
#include "dialog_passwordchange.h"
#include "imgfmt/HGPdf.h"
#include "imgfmt/HGImgFmt.h"
#include "imgproc/HGImgProc.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_password("123456")
, m_admin_loggedIn(false)
, m_currFilePath("")
, m_currIndex(-1)
, m_multiPageCount(0)
......@@ -170,7 +176,16 @@ MainWindow::MainWindow(QWidget *parent)
m_thumbMenu->addSeparator();
m_thumbMenu->addAction(act_thumbGrid);
menu_imageInsert->addAction(ui->act_insert);
menu_imageInsert->addAction(ui->act_acquireInto);
menu_imageInsert->addAction(ui->actionact_acquireInsert);
#ifdef HG_CMP_MSC
ui->menu_device->setEnabled(false);
m_twainDSM = nullptr;
HGTwain_LoadDSM(&m_twainDSM);
HGTwain_OpenDSM(m_twainDSM);
m_twainDS = nullptr;
HGTwain_GetDefaultDS(m_twainDSM, &m_twainDS);
#endif
m_dlgFullScreen = nullptr;
updateActionStatus();
......@@ -184,6 +199,12 @@ MainWindow::~MainWindow()
m_dlgFullScreen = nullptr;
}
#ifdef HG_CMP_MSC
HGTwain_CloseDSM(m_twainDSM);
HGTwain_UnloadDSM(m_twainDSM);
m_twainDSM = nullptr;
#endif
delete ui;
}
......@@ -559,6 +580,18 @@ void MainWindow::on_act_last_triggered()
}
}
QString MainWindow::getCacheFileName()
{
QString filePath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
filePath += "/Huago/ScannerApp/Cache";
HGBase_CreateDir(getStdString(getStdFileName(filePath)).c_str());
char uuid[256] = {0};
HGBase_GetUuid(uuid, 256);
QString fileName = getStdFileName(filePath + "/" + uuid + ".bmp");
return fileName;
}
HGImage MainWindow::createImage()
{
qDebug("createImage");
......@@ -686,6 +719,13 @@ void MainWindow::updateActionStatus()
ui->act_multiRotate->setEnabled(0 != count);
ui->menu_Rotate->setEnabled(0 != count || nullptr != img);
ui->act_autoCrop->setEnabled(nullptr != img);
ui->act_signIn->setEnabled(!m_admin_loggedIn);
ui->act_passwordChange->setEnabled(m_admin_loggedIn);
ui->act_signOut->setEnabled(m_admin_loggedIn);
ui->act_log->setEnabled(m_admin_loggedIn);
ui->act_clrCache->setEnabled(m_admin_loggedIn);
ui->act_consume->setEnabled(m_admin_loggedIn);
}
void MainWindow::on_act_openPageNum_triggered()
......@@ -1163,6 +1203,47 @@ void MainWindow::closeEvent(QCloseEvent *e)
on_act_closeAll_triggered();
}
#ifdef HG_CMP_MSC
void HGAPI MainWindow::DSEventCallback(HGTwainDS ds, HGUInt event, HGPointer param)
{
(void)ds;
MainWindow *p = (MainWindow *)param;
if (event == HGTWAIN_DSEVENT_XFERREADY)
{
while (1)
{
HGImage img = nullptr;
HGTwain_ImageNativeXfer(p->m_twainDS, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (nullptr != img)
{
QString fileName = p->getCacheFileName();
HGImgFmt_SaveImage(img, 0, nullptr, 0, getStdString(fileName).c_str());
p->m_thumb->addItem(fileName);
HGBase_DestroyImage(img);
}
HGUInt count = 0;
HGTwain_EndXfer(p->m_twainDS, &count);
if (0 == count)
{
break;
}
}
HGTwain_Reset(p->m_twainDS);
HGTwain_CloseDS(p->m_twainDS);
}
else if (event == HGTWAIN_DSEVENT_CLOSEDSREQ)
{
HGTwain_CloseDS(p->m_twainDS);
}
else if (event == HGTWAIN_DSEVENT_CLOSEDSOK)
{
HGTwain_CloseDS(p->m_twainDS);
}
}
#endif
void MainWindow::on_act_multiRotate_triggered()
{
int count = 0;
......@@ -1300,3 +1381,105 @@ void MainWindow::on_act_autoCrop_triggered()
}
}
}
void MainWindow::on_act_signIn_triggered()
{
if (m_admin_loggedIn)
{
return;
}
Dialog_Admin dlg(m_password, this);
m_admin_loggedIn = dlg.exec();
updateActionStatus();
}
void MainWindow::on_act_passwordChange_triggered()
{
if (!m_admin_loggedIn)
{
return;
}
Dialog_PasswordChange dlg(m_password, this);
if (dlg.exec())
{
m_password = dlg.getNewPassword();
}
}
void MainWindow::on_act_signOut_triggered()
{
if (!m_admin_loggedIn)
{
return;
}
int ret = QMessageBox::question(this, tr("Question"),
tr("Sure to sign out administrator account?"));
if (ret == QMessageBox::Yes)
{
m_admin_loggedIn = false;
updateActionStatus();
}
}
void MainWindow::on_act_log_triggered()
{
if (!m_admin_loggedIn)
{
return;
}
}
void MainWindow::on_act_clrCache_triggered()
{
if (!m_admin_loggedIn)
{
return;
}
}
void MainWindow::on_act_consume_triggered()
{
if (!m_admin_loggedIn)
{
return;
}
}
void MainWindow::on_act_help_triggered()
{
}
void MainWindow::on_act_about_triggered()
{
}
void MainWindow::on_act_scannerSettings_triggered()
{
#ifdef HG_CMP_MSC
if (HGBASE_ERR_OK == HGTwain_OpenDS(m_twainDS))
{
if (HGBASE_ERR_OK != HGTwain_EnableDSUIOnly(m_twainDS, HGTRUE, nullptr/*(HWND)this->winId()*/, DSEventCallback, this))
{
HGTwain_CloseDS(m_twainDS);
}
}
#endif
}
void MainWindow::on_act_acquire_triggered()
{
#ifdef HG_CMP_MSC
if (HGBASE_ERR_OK == HGTwain_OpenDS(m_twainDS))
{
if (HGBASE_ERR_OK != HGTwain_EnableDS(m_twainDS, HGFALSE, nullptr, DSEventCallback, this))
{
HGTwain_CloseDS(m_twainDS);
}
}
#endif
}
......@@ -5,6 +5,9 @@
#include <QLineEdit>
#include "HGImgView.h"
#include "HGImgThumb.h"
#ifdef HG_CMP_MSC
#include "twain_user/HGTwain.h"
#endif
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
......@@ -127,10 +130,35 @@ private slots:
void on_act_autoCrop_triggered();
void on_act_signIn_triggered();
void on_act_passwordChange_triggered();
void on_act_signOut_triggered();
void on_act_log_triggered();
void on_act_clrCache_triggered();
void on_act_consume_triggered();
void on_act_help_triggered();
void on_act_about_triggered();
void on_act_scannerSettings_triggered();
void on_act_acquire_triggered();
protected:
virtual void closeEvent(QCloseEvent *e);
private:
#ifdef HG_CMP_MSC
static void HGAPI DSEventCallback(HGTwainDS ds, HGUInt event, HGPointer param);
#endif
QString getCacheFileName();
HGImage createImage();
int getMultiPageCount();
void updateStatusBarPixelInfo();
......@@ -138,9 +166,15 @@ private:
private:
Ui::MainWindow *ui;
QString m_password;
bool m_admin_loggedIn;
HGImgView *m_view;
HGImgThumb *m_thumb;
QMenu *m_thumbMenu;
#ifdef HG_CMP_MSC
HGTwainDSM m_twainDSM;
HGTwainDS m_twainDS;
#endif
QString m_currFilePath;
int m_currIndex;
......
......@@ -65,6 +65,8 @@
<addaction name="act_acquire"/>
<addaction name="act_acquireSingle"/>
<addaction name="act_acquireInto"/>
<addaction name="separator"/>
<addaction name="actionact_acquireInsert"/>
</widget>
<widget class="QMenu" name="menu_view">
<property name="title">
......@@ -535,6 +537,11 @@
<string>act_about</string>
</property>
</action>
<action name="actionact_acquireInsert">
<property name="text">
<string>act_acquireInsert</string>
</property>
</action>
</widget>
<resources>
<include location="Scanner_resource.qrc"/>
......
......@@ -526,8 +526,6 @@ HGResult HGAPI HGBase_CreateImageFromDIB(HGLOBAL hMem, const HGImageRoi* roi,
DWORD bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
if (infoHeader->biBitCount <= 8)
bfOffBits += ((HGUInt)(1 << infoHeader->biBitCount) * sizeof(RGBQUAD));
else
bfOffBits += sizeof(RGBQUAD);
BITMAPFILEHEADER fileHeader = { 0 };
fileHeader.bfType = 0x4D42;
......
......@@ -14,6 +14,7 @@ HGTwain_OpenDS
HGTwain_CloseDS
HGTwain_SetCapability
HGTwain_GetCapability
HGTwain_EnableDSUIOnly
HGTwain_EnableDS
HGTwain_DisableDS
HGTwain_ImageNativeXfer
......
......@@ -198,7 +198,7 @@ void CHGTestDlg::OnBnClickedButton1()
}
HGTwain_OpenDS(m_ds);
HGTwain_EnableDS(m_ds, HGTRUE, m_hWnd, DSEventCallback, this);
HGTwain_EnableDS(m_ds, HGTRUE, NULL, DSEventCallback, this);
}
......@@ -245,4 +245,9 @@ void HGAPI CHGTestDlg::DSEventCallback(HGTwainDS ds, HGUInt event, HGPointer par
HGTwain_UnloadDSM(p->m_dsm);
p->m_dsm = NULL;
}
else if (HGTWAIN_DSEVENT_CLOSEDSOK == event)
{
HGTwain_UnloadDSM(p->m_dsm);
p->m_dsm = NULL;
}
}
......@@ -11,10 +11,9 @@ HG_DECLARE_HANDLE(HGTwainDS);
/* 未知事件, 可能是该库未进行处理的事件 */
#define HGTWAIN_DSEVENT_UNKNOWN 0L
/* 图像准备好了 */
#define HGTWAIN_DSEVENT_XFERREADY 1L
/* 用户点击了窗口上的关闭按钮 */
#define HGTWAIN_DSEVENT_CLOSEDSREQ 2L
#define HGTWAIN_DSEVENT_CLOSEDSOK 3L
/* twain事件回调
* 参数:
......@@ -136,6 +135,19 @@ HGEXPORT HGResult HGAPI HGTwain_SetCapability(HGTwainDS ds, HGUInt cap, HGInt va
*/
HGEXPORT HGResult HGAPI HGTwain_GetCapability(HGTwainDS ds, HGUInt cap, HGUInt* value);
/* 启动DS, 仅仅用作参数设置
* 参数:
* 1) ds: in, DS句柄
* 2) showUI: in, 是否显示UI
* 3) parent: in, 父窗口句柄
* 4) func: in, 回调函数
* 5) param: in, 回调参数
* 说明:
* 1) 执行此函数后,TWAIN状态从4变为5
*/
HGEXPORT HGResult HGAPI HGTwain_EnableDSUIOnly(HGTwainDS ds, HGBool showUI, HWND parent,
HGTwain_DSEventCallback func, HGPointer param);
/* 启动DS
* 参数:
* 1) ds: in, DS句柄
......
......@@ -148,6 +148,18 @@ HGResult HGAPI HGTwain_GetCapability(HGTwainDS ds, HGUInt cap, HGUInt* value)
return twainDSImpl->dsmImpl->GetCapability(twainDSImpl, cap, value);
}
HGResult HGAPI HGTwain_EnableDSUIOnly(HGTwainDS ds, HGBool showUI, HWND parent,
HGTwain_DSEventCallback func, HGPointer param)
{
if (NULL == ds)
{
return HGBASE_ERR_INVALIDARG;
}
HGTwainDSImpl* twainDSImpl = (HGTwainDSImpl*)ds;
return twainDSImpl->dsmImpl->EnableDSUIOnly(twainDSImpl, showUI, parent, func, param);
}
HGResult HGAPI HGTwain_EnableDS(HGTwainDS ds, HGBool showUI, HWND parent,
HGTwain_DSEventCallback func, HGPointer param)
{
......
......@@ -11,10 +11,9 @@ HG_DECLARE_HANDLE(HGTwainDS);
/* 未知事件, 可能是该库未进行处理的事件 */
#define HGTWAIN_DSEVENT_UNKNOWN 0L
/* 图像准备好了 */
#define HGTWAIN_DSEVENT_XFERREADY 1L
/* 用户点击了窗口上的关闭按钮 */
#define HGTWAIN_DSEVENT_CLOSEDSREQ 2L
#define HGTWAIN_DSEVENT_CLOSEDSOK 3L
/* twain事件回调
* 参数:
......@@ -136,6 +135,19 @@ HGEXPORT HGResult HGAPI HGTwain_SetCapability(HGTwainDS ds, HGUInt cap, HGInt va
*/
HGEXPORT HGResult HGAPI HGTwain_GetCapability(HGTwainDS ds, HGUInt cap, HGUInt* value);
/* 启动DS, 仅仅用作参数设置
* 参数:
* 1) ds: in, DS句柄
* 2) showUI: in, 是否显示UI
* 3) parent: in, 父窗口句柄
* 4) func: in, 回调函数
* 5) param: in, 回调参数
* 说明:
* 1) 执行此函数后,TWAIN状态从4变为5
*/
HGEXPORT HGResult HGAPI HGTwain_EnableDSUIOnly(HGTwainDS ds, HGBool showUI, HWND parent,
HGTwain_DSEventCallback func, HGPointer param);
/* 启动DS
* 参数:
* 1) ds: in, DS句柄
......
......@@ -376,6 +376,42 @@ HGResult HGTwainDSMImpl::GetCapability(HGTwainDSImpl* ds, HGUInt cap, HGUInt* va
return HGBASE_ERR_FAIL;
}
HGResult HGTwainDSMImpl::EnableDSUIOnly(HGTwainDSImpl* ds, HGBool showUI, HWND parent, HGTwain_DSEventCallback func, HGPointer param)
{
if (NULL == ds)
{
return HGBASE_ERR_INVALIDARG;
}
for (int i = 0; i < (int)m_DSList.size(); ++i)
{
if (ds == &m_DSList[i])
{
if (!m_DSList[i].open || m_DSList[i].enable)
{
return HGBASE_ERR_FAIL;
}
TW_USERINTERFACE twUI;
twUI.ShowUI = (TW_BOOL)showUI;
twUI.hParent = (TW_HANDLE)parent;
USHORT ret = m_pDSMProc(&m_AppId, &m_DSList[i].ds, DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDSUIONLY, (TW_MEMREF)&twUI);
if (TWRC_SUCCESS != ret)
{
return HGBASE_ERR_FAIL;
}
m_DSList[i].showUI = showUI;
m_DSList[i].parent = parent;
m_DSList[i].func = func;
m_DSList[i].param = param;
m_DSList[i].enable = HGTRUE;
return HGBASE_ERR_OK;
}
}
return HGBASE_ERR_FAIL;
}
HGResult HGTwainDSMImpl::EnableDS(HGTwainDSImpl* ds, HGBool showUI, HWND parent, HGTwain_DSEventCallback func, HGPointer param)
{
......@@ -589,6 +625,8 @@ LRESULT CALLBACK HGTwainDSMImpl::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPA
event = HGTWAIN_DSEVENT_XFERREADY;
else if (MSG_CLOSEDSREQ == twEvent.TWMessage)
event = HGTWAIN_DSEVENT_CLOSEDSREQ;
else if (MSG_CLOSEDSOK == twEvent.TWMessage)
event = HGTWAIN_DSEVENT_CLOSEDSOK;
p->m_DSList[i].func((HGTwainDS)&p->m_DSList[i], event, p->m_DSList[i].param);
}
}
......
......@@ -50,6 +50,7 @@ public:
HGResult SetCapability(HGTwainDSImpl* ds, HGUInt cap, HGInt value);
HGResult GetCapability(HGTwainDSImpl* ds, HGUInt cap, HGUInt* value);
HGResult EnableDSUIOnly(HGTwainDSImpl* ds, HGBool showUI, HWND parent, HGTwain_DSEventCallback func, HGPointer param);
HGResult EnableDS(HGTwainDSImpl* ds, HGBool showUI, HWND parent, HGTwain_DSEventCallback func, HGPointer param);
HGResult DisableDS(HGTwainDSImpl* ds);
HGResult ImageNativeXfer(HGTwainDSImpl* ds, HGUInt type, HGUInt origin, HGImage* image);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment