code_app/modules/twainui/dialog_progress_ui.cpp

96 lines
2.6 KiB
C++
Raw Normal View History

2023-04-20 09:49:48 +00:00
#include "dialog_progress_ui.h"
#include "ui_dialog_progress_ui.h"
#include "lang/app_language.h"
2023-05-08 12:01:43 +00:00
#include "huagao/hgscanner_error.h"
#include <QCloseEvent>
2023-04-27 03:04:52 +00:00
#include <QTimer>
2023-04-20 09:49:48 +00:00
Dialog_progress_ui *Dialog_progress_ui::m_param = nullptr;
Dialog_progress_ui::Dialog_progress_ui(std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify, QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_progress_ui)
{
int cp = lang_get_cur_code_page();
if (20127 == cp)
m_translator.load(":translation/TwainUI_zh_EN.qm");
else
m_translator.load(":translation/TwainUI_zh_CN.qm");
QCoreApplication::installTranslator(&m_translator);
setAttribute(Qt::WA_DeleteOnClose, true);
2023-04-20 09:49:48 +00:00
ui->setupUi(this);
2023-04-27 09:42:50 +00:00
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
2023-04-20 09:49:48 +00:00
ui->pbtn_cancelScan->setVisible(false);
ui->pbtn_close->setVisible(false);
2023-04-20 09:49:48 +00:00
m_callback = callback;
*notify = FuncNotify;
m_param = this;
2023-04-27 03:04:52 +00:00
m_timer = new QTimer(this);
connect(this, SIGNAL(scan_status(QString,bool)), this, SLOT(on_scan_status(QString,bool)), Qt::QueuedConnection);
2023-05-08 14:27:56 +00:00
connect(this, SIGNAL(scan_finish(int)), this, SLOT(on_scan_finish(int)), Qt::QueuedConnection);
2023-04-20 09:49:48 +00:00
}
Dialog_progress_ui::~Dialog_progress_ui()
{
delete ui;
QCoreApplication::removeTranslator(&m_translator);
2023-04-20 09:49:48 +00:00
}
void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
{
m_callback(UI_RESULT_CLOSE_CANCEL);
}
void Dialog_progress_ui::on_pbtn_close_clicked()
{
2023-04-27 03:04:52 +00:00
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(on_pbtn_close_clicked()));
m_callback(UI_RESULT_CLOSE_NORMAL);
close();
}
2023-04-27 03:04:52 +00:00
void Dialog_progress_ui::on_scan_status(QString finishInfo, bool isScanning)
2023-04-20 09:49:48 +00:00
{
ui->label->setText(finishInfo);
2023-04-27 03:04:52 +00:00
ui->pbtn_cancelScan->setVisible(isScanning);
ui->pbtn_close->setVisible(!isScanning);
2023-04-20 09:49:48 +00:00
}
2023-05-08 12:01:43 +00:00
void Dialog_progress_ui::on_scan_finish(int flag)
{
2023-05-08 14:27:56 +00:00
if (SCANNER_ERR_OK == flag || SCANNER_ERR_USER_CANCELED == flag)
2023-05-08 12:01:43 +00:00
{
m_timer->start(2000);
connect(m_timer, SIGNAL(timeout()), this, SLOT(on_pbtn_close_clicked()), Qt::QueuedConnection);
}
}
2023-04-20 09:49:48 +00:00
void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag)
{
Dialog_progress_ui *p = (Dialog_progress_ui *)m_param;
switch (event)
{
case SANE_EVENT_WORKING:
{
QString finishInfo((char*)msg);
2023-04-27 03:04:52 +00:00
emit p->scan_status(finishInfo, true);
}
break;
2023-04-20 09:49:48 +00:00
case SANE_EVENT_SCAN_FINISHED:
{
2023-05-08 12:01:43 +00:00
emit p->scan_finish(flag);
2023-04-20 09:49:48 +00:00
QString finishInfo((char*)msg);
2023-04-27 03:04:52 +00:00
emit p->scan_status(finishInfo, false);
2023-04-20 09:49:48 +00:00
}
break;
}
}