4481 lines
141 KiB
C++
4481 lines
141 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QDockWidget>
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
#include <QDateTime>
|
|
#include <QLineEdit>
|
|
#include <QRegExpValidator>
|
|
#include <QStandardPaths>
|
|
#include <QDesktopServices>
|
|
#include "widget_statusbar.h"
|
|
#include "dialog_openimageindex.h"
|
|
#include "dialog_saveas.h"
|
|
#include "dialog_export.h"
|
|
#include "dialog_exportimagefile.h"
|
|
#include "dialog_imageinfo.h"
|
|
#include "dialog_fullscreen.h"
|
|
#include "dialog_imgproc_adjust.h"
|
|
#include "dialog_multirotate.h"
|
|
#include "dialog_multirotateimagefile.h"
|
|
#include "dialog_imgproc_autocrop.h"
|
|
#include "dialog_admin.h"
|
|
#include "dialog_passwordchange.h"
|
|
#include "dialog_insertindex.h"
|
|
#include "dialog_aquireinto.h"
|
|
#include "dialog_logmanager.h"
|
|
#include "dialog_clrcache.h"
|
|
#include "dialog_moveto.h"
|
|
#include "dialog_imageeditor.h"
|
|
#include "dialog_updateprogress.h"
|
|
#include "dialog_upgrade.h"
|
|
#include "dialog_feedback.h"
|
|
#include "dialog_savemessagebox.h"
|
|
#include "dialog_waitingocr.h"
|
|
#include "base/HGInfo.h"
|
|
#include "huagao/hgscanner_error.h"
|
|
#include "base/HGTime.h"
|
|
#include "imgfmt/HGPdf.h"
|
|
#include "imgfmt/HGTiff.h"
|
|
#include "imgfmt/HGImgFmt.h"
|
|
#include "imgproc/HGImgProc.h"
|
|
#include "imgproc/HGOCR.h"
|
|
#include "base/HGUtility.h"
|
|
#include "base/HGCrash.h"
|
|
#include "HGUIGlobal.h"
|
|
#include "HGString.h"
|
|
#include "app_cfg.h"
|
|
#include "app_about_info/appAboutInfo.h"
|
|
#include <assert.h>
|
|
#include "lang/app_language.h"
|
|
#include "huagao/brand.h"
|
|
|
|
#define PASSWORD_KEY 4
|
|
|
|
MainWindow::MainWindow(const QString& appLang, QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, m_canClose(true)
|
|
, m_currLang(appLang)
|
|
, m_versionDll(nullptr)
|
|
, m_admin_loggedIn(false)
|
|
, m_currFilePath("")
|
|
, m_currIndex(-1)
|
|
, m_multiPageCount(0)
|
|
, m_multiIndex(-1)
|
|
, m_modify(false)
|
|
, m_scanType(ScanType_None)
|
|
, m_scanInsertPos(-1)
|
|
, m_scanCurIndex(-1)
|
|
, m_scanFileName("")
|
|
, m_scanImgFmtWriter(nullptr)
|
|
, m_isScanning(false)
|
|
, auto_save_changes_(false)
|
|
, save_from_changed_(false)
|
|
, m_closeTip(true)
|
|
, m_currScanCount(0)
|
|
, m_devSerialNum("")
|
|
, m_devVersionNum("")
|
|
, m_currDeviceName("")
|
|
, m_devPid("")
|
|
, m_cacheDirNotify(false)
|
|
, m_AquirePathNotify(false)
|
|
, m_bSideflag(false)
|
|
, m_bSideEditing(false)
|
|
, m_ocrMsgPump(NULL)
|
|
, m_ocrThread(NULL)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
m_aquireIntoSaveParam.m_fileNameStartIndex = -1;
|
|
|
|
m_versionDll = new VersionDll;
|
|
HGBase_RegisterCrashFunc(CrashFunc, this);
|
|
|
|
HGChar logFilePath[512];
|
|
HGBase_GetLogFilePath(logFilePath, 512);
|
|
deleteOverdueLogFile(QString::fromStdString(getStdString(logFilePath)));
|
|
|
|
HGChar cfgFilePath[512];
|
|
HGBase_GetConfigPath(cfgFilePath, 512);
|
|
deleteUpgradePkg(QString::fromStdString(getStdString(cfgFilePath)));
|
|
|
|
#if defined(OEM_HANWANG)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Hanvon_logo1.ico"));
|
|
this->setWindowTitle(tr("HanvonScan"));
|
|
m_oemName = HGVERSION_OEMNAME_HANVON;
|
|
#elif defined(OEM_LISICHENG)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Lanxum_logo.ico"));
|
|
this->setWindowTitle(tr("LanxumScan"));
|
|
m_oemName = HGVERSION_OEMNAME_LANXUM;
|
|
#elif defined(OEM_CANGTIAN)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Cumtenn_logo.ico"));
|
|
this->setWindowTitle(tr("CumtennScan"));
|
|
m_oemName = HGVERSION_OEMNAME_CUMTENN;
|
|
#elif defined(OEM_ZHONGJING)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Microtek_logo.ico"));
|
|
this->setWindowTitle(tr("MicrotekScan"));
|
|
m_oemName = HGVERSION_OEMNAME_MICROTEK;
|
|
#elif defined(OEM_ZIGUANG)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/uniscan.ico"));
|
|
this->setWindowTitle(tr("UniScan"));
|
|
m_oemName = HGVERSION_OEMNAME_UNIS;
|
|
#elif defined(OEM_NEUTRAL)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/NoBrand_logo.ico"));
|
|
this->setWindowTitle(tr("Scan"));
|
|
m_oemName = HGVERSION_OEMNAME_NEUTRAL;
|
|
#elif defined(OEM_DELI)
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/deli.ico"));
|
|
this->setWindowTitle(tr("DeliScan"));
|
|
m_oemName = HGVERSION_OEMNAME_DELI;
|
|
#else
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico"));
|
|
this->setWindowTitle(tr("HuaGoScan"));
|
|
m_oemName = HGVERSION_OEMNAME_HUAGO;
|
|
#endif
|
|
|
|
this->setAutoFillBackground(true);
|
|
this->setPalette(QPalette(QColor(230, 230, 230)));
|
|
|
|
QDesktopWidget *desktopWidget = QApplication::desktop();
|
|
QRect screenRect = desktopWidget->screenGeometry(this);
|
|
if(screenRect.width() > 1200 && screenRect.height() > 900)
|
|
{
|
|
resize(950, 720);
|
|
}
|
|
|
|
ui->act_clearRoller->setVisible(false);
|
|
ui->actionact_update->setVisible(false);
|
|
ui->act_feedback->setVisible(false);
|
|
|
|
#if !defined(OEM_HANWANG) && !defined(OEM_LISICHENG) && !defined(OEM_CANGTIAN) && !defined(OEM_ZHONGJING) && !defined(OEM_ZIGUANG) && !defined(OEM_NEUTRAL) && !defined(OEM_DELI)
|
|
if (m_versionDll->IsValid())
|
|
{
|
|
ui->actionact_update->setVisible(true);
|
|
ui->act_feedback->setVisible(true);
|
|
m_versionDll->PostUserOpenInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
|
|
}
|
|
#endif
|
|
|
|
ui->toolBar->addAction(ui->act_scannerSettings);
|
|
ui->toolBar->addAction(ui->act_acquire);
|
|
m_act_acquireInto2 = new QAction(QIcon(":/images/image_rsc/actions/scanInto.png"), tr("act_acquireInto"), this);
|
|
connect(m_act_acquireInto2, SIGNAL(triggered()), this, SLOT(on_AcquireInto2()));
|
|
ui->toolBar->addAction(m_act_acquireInto2);
|
|
ui->toolBar->addSeparator();
|
|
|
|
initAcquireIntoComboBox();
|
|
|
|
ui->toolBar->addAction(ui->act_fitWindowWidth);
|
|
ui->toolBar->addAction(ui->act_fitWindowSize);
|
|
ui->toolBar->addAction(ui->act_zoomIn);
|
|
ui->toolBar->addAction(ui->act_zoomOut);
|
|
ui->toolBar->addAction(ui->act_realSize);
|
|
ui->toolBar->addSeparator();
|
|
ui->toolBar->addAction(ui->act_90Left);
|
|
ui->toolBar->addAction(ui->act_90Right);
|
|
ui->toolBar->addAction(ui->act_imageEdit);
|
|
ui->toolBar->addSeparator();
|
|
ui->toolBar->addAction(ui->act_previous);
|
|
ui->toolBar->addAction(ui->act_next);
|
|
ui->toolBar->addAction(ui->act_previousPage);
|
|
ui->toolBar->addAction(ui->act_nextPage);
|
|
ui->toolBar->addAction(ui->act_sortPages);
|
|
ui->toolBar->addSeparator();
|
|
ui->toolBar->addAction(ui->act_help);
|
|
|
|
#if defined (OEM_ZHONGJING)
|
|
m_menu_language = new QMenu(tr("menu_language"));
|
|
m_act_simpCN = new QAction(tr("act_simpCN"),nullptr);
|
|
m_act_English = new QAction(tr("act_English"),nullptr);
|
|
m_act_simpCN->setCheckable(true);
|
|
m_act_English->setCheckable(true);
|
|
ui->menu_info->addMenu(m_menu_language);
|
|
m_menu_language->addAction(m_act_simpCN);
|
|
m_menu_language->addAction(m_act_English);
|
|
|
|
if (m_currLang == "english")
|
|
{
|
|
m_act_simpCN->setChecked(false);
|
|
m_act_English->setChecked(true);
|
|
}
|
|
else
|
|
{
|
|
m_act_simpCN->setChecked(true);
|
|
m_act_English->setChecked(false);
|
|
}
|
|
|
|
connect(m_act_simpCN, SIGNAL(triggered()), this, SLOT(on_act_simpCN_triggered()));
|
|
connect(m_act_English, SIGNAL(triggered()), this, SLOT(on_act_English_triggered()));
|
|
#endif
|
|
|
|
m_view = new HGImgView(ui->centralwidget);
|
|
ui->verticalLayout->addWidget(m_view);
|
|
ui->centralwidget->setMinimumWidth(160);
|
|
|
|
m_thumb = new HGImgThumb(ui->dockWidget);
|
|
ui->dockWidget->setMinimumWidth(200);
|
|
resizeDocks({ui->dockWidget}, {200}, Qt::Horizontal);
|
|
ui->dockWidget->setWidget(m_thumb);
|
|
ui->dockWidget->setTitleBarWidget(new QWidget());
|
|
ui->dockWidget->titleBarWidget()->setVisible(false);
|
|
|
|
QRegExp rx("[0-9,-]+$");
|
|
m_multiPageLineEdit = new HGLineEdit(this);
|
|
m_multiPageLineEdit->setValidator(new QRegExpValidator(rx, this));
|
|
m_multiPageLineEdit->setFixedWidth(100);
|
|
m_multiPageLineEdit->setAlignment(Qt::AlignHCenter);
|
|
ui->toolBar->insertWidget(ui->act_nextPage, m_multiPageLineEdit);
|
|
ui->toolBar->setStyleSheet("QToolBar::item{border: 0px}");
|
|
|
|
m_wndStatusBar = new Widget_StatusBar(ui->act_zoomIn, ui->act_zoomOut, ui->statusBar);
|
|
ui->statusBar->addWidget(m_wndStatusBar, 1);
|
|
m_wndStatusBar->setStyleSheet("QStatusBar::item{border: 0px}");
|
|
ui->statusBar->setSizeGripEnabled(false);
|
|
|
|
connect(m_view, SIGNAL(scaleChanged(double)), this, SLOT(on_viewerScale(double)));
|
|
connect(m_view, SIGNAL(mousePos(int, int)), this, SLOT(on_viewerMousePos(int, int)));
|
|
connect(m_view, SIGNAL(drop(const QObject*, const QStringList &)), this, SLOT(on_viewerDrop(const QObject*, const QStringList &)));
|
|
connect(m_view, SIGNAL(doubleClicked()), this, SLOT(on_viewerDblClick()));
|
|
connect(m_thumb, SIGNAL(keyDeleteDown()), this, SLOT(on_keyDeleteDown()));
|
|
connect(m_thumb, SIGNAL(itemCountChanged(int)), this, SLOT(on_itemCountChanged(int)));
|
|
connect(m_thumb, SIGNAL(itemSelectingChanged()), this, SLOT(on_itemSelectingChanged()));
|
|
connect(m_thumb, SIGNAL(currItemChanged(int)), this, SLOT(on_currItemChanged(int)));
|
|
connect(m_thumb, SIGNAL(itemDoubleClicked(int)), this, SLOT(on_itemDoubleClicked(int)));
|
|
connect(m_thumb, SIGNAL(contextMenuEvent(int)), this, SLOT(on_thumbContextMenu(int)));
|
|
connect(m_thumb, SIGNAL(drop(const QObject*, const QStringList &, int)), this, SLOT(on_thumbDrop(const QObject*, const QStringList &, int)));
|
|
|
|
connect(m_multiPageLineEdit, SIGNAL(editingFinished()), this, SLOT(on_multiPageLineEditFinished()));
|
|
|
|
m_view->enableScroll(true);
|
|
m_view->setScrollSize(16);
|
|
m_view->setMinScrollSliderSize(20);
|
|
|
|
QImage defItemImage(":images/image_rsc/scroll/defItemImage.png");
|
|
m_thumb->setDefItemImage(&defItemImage);
|
|
m_thumb->setType(HGImgThumb::ThumbType_Vert);
|
|
m_thumb->setItemSize(120);
|
|
m_thumb->setScrollSize(16);
|
|
m_thumb->setMinScrollSliderSize(20);
|
|
m_thumb->setItemTextHeight(0);
|
|
|
|
QImage nullScrollImage(":images/image_rsc/scroll/nullScrollImage.png");
|
|
m_view->setNullScrollImage(&nullScrollImage);
|
|
m_thumb->setNullScrollImage(&nullScrollImage);
|
|
|
|
QImage hScrollImage(":images/image_rsc/scroll/hScrollImage.png");
|
|
m_thumb->setHScrollImage(&hScrollImage, nullptr);
|
|
m_view->setHScrollImage(&hScrollImage, nullptr);
|
|
QImage vScrollImage(":images/image_rsc/scroll/vScrollImage.png");
|
|
m_thumb->setVScrollImage(&vScrollImage, nullptr);
|
|
m_view->setVScrollImage(&vScrollImage, nullptr);
|
|
|
|
QImage leftNormalImg(":images/image_rsc/scroll/left_Normal.png");
|
|
QImage leftHotImg(":images/image_rsc/scroll/left_Hot.png");
|
|
QImage leftPushImg(":images/image_rsc/scroll/left_Push.png");
|
|
m_thumb->setHScrollLeftImage(&leftNormalImg, &leftHotImg, &leftPushImg);
|
|
m_view->setHScrollLeftImage(&leftNormalImg, &leftHotImg, &leftPushImg);
|
|
|
|
QImage rightNormalImg(":images/image_rsc/scroll/right_Normal.png");
|
|
QImage rightHotImg(":images/image_rsc/scroll/right_Hot.png");
|
|
QImage rightPushImg(":images/image_rsc/scroll/right_Push.png");
|
|
m_thumb->setHScrollRightImage(&rightNormalImg, &rightHotImg, &rightPushImg);
|
|
m_view->setHScrollRightImage(&rightNormalImg, &rightHotImg, &rightPushImg);
|
|
|
|
QImage topNormalImg(":images/image_rsc/scroll/top_Normal.png");
|
|
QImage topHotImg(":images/image_rsc/scroll/top_Hot.png");
|
|
QImage topPushImg(":images/image_rsc/scroll/top_Push.png");
|
|
m_thumb->setVScrollTopImage(&topNormalImg, &topHotImg, &topPushImg);
|
|
m_view->setVScrollTopImage(&topNormalImg, &topHotImg, &topPushImg);
|
|
|
|
QImage bottomNormalImg(":images/image_rsc/scroll/bottom_Normal.png");
|
|
QImage bottomHotImg(":images/image_rsc/scroll/bottom_Hot.png");
|
|
QImage bottomPushImg(":images/image_rsc/scroll/bottom_Push.png");
|
|
m_thumb->setVScrollBottomImage(&bottomNormalImg, &bottomHotImg, &bottomPushImg);
|
|
m_view->setVScrollBottomImage(&bottomNormalImg, &bottomHotImg, &bottomPushImg);
|
|
|
|
HGRect hSliderStretchRect = { 4, 0, 196, 16 };
|
|
QImage hScrollSliderNormalImage(":images/image_rsc/scroll/hScrollSlider_Normal.png");
|
|
QImage hScrollSliderHotImage(":images/image_rsc/scroll/hScrollSlider_Hot.png");
|
|
QImage hScrollSliderPushImage(":images/image_rsc/scroll/hScrollSlider_Push.png");
|
|
m_thumb->setHScrollSliderImage(&hScrollSliderNormalImage, &hSliderStretchRect,
|
|
&hScrollSliderHotImage, &hSliderStretchRect, &hScrollSliderPushImage, &hSliderStretchRect);
|
|
m_view->setHScrollSliderImage(&hScrollSliderNormalImage, &hSliderStretchRect,
|
|
&hScrollSliderHotImage, &hSliderStretchRect, &hScrollSliderPushImage, &hSliderStretchRect);
|
|
|
|
HGRect vSliderStretchRect = { 0, 4, 16, 196 };
|
|
QImage vScrollSliderNormalImage(":images/image_rsc/scroll/vScrollSlider_Normal.png");
|
|
QImage vScrollSliderHotImage(":images/image_rsc/scroll/vScrollSlider_Hot.png");
|
|
QImage vScrollSliderPushImage(":images/image_rsc/scroll/vScrollSlider_Push.png");
|
|
m_thumb->setVScrollSliderImage(&vScrollSliderNormalImage, &vSliderStretchRect,
|
|
&vScrollSliderHotImage, &vSliderStretchRect, &vScrollSliderPushImage, &vSliderStretchRect);
|
|
m_view->setVScrollSliderImage(&vScrollSliderNormalImage, &vSliderStretchRect,
|
|
&vScrollSliderHotImage, &vSliderStretchRect, &vScrollSliderPushImage, &vSliderStretchRect);
|
|
|
|
m_act_thumbGrid = new QAction(tr("Grid"), this);
|
|
m_act_thumbGrid->setCheckable(true);
|
|
m_act_thumbGrid->setChecked(false);
|
|
connect(m_act_thumbGrid, SIGNAL(triggered(bool)), this, SLOT(on_act_thumbGrid_triggered(bool)));
|
|
|
|
m_moveToAction = new QAction(tr("Move To..."), this);
|
|
connect(m_moveToAction, SIGNAL(triggered()), this, SLOT(on_act_moveTo_triggered()));
|
|
|
|
m_thumbMenu = new QMenu(this);
|
|
m_menu_imageInsert = new QMenu(tr("Insert files"), m_thumbMenu);
|
|
|
|
m_thumbMenu->addAction(ui->act_deleteFile);
|
|
m_thumbMenu->addAction(ui->act_closeFile);
|
|
m_thumbMenu->addAction(ui->act_closeAll);
|
|
m_thumbMenu->addAction(ui->act_Export);
|
|
m_thumbMenu->addSeparator();
|
|
m_thumbMenu->addAction(m_moveToAction);
|
|
m_thumbMenu->addAction(m_menu_imageInsert->menuAction());
|
|
m_thumbMenu->addSeparator();
|
|
m_thumbMenu->addAction(m_act_thumbGrid);
|
|
m_menu_imageInsert->addAction(ui->act_insert);
|
|
m_menu_imageInsert->addAction(ui->act_insertFromScanner);
|
|
|
|
ui->act_consume->setVisible(false);
|
|
|
|
connect(this, SIGNAL(post_new_image(QString)), this, SLOT(on_post_new_image(QString)));
|
|
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false);
|
|
|
|
#if defined(OEM_HANWANG)
|
|
m_password = "hanvonscan";
|
|
#elif defined(OEM_LISICHENG)
|
|
m_password = "lanxum";
|
|
#elif defined(OEM_CANGTIAN)
|
|
m_password = "cumtenn";
|
|
#elif defined(OEM_ZHONGJING)
|
|
m_password = "microtek";
|
|
#elif defined(OEM_ZIGUANG)
|
|
m_password = "uniscan";
|
|
#elif defined(OEM_NEUTRAL)
|
|
m_password = "scan";
|
|
#elif defined(OEM_DELI)
|
|
m_password = "deliscan";
|
|
#else
|
|
m_password = "huagoscan";
|
|
#endif
|
|
|
|
m_devUserMgr = new DeviceUserMgr(m_password, this);
|
|
m_devUser = m_devUserMgr->OpenDefaultDeviceUser();
|
|
if (m_devUser != nullptr)
|
|
{
|
|
if (HGBASE_ERR_OK == m_devUser->OpenDefault())
|
|
{
|
|
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);
|
|
connect(m_devUser, SIGNAL(scanFinishEvent()), this, SLOT(on_scanFinishEvent()), Qt::QueuedConnection);
|
|
|
|
#if !defined(HG_CMP_MSC)
|
|
checkRollerLife();
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
delete m_devUser;
|
|
m_devUser = nullptr;
|
|
}
|
|
}
|
|
|
|
QString password = getCfgValue("login", "password", QString(""));
|
|
if (!password.isEmpty())
|
|
m_password = passwordDecrypt(password);
|
|
|
|
m_dlgFullScreen = nullptr;
|
|
ui->act_autoSave->setChecked(getCfgValue("save", "autoSave", false));
|
|
|
|
#if defined(OEM_LISICHENG)
|
|
ui->act_autoSave->setChecked(true);
|
|
#endif
|
|
|
|
auto_save_changes_ = ui->act_autoSave->isChecked();
|
|
ui->act_autoSave->setText(tr("auto save"));
|
|
ui->act_autoSave->setToolTip(tr("when switching pictures, save the edited pictures directly without reminding"));
|
|
|
|
auto_save_info_.index = 0;
|
|
|
|
m_pbtn_push = new QPushButton(this);
|
|
m_pbtn_push->setVisible(false);
|
|
m_pbtn_push->setText("<<");
|
|
|
|
#if defined (loongarch64)
|
|
m_pbtn_push->setGeometry(0, 0, 45, 50);
|
|
#else
|
|
m_pbtn_push->setGeometry(0, 0, 25, 50);
|
|
#endif
|
|
|
|
m_widget_sideBar = new Widget_Imgproc_SideBar(this);
|
|
|
|
connect(m_pbtn_push, SIGNAL(clicked()), this, SLOT(on_m_pbtn_push_clicked()));
|
|
connect(m_widget_sideBar, SIGNAL(applyToImage(HGImage,int,int,double,bool)), this, SLOT(on_dialog_sideBar_applyToImage(HGImage,int,int,double,bool)));
|
|
connect(m_widget_sideBar, SIGNAL(finish(bool)), this, SLOT(on_dialog_sideBar_finish(bool)));
|
|
|
|
updateSideBar();
|
|
updateActionStatus();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
if (nullptr != m_devUser)
|
|
{
|
|
disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)));
|
|
disconnect(m_devUser, SIGNAL(scanWorkingEvent()), this, SLOT(on_scanWorkingEvent()));
|
|
disconnect(m_devUser, SIGNAL(scanFinishEvent()), this, SLOT(on_scanFinishEvent()));
|
|
delete m_devUser;
|
|
m_devUser = nullptr;
|
|
}
|
|
|
|
delete m_devUserMgr;
|
|
m_devUserMgr = nullptr;
|
|
|
|
if (nullptr != m_dlgFullScreen)
|
|
{
|
|
delete m_dlgFullScreen;
|
|
m_dlgFullScreen = nullptr;
|
|
}
|
|
|
|
delete m_versionDll;
|
|
m_versionDll = nullptr;
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::exitFullScreen()
|
|
{
|
|
assert(nullptr != m_dlgFullScreen);
|
|
this->show();
|
|
delete m_dlgFullScreen;
|
|
m_dlgFullScreen = nullptr;
|
|
}
|
|
|
|
HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName)
|
|
{
|
|
if (!ocr)
|
|
{
|
|
return HGImgFmt_SaveImage(image, 0, info, fileName);
|
|
}
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
HGOCRMgr ocrMgr = nullptr;
|
|
ret = HGImgProc_CreateOCRMgr(0, &ocrMgr);
|
|
if (HGBASE_ERR_OK == ret)
|
|
{
|
|
ret = HGImgProc_ImageOCRToFile(ocrMgr, image, 0, fileName);
|
|
HGImgProc_DestroyOCRMgr(ocrMgr);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void MainWindow::on_act_90Left_triggered()
|
|
{
|
|
if (HGBASE_ERR_OK == m_view->rotateLeft())
|
|
{
|
|
m_modify = true;
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_90Right_triggered()
|
|
{
|
|
if (HGBASE_ERR_OK == m_view->rotateRight())
|
|
{
|
|
m_modify = true;
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_180_triggered()
|
|
{
|
|
if (HGBASE_ERR_OK == m_view->rotate180())
|
|
{
|
|
m_modify = true;
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_fitWindowSize_triggered()
|
|
{
|
|
m_view->fitWndSize();
|
|
}
|
|
|
|
void MainWindow::on_act_fitWindowWidth_triggered()
|
|
{
|
|
m_view->fitWndWidth();
|
|
}
|
|
|
|
void MainWindow::on_act_realSize_triggered()
|
|
{
|
|
m_view->realSize();
|
|
}
|
|
|
|
void MainWindow::on_act_zoomIn_triggered()
|
|
{
|
|
m_view->zoomIn(nullptr);
|
|
}
|
|
|
|
void MainWindow::on_act_zoomOut_triggered()
|
|
{
|
|
m_view->zoomOut(nullptr);
|
|
}
|
|
|
|
void MainWindow::on_act_statusBar_triggered(bool checked)
|
|
{
|
|
ui->statusBar->setVisible(checked);
|
|
if(checked)
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("statusBar displayed"), false);
|
|
}
|
|
else
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("statusBar hidden"), false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_toolBar_triggered(bool checked)
|
|
{
|
|
ui->toolBar->setVisible(checked);
|
|
if(checked)
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("toolBar displayed"), false);
|
|
}
|
|
else
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("toolBar hidden"), false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_colorInfo_triggered(bool checked)
|
|
{
|
|
m_view->showColorInfo(checked);
|
|
if(checked)
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("colorInfo enabled"), false);
|
|
}
|
|
else
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("colorInfo disenabled"), false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_fullscreen_triggered()
|
|
{
|
|
assert(nullptr == m_dlgFullScreen);
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (0 == count || -1 == m_currIndex || -1 == m_multiIndex)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QStringList fileNames;
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileNames.append(fileName);
|
|
}
|
|
|
|
m_dlgFullScreen = new Dialog_FullScreen(this, fileNames, m_currIndex, m_multiIndex);
|
|
m_dlgFullScreen->show();
|
|
this->hide();
|
|
}
|
|
|
|
void MainWindow::on_act_autoSave_triggered()
|
|
{
|
|
auto_save_changes_ = ui->act_autoSave->isChecked();
|
|
if(auto_save_changes_)
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("enabling automatic saving"), false);
|
|
}
|
|
else
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("cancel auto save"), false);
|
|
}
|
|
saveCfgValue("save", "autoSave", auto_save_changes_);
|
|
}
|
|
|
|
void MainWindow::on_AcquireInto2()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count != 0)
|
|
{
|
|
int result = startScanMessageBox(this);
|
|
if (cancelScan == result)
|
|
return;
|
|
}
|
|
|
|
m_scanType = ScanType_ScanInto;
|
|
m_scanInsertPos = -1;
|
|
m_scanCurIndex = -1;
|
|
|
|
Dialog_AquireInto dlg(-1, this);
|
|
m_aquireIntoSaveParam = dlg.getSaveParam();
|
|
m_aquireIntoInBlank = true;
|
|
m_aquireIntoBatchStartIndex = 0;
|
|
m_aquireIntoPageIndex = 0;
|
|
m_aquireIntoMultiPageCount = 0;
|
|
|
|
QDateTime dateTime = QDateTime::currentDateTime();
|
|
if (m_aquireIntoSaveParam.m_isUseSubfolderByTime)
|
|
{
|
|
m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyy-MM-dd") + "/");
|
|
}
|
|
|
|
if(!isLimitAccessFolder(2))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!judgeDiskSpace(m_aquireIntoSaveParam.m_savePath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
if (nullptr != m_devUser)
|
|
{
|
|
ret = m_devUser->StartScan();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_reloadAcquireIntoCfg()
|
|
{
|
|
disconnect(m_cbtn_acquireIntoCfg, SIGNAL(currentTextChanged(QString)), this, SLOT(on_m_acquireIntoCfg_changed(QString)));
|
|
m_cbtn_acquireIntoCfg->clear();
|
|
m_cbtn_acquireIntoCfg->addItem(tr("default scheme"));
|
|
connect(m_cbtn_acquireIntoCfg, SIGNAL(currentTextChanged(QString)), this, SLOT(on_m_acquireIntoCfg_changed(QString)));
|
|
QString allCfgName = getCfgValue("aquire", "cfgNameList", QString(""));
|
|
QStringList allCfgNameList = allCfgName.split(",");
|
|
if (!allCfgNameList.contains(QString("")))
|
|
{
|
|
m_cbtn_acquireIntoCfg->addItems(allCfgNameList);
|
|
m_cbtn_acquireIntoCfg->setCurrentText(getCfgValue("aquire", "currentKeyName", QString("aquire")));
|
|
}
|
|
else
|
|
{
|
|
allCfgNameList.removeOne(QString(""));
|
|
m_cbtn_acquireIntoCfg->setCurrentIndex(0);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_m_acquireIntoCfg_changed(QString schemeName)
|
|
{
|
|
QString selectedCfgName = m_cbtn_acquireIntoCfg->currentText();
|
|
Dialog_AquireInto dlg(-1, this);
|
|
dlg.setConfig(selectedCfgName);
|
|
}
|
|
|
|
void MainWindow::on_keyDeleteDown()
|
|
{
|
|
on_act_deleteFile_triggered();
|
|
}
|
|
|
|
void MainWindow::on_itemCountChanged(int count)
|
|
{
|
|
m_wndStatusBar->setPageInfo(count, m_currIndex);
|
|
updateActionStatus();
|
|
}
|
|
|
|
void MainWindow::on_itemSelectingChanged()
|
|
{
|
|
updateActionStatus();
|
|
}
|
|
|
|
void MainWindow::on_currItemChanged(int index)
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
|
|
{
|
|
assert(!m_currFilePath.isEmpty());
|
|
|
|
QString newCurrFilePath;
|
|
if (-1 != index)
|
|
m_thumb->getItemFileName(index, newCurrFilePath);
|
|
|
|
if (m_currFilePath != newCurrFilePath)
|
|
{
|
|
bool save = false;
|
|
if(auto_save_changes_)
|
|
{
|
|
QString info(tr("Automatically save the edited the edited iamge when switching pictures. To cancel, uncheck the menu item: image-> automatically save"));
|
|
m_wndStatusBar->setDeviceStatusInfo(info, false);
|
|
save = true;
|
|
}
|
|
else
|
|
{
|
|
Dialog_SaveMessageBox dlg(this);
|
|
if (dlg.exec())
|
|
{
|
|
if (dlg.m_result == dlg.result_Yes)
|
|
{
|
|
save = true;
|
|
}
|
|
else if (dlg.m_result == dlg.result_YesToAll)
|
|
{
|
|
save = true;
|
|
auto_save_changes_ = true;
|
|
ui->act_autoSave->setChecked(true);
|
|
}
|
|
else if (dlg.m_result == dlg.result_No)
|
|
{
|
|
m_modify = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(save)
|
|
{
|
|
save_from_changed_ = true;
|
|
on_act_save_triggered();
|
|
save_from_changed_ = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-1 != index)
|
|
{
|
|
QString oldCurrFilePath = m_currFilePath;
|
|
m_currIndex = index;
|
|
m_thumb->getItemFileName(m_currIndex, m_currFilePath);
|
|
assert(!m_currFilePath.isEmpty());
|
|
|
|
if (oldCurrFilePath != m_currFilePath)
|
|
{
|
|
m_multiPageCount = getMultiPageCount();
|
|
m_multiIndex = 0;
|
|
|
|
HGImage img2 = createImage();
|
|
if (nullptr != img2)
|
|
{
|
|
m_view->addImage(img2);
|
|
m_widget_sideBar->setImage(img2);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img2);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
|
|
QFileInfo info(m_currFilePath);
|
|
if (!info.isFile())
|
|
{
|
|
QMessageBox msg(QMessageBox::Question, tr("Question"),
|
|
tr("file lost, remove it?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
{
|
|
m_thumb->removeItem(index, HGImgThumb::ThumbRemoveFlag_NULL);
|
|
|
|
std::list<QString>::iterator iter;
|
|
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
|
|
{
|
|
if (*iter == m_currFilePath)
|
|
{
|
|
m_curBatchFileList.erase(iter);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_currFilePath.clear();
|
|
m_currIndex = -1;
|
|
m_multiPageCount = 0;
|
|
m_multiIndex = -1;
|
|
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
m_wndStatusBar->setPageInfo(count, m_currIndex);
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
}
|
|
|
|
void MainWindow::on_itemDoubleClicked(int index)
|
|
{
|
|
(void)index;
|
|
on_act_open_triggered();
|
|
}
|
|
|
|
void MainWindow::on_thumbContextMenu(int index)
|
|
{
|
|
qDebug("thumbnail menu index=%d", index);
|
|
|
|
m_thumbMenu->show();
|
|
m_thumbMenu->popup(QCursor::pos());
|
|
qDebug("show menu");
|
|
}
|
|
|
|
void MainWindow::on_viewerScale(double scale)
|
|
{
|
|
m_wndStatusBar->setScale(scale);
|
|
}
|
|
|
|
void MainWindow::on_viewerMousePos(int x, int y)
|
|
{
|
|
m_wndStatusBar->setMousePosInfo(x, y);
|
|
}
|
|
|
|
void MainWindow::on_thumbDrop(const QObject *source, const QStringList &fileNames, int pos)
|
|
{
|
|
if (source != m_thumb)
|
|
m_thumb->insertItems(fileNames, pos);
|
|
else
|
|
m_thumb->moveItems(fileNames, pos);
|
|
}
|
|
|
|
void MainWindow::on_viewerDrop(const QObject *source, const QStringList &fileNames)
|
|
{
|
|
if (source != m_thumb)
|
|
m_thumb->addItems(fileNames);
|
|
}
|
|
|
|
void MainWindow::on_viewerDblClick()
|
|
{
|
|
on_act_open_triggered();
|
|
}
|
|
|
|
void MainWindow::on_act_moveTo_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
|
|
Dialog_MoveTo dlg(count, (-1 != m_currIndex) ? m_currIndex : 0, this);
|
|
if (dlg.exec())
|
|
{
|
|
QStringList fileNames;
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool selected = false;
|
|
m_thumb->itemIsSelect(i, &selected);
|
|
if (selected)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileNames.append(fileName);
|
|
}
|
|
}
|
|
|
|
int index = dlg.getMoveToIndex();
|
|
m_thumb->moveItemsTo(fileNames, index);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_thumbGrid_triggered(bool checked)
|
|
{
|
|
if (checked)
|
|
{
|
|
m_thumb->setType(HGImgThumb::ThumbType_Grid);
|
|
resizeDocks({ui->dockWidget}, {300}, Qt::Horizontal);
|
|
}
|
|
|
|
else
|
|
{
|
|
m_thumb->setType(HGImgThumb::ThumbType_Vert);
|
|
resizeDocks({ui->dockWidget}, {200}, Qt::Horizontal);
|
|
}
|
|
|
|
}
|
|
|
|
void MainWindow::on_dialog_adjust_applyToImage(HGImage img)
|
|
{
|
|
m_view->addImage(img);
|
|
updateStatusBarPixelInfo();
|
|
}
|
|
|
|
void MainWindow::on_dialog_multirotate_refreshImgFile(const QString &fileName)
|
|
{
|
|
m_thumb->refreshItem(fileName);
|
|
}
|
|
|
|
void MainWindow::on_multiPageLineEditFinished()
|
|
{
|
|
if (-1 != m_currIndex && m_multiPageCount > 0)
|
|
{
|
|
int multiIndex = m_multiPageLineEdit->text().toInt() - 1;
|
|
if (multiIndex >= 0 && multiIndex < m_multiPageCount)
|
|
{
|
|
m_multiIndex = multiIndex;
|
|
|
|
HGImage img = createImage();
|
|
if (nullptr != img)
|
|
{
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
}
|
|
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_clearCache()
|
|
{
|
|
std::vector<int> removeItems;
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath()))
|
|
{
|
|
removeItems.push_back(i);
|
|
}
|
|
}
|
|
|
|
m_thumb->removeItems(removeItems, HGImgThumb::ThumbRemoveFlag_NULL);
|
|
}
|
|
|
|
void MainWindow::on_post_new_image(QString fileName)
|
|
{
|
|
HGULonglong t1;
|
|
HGBase_GetTickCount(&t1);
|
|
qDebug("on_post_new_image start, m_currScanCount=%d", m_currScanCount);
|
|
|
|
QString stdFileName;
|
|
if (-1 == m_scanInsertPos)
|
|
{
|
|
m_thumb->addItem(fileName, false);
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
m_thumb->getItemFileName(count - 1, stdFileName);
|
|
m_scanCurIndex = count - 1;
|
|
}
|
|
else
|
|
{
|
|
m_thumb->insertItem(fileName, m_scanInsertPos, false);
|
|
m_thumb->getItemFileName(m_scanInsertPos, stdFileName);
|
|
m_scanCurIndex = m_scanInsertPos;
|
|
++m_scanInsertPos;
|
|
}
|
|
|
|
if ((ScanType_ScanInto == m_scanType))
|
|
{
|
|
m_curBatchFileList.push_back(stdFileName);
|
|
}
|
|
else if (ScanType_InsertScanInto == m_scanType)
|
|
{
|
|
if (-1 == m_scanInsertPos)
|
|
{
|
|
m_curBatchFileList.push_back(stdFileName);
|
|
}
|
|
else
|
|
{
|
|
m_curBatchTmpFileList.push_back(stdFileName);
|
|
}
|
|
}
|
|
|
|
HGULonglong t2;
|
|
HGBase_GetTickCount(&t2);
|
|
HGDouble seconds;
|
|
HGBase_GetIntervalSeconds(t1, t2, &seconds);
|
|
qDebug("on_post_new_image end, m_currScanCount=%d, seconds=%f", m_currScanCount, seconds);
|
|
m_currScanCount++;
|
|
|
|
QString *filePath = new QString(fileName);
|
|
HGMsg msg;
|
|
msg.id = 1;
|
|
msg.data = filePath;
|
|
if (HGBASE_ERR_OK != HGBase_PostPumpMessage(m_ocrMsgPump, &msg))
|
|
{
|
|
delete filePath;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_newImage(void *image)
|
|
{
|
|
HGULonglong t1;
|
|
HGBase_GetTickCount(&t1);
|
|
qDebug("on_newImage start, m_currScanCount=%d", m_currScanCount);
|
|
|
|
if (ScanType_ScanToCache == m_scanType || ScanType_SingleScanToCache == m_scanType)
|
|
{
|
|
m_scanFileName = getCacheFileName((HGImage)image);
|
|
|
|
HGImgFmtSaveInfo info;
|
|
info.jpegQuality = 100;
|
|
info.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
info.tiffJpegQuality = 0;
|
|
if (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, 0, &info, getStdString(m_scanFileName).c_str()))
|
|
{
|
|
emit post_new_image(m_scanFileName);
|
|
}
|
|
|
|
m_scanFileName.clear();
|
|
}
|
|
else if (ScanType_ScanInto == m_scanType || ScanType_InsertScanInto == m_scanType)
|
|
{
|
|
++m_aquireIntoPageIndex;
|
|
if ((1 == m_aquireIntoSaveParam.m_fileNameOddEventType && 1 != m_aquireIntoPageIndex % 2)
|
|
|| (2 == m_aquireIntoSaveParam.m_fileNameOddEventType && 0 != m_aquireIntoPageIndex % 2))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_aquireIntoSaveParam.m_isSaveAsMultiPage)
|
|
{
|
|
if (nullptr == m_scanImgFmtWriter)
|
|
{
|
|
assert(m_scanFileName.isEmpty());
|
|
HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str());
|
|
|
|
QString scanFileName;
|
|
if (-1 == m_scanInsertPos)
|
|
{
|
|
while (1)
|
|
{
|
|
scanFileName = m_aquireIntoSaveParam.m_savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
|
|
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
|
|
.arg(m_aquireIntoSaveParam.m_fileNameExt);
|
|
QFileInfo fileInfo(scanFileName);
|
|
if (fileInfo.isFile())
|
|
{
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HGChar uuid[256];
|
|
HGBase_GetUuid(uuid, 256);
|
|
scanFileName = m_aquireIntoSaveParam.m_savePath + QString(uuid) + "." + m_aquireIntoSaveParam.m_fileNameExt;
|
|
}
|
|
|
|
HGUInt fmtType = 0;
|
|
if (m_aquireIntoSaveParam.m_isOcr)
|
|
fmtType = HGIMGFMT_TYPE_TIFF;
|
|
HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), fmtType, &m_scanImgFmtWriter);
|
|
if (nullptr != m_scanImgFmtWriter)
|
|
{
|
|
m_scanFileName = scanFileName;
|
|
}
|
|
}
|
|
|
|
if (nullptr != m_scanImgFmtWriter)
|
|
{
|
|
HGImgFmtSaveInfo saveInfo;
|
|
saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality;
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo((HGImage)image, &imgInfo);
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
{
|
|
if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
|
}
|
|
else
|
|
{
|
|
if (1 == m_aquireIntoSaveParam.m_tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == m_aquireIntoSaveParam.m_tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
|
}
|
|
|
|
if (m_aquireIntoSaveParam.m_isOcr)
|
|
{
|
|
saveInfo.jpegQuality = 100;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = 100;
|
|
}
|
|
|
|
if (HGBASE_ERR_OK == HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, (HGImage)image, &saveInfo))
|
|
{
|
|
++m_aquireIntoMultiPageCount;
|
|
if (1 == m_aquireIntoSaveParam.m_multiPagesType && m_aquireIntoMultiPageCount == m_aquireIntoSaveParam.m_customMultiPages)
|
|
{
|
|
HGImgFmt_CloseImageWriter(m_scanImgFmtWriter);
|
|
m_scanImgFmtWriter = nullptr;
|
|
emit post_new_image(m_scanFileName);
|
|
m_scanFileName.clear();
|
|
if (-1 == m_scanInsertPos)
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
m_aquireIntoMultiPageCount = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
assert(nullptr == m_scanImgFmtWriter);
|
|
|
|
QString savePath = m_aquireIntoSaveParam.m_savePath;
|
|
if (m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages)
|
|
{
|
|
HGBool isBlank = HGFALSE;
|
|
HGImgProc_ImageBlankCheck((HGImage)image, nullptr, &isBlank);
|
|
if (isBlank)
|
|
{
|
|
m_aquireIntoInBlank = true;
|
|
}
|
|
else
|
|
{
|
|
if (m_aquireIntoInBlank)
|
|
{
|
|
++m_aquireIntoBatchStartIndex;
|
|
}
|
|
|
|
m_aquireIntoInBlank = false;
|
|
}
|
|
|
|
char batchDir[20];
|
|
sprintf(batchDir, "batch%d", m_aquireIntoBatchStartIndex);
|
|
savePath = getStdFileName(savePath + batchDir + "/");
|
|
}
|
|
|
|
if (m_aquireIntoSaveParam.m_isUseSubfolderByColor)
|
|
{
|
|
QString colorModeName;
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo((HGImage)image, &imgInfo);
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
colorModeName = tr("binary");
|
|
else if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
|
colorModeName = tr("gray");
|
|
else
|
|
colorModeName = tr("rgb");
|
|
|
|
savePath = getStdFileName(savePath + colorModeName + "/");
|
|
}
|
|
|
|
HGBase_CreateDir(getStdString(savePath).c_str());
|
|
|
|
if (-1 == m_scanInsertPos)
|
|
{
|
|
while (1)
|
|
{
|
|
m_scanFileName = savePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
|
|
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
|
|
.arg(m_aquireIntoSaveParam.m_fileNameExt);
|
|
QFileInfo fileInfo(m_scanFileName);
|
|
if (fileInfo.isFile())
|
|
{
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HGChar uuid[256];
|
|
HGBase_GetUuid(uuid, 256);
|
|
m_scanFileName = m_aquireIntoSaveParam.m_savePath + QString(uuid) + "." + m_aquireIntoSaveParam.m_fileNameExt;
|
|
}
|
|
|
|
HGImgFmtSaveInfo saveInfo;
|
|
saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality;
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo((HGImage)image, &imgInfo);
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
{
|
|
if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
|
}
|
|
else
|
|
{
|
|
if (1 == m_aquireIntoSaveParam.m_tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == m_aquireIntoSaveParam.m_tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
|
}
|
|
|
|
HGUInt fmtType = 0;
|
|
if (m_aquireIntoSaveParam.m_isOcr)
|
|
{
|
|
fmtType = HGIMGFMT_TYPE_TIFF;
|
|
saveInfo.jpegQuality = 100;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = 100;
|
|
}
|
|
|
|
if (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, fmtType, &saveInfo, getStdString(m_scanFileName).c_str()))
|
|
{
|
|
emit post_new_image(m_scanFileName);
|
|
if (-1 == m_scanInsertPos)
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
}
|
|
|
|
m_scanFileName.clear();
|
|
}
|
|
}
|
|
|
|
HGULonglong t2;
|
|
HGBase_GetTickCount(&t2);
|
|
HGDouble seconds;
|
|
HGBase_GetIntervalSeconds(t1, t2, &seconds);
|
|
qDebug("on_newImage end, m_currScanCount=%d, seconds=%f", m_currScanCount, seconds);
|
|
}
|
|
|
|
void MainWindow::on_scanWorkingEvent()
|
|
{
|
|
m_isScanning = true;
|
|
updateActionStatus();
|
|
|
|
if (m_aquireIntoSaveParam.m_isOcr && (ScanType_ScanInto == m_scanType || ScanType_InsertScanInto == m_scanType))
|
|
{
|
|
m_dlgWaitingOcr = new Dialog_WaitingOcr(this);
|
|
|
|
HGBase_CreateMsgPump(&m_ocrMsgPump);
|
|
HGBase_OpenThread(ocrThreadFunc, this, &m_ocrThread);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_scanFinishEvent()
|
|
{
|
|
m_isScanning = false;
|
|
updateActionStatus();
|
|
|
|
if (nullptr != m_scanImgFmtWriter)
|
|
{
|
|
HGImgFmt_CloseImageWriter(m_scanImgFmtWriter);
|
|
m_scanImgFmtWriter = nullptr;
|
|
emit post_new_image(m_scanFileName);
|
|
m_scanFileName.clear();
|
|
if (-1 == m_scanInsertPos)
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
m_aquireIntoMultiPageCount = 0;
|
|
}
|
|
|
|
if (NULL != m_ocrMsgPump)
|
|
{
|
|
HGBase_ExitMsgPump(m_ocrMsgPump);
|
|
|
|
m_dlgWaitingOcr->exec();
|
|
|
|
HGBase_CloseThread(m_ocrThread);
|
|
m_ocrThread = NULL;
|
|
HGBase_DestroyMsgPump(m_ocrMsgPump);
|
|
m_ocrMsgPump = NULL;
|
|
}
|
|
|
|
QMessageBox msg(QMessageBox::Information, tr("Prompt"), tr("This scan is complete. Do you want to continue scanning?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
{
|
|
if (m_devUser != nullptr)
|
|
{
|
|
if (ScanType_SingleScanToCache == m_scanType)
|
|
m_devUser->StartSingleScan();
|
|
else
|
|
m_devUser->StartScan();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (-1 != m_scanCurIndex)
|
|
{
|
|
m_thumb->setCurrItem(m_scanCurIndex);
|
|
}
|
|
|
|
if (!m_curBatchTmpFileList.empty())
|
|
{
|
|
assert(ScanType_InsertScanInto == m_scanType);
|
|
assert(-1 != m_scanInsertPos);
|
|
|
|
std::list<QString> backupNames;
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = m_scanInsertPos; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
|
|
std::list<QString>::iterator iter;
|
|
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
|
|
{
|
|
if (*iter == fileName)
|
|
{
|
|
HGChar filePath[256];
|
|
HGBase_GetFilePath(fileName.toLocal8Bit().toStdString().c_str(), filePath, 256);
|
|
HGChar name[256];
|
|
HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256);
|
|
HGChar filePrefix[256];
|
|
HGBase_GetFilePrefix(name, filePrefix, 256);
|
|
HGChar fileSuffix[256];
|
|
HGBase_GetFileSuffix(name, fileSuffix, 256);
|
|
HGChar uuid[256];
|
|
HGBase_GetUuid(uuid, 256);
|
|
|
|
QString strFilePath = QString::fromLocal8Bit(filePath);
|
|
QString strFileSuffix = QString::fromLocal8Bit(fileSuffix);
|
|
QString strUuid = QString::fromLocal8Bit(uuid);
|
|
QString newFileName = strFilePath + strUuid + "." + strFileSuffix;
|
|
|
|
QFile file(fileName);
|
|
file.rename(newFileName);
|
|
m_thumb->updateItem(fileName, newFileName, false);
|
|
|
|
m_curBatchFileList.erase(iter);
|
|
backupNames.push_back(filePrefix);
|
|
m_curBatchTmpFileList.push_back(newFileName);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::list<QString>::iterator iter;
|
|
for (iter = m_curBatchTmpFileList.begin(); iter != m_curBatchTmpFileList.end(); ++iter)
|
|
{
|
|
HGChar filePath[256];
|
|
HGBase_GetFilePath((*iter).toLocal8Bit().toStdString().c_str(), filePath, 256);
|
|
HGChar fileSuffix[256];
|
|
HGBase_GetFileSuffix((*iter).toLocal8Bit().toStdString().c_str(), fileSuffix, 256);
|
|
|
|
QString strFilePath = QString::fromLocal8Bit(filePath);
|
|
QString strFileSuffix = QString::fromLocal8Bit(fileSuffix);
|
|
|
|
QString newFileName;
|
|
while (!backupNames.empty())
|
|
{
|
|
QString fileName = strFilePath + backupNames.front() + "." + strFileSuffix;
|
|
QFileInfo fileInfo(fileName);
|
|
if (fileInfo.isFile())
|
|
{
|
|
backupNames.erase(backupNames.begin());
|
|
}
|
|
else
|
|
{
|
|
newFileName = fileName;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!newFileName.isEmpty())
|
|
{
|
|
QFile file(*iter);
|
|
file.rename(newFileName);
|
|
m_thumb->updateItem(*iter, newFileName, false);
|
|
m_curBatchFileList.push_back(newFileName);
|
|
backupNames.erase(backupNames.begin());
|
|
}
|
|
else
|
|
{
|
|
while (1)
|
|
{
|
|
QString fileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
|
|
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
|
|
.arg(strFileSuffix);
|
|
QFileInfo fileInfo(fileName);
|
|
if (fileInfo.isFile())
|
|
{
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
}
|
|
else
|
|
{
|
|
newFileName = fileName;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!newFileName.isEmpty())
|
|
{
|
|
QFile file(*iter);
|
|
file.rename(newFileName);
|
|
m_thumb->updateItem(*iter, newFileName, false);
|
|
m_curBatchFileList.push_back(newFileName);
|
|
++m_aquireIntoSaveParam.m_fileNameStartIndex;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_curBatchTmpFileList.clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_m_pbtn_push_clicked()
|
|
{
|
|
int mainWndWidth = this->rect().width();
|
|
int mainWndHeight = this->rect().height();
|
|
int sideBarWidth = m_widget_sideBar->width();
|
|
int sideBarHeight = m_widget_sideBar->height();
|
|
|
|
if(!m_bSideflag)
|
|
{
|
|
m_propertyAnimation->setStartValue(QRect(mainWndWidth, mainWndHeight/2 - sideBarHeight/2, sideBarWidth, sideBarHeight));
|
|
m_propertyAnimation->setEndValue(QRect(mainWndWidth - sideBarWidth, mainWndHeight/2 - sideBarHeight/2, sideBarWidth, sideBarHeight));
|
|
m_propertyAnimation->start();
|
|
m_propertyAnimation2->setStartValue(QRect(mainWndWidth - m_pbtn_push->width(), mainWndHeight/2 - m_pbtn_push->height()/2, m_pbtn_push->width(), m_pbtn_push->height()));
|
|
m_propertyAnimation2->setEndValue(QRect(mainWndWidth - m_pbtn_push->width() - sideBarWidth, mainWndHeight/2 - m_pbtn_push->height()/2, m_pbtn_push->width(), m_pbtn_push->height()));
|
|
m_propertyAnimation2->start();
|
|
m_pbtn_push->setText(">>");
|
|
m_bSideflag = !m_bSideflag;
|
|
}
|
|
else
|
|
{
|
|
m_propertyAnimation->setStartValue(QRect(mainWndWidth - sideBarWidth, mainWndHeight/2 - sideBarHeight/2,sideBarWidth, sideBarHeight));
|
|
m_propertyAnimation->setEndValue(QRect(mainWndWidth, mainWndHeight/2 - sideBarHeight/2, sideBarWidth, sideBarHeight));
|
|
m_propertyAnimation->start();
|
|
m_propertyAnimation2->setStartValue(QRect(mainWndWidth - m_pbtn_push->width() - sideBarWidth, mainWndHeight/2 - m_pbtn_push->height()/2, m_pbtn_push->width(), m_pbtn_push->height()));
|
|
m_propertyAnimation2->setEndValue(QRect(mainWndWidth - m_pbtn_push->width(), mainWndHeight/2 - m_pbtn_push->height()/2, m_pbtn_push->width(), m_pbtn_push->height()));
|
|
m_propertyAnimation2->start();
|
|
m_pbtn_push->setText("<<");
|
|
m_bSideflag = !m_bSideflag;
|
|
}
|
|
|
|
updateActionStatus();
|
|
}
|
|
|
|
void MainWindow::on_dialog_sideBar_applyToImage(HGImage img, int brightness, int contrast, double gamma, bool enhanceText)
|
|
{
|
|
assert(nullptr != img);
|
|
|
|
HGImage destImg = nullptr;
|
|
HGBase_CloneImage(img, 0, 0, &destImg);
|
|
if (nullptr != destImg)
|
|
{
|
|
HGImgProc_ImageAdjustColors(destImg, destImg, brightness, contrast, (HGFloat)gamma);
|
|
if (enhanceText)
|
|
HGImgProc_ImageBinarization(destImg, destImg, HGIMGPROC_THRESHTYPE_ADAPTIVE_MEAN, 120, 51, 41);
|
|
|
|
m_view->addImage(destImg);
|
|
m_widget_sideBar->enableUI(m_multiPageCount == 1);
|
|
m_bSideEditing = true;
|
|
HGBase_DestroyImage(destImg);
|
|
updateActionStatus();
|
|
updateStatusBarPixelInfo();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_dialog_sideBar_finish(bool ok)
|
|
{
|
|
m_modify = ok;
|
|
m_bSideEditing = false;
|
|
updateActionStatus();
|
|
if (ok)
|
|
{
|
|
HGImage image = nullptr;
|
|
m_view->getImage(&image);
|
|
m_widget_sideBar->setImage(image);
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
m_widget_sideBar->enableUI(false);
|
|
emit m_pbtn_push->clicked();
|
|
}
|
|
|
|
void MainWindow::on_act_thumbnailBar_triggered(bool checked)
|
|
{
|
|
ui->dockWidget->setVisible(checked);
|
|
if(checked)
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("thumbnailBar enabled"), false);
|
|
}
|
|
else
|
|
{
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("thumbnailBar hidden"), false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_previous_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count > 0 && (-1 == m_currIndex || m_currIndex > 0))
|
|
{
|
|
if (-1 == m_currIndex)
|
|
m_thumb->setCurrItem(0);
|
|
else
|
|
m_thumb->setCurrItem(m_currIndex - 1);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_next_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count > 0 && (-1 == m_currIndex || m_currIndex < count - 1))
|
|
{
|
|
if (-1 == m_currIndex)
|
|
m_thumb->setCurrItem(0);
|
|
else
|
|
m_thumb->setCurrItem(m_currIndex + 1);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_first_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count > 0 && 0 != m_currIndex)
|
|
{
|
|
m_thumb->setCurrItem(0);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_last_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count > 0 && count - 1 != m_currIndex)
|
|
{
|
|
m_thumb->setCurrItem(count - 1);
|
|
}
|
|
}
|
|
|
|
QString MainWindow::getCacheFileName(HGImage img)
|
|
{
|
|
assert(nullptr != img);
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
|
|
QString cachePath = Dialog_ClrCache::getCachePath();
|
|
HGBase_CreateDir(getStdString(cachePath).c_str());
|
|
|
|
char uuid[256] = {0};
|
|
HGBase_GetUuid(uuid, 256);
|
|
QString suffix = (HGBASE_IMGTYPE_BINARY == imgInfo.type) ? ".bmp" : ".jpg";
|
|
QString fileName = getStdFileName(cachePath + uuid + suffix);
|
|
return fileName;
|
|
}
|
|
|
|
HGImage MainWindow::createImage()
|
|
{
|
|
//qDebug("createImage");
|
|
|
|
assert(-1 != m_currIndex && -1 != m_multiIndex);
|
|
assert(!m_currFilePath.isEmpty());
|
|
|
|
HGImage img = nullptr;
|
|
HGImgFmtReader imgFmtReader = nullptr;
|
|
HGImgFmt_OpenImageReader(getStdString(m_currFilePath).c_str(), 0, &imgFmtReader);
|
|
if (nullptr != imgFmtReader)
|
|
{
|
|
HGImgFmt_LoadImageFromReader(imgFmtReader, (HGUInt)m_multiIndex, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img);
|
|
HGImgFmt_CloseImageReader(imgFmtReader);
|
|
}
|
|
|
|
return img;
|
|
}
|
|
|
|
int MainWindow::getMultiPageCount()
|
|
{
|
|
assert(-1 != m_currIndex);
|
|
assert(!m_currFilePath.isEmpty());
|
|
|
|
int count = 0;
|
|
|
|
HGImgFmtReader imgFmtReader = nullptr;
|
|
HGImgFmt_OpenImageReader(getStdString(m_currFilePath).c_str(), 0, &imgFmtReader);
|
|
if (nullptr != imgFmtReader)
|
|
{
|
|
HGImgFmt_GetImagePageCount(imgFmtReader, (HGUInt *)&count);
|
|
HGImgFmt_CloseImageReader(imgFmtReader);
|
|
}
|
|
|
|
//qDebug("pageCount=%d", count);
|
|
return count;
|
|
}
|
|
|
|
void MainWindow::updateStatusBarPixelInfo()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img)
|
|
{
|
|
m_wndStatusBar->setPixelInfo(0, 0, 0);
|
|
}
|
|
else
|
|
{
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
int bpp = 0;
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
bpp = 1;
|
|
else if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
|
bpp = 8;
|
|
else if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_RGB == imgInfo.type)
|
|
bpp = 24;
|
|
else
|
|
bpp = 32;
|
|
m_wndStatusBar->setPixelInfo((int)imgInfo.width, (int)imgInfo.height, bpp);
|
|
}
|
|
}
|
|
|
|
void MainWindow::updateActionStatus()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
std::vector<int> selectIndexs;
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(i, &select);
|
|
if (select)
|
|
selectIndexs.push_back(i);
|
|
}
|
|
|
|
m_thumb->setAcceptDrops(!m_isScanning);
|
|
|
|
ui->act_open->setEnabled(!m_isScanning);
|
|
ui->act_insert->setEnabled(!m_isScanning);
|
|
ui->act_save->setEnabled(nullptr != img && -1 != m_currIndex && m_multiPageCount == 1
|
|
&& (!m_isScanning));
|
|
ui->act_saveAs->setEnabled(nullptr != img);
|
|
ui->act_Export->setEnabled(0 != count && (!m_isScanning));
|
|
ui->act_deleteFile->setEnabled(!selectIndexs.empty() && (!m_isScanning));
|
|
ui->act_closeFile->setEnabled(!selectIndexs.empty() && (!m_isScanning));
|
|
ui->act_closeAll->setEnabled(0 != count && (!m_isScanning));
|
|
ui->act_imageInfo->setEnabled(-1 != m_currIndex && (!m_isScanning));
|
|
ui->menu_multiPages->setEnabled(m_multiPageCount > 1 && (!m_isScanning));
|
|
ui->act_previous->setEnabled(count > 0 && (-1 == m_currIndex || m_currIndex > 0)
|
|
&& (!m_isScanning));
|
|
ui->act_next->setEnabled(count > 0 && (-1 == m_currIndex || m_currIndex < count - 1)
|
|
&& (!m_isScanning));
|
|
ui->act_first->setEnabled(count > 0 && 0 != m_currIndex && (!m_isScanning));
|
|
ui->act_last->setEnabled(count > 0 && count - 1 != m_currIndex && (!m_isScanning));
|
|
ui->act_openPageNum->setEnabled(count > 1 && (!m_isScanning));
|
|
ui->act_previousPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex > 0
|
|
&& (!m_isScanning));
|
|
ui->act_nextPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && -1 != m_multiIndex && m_multiIndex < m_multiPageCount - 1
|
|
&& (!m_isScanning));
|
|
ui->act_firstPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && 0 != m_multiIndex
|
|
&& (!m_isScanning));
|
|
ui->act_lastPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex != m_multiPageCount - 1
|
|
&& (!m_isScanning));
|
|
m_multiPageLineEdit->setText(QString("%1/%2").arg(m_multiIndex + 1).arg(m_multiPageCount));
|
|
ui->toolBar->actions().at(18)->setVisible(-1 != m_currIndex && m_multiPageCount > 1 && -1 != m_multiIndex
|
|
&& (!m_isScanning));
|
|
ui->act_sortPages->setEnabled(0 != count && (!m_isScanning));
|
|
|
|
ui->act_imageEdit->setEnabled(m_multiPageCount == 1 && nullptr != img);
|
|
ui->act_zoomIn->setEnabled(nullptr != img);
|
|
ui->act_zoomOut->setEnabled(nullptr != img);
|
|
ui->act_fullscreen->setEnabled(count > 0 && -1 != m_currIndex && -1 != m_multiIndex
|
|
&& (!m_isScanning));
|
|
ui->act_fitWindowSize->setEnabled(nullptr != img);
|
|
ui->act_fitWindowWidth->setEnabled(nullptr != img);
|
|
ui->act_realSize->setEnabled(nullptr != img);
|
|
ui->act_90Left->setEnabled(m_multiPageCount == 1 && nullptr != img);
|
|
ui->act_90Right->setEnabled(m_multiPageCount == 1 && nullptr != img);
|
|
ui->act_180->setEnabled(m_multiPageCount == 1 && nullptr != img);
|
|
ui->menu_Auto_Image_Size->setEnabled(nullptr != img);
|
|
ui->act_multiRotate->setEnabled(0 != count && (!m_isScanning));
|
|
ui->menu_Rotate->setEnabled((0 != count || nullptr != img) && (!m_isScanning));
|
|
ui->act_autoCrop->setEnabled(m_multiPageCount == 1 && 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);
|
|
// ui->act_clearRoller->setEnabled(m_admin_loggedIn);
|
|
|
|
ui->act_acquireInto->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
|
m_act_acquireInto2->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
|
ui->act_acquireSingle->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
|
ui->act_acquire->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
|
ui->act_scannerSettings->setEnabled(!m_isScanning && (m_devUser != nullptr));
|
|
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 && (m_devUser != nullptr));
|
|
// if(m_dialogLog != nullptr)
|
|
// m_dialogLog->pbtn_export->setEnabled(ui->act_Export->isEnabled());
|
|
|
|
m_moveToAction->setEnabled(!selectIndexs.empty() && (!m_isScanning));
|
|
|
|
if (m_pbtn_push != nullptr && m_widget_sideBar!= nullptr)
|
|
{
|
|
m_pbtn_push->setVisible(m_multiPageCount == 1 && nullptr != img);
|
|
m_widget_sideBar->setVisible(m_multiPageCount == 1 && nullptr != img);
|
|
}
|
|
m_cbtn_acquireIntoCfg->setEnabled(!m_isScanning);
|
|
|
|
ui->act_adjust->setEnabled(m_multiPageCount == 1 && !m_bSideEditing && nullptr != img);
|
|
}
|
|
|
|
void MainWindow::startSaveMessageBox(QWidget* parent)
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
|
|
{
|
|
QMessageBox msg(QMessageBox::Question, tr("Question"),
|
|
tr("modified, save it?"),
|
|
QMessageBox::Yes | QMessageBox::No, parent);
|
|
msg.exec();
|
|
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
|
|
{
|
|
m_modify = false;
|
|
updateActionStatus();
|
|
}
|
|
else
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
|
|
askIfClear MainWindow::startScanMessageBox(QWidget *parent)
|
|
{
|
|
QMessageBox box(parent);
|
|
QPushButton* clearBtn = box.addButton(tr("Clear, then start scan"), QMessageBox::ActionRole);
|
|
box.addButton(tr("Do NOT clear, then start scan"), QMessageBox::ActionRole);
|
|
QPushButton* cancelBtn = box.addButton(QMessageBox::Cancel);
|
|
cancelBtn->setText(tr("cancel"));
|
|
box.setWindowTitle(tr("Question"));
|
|
box.setText(tr("Already exist images in image list.\nDo you want to clear?"));
|
|
box.exec();
|
|
if (box.clickedButton() == cancelBtn)
|
|
return cancelScan;
|
|
else if (box.clickedButton() == clearBtn)
|
|
{
|
|
on_act_closeAll_triggered();
|
|
return clearAndScan;
|
|
}
|
|
return notClearAndScan;
|
|
}
|
|
|
|
QString MainWindow::passwordEncrypt(const QString& password)
|
|
{
|
|
QString p = password;
|
|
int num = PASSWORD_KEY - p.length() % PASSWORD_KEY;
|
|
for (int i = 0; i < num; i++)
|
|
p.append("+");
|
|
int rows = p.length() / 4;
|
|
QString transcode;
|
|
for (int i = 0; i < PASSWORD_KEY; i++)
|
|
for (int j = 0; j < rows; j++)
|
|
transcode.append(p[i + j * PASSWORD_KEY]);
|
|
|
|
return transcode;
|
|
}
|
|
|
|
QString MainWindow::passwordDecrypt(const QString& transcode)
|
|
{
|
|
QString t = transcode;
|
|
int cols = t.length() / 4;
|
|
QString password;
|
|
for (int i = 0; i < cols; i++)
|
|
for (int j = 0; j < PASSWORD_KEY; j++)
|
|
password.append(t[i + j * cols]);
|
|
password.remove("+");
|
|
return password;
|
|
}
|
|
|
|
void MainWindow::on_act_openPageNum_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (0 == count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_OpenImageIndex dlg(count, (-1 == m_currIndex) ? 0 : m_currIndex, this);
|
|
if (dlg.exec())
|
|
{
|
|
int index = dlg.getIndex();
|
|
m_thumb->setCurrItem(index);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_previousPage_triggered()
|
|
{
|
|
if (-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex > 0)
|
|
{
|
|
--m_multiIndex;
|
|
|
|
HGImage img = createImage();
|
|
if (nullptr != img)
|
|
{
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_nextPage_triggered()
|
|
{
|
|
if (-1 != m_currIndex && m_multiPageCount > 0 && -1 != m_multiIndex && m_multiIndex < m_multiPageCount - 1)
|
|
{
|
|
++m_multiIndex;
|
|
|
|
HGImage img = createImage();
|
|
if (nullptr != img)
|
|
{
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_firstPage_triggered()
|
|
{
|
|
if (-1 != m_currIndex && m_multiPageCount > 0 && 0 != m_multiIndex)
|
|
{
|
|
m_multiIndex = 0;
|
|
|
|
HGImage img = createImage();
|
|
if (nullptr != img)
|
|
{
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_lastPage_triggered()
|
|
{
|
|
if (-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex != m_multiPageCount - 1)
|
|
{
|
|
m_multiIndex = m_multiPageCount - 1;
|
|
|
|
HGImage img = createImage();
|
|
if (nullptr != img)
|
|
{
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = false;
|
|
}
|
|
else
|
|
{
|
|
m_view->clearImage();
|
|
m_wndStatusBar->setMousePosInfo(0, 0);
|
|
m_modify = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_adjust_triggered()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGUInt xDpi = 0;
|
|
HGUInt yDpi = 0;
|
|
HGBase_GetImageDpi(img, &xDpi, &yDpi);
|
|
|
|
Dialog_ImgProc_Adjust dlg(img, this);
|
|
connect(&dlg, SIGNAL(applyToImage(HGImage)), this, SLOT(on_dialog_adjust_applyToImage(HGImage)));
|
|
|
|
HGImage image = NULL;
|
|
if (dlg.exec())
|
|
{
|
|
image = dlg.getAfterImage();
|
|
HGBase_SetImageDpi(image, xDpi, yDpi);
|
|
m_view->addImage(image);
|
|
m_widget_sideBar->setImage(image);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
m_modify = true;
|
|
}
|
|
else
|
|
{
|
|
image = dlg.getBeforeImage();
|
|
HGBase_SetImageDpi(image, xDpi, yDpi);
|
|
m_view->addImage(image);
|
|
m_widget_sideBar->setImage(image);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
}
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
|
|
disconnect(&dlg, SIGNAL(applyToImage(HGImage)), this, SLOT(on_dialog_adjust_applyToImage(HGImage)));
|
|
}
|
|
|
|
void MainWindow::on_act_open_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, tr("Open images"), "", "(*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif)");
|
|
m_thumb->addItems(fileNames);
|
|
}
|
|
|
|
void MainWindow::on_act_insert_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, tr("Insert images"), "", "(*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif)");
|
|
if (-1 != m_currIndex)
|
|
m_thumb->insertItems(fileNames, m_currIndex);
|
|
else
|
|
m_thumb->addItems(fileNames);
|
|
}
|
|
|
|
void MainWindow::on_act_closeFile_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::vector<int> selectIndexs;
|
|
std::vector<QString> selectFileNames;
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(i, &select);
|
|
if (select)
|
|
{
|
|
selectIndexs.push_back(i);
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
selectFileNames.push_back(fileName);
|
|
}
|
|
}
|
|
|
|
if (selectIndexs.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (-1 != m_currIndex)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(m_currIndex, &select);
|
|
if (select)
|
|
{
|
|
startSaveMessageBox(this);
|
|
}
|
|
}
|
|
|
|
m_thumb->removeItems(selectIndexs, HGImgThumb::ThumbRemoveFlag_NULL);
|
|
|
|
std::list<QString>::iterator iter;
|
|
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
|
|
{
|
|
bool find = false;
|
|
for (int i = 0; i < (int)selectFileNames.size(); ++i)
|
|
{
|
|
if (*iter == selectFileNames[i])
|
|
{
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (find)
|
|
{
|
|
iter = m_curBatchFileList.erase(iter);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_closeAll_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
auto_save_info_.index = 0;
|
|
auto_save_info_.path = "";
|
|
m_thumb->getItemCount(&count);
|
|
if (0 == count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
m_thumb->removeAllItems(HGImgThumb::ThumbRemoveFlag_NULL);
|
|
m_curBatchFileList.clear();
|
|
}
|
|
|
|
void MainWindow::on_act_exit_triggered()
|
|
{
|
|
close();
|
|
}
|
|
|
|
void MainWindow::on_act_save_triggered()
|
|
{
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img || -1 == m_currIndex || 1 != m_multiPageCount)
|
|
{
|
|
return;
|
|
}
|
|
|
|
assert(!m_currFilePath.isEmpty());
|
|
if (0 == m_currFilePath.indexOf(Dialog_ClrCache::getCachePath()))
|
|
{
|
|
QString savePath;
|
|
bool isOcr =false;
|
|
if (!auto_save_changes_)
|
|
{
|
|
savePath = auto_save_info_.path;
|
|
isOcr = auto_save_info_.isOcr;
|
|
}
|
|
else
|
|
savePath = m_currFilePath;
|
|
|
|
int jpegQuality = auto_save_info_.jpegQuality;
|
|
int tiffCompressionBW = auto_save_info_.tiffCompressionBW;
|
|
int tiffCompression = auto_save_info_.tiffCompression;
|
|
int tiffQuality = auto_save_info_.tiffQuality;
|
|
bool find = false;
|
|
int count = 0;
|
|
|
|
if(!auto_save_changes_ || auto_save_info_.path.isEmpty())
|
|
{
|
|
Dialog_SaveAs dlg(false, this);
|
|
if(savePath.length())
|
|
{
|
|
int pos = savePath.lastIndexOf('/');
|
|
if(pos > 0)
|
|
dlg.set_current_directory(savePath.left(pos));
|
|
}
|
|
|
|
if (!auto_save_changes_)
|
|
{
|
|
if (!dlg.exec())
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
savePath = m_currFilePath;
|
|
|
|
if (!auto_save_changes_)
|
|
{
|
|
savePath = auto_save_info_.path = dlg.getSavePath();
|
|
isOcr = auto_save_info_.isOcr = dlg.isOcr();
|
|
}
|
|
|
|
jpegQuality = auto_save_info_.jpegQuality = dlg.getJpegQuality();
|
|
tiffQuality = auto_save_info_.tiffQuality = dlg.getTiffQuality();
|
|
tiffCompression = auto_save_info_.tiffCompression = dlg.getTiffCompression();
|
|
tiffCompressionBW = auto_save_info_.tiffCompressionBW = dlg.getTiffCompressionBW();
|
|
}
|
|
if(auto_save_changes_ && save_from_changed_)
|
|
{
|
|
// appendix ...
|
|
int pos = savePath.lastIndexOf('.');
|
|
char index[20] = {0};
|
|
if (!auto_save_changes_)
|
|
{
|
|
sprintf(index, "_%03u", ++auto_save_info_.index);
|
|
}
|
|
|
|
savePath.insert(pos, QString::fromStdString(index));
|
|
m_thumb->notify_mouse_leave();
|
|
}
|
|
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
assert(!fileName.isEmpty());
|
|
|
|
if (!auto_save_changes_)
|
|
{
|
|
if (fileName == savePath)
|
|
{
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (!find)
|
|
{
|
|
HGImgFmtSaveInfo saveInfo;
|
|
saveInfo.jpegQuality = (HGUInt)jpegQuality;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = (HGUInt)tiffQuality;
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
{
|
|
if (1 == tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
|
}
|
|
else
|
|
{
|
|
if (1 == tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
|
}
|
|
|
|
ret = saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str());
|
|
if (HGBASE_ERR_OK == ret)
|
|
{
|
|
if (auto_save_changes_)
|
|
{
|
|
m_thumb->refreshItem(m_currIndex);
|
|
}
|
|
else
|
|
m_thumb->updateItem(m_currIndex, savePath, false);
|
|
|
|
m_currFilePath = savePath;
|
|
m_modify = false;
|
|
if(!auto_save_changes_)
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("save succeed"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::critical(this, tr("tips"), tr("save image doc failed: ") + getLogInfo(ret));
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("save image doc failed: ") + getLogInfo(ret), true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail"));
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
HGUInt fmtType = 0;
|
|
HGImgFmt_GetImgFmtTypeFromFileName(getStdString(m_currFilePath).c_str(), &fmtType);
|
|
if (HGIMGFMT_TYPE_TIFF == fmtType)
|
|
{
|
|
HGUInt compression = HGIMGFMT_TIFFCOMP_LZW;
|
|
|
|
HGTiffReader tiffReader = nullptr;
|
|
HGImgFmt_OpenTiffReader(getStdString(m_currFilePath).c_str(), &tiffReader);
|
|
if (nullptr != tiffReader)
|
|
{
|
|
HGTiffLoadInfo tiffInfo;
|
|
HGImgFmt_LoadImageFromTiffReader(tiffReader, 0, &tiffInfo, 0, 0, nullptr);
|
|
compression = tiffInfo.compression;
|
|
HGImgFmt_CloseTiffReader(tiffReader);
|
|
}
|
|
|
|
HGUInt xDpi, yDpi;
|
|
HGBase_GetImageDpi(img, &xDpi, &yDpi);
|
|
HGTiffSaveInfo tiffInfo;
|
|
tiffInfo.compression = compression;
|
|
tiffInfo.jpegQuality = 80;
|
|
tiffInfo.resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH;
|
|
tiffInfo.xResolution = xDpi;
|
|
tiffInfo.yResolution = yDpi;
|
|
|
|
HGTiffWriter tiffWriter = nullptr;
|
|
ret = HGImgFmt_OpenTiffWriter(getStdString(m_currFilePath).c_str(), &tiffWriter);
|
|
if (HGBASE_ERR_OK == ret)
|
|
{
|
|
ret = HGImgFmt_SaveImageToTiffWriter(tiffWriter, img, &tiffInfo);
|
|
HGImgFmt_CloseTiffWriter(tiffWriter);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ret = HGImgFmt_SaveImage(img, 0, nullptr, getStdString(m_currFilePath).c_str());
|
|
}
|
|
|
|
if (HGBASE_ERR_OK == ret)
|
|
{
|
|
if(auto_save_changes_ && save_from_changed_)
|
|
m_thumb->notify_mouse_leave();
|
|
m_thumb->refreshItem(m_currFilePath);
|
|
m_modify = false;
|
|
updateActionStatus();
|
|
if(!auto_save_changes_)
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("save succeed"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::critical(this, tr("tips"), tr("save image doc failed: ") + getLogInfo(ret));
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("save image doc failed: ") + getLogInfo(ret), true);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_saveAs_triggered()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_SaveAs dlg(true, this);
|
|
if (dlg.exec())
|
|
{
|
|
QString savePath = dlg.getSavePath();
|
|
|
|
bool find = false;
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
assert(!fileName.isEmpty());
|
|
|
|
if (fileName == savePath)
|
|
{
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!find)
|
|
{
|
|
int jpegQuality = dlg.getJpegQuality();
|
|
int tiffCompressionBW = dlg.getTiffCompressionBW();
|
|
int tiffCompression = dlg.getTiffCompression();
|
|
int tiffQuality = dlg.getTiffQuality();
|
|
bool isOcr = dlg.isOcr();
|
|
|
|
HGImgFmtSaveInfo saveInfo;
|
|
saveInfo.jpegQuality = (HGUInt)jpegQuality;
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
|
saveInfo.tiffJpegQuality = (HGUInt)tiffQuality;
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type)
|
|
{
|
|
if (1 == tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == tiffCompressionBW)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
|
}
|
|
else
|
|
{
|
|
if (1 == tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
|
else if (2 == tiffCompression)
|
|
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
|
}
|
|
|
|
HGResult ret = saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str());
|
|
if (HGBASE_ERR_OK == ret)
|
|
{
|
|
if(!auto_save_changes_)
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("save succeed"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::critical(this, tr("tips"), tr("save image doc failed: ") + getLogInfo(ret));
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("save image doc failed: ") + getLogInfo(ret), true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail"));
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_Export_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (0 == count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::vector<int> selectIndexs;
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(i, &select);
|
|
if (select)
|
|
selectIndexs.push_back(i);
|
|
}
|
|
if (selectIndexs.size() == 0)
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("Please select at least one picture before export"));
|
|
return;
|
|
}
|
|
|
|
Dialog_Export dlg(count, selectIndexs, this);
|
|
if (dlg.exec())
|
|
{
|
|
QStringList srcFiles;
|
|
|
|
std::vector<int> saveIndexs;
|
|
dlg.getSaveIndexs(saveIndexs);
|
|
for (size_t i = 0; i < saveIndexs.size(); ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(saveIndexs[i], fileName);
|
|
srcFiles.append(fileName);
|
|
}
|
|
|
|
if (!srcFiles.isEmpty())
|
|
{
|
|
QString savePath = dlg.getSavePath();
|
|
QString saveName = dlg.getSaveName();
|
|
QString saveExt = dlg.getSaveExt();
|
|
bool isSaveAsMulti = dlg.isSaveAsMultiPage();
|
|
int jpegQuality = dlg.getJpegQuality();
|
|
int tiffCompressionBW = dlg.getTiffCompressionBW();
|
|
int tiffCompression = dlg.getTiffCompression();
|
|
int tiffQuality = dlg.getTiffQuality();
|
|
bool isOcr = dlg.isOcr();
|
|
|
|
Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality,
|
|
tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this);
|
|
dlgExport.exec();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_imageInfo_triggered()
|
|
{
|
|
if (-1 == m_currIndex)
|
|
{
|
|
return;
|
|
}
|
|
|
|
assert(!m_currFilePath.isEmpty());
|
|
QFileInfo info(m_currFilePath);
|
|
|
|
HGImage image = NULL;
|
|
m_view->getImage(&image);
|
|
if (nullptr == image)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(image, &imgInfo);
|
|
|
|
HGUInt xDpi, yDpi;
|
|
HGBase_GetImageDpi(image, &xDpi, &yDpi);
|
|
|
|
QStringList fileKeys;
|
|
fileKeys << tr("File name") << tr("File path") << tr("File size") << tr("Creation date/time") << tr("Modified date/time") << tr("Accessed date/time");
|
|
|
|
QStringList fileValues;
|
|
fileValues.append(info.completeBaseName());//add Filename
|
|
fileValues.append(info.absoluteFilePath());//add Filepath
|
|
qint64 size_B = info.size();
|
|
QDateTime c_date = info.created();
|
|
QString createTime = c_date.toString("yyyy-MM-dd hh:mm:ss");
|
|
fileValues.append(createTime);//add File created time
|
|
QDateTime m_date = info.lastModified();
|
|
QString modifiedTime = m_date.toString("yyyy-MM-dd hh:mm:ss");
|
|
fileValues.append(modifiedTime);//add File modified time
|
|
QDateTime r_date = info.lastRead();
|
|
QString accessTime = r_date.toString("yyyy-MM-dd hh:mm:ss");
|
|
fileValues.append(accessTime);//add File access time
|
|
|
|
double s = size_B;
|
|
int unit = 0;
|
|
while (true)
|
|
{
|
|
if (s > 1024.0)
|
|
{
|
|
s /= 1024.0;
|
|
unit += 1;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
QString unitstring = unit == 3 ? "GB" : (unit == 2 ? "MB" : (unit == 1 ? "KB" : "B"));
|
|
QString sstring = QString::number(s, 'f', 2);
|
|
QString Bstring = QString::number(size_B);
|
|
int commaNum = Bstring.size() / 3;
|
|
if (Bstring.size() % 3 == 0)
|
|
commaNum -= 1;
|
|
int offset = 0;
|
|
for (int i = 0; i < commaNum; i++)
|
|
{
|
|
Bstring.insert(Bstring.size() - 3 - offset * 4, ",");
|
|
offset += 1;
|
|
}
|
|
fileValues.insert(2, sstring + " " + unitstring + " (" + Bstring + ")");//add Filesize
|
|
|
|
QStringList imageKeys;
|
|
imageKeys << tr("Format") << tr("Width") << tr("Height") << tr("depth") << tr("Color model") << tr("DPI") << tr("Print size") << tr("Frame");
|
|
QStringList imageValues;
|
|
imageValues.append(info.suffix());//add image format
|
|
imageValues.append(QString::number(imgInfo.width));//add image width
|
|
imageValues.append(QString::number(imgInfo.height));//add image height
|
|
|
|
int depth = 1;
|
|
if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
|
depth = 8;
|
|
else if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_RGB == imgInfo.type)
|
|
depth = 24;
|
|
else if (HGBASE_IMGTYPE_BGRA == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type)
|
|
depth = 32;
|
|
imageValues.append(QString::number(depth));//add image depth
|
|
imageValues.append(depth == 0 ? tr("None") : (depth == 1 ? tr("Mono") : (depth == 8 ? tr("Gray") : tr("Color"))));//add image color
|
|
|
|
HGUInt imgFmtType = 0;
|
|
HGImgFmt_GetImgFmtType(m_currFilePath.toLocal8Bit().toStdString().c_str(), &imgFmtType);
|
|
if (HGIMGFMT_TYPE_PDF == imgFmtType || HGIMGFMT_TYPE_GIF == imgFmtType
|
|
|| HGIMGFMT_TYPE_PNM == imgFmtType)
|
|
{
|
|
QString info = tr("Not supported");
|
|
imageValues.append(info);
|
|
imageValues.append(info);
|
|
}
|
|
else
|
|
{
|
|
QString dpi = QString::number(xDpi) + " x " + QString::number(yDpi);
|
|
imageValues.append(dpi);//add image dpi
|
|
|
|
double cm_x = (0 == xDpi) ? 0 : 2.54 * imgInfo.width / xDpi;
|
|
double cm_y = (0 == yDpi) ? 0 : 2.54 * imgInfo.height / yDpi;
|
|
QString cm_printsize = QString::number(cm_x, 'f', 2) + " x " + QString::number(cm_y, 'f', 2) + " cm";
|
|
double inch_x = cm_x / 2.54;
|
|
double inch_y = cm_y / 2.54;
|
|
QString inch_printsize = QString::number(inch_x, 'f', 2) + " x " + QString::number(inch_y, 'f', 2) + " inches";
|
|
imageValues.append(cm_printsize + ", " + inch_printsize);//add image print size
|
|
}
|
|
imageValues.append(QString::number(m_multiIndex));
|
|
|
|
Dialog_ImageInfo d(fileKeys, fileValues, imageKeys, imageValues, this);
|
|
d.exec();
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *e)
|
|
{
|
|
if (!m_canClose)
|
|
{
|
|
e->ignore();
|
|
return;
|
|
}
|
|
|
|
if (m_isScanning)
|
|
{
|
|
m_closeTip = true;
|
|
QMessageBox::warning(this, tr("Warning"), tr("Device is Running!\nPlease finish scanning first."));
|
|
e->ignore();
|
|
return;
|
|
}
|
|
|
|
bool cache_saved = true;
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath()))
|
|
{
|
|
cache_saved = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(m_closeTip)
|
|
{
|
|
if (!cache_saved || m_modify)
|
|
{
|
|
QMessageBox msg(QMessageBox::Question, tr("Question"),
|
|
tr("There are pictures that have not been saved.\nAre you sure to close?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
|
|
{
|
|
e->ignore();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox msg(QMessageBox::Question, tr("tips"),
|
|
tr("Are you sure to close?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
|
|
{
|
|
e->ignore();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
QString cachePath = Dialog_ClrCache::getCachePath();
|
|
QDir dir = QDir(cachePath);
|
|
if (dir.exists() && (cachePath.endsWith("Cache/") || cachePath.endsWith("Cache\\")))
|
|
dir.removeRecursively();
|
|
|
|
m_versionDll->PostUserCloseInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
|
|
}
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *e)
|
|
{
|
|
(void)e;
|
|
|
|
if (m_bSideflag)
|
|
{
|
|
int mainWndWidth = this->rect().width();
|
|
int mainWndHeight = this->rect().height();
|
|
int sideBarWidth = m_widget_sideBar->width();
|
|
int sideBarHeight = m_widget_sideBar->height();
|
|
|
|
m_widget_sideBar->move(mainWndWidth - sideBarWidth, mainWndHeight/2 - sideBarHeight/2);
|
|
m_pbtn_push->move(mainWndWidth - m_pbtn_push->width() - sideBarWidth, mainWndHeight/2 - m_pbtn_push->height()/2);
|
|
}
|
|
else
|
|
{
|
|
updateSideBar();
|
|
}
|
|
}
|
|
|
|
void HGAPI MainWindow::CrashFunc(HGPointer crashAddr, HGPointer param)
|
|
{
|
|
MainWindow *p = (MainWindow *)param;
|
|
|
|
|
|
HGChar crashName[256];
|
|
HGBase_GetLogFilePath(crashName, 256);
|
|
strcat(crashName, "crash.dmp");
|
|
if (HGBASE_ERR_OK == HGBase_MakeCrashFile(crashName))
|
|
{
|
|
HGChar excpStr[64];
|
|
#ifdef HG_64BIT
|
|
sprintf(excpStr, "0x%016p", crashAddr);
|
|
#else
|
|
sprintf(excpStr, "0x%08p", crashAddr);
|
|
#endif
|
|
|
|
p->m_versionDll->PostCrashInfo(HGVERSION_APPNAME_SCANNER, p->m_oemName, "crash", crashName, excpStr);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_multiRotate_triggered()
|
|
{
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (0 == count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_MultiRotate dlg(this);
|
|
if (dlg.exec())
|
|
{
|
|
int rotateType = dlg.getRotateType();
|
|
int rotatePageType = dlg.getRotatePageType();
|
|
|
|
QStringList fileList;
|
|
switch (rotatePageType)
|
|
{
|
|
case 0:
|
|
{
|
|
if (-1 != m_currIndex)
|
|
{
|
|
assert(!m_currFilePath.isEmpty());
|
|
fileList.append(m_currFilePath);
|
|
}
|
|
}
|
|
break;
|
|
case 1:
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool selected = false;
|
|
m_thumb->itemIsSelect(i, &selected);
|
|
if (selected)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileList.append(fileName);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
if ((i + 1) % 2 != 0)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileList.append(fileName);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 3:
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
if ((i + 1) % 2 == 0)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileList.append(fileName);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 4:
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
fileList.append(fileName);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (!fileList.isEmpty())
|
|
{
|
|
Dialog_MultiRotateImageFile processDlg(fileList, rotateType, this);
|
|
connect(&processDlg, SIGNAL(refreshImageFile(const QString &)), this, SLOT(on_dialog_multirotate_refreshImgFile(const QString &)));
|
|
processDlg.exec();
|
|
disconnect(&processDlg, SIGNAL(refreshImageFile(const QString &)), this, SLOT(on_dialog_multirotate_refreshImgFile(const QString &)));
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_autoCrop_triggered()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGUInt xDpi = 0;
|
|
HGUInt yDpi = 0;
|
|
HGBase_GetImageDpi(img, &xDpi, &yDpi);
|
|
|
|
Dialog_ImgProc_AutoCrop dlg(this);
|
|
if (dlg.exec())
|
|
{
|
|
bool isCrop = dlg.isCrop();
|
|
bool isDeskew = dlg.isDeskew();
|
|
bool isFillBlank = dlg.isFillBlank();
|
|
bool isConvex = dlg.isConvex();
|
|
bool isAutoColor = dlg.isAutoColor();
|
|
bool isUseAdvParam = dlg.isUseAdvancedParam();
|
|
int threshold = dlg.getThreshold();
|
|
int noise = dlg.getNoise();
|
|
int indent = dlg.getIndent();
|
|
|
|
HGImgAutoCropParam autoCropParam;
|
|
autoCropParam.normalCrop = HGFALSE;
|
|
autoCropParam.dispersion = HGTRUE;
|
|
|
|
if (isFillBlank)
|
|
{
|
|
autoCropParam.convex = (HGBool)isConvex;
|
|
autoCropParam.fillColor = (HGBool)isAutoColor;
|
|
}
|
|
else
|
|
{
|
|
autoCropParam.convex = HGTRUE;
|
|
autoCropParam.fillColor = HGFALSE;
|
|
}
|
|
|
|
if (isUseAdvParam)
|
|
{
|
|
autoCropParam.threshold = threshold;
|
|
autoCropParam.noise = noise;
|
|
autoCropParam.indent = indent;
|
|
}
|
|
else
|
|
{
|
|
autoCropParam.threshold = 40.0;
|
|
autoCropParam.noise = 8;
|
|
autoCropParam.indent = 5;
|
|
}
|
|
|
|
if (isCrop || isDeskew || isFillBlank)
|
|
{
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
|
|
HGImage destImage = nullptr;
|
|
HGUInt destWidth = imgInfo.width;
|
|
HGUInt destHeight = imgInfo.height;
|
|
|
|
HGImgProc_ImageAutoCrop(img, (HGBool)isCrop, (HGBool)isDeskew, (HGBool)isFillBlank, &autoCropParam, destWidth, destHeight,
|
|
imgInfo.type, HGBASE_IMGORIGIN_TOP, &destImage);
|
|
if (nullptr != destImage)
|
|
{
|
|
HGBase_SetImageDpi(destImage, xDpi, yDpi);
|
|
m_view->addImage(destImage);
|
|
m_widget_sideBar->setImage(destImage);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(destImage);
|
|
m_modify = true;
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_signIn_triggered()
|
|
{
|
|
if (m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_Admin dlg(m_password, this);
|
|
m_admin_loggedIn = dlg.exec();
|
|
updateActionStatus();
|
|
if (m_admin_loggedIn)
|
|
{
|
|
if (m_devUser != nullptr)
|
|
{
|
|
m_devUser->Login();
|
|
}
|
|
m_versionDll->PostUserLoginInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_passwordChange_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_PasswordChange dlg(m_password, this);
|
|
if (dlg.exec())
|
|
{
|
|
m_password = dlg.getNewPassword();
|
|
saveCfgValue("login", "password", passwordEncrypt(m_password));
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_signOut_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_devUser != nullptr)
|
|
{
|
|
m_devUser->Logout();
|
|
}
|
|
|
|
QMessageBox msg(QMessageBox::Question, tr("Question"),
|
|
tr("Sure to sign out administrator account?"), QMessageBox::Yes | QMessageBox::No);
|
|
msg.exec();
|
|
if(msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
{
|
|
m_admin_loggedIn = false;
|
|
updateActionStatus();
|
|
m_versionDll->PostUserLogoutInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_log_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_LogManager d(this);
|
|
d.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
d.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_clrCache_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_ClrCache dlg(this);
|
|
dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
connect(&dlg, SIGNAL(clearCache()), this, SLOT(on_clearCache()));
|
|
dlg.exec();
|
|
disconnect(&dlg, SIGNAL(clearCache()), this, SLOT(on_clearCache()));
|
|
}
|
|
|
|
void MainWindow::on_act_consume_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_clearRoller_triggered()
|
|
{
|
|
if (!m_admin_loggedIn)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QMessageBox msg(QMessageBox::Question, tr("confirm operation"),
|
|
tr("are you sure to clear the roller count?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if(msg.clickedButton() != msg.button(QMessageBox::Yes))
|
|
return;
|
|
|
|
if (m_devUser != nullptr)
|
|
{
|
|
HGResult ret = m_devUser->ClearRollerCount();
|
|
if(ret == HGBASE_ERR_OK)
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("Roller scanned count has been set to 0."));
|
|
// m_versionDll->PostDeviceClearRollerInfo();
|
|
}
|
|
else
|
|
QMessageBox::information(this, tr("tips"), tr("Roller scanned count reset failed."));
|
|
}
|
|
}
|
|
|
|
static std::string GetOSName()
|
|
{
|
|
std::string osName;
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
osName = "Windows";
|
|
#else
|
|
osName = "Linux";
|
|
FILE* fp = popen("cat /etc/issue | cut -d\' \' -f1", "r");
|
|
if (NULL != fp)
|
|
{
|
|
char buff[1024] = { 0 };
|
|
fread(buff, 1024, 1, fp);
|
|
|
|
int len = (int)strlen(buff);
|
|
for (int i = 0; i < len; ++i)
|
|
{
|
|
if (buff[i] == '\n')
|
|
buff[i] = '\0';
|
|
}
|
|
|
|
osName = buff;
|
|
pclose(fp);
|
|
}
|
|
#endif
|
|
|
|
return osName;
|
|
}
|
|
|
|
void MainWindow::on_act_help_triggered()
|
|
{
|
|
QString filename;
|
|
#if defined(HG_CMP_MSC)
|
|
#if defined(OEM_HANWANG)
|
|
filename = QApplication::applicationDirPath() + "/HanvonScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_LISICHENG)
|
|
filename = QApplication::applicationDirPath() + "/LanxumScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_CANGTIAN)
|
|
filename = QApplication::applicationDirPath() + "/CumtennScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_ZHONGJING)
|
|
filename = QApplication::applicationDirPath() + "/MicrotekScan_App_Help_manual.pdf";
|
|
if (m_currLang == "english")
|
|
filename = QApplication::applicationDirPath() + "/MicrotekScan_App_Help_manual_EN.pdf";
|
|
#elif defined(OEM_ZIGUANG)
|
|
filename = QApplication::applicationDirPath() + "/UniScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_NEUTRAL)
|
|
filename = QApplication::applicationDirPath() + "/NeuScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_DELI)
|
|
filename = QApplication::applicationDirPath() + "/DeliScan_App_Help_manual.pdf";
|
|
#else
|
|
filename = QApplication::applicationDirPath() + "/HuaGoScan_App_Help_manual.pdf";
|
|
#endif
|
|
#else
|
|
std::string osName = GetOSName();
|
|
if ("UnionTech" == osName)
|
|
{
|
|
#if defined(OEM_HANWANG)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/HanvonScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_LISICHENG)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/LanxumScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_CANGTIAN)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/CumtennScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_ZHONGJING)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/MicrotekScan_App_Help_manual.pdf";
|
|
if (m_currLang == "english")
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/MicrotekScan_App_Help_manual_EN.pdf";
|
|
#elif defined(OEM_ZIGUANG)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/UniScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_NEUTRAL)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/NeuScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_DELI)
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/DeliScan_App_Help_manual.pdf";
|
|
#else
|
|
filename = QApplication::applicationDirPath() + "/../../entries/help/HuaGoScan_App_Help_manual.pdf";
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#if defined(OEM_HANWANG)
|
|
filename = QApplication::applicationDirPath() + "/../doc/HanvonScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_LISICHENG)
|
|
filename = QApplication::applicationDirPath() + "/../doc/LanxumScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_CANGTIAN)
|
|
filename = QApplication::applicationDirPath() + "/../doc/CumtennScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_ZHONGJING)
|
|
filename = QApplication::applicationDirPath() + "/../doc/MicrotekScan_App_Help_manual.pdf";
|
|
if (m_currLang == "english")
|
|
filename = QApplication::applicationDirPath() + "/../doc/MicrotekScan_App_Help_manual_EN.pdf";
|
|
#elif defined(OEM_ZIGUANG)
|
|
filename = QApplication::applicationDirPath() + "/../doc/UniScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_NEUTRAL)
|
|
filename = QApplication::applicationDirPath() + "/../doc/NeuScan_App_Help_manual.pdf";
|
|
#elif defined(OEM_DELI)
|
|
filename = QApplication::applicationDirPath() + "/../doc/DeliScan_App_Help_manual.pdf";
|
|
#else
|
|
filename = QApplication::applicationDirPath() + "/../doc/HuaGoScan_App_Help_manual.pdf";
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
QFileInfo info(filename);
|
|
if (!info.exists())
|
|
QMessageBox::warning(this, tr("Error"), tr("Document missing! It would be deleted or renamed."));
|
|
else
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
|
|
}
|
|
|
|
static bool isLeap(int year)
|
|
{
|
|
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static int getDays(int year, int month)
|
|
{
|
|
if (2 == month)
|
|
{
|
|
if (isLeap(year))
|
|
return 29;
|
|
else
|
|
return 28;
|
|
}
|
|
|
|
if (4 == month || 6 == month || 9 == month || 11 == month)
|
|
{
|
|
return 30;
|
|
}
|
|
|
|
return 31;
|
|
}
|
|
|
|
static int getPatchVersion()
|
|
{
|
|
const char *buildDate = __DATE__;
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "buildDate: %s", buildDate);
|
|
QDate date = QLocale(QLocale::English).toDate(QString(buildDate).replace(" ", " 0"), "MMM dd yyyy");
|
|
int year = date.year();
|
|
int day = date.day();
|
|
int month = date.month();
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "buildDate: %d %d %d", year, month, day);
|
|
|
|
int ret = year % 100;
|
|
ret *= 1000;
|
|
|
|
for (int i = 1; i < month; ++i)
|
|
{
|
|
ret += getDays(year, i);
|
|
}
|
|
|
|
ret += day;
|
|
return ret;
|
|
}
|
|
|
|
void MainWindow::on_act_about_triggered()
|
|
{
|
|
int mainVersion = VERSION_MAIN;
|
|
int subVersion = VERSION_SUB;
|
|
int buildVersion = 10;
|
|
int patchVersion = 0;
|
|
|
|
|
|
#if defined (OEM_LISICHENG)
|
|
buildVersion = 14;
|
|
#elif defined (OEM_HANWNAG)
|
|
buildVersion = 16;
|
|
#elif defined (OEM_CANGTIAN)
|
|
buildVersion = 18;
|
|
#elif defined (OEM_ZHONGJING)
|
|
buildVersion = 20;
|
|
#elif defined (OEM_ZIGUANG)
|
|
buildVersion = 22;
|
|
#elif defined (OEM_DELI)
|
|
buildVersion = 24;
|
|
#elif defined (OEM_NEUTRAL)
|
|
buildVersion = 26;
|
|
#endif
|
|
|
|
buildVersion = buildVersion * 10;
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
#if defined(_WIN64)
|
|
buildVersion += 1;
|
|
#else
|
|
buildVersion += 0;
|
|
#endif
|
|
#else
|
|
#if defined (x86_64)
|
|
buildVersion += 5;
|
|
#elif defined (aarch64)
|
|
buildVersion += 2;
|
|
#elif defined (mips64)
|
|
buildVersion += 3;
|
|
#elif defined (loongarch64)
|
|
buildVersion += 4;
|
|
#endif
|
|
#endif
|
|
|
|
buildVersion *= 100;
|
|
|
|
#if !defined(HG_CMP_MSC)
|
|
std::string osName = GetOSName();
|
|
if ("UnionTech" == osName)
|
|
{
|
|
buildVersion += 20;
|
|
}
|
|
else if ("Kylin" == osName)
|
|
{
|
|
buildVersion += 21;
|
|
}
|
|
else
|
|
{
|
|
buildVersion += 10;
|
|
}
|
|
#endif
|
|
|
|
patchVersion = getPatchVersion();
|
|
|
|
HGChar version[32] = { 0 };
|
|
sprintf(version, "%d.%d.%d.%d", mainVersion, subVersion, buildVersion, patchVersion);
|
|
|
|
QString title = tr("about %1").arg(windowTitle());
|
|
QString content;
|
|
content += tr("<p>DriverVer: %1</p>").arg(QString::fromLocal8Bit(version));
|
|
|
|
#if defined(OEM_NEUTRAL)
|
|
QMessageBox::about(this, title, content);
|
|
#else
|
|
|
|
#if defined(OEM_ZHONGJING)
|
|
QString appLang = getCfgValue("global", "language", QString("chinese"));
|
|
if (appLang == "chinese")
|
|
{
|
|
content += tr("<p>Vendor: %1</p>").arg(QString::fromLocal8Bit(COMPANY_NAME));
|
|
content += tr("<p>Company address: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_ADDRESS));
|
|
content += tr("<p>Company telephone: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_TEL));
|
|
content += tr("<p>Company website: <a href=\"%1\">%1</a></p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_URL));
|
|
content += tr("<p>Copyright: %1</p>").arg(QString::fromLocal8Bit(BRAND_COPYRIGHT));
|
|
}
|
|
else if(appLang == "english")
|
|
{
|
|
content += tr("<p>Vendor: %1</p>").arg(QString::fromLocal8Bit(COMPANY_NAME_EN));
|
|
content += tr("<p>Company address: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_ADDRESS_EN));
|
|
content += tr("<p>Company telephone: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_TEL_EN));
|
|
content += tr("<p>Company website: <a href=\"%1\">%1</a></p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_URL));
|
|
content += tr("<p>Copyright: %1</p>").arg(QString::fromLocal8Bit(BRAND_COPYRIGHT_EN));
|
|
}
|
|
#else
|
|
content += tr("<p>Vendor: %1</p>").arg(QString::fromLocal8Bit(COMPANY_NAME));
|
|
content += tr("<p>Copyright: %1</p>").arg(QString::fromLocal8Bit(BRAND_COPYRIGHT));
|
|
content += tr("<p>Company website: <a href=\"%1\">%1</a></p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_URL));
|
|
content += tr("<p>Company address: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_ADDRESS));
|
|
content += tr("<p>Company telephone: %1</p>").arg(QString::fromLocal8Bit(BRAND_COMPANY_TEL));
|
|
content += tr("<p>Company GPS: <a href=\"%1\">%2</a></p>").arg(QString::fromLocal8Bit(BRAND_URL_GPS)).arg(tr("Baidu map access"));
|
|
#endif
|
|
|
|
QMessageBox::about(this, title, content);
|
|
|
|
#endif
|
|
}
|
|
|
|
void MainWindow::on_act_scannerSettings_triggered()
|
|
{
|
|
if (nullptr == m_devUser)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGResult ret = m_devUser->ShowSettingDlg();
|
|
bool deviceIsOnline = true;
|
|
bool openSucceed = true;
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
if (HGTWAIN_ERR_DEVICEOFFLINE == ret)
|
|
deviceIsOnline = false;
|
|
else if (HGTWAIN_ERR_FAIL == ret)
|
|
openSucceed = false;
|
|
#else
|
|
if (HGSANE_ERR_DEVICEOFFLINE == ret)
|
|
deviceIsOnline = false;
|
|
else if (HGSANE_ERR_FAIL == ret)
|
|
openSucceed = false;
|
|
#endif
|
|
|
|
if (!deviceIsOnline)
|
|
{
|
|
QMessageBox::information(this, tr("Prompt"), tr("Device is offline"));
|
|
deleteDevUser();
|
|
}
|
|
else if (!openSucceed)
|
|
{
|
|
QMessageBox::information(this, tr("Prompt"), tr("Open failed"));
|
|
deleteDevUser();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_acquire_triggered()
|
|
{
|
|
if(!isLimitAccessFolder(1))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!judgeDiskSpace(Dialog_ClrCache::getCachePath()))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count != 0)
|
|
{
|
|
int result = startScanMessageBox(this);
|
|
if (cancelScan == result)
|
|
return;
|
|
}
|
|
|
|
m_scanType = ScanType_ScanToCache;
|
|
m_scanInsertPos = -1;
|
|
m_scanCurIndex = -1;
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
if (nullptr != m_devUser)
|
|
{
|
|
ret = m_devUser->StartScan();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_acquireSingle_triggered()
|
|
{
|
|
if(!isLimitAccessFolder(1))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count != 0)
|
|
{
|
|
int result = startScanMessageBox(this);
|
|
if (cancelScan == result)
|
|
return;
|
|
}
|
|
|
|
m_scanType = ScanType_SingleScanToCache;
|
|
m_scanInsertPos = -1;
|
|
m_scanCurIndex = -1;
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
if (nullptr != m_devUser)
|
|
{
|
|
ret = m_devUser->StartSingleScan();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_acquireInto_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
if (count != 0)
|
|
{
|
|
int result = startScanMessageBox(this);
|
|
if (cancelScan == result)
|
|
return;
|
|
}
|
|
|
|
Dialog_AquireInto dlg(m_aquireIntoSaveParam.m_fileNameStartIndex, this);
|
|
connect(&dlg, SIGNAL(reloadAcquireIntoCfg()), this, SLOT(on_reloadAcquireIntoCfg()));
|
|
if (dlg.exec())
|
|
{
|
|
m_scanType = ScanType_ScanInto;
|
|
m_scanInsertPos = -1;
|
|
m_scanCurIndex = -1;
|
|
|
|
m_aquireIntoSaveParam = dlg.getSaveParam();
|
|
m_aquireIntoInBlank = true;
|
|
m_aquireIntoBatchStartIndex = 0;
|
|
m_aquireIntoPageIndex = 0;
|
|
m_aquireIntoMultiPageCount = 0;
|
|
|
|
QDateTime dateTime = QDateTime::currentDateTime();
|
|
if (m_aquireIntoSaveParam.m_isUseSubfolderByTime)
|
|
{
|
|
m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyy-MM-dd") + "/");
|
|
}
|
|
|
|
if(!isLimitAccessFolder(2))
|
|
{
|
|
return;
|
|
}
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
if (nullptr != m_devUser)
|
|
{
|
|
ret = m_devUser->StartScan();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_insertFromScanner_triggered()
|
|
{
|
|
if(!isLimitAccessFolder(1))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_InsertIndex dlg(this);
|
|
if (dlg.exec())
|
|
{
|
|
m_scanType = ScanType_InsertScanInto;
|
|
m_scanInsertPos = -1;
|
|
m_scanCurIndex = -1;
|
|
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
switch (dlg.selectedLocation())
|
|
{
|
|
case 0:
|
|
if (count > 0)
|
|
m_scanInsertPos = 0;
|
|
break;
|
|
case 1:
|
|
if (-1 != m_currIndex)
|
|
m_scanInsertPos = m_currIndex;
|
|
break;
|
|
case 2:
|
|
if (-1 != m_currIndex && m_currIndex + 1 < count)
|
|
m_scanInsertPos = m_currIndex + 1;
|
|
break;
|
|
}
|
|
|
|
Dialog_AquireInto dlg2(-1, this);
|
|
m_aquireIntoSaveParam = dlg2.getSaveParam();
|
|
m_aquireIntoInBlank = true;
|
|
m_aquireIntoBatchStartIndex = 0;
|
|
m_aquireIntoPageIndex = 0;
|
|
m_aquireIntoMultiPageCount = 0;
|
|
|
|
QDateTime dateTime = QDateTime::currentDateTime();
|
|
if (m_aquireIntoSaveParam.m_isUseSubfolderByTime)
|
|
{
|
|
m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyy-MM-dd") + "/");
|
|
}
|
|
|
|
if(!isLimitAccessFolder(2))
|
|
{
|
|
return;
|
|
}
|
|
|
|
startSaveMessageBox(this);
|
|
|
|
HGResult ret = HGBASE_ERR_FAIL;
|
|
if (nullptr != m_devUser)
|
|
{
|
|
ret = m_devUser->StartScan();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_act_imageEdit_triggered()
|
|
{
|
|
HGImage img = nullptr;
|
|
m_view->getImage(&img);
|
|
if (nullptr == img)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGUInt xDpi = 0;
|
|
HGUInt yDpi = 0;
|
|
HGBase_GetImageDpi(img, &xDpi, &yDpi);
|
|
|
|
HGImageInfo info;
|
|
HGBase_GetImageInfo(img, &info);
|
|
|
|
QImage::Format fmt = QImage::Format_Invalid;
|
|
if (info.type == HGBASE_IMGTYPE_BINARY)
|
|
fmt = QImage::Format_Mono;
|
|
else if (info.type == HGBASE_IMGTYPE_GRAY)
|
|
fmt = QImage::Format_Grayscale8;
|
|
else if (info.type == HGBASE_IMGTYPE_RGB)
|
|
fmt = QImage::Format_RGB888;
|
|
else if (info.type == HGBASE_IMGTYPE_RGBA)
|
|
fmt = QImage::Format_RGBA8888;
|
|
if (QImage::Format_Invalid == fmt)
|
|
{
|
|
return;
|
|
}
|
|
|
|
HGByte *data = nullptr;
|
|
HGBase_GetImageData(img, &data);
|
|
QImage image(data, (int)info.width, (int)info.height, (int)info.widthStep, fmt);
|
|
if (image.isNull())
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dialog_ImageEditor dlg(this);
|
|
dlg.setImage(image);
|
|
if (dlg.exec())
|
|
{
|
|
QImage image = dlg.exportImage();
|
|
if (!image.isNull())
|
|
{
|
|
info.width = (HGUInt)image.width();
|
|
info.height = (HGUInt)image.height();
|
|
info.type = 0;
|
|
if (QImage::Format_Mono == image.format())
|
|
info.type = HGBASE_IMGTYPE_BINARY;
|
|
else if (QImage::Format_Grayscale8 == image.format())
|
|
info.type = HGBASE_IMGTYPE_GRAY;
|
|
else if (QImage::Format_RGB888 == image.format())
|
|
info.type = HGBASE_IMGTYPE_RGB;
|
|
else if (QImage::Format_RGBA8888 == image.format())
|
|
info.type = HGBASE_IMGTYPE_RGBA;
|
|
info.widthStep = (HGUInt)image.bytesPerLine();
|
|
info.origin = HGBASE_IMGORIGIN_TOP;
|
|
|
|
HGImage img = nullptr;
|
|
HGBase_CreateImageWithData((HGByte *)image.bits(), &info, &img);
|
|
if (nullptr != img)
|
|
{
|
|
HGBase_SetImageDpi(img, xDpi, yDpi);
|
|
m_view->addImage(img);
|
|
m_widget_sideBar->setImage(img);
|
|
m_widget_sideBar->enableUI(false);
|
|
m_bSideEditing = false;
|
|
HGBase_DestroyImage(img);
|
|
m_modify = true;
|
|
|
|
updateStatusBarPixelInfo();
|
|
updateActionStatus();
|
|
|
|
if (auto_save_changes_)
|
|
{
|
|
on_act_save_triggered();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool MainWindow::judgeDiskSpace(QString currentPath)
|
|
{
|
|
QStorageInfo storage = QStorageInfo::root();
|
|
storage.refresh();
|
|
storage.device();
|
|
storage.setPath(currentPath);
|
|
|
|
qint64 available_size = 0;
|
|
available_size = storage.bytesAvailable()/1024/1024;
|
|
if(available_size < 1024)
|
|
{
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "disk space is unsufficient!");
|
|
QMessageBox msg(QMessageBox::Warning, tr("tips"), tr("Detected that there is less than 1GB of disk space. Do you want to continue?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::upgradeApp(QString pkgPath)
|
|
{
|
|
HGChar moduleName[256];
|
|
HGBase_GetModuleName(nullptr, moduleName, 256);
|
|
HGChar curPath2[256];
|
|
HGBase_GetFilePath(moduleName, curPath2, 256);
|
|
QString curPath(curPath2);
|
|
HGChar tmpPath2[256];
|
|
HGBase_GetTmpPath(tmpPath2, 256);
|
|
QString tmpPath(tmpPath2);
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
// #if defined(OEM_HANWANG)
|
|
// QFile::remove(tmpPath + "HwUpgradeApp.exe");
|
|
// QFile::copy(curPath + "HwUpgradeApp.exe", tmpPath + "HwUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "HwBase.dll");
|
|
// QFile::copy(curPath + "HwBase.dll", tmpPath + "HwBase.dll");
|
|
// QFile::remove(tmpPath + "HwVersion.dll");
|
|
// QFile::copy(curPath + "HwVersion.dll", tmpPath + "HwVersion.dll");
|
|
// #elif defined(OEM_LISICHENG)
|
|
// QFile::remove(tmpPath + "LscUpgradeApp.exe");
|
|
// QFile::copy(curPath + "LscUpgradeApp.exe", tmpPath + "LscUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "LscBase.dll");
|
|
// QFile::copy(curPath + "LscBase.dll", tmpPath + "LscBase.dll");
|
|
// QFile::remove(tmpPath + "LscVersion.dll");
|
|
// QFile::copy(curPath + "LscVersion.dll", tmpPath + "LscVersion.dll");
|
|
// #elif defined(OEM_CANGTIAN)
|
|
// QFile::remove(tmpPath + "CtsUpgradeApp.exe");
|
|
// QFile::copy(curPath + "CtsUpgradeApp.exe", tmpPath + "CtsUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "CtsBase.dll");
|
|
// QFile::copy(curPath + "CtsBase.dll", tmpPath + "CtsBase.dll");
|
|
// QFile::remove(tmpPath + "CtsVersion.dll");
|
|
// QFile::copy(curPath + "CtsVersion.dll", tmpPath + "CtsVersion.dll");
|
|
// #elif defined(OEM_ZHONGJING)
|
|
// QFile::remove(tmpPath + "ZJUpgradeApp.exe");
|
|
// QFile::copy(curPath + "ZJUpgradeApp.exe", tmpPath + "ZJUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "ZJBase.dll");
|
|
// QFile::copy(curPath + "ZJBase.dll", tmpPath + "ZJBase.dll");
|
|
// QFile::remove(tmpPath + "ZJVersion.dll");
|
|
// QFile::copy(curPath + "ZJVersion.dll", tmpPath + "ZJVersion.dll");
|
|
// #elif defined(OEM_ZIGUANG)
|
|
// QFile::remove(tmpPath + "ZGUpgradeApp.exe");
|
|
// QFile::copy(curPath + "ZGUpgradeApp.exe", tmpPath + "ZGUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "ZGBase.dll");
|
|
// QFile::copy(curPath + "ZGBase.dll", tmpPath + "ZGBase.dll");
|
|
// QFile::remove(tmpPath + "ZGVersion.dll");
|
|
// QFile::copy(curPath + "ZGVersion.dll", tmpPath + "ZGVersion.dll");
|
|
// #elif defined(OEM_DELI)
|
|
// QFile::remove(tmpPath + "DLUpgradeApp.exe");
|
|
// QFile::copy(curPath + "DLUpgradeApp.exe", tmpPath + "DLUpgradeApp.exe");
|
|
// QFile::remove(tmpPath + "DLBase.dll");
|
|
// QFile::copy(curPath + "DLBase.dll", tmpPath + "DLBase.dll");
|
|
// QFile::remove(tmpPath + "DLVersion.dll");
|
|
// QFile::copy(curPath + "DLVersion.dll", tmpPath + "DLVersion.dll");
|
|
// #else
|
|
QFile::remove(tmpPath + "HGUpgradeApp.exe");
|
|
QFile::copy(curPath + "HGUpgradeApp.exe", tmpPath + "HGUpgradeApp.exe");
|
|
QFile::remove(tmpPath + "HGBase.dll");
|
|
QFile::copy(curPath + "HGBase.dll", tmpPath + "HGBase.dll");
|
|
QFile::remove(tmpPath + "HGVersion.dll");
|
|
QFile::copy(curPath + "HGVersion.dll", tmpPath + "HGVersion.dll");
|
|
// #endif
|
|
|
|
QDir dd(curPath);
|
|
QFileInfoList fileInfoList = dd.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
|
|
foreach (auto fileInfo, fileInfoList)
|
|
{
|
|
if (fileInfo.isFile())
|
|
{
|
|
QString fileName = fileInfo.fileName();
|
|
if (fileName.startsWith("api", Qt::CaseInsensitive))
|
|
{
|
|
QFile::remove(tmpPath + fileName);
|
|
QFile::copy(curPath + fileName, tmpPath + fileName);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
QFile::remove(tmpPath + "msvcp140.dll");
|
|
QFile::copy(curPath + "msvcp140.dll", tmpPath + "msvcp140.dll");
|
|
QFile::remove(tmpPath + "Qt5Core.dll");
|
|
QFile::copy(curPath + "Qt5Core.dll", tmpPath + "Qt5Core.dll");
|
|
QFile::remove(tmpPath + "Qt5Gui.dll");
|
|
QFile::copy(curPath + "Qt5Gui.dll", tmpPath + "Qt5Gui.dll");
|
|
QFile::remove(tmpPath + "Qt5Widgets.dll");
|
|
QFile::copy(curPath + "Qt5Widgets.dll", tmpPath + "Qt5Widgets.dll");
|
|
QFile::remove(tmpPath + "Qt5Svg.dll");
|
|
QFile::copy(curPath + "Qt5Svg.dll", tmpPath + "Qt5Svg.dll");
|
|
QFile::remove(tmpPath + "vcruntime140.dll");
|
|
QFile::copy(curPath + "vcruntime140.dll", tmpPath + "vcruntime140.dll");
|
|
QFile::remove(tmpPath + "concrt140.dll");
|
|
QFile::copy(curPath + "concrt140.dll", tmpPath + "concrt140.dll");
|
|
QFile::remove(tmpPath + "vcruntime140_1.dll");
|
|
QFile::copy(curPath + "vcruntime140_1.dll", tmpPath + "vcruntime140_1.dll");
|
|
|
|
QDir dir;
|
|
|
|
dir.mkdir(tmpPath + "iconengines");
|
|
QFile::remove(tmpPath + "iconengines/qsvgicon.dll");
|
|
QFile::copy(curPath + "iconengines/qsvgicon.dll", tmpPath + "iconengines/qsvgicon.dll");
|
|
|
|
dir.mkdir(tmpPath + "imageformats");
|
|
QFile::remove(tmpPath + "imageformats/qgif.dll");
|
|
QFile::copy(curPath + "imageformats/qgif.dll", tmpPath + "imageformats/qgif.dll");
|
|
QFile::remove(tmpPath + "imageformats/qicns.dll");
|
|
QFile::copy(curPath + "imageformats/qicns.dll", tmpPath + "imageformats/qicns.dll");
|
|
QFile::remove(tmpPath + "imageformats/qico.dll");
|
|
QFile::copy(curPath + "imageformats/qico.dll", tmpPath + "imageformats/qico.dll");
|
|
QFile::remove(tmpPath + "imageformats/qjpeg.dll");
|
|
QFile::copy(curPath + "imageformats/qjpeg.dll", tmpPath + "imageformats/qjpeg.dll");
|
|
QFile::remove(tmpPath + "imageformats/qsvg.dll");
|
|
QFile::copy(curPath + "imageformats/qsvg.dll", tmpPath + "imageformats/qsvg.dll");
|
|
QFile::remove(tmpPath + "imageformats/qtga.dll");
|
|
QFile::copy(curPath + "imageformats/qtga.dll", tmpPath + "imageformats/qtga.dll");
|
|
QFile::remove(tmpPath + "imageformats/qtiff.dll");
|
|
QFile::copy(curPath + "imageformats/qtiff.dll", tmpPath + "imageformats/qtiff.dll");
|
|
QFile::remove(tmpPath + "imageformats/qwbmp.dll");
|
|
QFile::copy(curPath + "imageformats/qwbmp.dll", tmpPath + "imageformats/qwbmp.dll");
|
|
QFile::remove(tmpPath + "imageformats/qwebp.dll");
|
|
QFile::copy(curPath + "imageformats/qwebp.dll", tmpPath + "imageformats/qwebp.dll");
|
|
|
|
dir.mkdir(tmpPath + "platforms");
|
|
QFile::remove(tmpPath + "platforms/qwindows.dll");
|
|
QFile::copy(curPath + "platforms/qwindows.dll", tmpPath + "platforms/qwindows.dll");
|
|
|
|
dir.mkdir(tmpPath + "styles");
|
|
QFile::remove(tmpPath + "styles/qwindowsvistastyle.dll");
|
|
QFile::copy(curPath + "styles/qwindowsvistastyle.dll", tmpPath + "styles/qwindowsvistastyle.dll");
|
|
#else
|
|
// #if defined(OEM_HANWANG)
|
|
// QFile::remove(tmpPath + "HwUpgradeApp");
|
|
// QFile::copy(curPath + "HwUpgradeApp", tmpPath + "HwUpgradeApp");
|
|
// QFile::remove(tmpPath + "libHwBase.so");
|
|
// QFile::copy(curPath + "libHwBase.so", tmpPath + "libHwBase.so");
|
|
// QFile::remove(tmpPath + "libHwVersion.so");
|
|
// QFile::copy(curPath + "libHwVersion.so", tmpPath + "libHwVersion.so");
|
|
// #elif defined(OEM_LISICHENG)
|
|
// QFile::remove(tmpPath + "LscUpgradeApp");
|
|
// QFile::copy(curPath + "LscUpgradeApp", tmpPath + "LscUpgradeApp");
|
|
// QFile::remove(tmpPath + "libLscBase.so");
|
|
// QFile::copy(curPath + "libLscBase.so", tmpPath + "libLscBase.so");
|
|
// QFile::remove(tmpPath + "libLscVersion.so");
|
|
// QFile::copy(curPath + "libLscVersion.so", tmpPath + "libLscVersion.so");
|
|
// #elif defined(OEM_CANGTIAN)
|
|
// QFile::remove(tmpPath + "CtsUpgradeApp");
|
|
// QFile::copy(curPath + "CtsUpgradeApp", tmpPath + "CtsUpgradeApp");
|
|
// QFile::remove(tmpPath + "libCtsBase.so");
|
|
// QFile::copy(curPath + "libCtsBase.so", tmpPath + "libCtsBase.so");
|
|
// QFile::remove(tmpPath + "libCtsVersion.so");
|
|
// QFile::copy(curPath + "libCtsVersion.so", tmpPath + "libCtsVersion.so");
|
|
// #elif defined(OEM_ZHONGJING)
|
|
// QFile::remove(tmpPath + "ZjUpgradeApp");
|
|
// QFile::copy(curPath + "ZjUpgradeApp", tmpPath + "ZjUpgradeApp");
|
|
// QFile::remove(tmpPath + "libZjBase.so");
|
|
// QFile::copy(curPath + "libZjBase.so", tmpPath + "libZjBase.so");
|
|
// QFile::remove(tmpPath + "libZjVersion.so");
|
|
// QFile::copy(curPath + "libZjVersion.so", tmpPath + "libZjVersion.so");
|
|
// #elif defined(OEM_ZIGUANG)
|
|
// QFile::remove(tmpPath + "ZgUpgradeApp");
|
|
// QFile::copy(curPath + "ZgUpgradeApp", tmpPath + "ZgUpgradeApp");
|
|
// QFile::remove(tmpPath + "libZgBase.so");
|
|
// QFile::copy(curPath + "libZgBase.so", tmpPath + "libZgBase.so");
|
|
// QFile::remove(tmpPath + "libZgVersion.so");
|
|
// QFile::copy(curPath + "libZgVersion.so", tmpPath + "libZgVersion.so");
|
|
// #elif defined(OEM_DELI)
|
|
// QFile::remove(tmpPath + "DlUpgradeApp");
|
|
// QFile::copy(curPath + "DlUpgradeApp", tmpPath + "DlUpgradeApp");
|
|
// QFile::remove(tmpPath + "libDlBase.so");
|
|
// QFile::copy(curPath + "libDlBase.so", tmpPath + "libDlBase.so");
|
|
// QFile::remove(tmpPath + "libDlVersion.so");
|
|
// QFile::copy(curPath + "libDlVersion.so", tmpPath + "libDlVersion.so");
|
|
// #else
|
|
QFile::remove(tmpPath + "HGUpgradeApp");
|
|
QFile::copy(curPath + "HGUpgradeApp", tmpPath + "HGUpgradeApp");
|
|
//QFile::remove(tmpPath + "libHGBase.so");
|
|
//QFile::copy(curPath + "libHGBase.so", tmpPath + "libHGBase.so");
|
|
//QFile::remove(tmpPath + "libHGVersion.so");
|
|
//QFile::copy(curPath + "libHGVersion.so", tmpPath + "libHGVersion.so");
|
|
// #endif
|
|
#endif
|
|
|
|
QProcess proc;
|
|
bool isSuccessdStart = false;
|
|
|
|
QStringList argList;
|
|
argList.push_back(QString("-appName=%1").arg(HGVERSION_APPNAME_SCANNER));
|
|
argList.push_back(QString("-oemName=%1").arg(m_oemName));
|
|
argList.push_back(QString("-pkgpath=%1").arg(pkgPath.toStdString().c_str()));
|
|
argList.push_back(QString("-type=%1").arg("upgrade"));
|
|
argList.push_back(QString("-language=%1").arg(m_currLang.toStdString().c_str()));
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
// #if defined(OEM_HANWANG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "HwUpgradeApp.exe", argList);
|
|
// #elif defined(OEM_LISICHENG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "LscUpgradeApp.exe", argList);
|
|
// #elif defined(OEM_CANGTIAN)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "CtsUpgradeApp.exe", argList);
|
|
// #elif defined(OEM_ZHONGJING)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "ZJUpgradeApp.exe", argList);
|
|
// #elif defined(OEM_ZIGUANG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "ZGUpgradeApp.exe", argList);
|
|
// #elif defined(OEM_DELI)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "DLUpgradeApp.exe", argList);
|
|
// #else
|
|
proc.setWorkingDirectory(tmpPath);
|
|
isSuccessdStart = proc.startDetached(tmpPath + "HGUpgradeApp.exe", argList);
|
|
// #endif
|
|
#else
|
|
// #if defined(OEM_HANWANG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "HwUpgradeApp", argList);
|
|
// #elif defined(OEM_LISICHENG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "LscUpgradeApp", argList);
|
|
// #elif defined(OEM_CANGTIAN)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "CtsUpgradeApp", argList);
|
|
// #elif defined(OEM_ZHONGJING)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "ZjUpgradeApp", argList);
|
|
// #elif defined(OEM_ZIGUANG)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "ZgUpgradeApp", argList);
|
|
// #elif defined(OEM_DELI)
|
|
// isSuccessdStart = proc.startDetached(tmpPath + "DlUpgradeApp", argList);
|
|
// #else
|
|
isSuccessdStart = proc.startDetached(tmpPath + "HGUpgradeApp", argList);
|
|
// #endif
|
|
#endif
|
|
|
|
if (isSuccessdStart)
|
|
{
|
|
m_closeTip = false;
|
|
close();
|
|
}
|
|
else
|
|
{
|
|
QMessageBox msg(QMessageBox::Critical, tr("error"),
|
|
tr("start failed!"),
|
|
QMessageBox::Ok, this);
|
|
msg.exec();
|
|
}
|
|
}
|
|
|
|
bool MainWindow::isLimitAccessFolder(int type)
|
|
{
|
|
QString cachePath = Dialog_ClrCache::getCachePath();
|
|
QString aquireIntoPath = m_aquireIntoSaveParam.m_savePath;
|
|
QString filePath;
|
|
|
|
HGChar uuid[512];
|
|
HGBase_GetUuid(uuid, 512);
|
|
|
|
if (1 == type)
|
|
{
|
|
filePath = cachePath + uuid;
|
|
}
|
|
else if (2 == type)
|
|
{
|
|
filePath = aquireIntoPath + uuid;
|
|
}
|
|
|
|
HGResult ret = HGBase_CreateDir(getStdString(filePath).c_str());
|
|
if (ret != HGBASE_ERR_OK)
|
|
{
|
|
QString info;
|
|
if (1 == type)
|
|
{
|
|
info = tr("cache path folder limit:%1").arg(cachePath);
|
|
}
|
|
else if (2 == type)
|
|
{
|
|
info = tr("aquireinto folder limit:%1").arg(aquireIntoPath);
|
|
}
|
|
|
|
QMessageBox::critical(this, tr("error"), info);
|
|
m_wndStatusBar->setDeviceStatusInfo(info, true);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
HGBase_DeleteDir(getStdString(filePath).c_str());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
QString MainWindow::GetDevType(const QString& fwVersion, bool &canLock)
|
|
{
|
|
canLock = false;
|
|
|
|
QString devType;
|
|
if (fwVersion.length() == 10)
|
|
{
|
|
QString dev = fwVersion.left(2);
|
|
if (fwVersion.mid(2, 2) == "40" || fwVersion.mid(2, 2) == "50"
|
|
|| fwVersion.mid(2, 2) == "60" || fwVersion.mid(2, 2) == "70")
|
|
{
|
|
// 3288
|
|
QString ver = fwVersion.mid(2, 2);
|
|
QString date = fwVersion.mid(4, 6);
|
|
}
|
|
else
|
|
{
|
|
// 3399
|
|
QString ver = fwVersion.mid(2, 3);
|
|
QString date = fwVersion.mid(5, 5);
|
|
if ((dev == "G1" || dev == "G2") && ver == "393")
|
|
{
|
|
if (date >= "A1220" && date <= "A1230")
|
|
{
|
|
devType = dev + ver + "/" + "A1220-A1230";
|
|
if (date >= "A1224")
|
|
{
|
|
canLock = true;
|
|
}
|
|
}
|
|
else if (date >= "B0326" && date <= "B0334")
|
|
{
|
|
devType = dev + ver + "/" + "B0326-B0334";
|
|
if (date >= "B0333")
|
|
{
|
|
canLock = true;
|
|
}
|
|
}
|
|
else if (date >= "B0429")
|
|
{
|
|
devType = dev + ver + "/" + "B0429-";
|
|
if (date >= "B1031" || date == "B0500")
|
|
{
|
|
canLock = true;
|
|
}
|
|
}
|
|
}
|
|
else if (dev == "G4" && ver == "393")
|
|
{
|
|
devType = dev + ver + "/";
|
|
if (date >= "B1108")
|
|
{
|
|
canLock = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return devType;
|
|
}
|
|
|
|
QString MainWindow::getLogInfo(HGResult ret)
|
|
{
|
|
QString str;
|
|
if (HGBASE_ERR_ACCESSDENIED == ret)
|
|
{
|
|
str = tr("Insufficient access rights");
|
|
}
|
|
else if (HGIMGPROC_ERR_FAIL == ret)
|
|
{
|
|
str = tr("Image processing failed");
|
|
}
|
|
else if (HGIMGPROC_ERR_OCRINIT == ret)
|
|
{
|
|
str = tr("Ocr init failed");
|
|
}
|
|
else if (HGIMGPROC_ERR_OCR == ret)
|
|
{
|
|
str = tr("Ocr failed");
|
|
}
|
|
else if (HGBASE_ERR_FILENOTEXIST == ret)
|
|
{
|
|
str = tr("File does not exist");
|
|
}
|
|
else if (HGBASE_ERR_LOADLIBRARY == ret)
|
|
{
|
|
str = tr("Failed to load dynamic library");
|
|
}
|
|
else if (HGBASE_ERR_FILEERROR == ret)
|
|
{
|
|
str = tr("File data error");
|
|
}
|
|
else if (HGIMGFMT_ERR_FAIL == ret)
|
|
{
|
|
str = tr("Image format processing error");
|
|
}
|
|
else if (HGBASE_ERR_OUTOFMEMORY == ret)
|
|
{
|
|
str = tr("Out of memory");
|
|
}
|
|
else
|
|
{
|
|
str = tr("Failed");
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
void MainWindow::ocrThreadFunc(HGThread thread, HGPointer param)
|
|
{
|
|
MainWindow *p = (MainWindow*)param;
|
|
HGBase_RunMsgPump(p->m_ocrMsgPump, ocrMsgPumpFunc, param);
|
|
|
|
emit p->m_dlgWaitingOcr->ocrFinish();
|
|
}
|
|
|
|
void MainWindow::ocrMsgPumpFunc(HGMsgPump msgPump, const HGMsg *msg, HGPointer param)
|
|
{
|
|
MainWindow *p = (MainWindow*)param;
|
|
if (msg->id == 1)
|
|
{
|
|
QString *filePath = (QString *)msg->data;
|
|
|
|
#if 0
|
|
HGChar moduleName[256];
|
|
HGBase_GetModuleName(nullptr, moduleName, 256);
|
|
HGChar curPath2[256];
|
|
HGBase_GetFilePath(moduleName, curPath2, 256);
|
|
QString curPath(curPath2);
|
|
|
|
QProcess proc;
|
|
QStringList argList;
|
|
argList.push_back(QString("-filePath=%1").arg(*filePath));
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
#if defined(OEM_HANWANG)
|
|
proc.startDetached(curPath + "HwOCR.exe", argList);
|
|
#elif defined(OEM_LISICHENG)
|
|
proc.startDetached(curPath + "LscOCR.exe", argList);
|
|
#elif defined(OEM_CANGTIAN)
|
|
proc.startDetached(curPath + "CtsOCR.exe", argList);
|
|
#elif defined(OEM_ZHONGJING)
|
|
proc.startDetached(curPath + "ZjOCR.exe", argList);
|
|
#elif defined(OEM_ZIGUANG)
|
|
proc.startDetached(curPath + "ZgOCR.exe", argList);
|
|
#elif defined(OEM_NEUTRAL)
|
|
proc.startDetached(curPath + "NeuOCR.exe", argList);
|
|
#elif defined(OEM_DELI)
|
|
proc.startDetached(curPath + "DlOCR.exe", argList);
|
|
#else
|
|
proc.startDetached(curPath + "HGOCR.exe", argList);
|
|
#endif
|
|
#else
|
|
#if defined(OEM_HANWANG)
|
|
proc.startDetached(curPath + "HwOCR", argList);
|
|
#elif defined(OEM_LISICHENG)
|
|
proc.startDetached(curPath + "LscOCR", argList);
|
|
#elif defined(OEM_CANGTIAN)
|
|
proc.startDetached(curPath + "CtsOCR", argList);
|
|
#elif defined(OEM_ZHONGJING)
|
|
proc.startDetached(curPath + "ZjOCR", argList);
|
|
#elif defined(OEM_ZIGUANG)
|
|
proc.startDetached(curPath + "ZgOCR", argList);
|
|
#elif defined(OEM_NEUTRAL)
|
|
proc.startDetached(curPath + "NeuOCR", argList);
|
|
#elif defined(OEM_DELI)
|
|
proc.startDetached(curPath + "DlOCR", argList);
|
|
#else
|
|
proc.startDetached(curPath + "HGOCR", argList);
|
|
#endif
|
|
#endif
|
|
|
|
#else
|
|
HGOCRMgr ocrMgr = NULL;
|
|
HGImgProc_CreateOCRMgr(HGIMGPROC_OCRALGO_DEFAULT, &ocrMgr);
|
|
if (NULL != ocrMgr)
|
|
{
|
|
HGImgFmtReader reader = NULL;
|
|
HGImgFmt_OpenImageReader(filePath->toLocal8Bit().toStdString().c_str(), 0, &reader);
|
|
if (NULL != reader)
|
|
{
|
|
HGUInt count = 0;
|
|
HGImgFmt_GetImagePageCount(reader, &count);
|
|
for (HGUInt i = 0; i < count; ++i)
|
|
{
|
|
HGImage image = NULL;
|
|
HGImgFmt_LoadImageFromReader(reader, i, NULL, 0, 0, &image);
|
|
if (NULL != image)
|
|
{
|
|
HGImgProc_AddToImageOCRList(ocrMgr, image);
|
|
HGBase_DestroyImage(image);
|
|
}
|
|
}
|
|
|
|
HGImgFmt_CloseImageReader(reader);
|
|
}
|
|
|
|
HGBase_DeleteFile(filePath->toLocal8Bit().toStdString().c_str());
|
|
HGImgProc_ImageListOCRToFile(ocrMgr, 0, filePath->toLocal8Bit().toStdString().c_str(), NULL, NULL);
|
|
|
|
HGImgProc_DestroyOCRMgr(ocrMgr);
|
|
}
|
|
|
|
#endif
|
|
|
|
delete filePath;
|
|
}
|
|
}
|
|
|
|
void MainWindow::deleteOverdueLogFile(const QString& logFilePath)
|
|
{
|
|
QDir dir(logFilePath);
|
|
if(!dir.exists())
|
|
{
|
|
return;
|
|
}
|
|
dir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
QFileInfoList list = dir.entryInfoList();
|
|
|
|
int count = list.count();
|
|
if(count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for(int i=0; i < count; i++)
|
|
{
|
|
QFileInfo info = list.at(i);
|
|
QString suffix = info.suffix();
|
|
if(suffix == "log")
|
|
{
|
|
QDateTime nowTime = QDateTime::currentDateTime();
|
|
QDateTime createTime = info.created();
|
|
int days = createTime.daysTo(nowTime);
|
|
if (days > 14)
|
|
{
|
|
HGBase_DeleteFile(info.absoluteFilePath().toStdString().c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::deleteUpgradePkg(const QString &cfgFilePath)
|
|
{
|
|
QDir dir(cfgFilePath);
|
|
if(!dir.exists())
|
|
{
|
|
return;
|
|
}
|
|
dir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
QFileInfoList list = dir.entryInfoList();
|
|
|
|
int count = list.count();
|
|
if(count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for(int i=0; i < count; i++)
|
|
{
|
|
QFileInfo info = list.at(i);
|
|
QString suffix = info.suffix();
|
|
if(suffix == "exe")
|
|
{
|
|
HGBase_DeleteFile(info.absoluteFilePath().toStdString().c_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::initAcquireIntoComboBox()
|
|
{
|
|
m_cbtn_acquireIntoCfg = new QComboBox;
|
|
|
|
m_cbtn_acquireIntoCfg->setFixedWidth(150);
|
|
ui->toolBar->addWidget(m_cbtn_acquireIntoCfg);
|
|
m_cbtn_acquireIntoCfg->addItem(tr("default scheme"));
|
|
QString allCfgName = getCfgValue("aquire", "cfgNameList", QString(""));
|
|
QStringList allCfgNameList = allCfgName.split(",");
|
|
if (!allCfgNameList.contains(QString("")))
|
|
{
|
|
m_cbtn_acquireIntoCfg->addItems(allCfgNameList);
|
|
m_cbtn_acquireIntoCfg->setCurrentText(getCfgValue("aquire", "currentKeyName", QString("aquire")));
|
|
}
|
|
else
|
|
{
|
|
allCfgNameList.removeOne(QString(""));
|
|
m_cbtn_acquireIntoCfg->setCurrentIndex(0);
|
|
}
|
|
|
|
connect(m_cbtn_acquireIntoCfg, SIGNAL(currentTextChanged(QString)), this, SLOT(on_m_acquireIntoCfg_changed(QString)));
|
|
}
|
|
|
|
void MainWindow::updateSideBar()
|
|
{
|
|
int mainWndWidth = this->rect().width();
|
|
int mainWndHeight = this->rect().height();
|
|
int sideBarHeight = m_widget_sideBar->height();
|
|
|
|
m_widget_sideBar->move(mainWndWidth, mainWndHeight/2 - sideBarHeight/2);
|
|
m_pbtn_push->move(mainWndWidth - m_pbtn_push->width(), mainWndHeight/2 - m_pbtn_push->height()/2);
|
|
|
|
m_propertyAnimation = new QPropertyAnimation(m_widget_sideBar, "geometry");
|
|
m_propertyAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
|
m_propertyAnimation->setDuration(600);
|
|
m_propertyAnimation2 = new QPropertyAnimation(m_pbtn_push, "geometry");
|
|
m_propertyAnimation2->setEasingCurve(QEasingCurve::InOutSine);
|
|
m_propertyAnimation2->setDuration(600);
|
|
}
|
|
|
|
void MainWindow::deleteDevUser()
|
|
{
|
|
if (nullptr != m_devUser)
|
|
{
|
|
disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)));
|
|
disconnect(m_devUser, SIGNAL(scanWorkingEvent()), this, SLOT(on_scanWorkingEvent()));
|
|
disconnect(m_devUser, SIGNAL(scanFinishEvent()), this, SLOT(on_scanFinishEvent()));
|
|
m_devUser->Logout();
|
|
delete m_devUser;
|
|
m_devUser = nullptr;
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false);
|
|
updateActionStatus();
|
|
}
|
|
}
|
|
|
|
#if !defined(HG_CMP_MSC)
|
|
void MainWindow::checkRollerLife()
|
|
{
|
|
if (m_devUser != nullptr)
|
|
{
|
|
int life = m_devUser->GetDeviceRollerLife();
|
|
HGSaneDeviceCustomInfo info = {0};
|
|
m_devUser->GetDeviceCustomInfo(&info);
|
|
if (info.rollerCount >= life)
|
|
{
|
|
QMessageBox::information(this, tr("Prompt"), tr("The Device has reached roller life"), QMessageBox::Ok);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
void MainWindow::on_act_sortPages_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_thumb->bookSort();
|
|
}
|
|
|
|
void MainWindow::on_actionact_update_triggered()
|
|
{
|
|
HGVersionInfo *versionInfo = NULL;
|
|
HGUInt versionCount = 0;
|
|
HGResult ret = m_versionDll->GetVersionList(HGVERSION_APPNAME_SCANNER, m_oemName, &versionInfo, &versionCount);
|
|
if (ret != HGBASE_ERR_OK)
|
|
{
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "GetVersionList:%u", ret);
|
|
}
|
|
if(versionCount > 0)
|
|
{
|
|
Dialog_upgrade dlg(m_versionDll, versionInfo, this);
|
|
if (dlg.exec())
|
|
{
|
|
QString url, md5;
|
|
|
|
QString versionNum = dlg.getVersionNum();
|
|
for (HGUInt i = 0; i < versionCount; ++i)
|
|
{
|
|
if (versionNum == versionInfo[i].version)
|
|
{
|
|
url = versionInfo[i].url;
|
|
md5 = versionInfo[i].md5;
|
|
break;
|
|
}
|
|
}
|
|
|
|
assert(!url.isEmpty() && !md5.isEmpty());
|
|
|
|
HGChar suffix[64];
|
|
HGBase_GetFileSuffix(url.toStdString().c_str(), suffix, 64);
|
|
|
|
HGChar savePath[512];
|
|
HGBase_GetConfigPath(savePath, 512);
|
|
HGBase_CreateDir(savePath);
|
|
|
|
HGChar fileName[128];
|
|
sprintf(fileName, "%s.%s", versionNum.toStdString().c_str(), suffix);
|
|
strcat(savePath, fileName);
|
|
|
|
QFile saveFile(savePath);
|
|
saveFile.open(QFile::ReadOnly);
|
|
QByteArray fileMsg = saveFile.readAll();
|
|
saveFile.close();
|
|
QString md5_2 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
|
|
|
|
QFile f(savePath);
|
|
if(!f.exists() || md5 != md5_2)
|
|
{
|
|
Dialog_updateProgress dlg(m_versionDll, url, savePath, this);
|
|
if (dlg.exec())
|
|
{
|
|
QFile saveFile(savePath);
|
|
saveFile.open(QFile::ReadOnly);
|
|
QByteArray fileMsg = saveFile.readAll();
|
|
saveFile.close();
|
|
QString md5_2 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
|
|
|
|
if (md5 == md5_2)
|
|
{
|
|
upgradeApp(savePath);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
upgradeApp(savePath);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::information(this, tr("tip"), tr("Other versions not available"));
|
|
}
|
|
m_versionDll->ReleaseVersionList(versionInfo, versionCount);
|
|
}
|
|
|
|
void MainWindow::on_act_feedback_triggered()
|
|
{
|
|
Dialog_Feedback dlg(m_versionDll, this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_driver_log_triggered()
|
|
{
|
|
if (m_devUser != nullptr)
|
|
{
|
|
QString driverLogPath = m_devUser->GetDriverLog();
|
|
if (!driverLogPath.isEmpty())
|
|
{
|
|
if (driverLogPath == "Fail")
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("The device does not support this operation"));
|
|
}
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(driverLogPath));
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_device_log_triggered()
|
|
{
|
|
if (m_devUser != nullptr)
|
|
{
|
|
QString deviceLogPath = m_devUser->GetDeviceLog();
|
|
if (!deviceLogPath.isEmpty())
|
|
{
|
|
if (deviceLogPath == "Fail")
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("The device does not support this operation"));
|
|
}
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(deviceLogPath));
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_simpCN_triggered()
|
|
{
|
|
m_act_simpCN->setChecked(true);
|
|
m_act_English->setChecked(false);
|
|
|
|
if (m_currLang == "chinese")
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_currLang = "chinese";
|
|
saveCfgValue("global", "language", m_currLang);
|
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"),
|
|
tr("The language switch is successful and takes effect the next time the software is started!"),
|
|
QMessageBox::Ok, this);
|
|
msg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_English_triggered()
|
|
{
|
|
m_act_simpCN->setChecked(false);
|
|
m_act_English->setChecked(true);
|
|
|
|
if (m_currLang == "english")
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_currLang = "english";
|
|
saveCfgValue("global", "language", m_currLang);
|
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"),
|
|
tr("The language switch is successful and takes effect the next time the software is started!"),
|
|
QMessageBox::Ok, this);
|
|
msg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_deleteFile_triggered()
|
|
{
|
|
if (m_isScanning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::vector<int> selectIndexs;
|
|
std::vector<QString> selectFileNames;
|
|
int count = 0;
|
|
m_thumb->getItemCount(&count);
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(i, &select);
|
|
if (select)
|
|
{
|
|
selectIndexs.push_back(i);
|
|
QString fileName;
|
|
m_thumb->getItemFileName(i, fileName);
|
|
selectFileNames.push_back(fileName);
|
|
}
|
|
}
|
|
|
|
if (selectIndexs.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (-1 != m_currIndex)
|
|
{
|
|
bool select = false;
|
|
m_thumb->itemIsSelect(m_currIndex, &select);
|
|
if (select)
|
|
{
|
|
startSaveMessageBox(this);
|
|
}
|
|
}
|
|
|
|
QMessageBox msg(QMessageBox::Question, tr("tips"), tr("Are you sure to delete selected file?"),
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
msg.exec();
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
{
|
|
m_thumb->removeItems(selectIndexs, HGImgThumb::ThumbRemoveFlag_Delete);
|
|
|
|
std::list<QString>::iterator iter;
|
|
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
|
|
{
|
|
bool find = false;
|
|
for (int i = 0; i < (int)selectFileNames.size(); ++i)
|
|
{
|
|
if (*iter == selectFileNames[i])
|
|
{
|
|
find = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (find)
|
|
{
|
|
iter = m_curBatchFileList.erase(iter);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_selectDevice_triggered()
|
|
{
|
|
if (nullptr != m_devUser)
|
|
{
|
|
disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)));
|
|
disconnect(m_devUser, SIGNAL(scanWorkingEvent()), this, SLOT(on_scanWorkingEvent()));
|
|
disconnect(m_devUser, SIGNAL(scanFinishEvent()), this, SLOT(on_scanFinishEvent()));
|
|
m_devUser->Logout();
|
|
delete m_devUser;
|
|
m_devUser = nullptr;
|
|
m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false);
|
|
updateActionStatus();
|
|
}
|
|
|
|
this->setEnabled(false);
|
|
m_canClose = false;
|
|
|
|
DeviceUser *devUser = m_devUserMgr->OpenDeviceUser();
|
|
if (devUser != nullptr)
|
|
{
|
|
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);
|
|
connect(m_devUser, SIGNAL(scanFinishEvent()), this, SLOT(on_scanFinishEvent()), Qt::QueuedConnection);
|
|
#if !defined(HG_CMP_MSC)
|
|
checkRollerLife();
|
|
#endif
|
|
updateActionStatus();
|
|
}
|
|
else
|
|
{
|
|
delete devUser;
|
|
}
|
|
}
|
|
|
|
this->setEnabled(true);
|
|
m_canClose = true;
|
|
}
|