From bc80b1ea74f557d92932d83d325bb6fd3f5270c8 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Wed, 29 Nov 2023 14:39:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=89=E6=96=B9=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=97=B6=E4=B8=8D=E5=85=B3=E9=97=AD=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=EF=BC=8C=E7=A6=81=E7=94=A8=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/twainui/Manager.cpp | 32 +++++++++++++---- modules/twainui/Manager.h | 5 +-- modules/twainui/hg_settingdialog.cpp | 54 +++++++++++++++++++++++++++- modules/twainui/hg_settingdialog.h | 12 ++++++- modules/twainui/twainui.cpp | 4 +-- modules/twainui/twainui.h | 2 +- 6 files changed, 95 insertions(+), 14 deletions(-) diff --git a/modules/twainui/Manager.cpp b/modules/twainui/Manager.cpp index c0b1d6f2..76c6b78e 100644 --- a/modules/twainui/Manager.cpp +++ b/modules/twainui/Manager.cpp @@ -15,7 +15,8 @@ extern Manager* g_manager; Manager::Manager() : QObject(nullptr) , m_progressUiCallback(std::function()) - , m_notify(nullptr) + , m_progNotify(nullptr) + , m_settingNotify(nullptr) , m_settingUiCallback(std::function()) , m_settingUi(nullptr) , m_progressUi(nullptr) @@ -72,7 +73,7 @@ int Manager::showDeviceSelect(const std::vector& devs) return m_DeviceSelectResult; } -int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function callback) +int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function callback, std::function* notify) { // param m_device = device; @@ -82,6 +83,7 @@ int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const m_devName = devName; m_with_scan = with_scan; m_settingUiCallback = callback; + m_settingNotify = notify; void *hStopEvent = nullptr; #ifdef HG_CMP_MSC @@ -93,6 +95,15 @@ int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const emit createSettingUi(hStopEvent); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showSettingUi] emit createSettingUi(ThreadId)"); + +#ifdef HG_CMP_MSC + if (nullptr != hStopEvent) + { + msgLoop(hStopEvent); + CloseHandle(hStopEvent); + } +#endif + return 0; } @@ -101,7 +112,7 @@ int Manager::showProgressUi(HWND parent, std::function callbac // param m_progressUiparent = (HGWindow)parent; m_progressUiCallback = callback; - m_notify = notify; + m_progNotify = notify; void *hStopEvent = nullptr; #ifdef HG_CMP_MSC @@ -324,7 +335,8 @@ void Manager::clear_functions(void) { m_settingUiCallback = std::function(); m_progressUiCallback = std::function(); - m_notify = nullptr; + m_progNotify = nullptr; + m_settingNotify = nullptr; if (m_progressUi) m_progressUi->clear_callback(); if (m_settingUi) @@ -418,11 +430,17 @@ void Manager::on_createSettingUi(void *hEvent) if (m_settingUi != nullptr) delete m_settingUi; - m_settingUi = new hg_settingdialog(this, m_device, &m_api, m_with_scan, m_devName.c_str(), scanner_cfg_, close_prog, qParent); + m_settingUi = new hg_settingdialog(this, m_device, &m_api, m_with_scan, m_devName.c_str(), scanner_cfg_, close_prog, m_settingNotify, qParent); m_settingUi->setModal(true); m_settingUi->show(); - HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createSettingUi] m_settingUi->show()"); + +#ifdef HG_CMP_MSC + if (nullptr != hEvent) + { + SetEvent((HANDLE)hEvent); + } +#endif } void Manager::on_createProgressUi(void *hEvent) @@ -453,7 +471,7 @@ void Manager::on_createProgressUi(void *hEvent) }; if (m_progressUi != nullptr) delete m_progressUi; - m_progressUi = new Dialog_progress_ui(this, close_prog, m_notify, qParent); + m_progressUi = new Dialog_progress_ui(this, close_prog, m_progNotify, qParent); m_progressUi->setModal(true); m_progressUi->show(); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createProgressUi] m_progressUi->show()"); diff --git a/modules/twainui/Manager.h b/modules/twainui/Manager.h index 37abd2c0..9038a494 100644 --- a/modules/twainui/Manager.h +++ b/modules/twainui/Manager.h @@ -18,7 +18,7 @@ public: ~Manager(); int showDeviceSelect(const std::vector& devs); - int showSettingUi(SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function callback); + int showSettingUi(SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function callback, std::function* notify); int showProgressUi(HWND parent, std::function callback, std::function *notify); int showMessageBoxUi(HWND parent, int event, void *msg, int flag); int showTwainSrcUi(const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds); @@ -79,11 +79,12 @@ public: bool m_with_scan; gb::scanner_cfg* scanner_cfg_; std::function m_settingUiCallback; + std::function* m_settingNotify; Dialog_progress_ui *m_progressUi; HGWindow m_progressUiparent; std::function m_progressUiCallback; - std::function *m_notify; + std::function * m_progNotify; HGWindow m_messageBoxUiParent; int m_notifyEvent; diff --git a/modules/twainui/hg_settingdialog.cpp b/modules/twainui/hg_settingdialog.cpp index 9bbe7fa7..1fc6c788 100644 --- a/modules/twainui/hg_settingdialog.cpp +++ b/modules/twainui/hg_settingdialog.cpp @@ -21,8 +21,10 @@ std::string hg_settingdialog::property_combox_data_type_ = "combox_value_type"; static int m_customCutAreaUnit = 0; +extern Manager* g_manager; + hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const SANEAPI* saneApi, bool showScan, const char* devName, gb::scanner_cfg* cfg, - std::function callback, QWidget *parent) + std::function callback, std::function* notify, QWidget *parent) : QDialog(parent) , save_(false) , btn_cut_area_(nullptr), btn_gamma_(nullptr), clicked_gamma_(false) @@ -35,6 +37,7 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const , changed_count_(0) , cur_cfg_(cfg) , m_isMultiOutMode(false) + , m_isScanning(false) { m_mgr = mgr; @@ -80,6 +83,10 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const m_originGammaData = m_gammaData; connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed())); + connect(this, SIGNAL(scan_start()),this, SLOT(on_scan_start()), Qt::QueuedConnection); + connect(this, SIGNAL(scan_finish()), this, SLOT(on_scan_finish()), Qt::QueuedConnection); + + *notify = FuncNotify; } hg_settingdialog::~hg_settingdialog() @@ -172,6 +179,30 @@ void hg_settingdialog::apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_con } } +void hg_settingdialog::FuncNotify(int event, void* msg, int flag) +{ + hg_settingdialog* p = (hg_settingdialog*)g_manager->m_settingUi; + if (nullptr == p) + { + return; + } + + switch (event) + { + case SANE_EVENT_WORKING: + { + emit p->scan_start(); + } + break; + + case SANE_EVENT_SCAN_FINISHED: + { + emit p->scan_finish(); + } + break; + } +} + void hg_settingdialog::initUi() { update_opt_value_from_driver(); @@ -1169,6 +1200,20 @@ void hg_settingdialog::updateUIStatus() } } +void hg_settingdialog::on_scan_start() +{ + m_isScanning = true; + this->setEnabled(false); + setAttribute(Qt::WA_DeleteOnClose, false); +} + +void hg_settingdialog::on_scan_finish() +{ + m_isScanning = false; + this->setEnabled(true); + setAttribute(Qt::WA_DeleteOnClose, true); +} + void hg_settingdialog::slot_checkedClicked() { QCheckBox *checkBox = qobject_cast(sender()); @@ -2053,6 +2098,13 @@ void hg_settingdialog::closeEvent(QCloseEvent* e) // 3、点击确定按钮后,如果当前方案非用户模板,则保存进默认配置;如果为用户模板,则更新当前方案索引 // 4、点出取消按钮,恢复驱动值至该对话框初始化状态,不对配置作变更 // + + if (m_isScanning) + { + e->ignore(); + return; + } + int index = comb_->currentIndex(); if (m_closeButton == closeButtonOk) { diff --git a/modules/twainui/hg_settingdialog.h b/modules/twainui/hg_settingdialog.h index 8032b654..507f84c2 100644 --- a/modules/twainui/hg_settingdialog.h +++ b/modules/twainui/hg_settingdialog.h @@ -51,10 +51,11 @@ class hg_settingdialog : public QDialog public: explicit hg_settingdialog(class Manager *mgr, SANE_Handle handle, const SANEAPI* saneApi, bool showScan, const char* devName, gb::scanner_cfg* cfg, - std::function callback, QWidget *parent = nullptr); + std::function callback, std::function* notify, QWidget *parent = nullptr); ~hg_settingdialog(); static void apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_config_schm* schm); + static void FuncNotify(int event, void* msg, int flag); public: void initUi(); @@ -135,6 +136,14 @@ private: QVector m_list_deviceNames; QVector m_list_widgets; +signals: + void scan_start(); + void scan_finish(); + +private slots: + void on_scan_start(); + void on_scan_finish(); + private slots: void slot_checkedClicked(); void slot_sliderClicked(int value); @@ -179,6 +188,7 @@ private: bool m_isRefreshUi; bool m_isMultiOutMode; + bool m_isScanning; }; #endif // HG_SETTING_DIALOG_H diff --git a/modules/twainui/twainui.cpp b/modules/twainui/twainui.cpp index 8803e5f4..cfa9a5b8 100644 --- a/modules/twainui/twainui.cpp +++ b/modules/twainui/twainui.cpp @@ -193,11 +193,11 @@ void twain_ui_free(void *buf) } } -int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function callback) +int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function callback, std::function *notify) { Init(); - return g_manager->showSettingUi(device, parent, api, devName, scanner_cfg_, with_scan, callback); + return g_manager->showSettingUi(device, parent, api, devName, scanner_cfg_, with_scan, callback, notify); } int show_progress_ui(HWND parent, std::function callback, std::function *notify) diff --git a/modules/twainui/twainui.h b/modules/twainui/twainui.h index 15f32325..472b1183 100644 --- a/modules/twainui/twainui.h +++ b/modules/twainui/twainui.h @@ -77,7 +77,7 @@ enum ui_result // // 返回: ui_result 类型, UI_RESULT_FAILED or UI_RESULT_OK //int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan/*是否显示“扫描”按钮*/); -HGEXPORT int show_setting_ui(SANE_Handle device,HWND parent, LPSANEAPI api, const char *devName, bool with_scan/*是否显示“扫描”按钮*/,std::function callback); +HGEXPORT int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devName, bool with_scan, std::function callback, std::function* notify); // 功能: 显示扫描进度界面,非模态 //