调整进度指示器关闭窗口线程调用方式
This commit is contained in:
parent
7cdbfa9bd2
commit
c7e07e45a3
|
@ -1752,7 +1752,7 @@ void MainWindow::updateActionStatus()
|
|||
ui->act_insertFromScanner->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
||||
ui->menu_scan->setEnabled(!m_isScanning);
|
||||
ui->act_device_log->setEnabled(m_admin_loggedIn && !m_isScanning && (m_devUser != nullptr));
|
||||
ui->act_driver_log->setEnabled(m_admin_loggedIn);
|
||||
ui->act_driver_log->setEnabled(m_admin_loggedIn && (m_devUser != nullptr));
|
||||
// if(m_dialogLog != nullptr)
|
||||
// m_dialogLog->pbtn_export->setEnabled(ui->act_Export->isEnabled());
|
||||
|
||||
|
@ -4484,6 +4484,7 @@ void MainWindow::on_act_selectDevice_triggered()
|
|||
if (HGBASE_ERR_OK == devUser->Open())
|
||||
{
|
||||
m_devUser = devUser;
|
||||
m_devUser->Login();
|
||||
m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false);
|
||||
connect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)), Qt::DirectConnection);
|
||||
connect(m_devUser, SIGNAL(scanWorkingEvent()), this, SLOT(on_scanWorkingEvent()), Qt::QueuedConnection);
|
||||
|
|
|
@ -13,10 +13,9 @@ static int imageRecivedCount = 0;
|
|||
Dialog_progress_ui::Dialog_progress_ui(class Manager *mgr, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Dialog_progress_ui)
|
||||
, m_isScanning(false)
|
||||
, m_isScanning(false)
|
||||
, m_thread(nullptr)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint);
|
||||
|
@ -43,6 +42,8 @@ Dialog_progress_ui::Dialog_progress_ui(class Manager *mgr, std::function<void (u
|
|||
|
||||
Dialog_progress_ui::~Dialog_progress_ui()
|
||||
{
|
||||
HGBase_CloseThread(m_thread);
|
||||
m_thread = nullptr;
|
||||
m_mgr->m_progressUi = nullptr;
|
||||
|
||||
imageRecivedCount = 0;
|
||||
|
@ -58,6 +59,14 @@ void Dialog_progress_ui::keyPressEvent(QKeyEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
void Dialog_progress_ui::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
if (e->spontaneous())
|
||||
{
|
||||
e->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
|
||||
{
|
||||
if (!quit_)
|
||||
|
@ -66,23 +75,15 @@ void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
|
|||
ui->label->setText(tr("stop scanning"));
|
||||
}
|
||||
|
||||
void notify_close(std::function<void (ui_result)> callback)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
if (callback)
|
||||
callback(UI_RESULT_CLOSE_NORMAL);
|
||||
}
|
||||
|
||||
void Dialog_progress_ui::on_pbtn_close_clicked()
|
||||
{
|
||||
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(on_pbtn_close_clicked()));
|
||||
//CloseHandle(CreateThread(NULL, 0, notify_close, (void*)m_callback, 0, 0));
|
||||
|
||||
if (!quit_)
|
||||
{
|
||||
std::thread th_close(notify_close, m_callback);
|
||||
th_close.detach();
|
||||
HGBase_OpenThread(ThreadFunc, this, &m_thread);
|
||||
}
|
||||
// m_callback(UI_RESULT_CLOSE_NORMAL);
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
|
@ -117,6 +118,19 @@ void Dialog_progress_ui::on_image_recived()
|
|||
ui->lineEdit_imgRecived->setText(QString::number(++imageRecivedCount));
|
||||
}
|
||||
|
||||
void HGAPI Dialog_progress_ui::ThreadFunc(HGThread thread, HGPointer param)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
Sleep(500);
|
||||
#else
|
||||
usleep(500 * 1000);
|
||||
#endif
|
||||
|
||||
Dialog_progress_ui* p = (Dialog_progress_ui*)param;
|
||||
if (p->m_callback)
|
||||
p->m_callback(UI_RESULT_CLOSE_NORMAL);
|
||||
}
|
||||
|
||||
void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag)
|
||||
{
|
||||
Dialog_progress_ui *p = (Dialog_progress_ui *)g_manager->m_progressUi;
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include <qtranslator.h>
|
||||
#include <QCloseEvent>
|
||||
#include "twainui.h"
|
||||
#include "base/HGThread.h"
|
||||
|
||||
namespace Ui {
|
||||
class Dialog_progress_ui;
|
||||
|
@ -19,7 +21,8 @@ public:
|
|||
~Dialog_progress_ui();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
virtual void keyPressEvent(QKeyEvent *e) override;
|
||||
virtual void closeEvent(QCloseEvent *e) override;
|
||||
|
||||
signals:
|
||||
void scan_status(QString finishInfo, bool isScanning);
|
||||
|
@ -35,6 +38,7 @@ private slots:
|
|||
void on_image_recived();
|
||||
|
||||
public:
|
||||
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
|
||||
static void FuncNotify(int event, void *msg, int flag);
|
||||
void clear_callback(void)
|
||||
{
|
||||
|
@ -49,6 +53,7 @@ private:
|
|||
std::function<void (ui_result)> m_callback;
|
||||
QTimer *m_timer;
|
||||
bool m_isScanning;
|
||||
HGThread m_thread;
|
||||
};
|
||||
|
||||
#endif // DIALOG_PROGRESS_UI_H
|
||||
|
|
|
@ -38,43 +38,7 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const
|
|||
{
|
||||
m_mgr = mgr;
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
setIcon();
|
||||
//m_scheme = new gb::sane_config_schm();
|
||||
|
||||
//HGChar cfgpath[512] = {0};
|
||||
//GetConfigPath(cfgpath, 512);
|
||||
//
|
||||
//HGBase_CreateDir(cfgpath);
|
||||
//dev_que_.set_root_dir(cfgpath);
|
||||
//QString old = QString::fromStdString(cfgpath) + PATH_SYMBOL + "scanner.schm";
|
||||
//if(QFile::exists(old))
|
||||
// dev_que::update_old_cfg(old.toStdString().c_str());
|
||||
//
|
||||
//int pid = 0;
|
||||
//saneApi->sane_control_option_api(m_devHandle, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL);
|
||||
//
|
||||
//char buf[10] = { 0 };
|
||||
//sprintf(buf, "%x", pid);
|
||||
//std::string deviceName = m_devName;
|
||||
//if (pid != 0)
|
||||
//{
|
||||
// deviceName = deviceName.substr(0, deviceName.find(" ")) + " " + buf;
|
||||
//}
|
||||
//dev_que_.add_scanner(deviceName.c_str());
|
||||
//dev_que_.open_scanner(saneApi, handle, deviceName.c_str(), false);
|
||||
//
|
||||
//std::string n(dev_que_.opened_scanner_name());
|
||||
//for(int i = 0; i < dev_que_.scanners(); ++i)
|
||||
//{
|
||||
// SCANNER s = dev_que_.get_at(i);
|
||||
// if(s.name == n)
|
||||
// {
|
||||
// cur_cfg_ = s.cfg;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
cur_scheme_ = cur_cfg_->get_scheme();
|
||||
if (!cur_scheme_)
|
||||
|
|
Loading…
Reference in New Issue