From 2bf3448df0a3aefb9b444f639411d73213d16483 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Sun, 7 Apr 2024 18:11:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0HGLibTest=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E4=B8=BB=E8=A6=81=E5=8A=9F=E8=83=BD=E4=B8=BA=E5=9F=BA?= =?UTF-8?q?=E4=BA=8Esane=E7=9A=84=E7=83=AD=E6=8B=94=E6=8F=92=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=B5=8B=E8=AF=95SDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libtest/main.cpp | 12 +++ app/libtest/mainwindow.cpp | 131 ++++++++++++++++++++++++++++++ app/libtest/mainwindow.h | 45 ++++++++++ app/libtest/mainwindow.ui | 96 ++++++++++++++++++++++ build2/qt/HGLibTest/HGLibTest.pro | 104 ++++++++++++++++++++++++ build2/qt/HGSolutionWin.pro | 1 + 6 files changed, 389 insertions(+) create mode 100644 app/libtest/main.cpp create mode 100644 app/libtest/mainwindow.cpp create mode 100644 app/libtest/mainwindow.h create mode 100644 app/libtest/mainwindow.ui create mode 100644 build2/qt/HGLibTest/HGLibTest.pro diff --git a/app/libtest/main.cpp b/app/libtest/main.cpp new file mode 100644 index 00000000..690159af --- /dev/null +++ b/app/libtest/main.cpp @@ -0,0 +1,12 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/app/libtest/mainwindow.cpp b/app/libtest/mainwindow.cpp new file mode 100644 index 00000000..abd91ee2 --- /dev/null +++ b/app/libtest/mainwindow.cpp @@ -0,0 +1,131 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) + , m_device(nullptr) +{ + ui->setupUi(this); + ui->label_devInfo->clear(); + ui->pushButton_scan->setEnabled(false); + + connect(this, SIGNAL(sane_dev_arrive(QString)), this, SLOT(on_sane_dev_arrive(QString)), Qt::QueuedConnection); + connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection); + + HGLib_InitDevice(DeviceHotPlugEventFunc, this); +} + +MainWindow::~MainWindow() +{ + HGLib_DeinitDevice(); + delete ui; +} + +void MainWindow::DeviceHotPlugEventFunc(HGUInt event, const HGChar *deviceName, HGPointer param) +{ + MainWindow* p = (MainWindow*)param; + + if (HGLIB_DEVHOTPLUG_EVENT_ARRIVE == event) + { + emit p->sane_dev_arrive(deviceName); + } + else if (HGLIB_DEVHOTPLUG_EVENT_REMOVE == event) + { + emit p->sane_dev_remove(deviceName); + } +} + +void MainWindow::DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGInt operateCode, const HGChar *info, HGPointer param) +{ + MainWindow *p = (MainWindow*)param; + p->addContent(info); +} + +void MainWindow::DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param) +{ + +} + +void MainWindow::on_sane_dev_arrive(QString devName) +{ + int idx = -1; + int count = ui->comboDevList->count(); + for (int i = 0; i < count; ++i) + { + QString name = ui->comboDevList->itemText(i); + if (name == devName) + { + idx = i; + break; + } + } + + if (-1 == idx) + { + ui->comboDevList->addItem(devName); + } +} +void MainWindow::on_sane_dev_remove(QString devName) +{ + int idx = -1; + int count = ui->comboDevList->count(); + for (int i = 0; i < count; ++i) + { + QString name = ui->comboDevList->itemText(i); + if (name == devName) + { + idx = i; + break; + } + } + + if (-1 != idx) + { + QString info = tr("The device %1 is disconnected.").arg(devName); + ui->label_devInfo->setText(info); + addContent(info); + ui->comboDevList->removeItem(idx); + } +} + +void MainWindow::on_comboDevList_currentIndexChanged(int index) +{ + if (-1 != index) + { + if (m_device != nullptr) + { + HGLib_CloseDevice(m_device); + ui->label_devInfo->clear(); + ui->pushButton_scan->setEnabled(false); + } + + QString name = ui->comboDevList->itemText(index); + m_device = HGLib_OpenDevice(name.toStdString().c_str()); + if (m_device != nullptr) + { + QString info = tr("The device %1 is open.").arg(name); + ui->label_devInfo->setText(info); + addContent(info); + ui->pushButton_scan->setEnabled(true); + } + else + { + QString info = tr("The device %1 open failed.").arg(name); + addContent(info); + } + } +} + +void MainWindow::on_pushButton_scan_clicked() +{ + HGLib_StartDeviceScan(m_device, DeviceScanEventFunc, this, DeviceScanImageFunc, this); +} + +void MainWindow::addContent(QString content) +{ + ui->textBrowser->insertPlainText(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm] ") + content + "\n"); + ui->textBrowser->moveCursor(QTextCursor::End); + ui->textBrowser->setTextColor(Qt::black); +} diff --git a/app/libtest/mainwindow.h b/app/libtest/mainwindow.h new file mode 100644 index 00000000..9a00b17b --- /dev/null +++ b/app/libtest/mainwindow.h @@ -0,0 +1,45 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "HGScannerLib.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + + static void HGAPI DeviceHotPlugEventFunc(HGUInt event, const HGChar *deviceName, HGPointer param); + static void HGAPI DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGInt operateCode, const HGChar *info, HGPointer param); + static void HGAPI DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param); + +signals: + void sane_dev_arrive(QString devName); + void sane_dev_remove(QString devName); + +private slots: + void on_sane_dev_arrive(QString devName); + void on_sane_dev_remove(QString devName); + +private slots: + void on_comboDevList_currentIndexChanged(int index); + + void on_pushButton_scan_clicked(); + + +private: + void addContent(QString content); + +private: + Ui::MainWindow *ui; + + HGLibDevice m_device; +}; +#endif // MAINWINDOW_H diff --git a/app/libtest/mainwindow.ui b/app/libtest/mainwindow.ui new file mode 100644 index 00000000..7f367eeb --- /dev/null +++ b/app/libtest/mainwindow.ui @@ -0,0 +1,96 @@ + + + MainWindow + + + + 0 + 0 + 706 + 506 + + + + MainWindow + + + + + + 150 + 40 + 221 + 22 + + + + + + + 60 + 40 + 81 + 16 + + + + Device List: + + + + + + 60 + 100 + 321 + 16 + + + + TextLabel + + + + + + 150 + 240 + 111 + 51 + + + + Scan + + + + + + 390 + 40 + 256 + 371 + + + + + + + + 0 + 0 + 706 + 22 + + + + + + + act_selectDevice + + + + + + diff --git a/build2/qt/HGLibTest/HGLibTest.pro b/build2/qt/HGLibTest/HGLibTest.pro new file mode 100644 index 00000000..3174c2e8 --- /dev/null +++ b/build2/qt/HGLibTest/HGLibTest.pro @@ -0,0 +1,104 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TEMPLATE = app +DEFINES += UNTITLED_LIBRARY + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS +DEFINES += QT_NO_VERSION_TAGGING + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +include($$PWD/../HGOEM.pri) + +CONFIG(debug, debug|release) { + MY_CONFIGURE = Debug +} +CONFIG(release, debug|release) { + MY_CONFIGURE = Release +} + +win32 { + + MY_OS = windows + TARGET = $${OEM_PREFIX}LibTestApp + + contains(QT_ARCH, i386) { + MY_ARCH = x86 + } + contains(QT_ARCH, x86_64) { + MY_ARCH = x64 + } + + CONFIG(release, debug|release) { + QMAKE_LFLAGS_RELEASE += /MAP + QMAKE_CFLAGS_RELEASE += /Zi + QMAKE_LFLAGS_RELEASE += /debug /opt:ref + } + + LIBS += -lgdi32 -lgdiplus -ldbghelp -luser32 -ladvapi32 + LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}ScannerLib + + LIBS += -L$$PWD/../../../../release/win/$${MY_ARCH}/OEM/$${OEM_NAME} +} + +INCLUDEPATH += $$PWD/../../../sdk/scannerlib +INCLUDEPATH += $$PWD/../../../modules/base + +DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} +UI_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET} +MOC_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET} +OBJECTS_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET} +RCC_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET} + +message(MY_OS: $$MY_OS) +message(MY_ARCH: $$MY_ARCH) +message(OEM_PREFIX: $$OEM_PREFIX) +message(OEM_PREFIX2: $$OEM_PREFIX2) +message(OEM_NAME: $$OEM_NAME) +message(MY_CONFIGURE: $$MY_CONFIGURE) +message(TARGET: $$TARGET) +message(DESTDIR: $$DESTDIR) +message(UI_DIR: $$UI_DIR) +message(MOC_DIR: $$MOC_DIR) +message(OBJECTS_DIR: $$OBJECTS_DIR) +message(RCC_DIR: $$RCC_DIR) + +win32 { + + CONFIG(release, debug|release) { + DESTEXE_PATH = $${PWD}/../../../../release/win/$${MY_ARCH}/$${MY_CONFIGURE}/ + DESTEXE_PATH = $$replace(DESTEXE_PATH, /, \\) + message(DESTEXE_PATH: $$DESTEXE_PATH) + + SRCEXE_FILE = $${DESTDIR}/$${TARGET}.exe + SRCEXE_FILE = $$replace(SRCEXE_FILE, /, \\) + message(SRCEXE_FILE: $$SRCEXE_FILE) + SRCPDB_FILE = $${DESTDIR}/$${TARGET}.pdb + SRCPDB_FILE = $$replace(SRCPDB_FILE, /, \\) + message(SRCPDB_FILE: $$SRCPDB_FILE) + + QMAKE_POST_LINK += xcopy /y $$SRCEXE_FILE $$DESTEXE_PATH && xcopy /y $$SRCPDB_FILE $$DESTEXE_PATH + } +} + +SOURCES += \ + ../../../app/libtest/main.cpp \ + ../../../app/libtest/mainwindow.cpp \ + + +HEADERS += \ + ../../../app/libtest/mainwindow.h \ + +FORMS += \ + ../../../app/libtest/mainwindow.ui diff --git a/build2/qt/HGSolutionWin.pro b/build2/qt/HGSolutionWin.pro index 766dd0d7..cda6476a 100644 --- a/build2/qt/HGSolutionWin.pro +++ b/build2/qt/HGSolutionWin.pro @@ -7,6 +7,7 @@ SUBDIRS += \ HGTwainUI \ HGTwainUser \ HGTwainTest \ + HGLibTest \ HGVersion \ HGScannerLib \ HGWebService \