From 6e3db40cd079be5d2108bf00b59808d163ab5121 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Mon, 11 Dec 2023 11:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=AF=BC=E5=87=BA/=E4=BF=9D?= =?UTF-8?q?=E5=AD=98/=E5=8F=A6=E5=AD=98=E4=B8=BA=E4=B8=8E=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=B7=AF=E5=BE=84=E6=96=87=E4=BB=B6=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=9C=AA=E5=81=9A=E6=9B=BF=E6=8D=A2=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8F=90=E9=86=92=E7=9A=84=E9=97=AE=E9=A2=98-BUG=2080?= =?UTF-8?q?7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/dialog_export.cpp | 75 ++++------------------- app/scanner2/dialog_export.ui | 6 +- app/scanner2/dialog_saveas.cpp | 107 +++++++++------------------------ app/scanner2/dialog_saveas.h | 13 ++++ app/scanner2/dialog_saveas.ui | 6 +- app/scanner2/mainwindow.cpp | 29 ++++++++- modules/base/HGDef.h | 6 ++ 7 files changed, 92 insertions(+), 150 deletions(-) diff --git a/app/scanner2/dialog_export.cpp b/app/scanner2/dialog_export.cpp index 4dd473bb..a7209202 100644 --- a/app/scanner2/dialog_export.cpp +++ b/app/scanner2/dialog_export.cpp @@ -40,10 +40,8 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, m_supportType.push_back(SupportType(".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS)); m_supportType.push_back(SupportType(".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS)); m_supportType.push_back(SupportType(".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); -#if 0 - if (!getOcrPath().empty()) - m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); -#elif !defined (x86_64) && !defined (loongarch64) + +#if !defined (x86_64) && !defined (loongarch64) m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); @@ -55,14 +53,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item ui->fileDialog->setSizeGripEnabled(false); -// ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;" -// "BMP - Windows Bitmap(*.bmp);;" -// "PNG - Portable Network Graphics(*.png);;" -// "TIF - TIFF Revision 6(*.tif);;" -// "PDF - Portable Document Format(*.pdf);;" -// "OFD - Open Fixed-layout Document(*.ofd);;" -// "OCR->PDF - Portable Document Format(*.pdf);;" -// "OCR->OFD - Open Fixed-layout Document(*.ofd)"); QStringList filters; for(int i = 0; i < m_supportType.size(); ++i) filters.push_back(m_supportType[i].title + "(*" + m_supportType[i].ext + ")"); @@ -136,18 +126,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, ui->label_ocrType->setVisible(false); ui->comboBox_ocrType->setVisible(false); - -#if 0 - if (!getOcrPath().empty()) - { - ui->label_ocrType->setVisible(isOcr()); - ui->comboBox_ocrType->setVisible(isOcr()); - QStringList ocrType = { tr("English"), tr("Simplified Chinese"), tr("Traditional Chinese"), tr("Japanese"), tr("Korean") }; - ui->comboBox_ocrType->addItems(ocrType); - ui->comboBox_ocrType->setCurrentIndex(getCfgValue("export", "ocrLanguage", 0)); - } - -#endif } Dialog_Export::~Dialog_Export() @@ -209,33 +187,6 @@ void Dialog_Export::getSaveIndexs(std::vector &indexs) void Dialog_Export::on_dialog_accepted() { QString extName(m_supportType[m_suffix].ext); -// switch (m_suffix) -// { -// case 0: -// extName = ".jpg"; -// break; -// case 1: -// extName = ".bmp"; -// break; -// case 2: -// extName = ".png"; -// break; -// case 3: -// extName = ".tif"; -// break; -// case 4: -// extName = ".pdf"; -// break; -// case 5: -// extName = ".ofd"; -// break; -// case 6: -// extName = ".pdf"; -// break; -// case 7: -// extName = ".ofd"; -// break; -// } assert(!extName.isEmpty()); @@ -261,9 +212,15 @@ void Dialog_Export::on_dialog_accepted() makeSaveIndexs(); - // ćŒćè­Šć‘Š - if(warning && avoid_overwriting(m_savePath + "/" + m_saveName + m_saveExt)) - return; + QFile file(m_savePath + m_saveName + m_saveExt); + if (file.exists()) + { + int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?")); + if (ret != QMessageBox::Yes) + { + return; + } + } saveCfgValue("export", "suffix", m_suffix); @@ -277,11 +234,6 @@ void Dialog_Export::on_dialog_accepted() saveCfgValue("export", "exportType", exportType); saveCfgValue("export", "saveAsMulti", ui->check_saveAsMulti->isChecked()); -#if 0 - int ocrLanguage = ui->comboBox_ocrType->currentIndex(); - saveCfgValue("export", "ocrLanguage", ocrLanguage); -#endif - accept(); } @@ -291,11 +243,6 @@ void Dialog_Export::on_filterSelected(const QString& filterName) m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); -#if 0 - ui->label_ocrType->setVisible(isOcr()); - ui->comboBox_ocrType->setVisible(isOcr()); -#endif - enabled = (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES; ui->check_saveAsMulti->setEnabled(enabled); // ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6); diff --git a/app/scanner2/dialog_export.ui b/app/scanner2/dialog_export.ui index de0b806a..3c289116 100644 --- a/app/scanner2/dialog_export.ui +++ b/app/scanner2/dialog_export.ui @@ -15,7 +15,7 @@ - + @@ -183,9 +183,9 @@ Page range will be "Chosen Pages". - QFileDialog + MyFileDialog QWidget -
qfiledialog.h
+
dialog_saveas.h
1
diff --git a/app/scanner2/dialog_saveas.cpp b/app/scanner2/dialog_saveas.cpp index a4b29b28..0b82577f 100644 --- a/app/scanner2/dialog_saveas.cpp +++ b/app/scanner2/dialog_saveas.cpp @@ -8,57 +8,24 @@ #include #include #include +#include -class del_delegate : public QAbstractProxyModel +MyFileDialog::MyFileDialog(QWidget *parent) + : QFileDialog(parent) { - QAbstractProxyModel* prev_ = nullptr; - QFileDialog* dlg_ = nullptr; -public: - del_delegate(QFileDialog* fd) : dlg_(fd) - { - prev_ = dlg_->proxyModel(); - dlg_->setProxyModel(this); - dlg_->setOption(QFileDialog::Option::ReadOnly, true); - } - ~del_delegate() - { - dlg_->setProxyModel(prev_); - prev_ = nullptr; - } +} -public: - virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override - { - return prev_->removeRows(row, count, parent); - } - Q_INVOKABLE virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const override - { - return prev_->mapToSource(proxyIndex); - } - Q_INVOKABLE virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override - { - return prev_->mapFromSource(sourceIndex); - } - Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override - { - return prev_->rowCount(parent); - } - Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override - { - return prev_->columnCount(parent); - } - Q_INVOKABLE virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override - { - return prev_->index(row, column, parent); - } - Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const override - { - return prev_->parent(child); - } +MyFileDialog::~MyFileDialog() +{ + +} + +void MyFileDialog::accept() +{ + emit accepted(); +} -}; Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) : QDialog(parent) @@ -102,14 +69,12 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) : ";;PDF - Portable Document Format(*.pdf)" ";;OFD - Open Fixed-layout Document(*.ofd)" ";;GIF - Graphics Interchange Format(*.gif)"; -#if 0 - if (!getOcrPath().empty()) - filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; -#elif !defined (x86_64) && !defined (loongarch64) - filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; - filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)"; - if (m_isSaveAs) - filter += ";;OCR->RTF - Rich Text Format(*.rtf)"; + +#if !defined (x86_64) && !defined (loongarch64) + filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; + filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)"; + if (m_isSaveAs) + filter += ";;OCR->RTF - Rich Text Format(*.rtf)"; #endif ui->fileDialog->setNameFilter(filter); @@ -131,18 +96,6 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) : ui->label_ocrType->setVisible(false); ui->comboBox_ocrType->setVisible(false); - -#if 0 - if (!getOcrPath().empty()) - { - ui->label_ocrType->setVisible(isOcr()); - ui->comboBox_ocrType->setVisible(isOcr()); - QStringList ocrType = { tr("English"), tr("Simplified Chinese"), tr("Traditional Chinese"), tr("Japanese"), tr("Korean") }; - ui->comboBox_ocrType->addItems(ocrType); - ui->comboBox_ocrType->setCurrentIndex(getCfgValue("saveAs", "ocrLanguage", 0)); - } - -#endif } Dialog_SaveAs::~Dialog_SaveAs() @@ -255,15 +208,20 @@ void Dialog_SaveAs::on_dialog_accepted() } if(name.endsWith(extName)) - m_savePath = getStdFileName(path + "/" + name); + m_savePath = getStdFileName(path + name); else - m_savePath = getStdFileName(path + "/" + name + extName); + m_savePath = getStdFileName(path + name + extName); } -#if 0 - int ocrLanguage = ui->comboBox_ocrType->currentIndex(); - saveCfgValue("saveAs", "ocrLanguage", ocrLanguage); -#endif + QFile file(m_savePath); + if (file.exists()) + { + int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?")); + if (ret != QMessageBox::Yes) + { + return; + } + } saveCfgValue("saveAs", "suffix", m_suffix); saveCfgValue("saveAs", "subFolderByTime", ui->cbox_subFolder->isChecked()); @@ -274,11 +232,6 @@ void Dialog_SaveAs::on_filterSelected(const QString& filterName) { m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix || 7 == m_suffix || 8 == m_suffix); - -#if 0 - ui->label_ocrType->setVisible(isOcr()); - ui->comboBox_ocrType->setVisible(isOcr()); -#endif } void Dialog_SaveAs::on_btn_option_clicked() diff --git a/app/scanner2/dialog_saveas.h b/app/scanner2/dialog_saveas.h index f57b3189..d0267c06 100644 --- a/app/scanner2/dialog_saveas.h +++ b/app/scanner2/dialog_saveas.h @@ -2,11 +2,24 @@ #define DIALOG_SAVEAS_H #include +#include namespace Ui { class Dialog_SaveAs; } +class MyFileDialog : public QFileDialog +{ + Q_OBJECT + +public: + explicit MyFileDialog(QWidget *parent = nullptr); + ~MyFileDialog(); + +protected: + void accept() override; +}; + class Dialog_SaveAs : public QDialog { Q_OBJECT diff --git a/app/scanner2/dialog_saveas.ui b/app/scanner2/dialog_saveas.ui index b02c1f83..c89b3d90 100644 --- a/app/scanner2/dialog_saveas.ui +++ b/app/scanner2/dialog_saveas.ui @@ -15,7 +15,7 @@ - + @@ -69,9 +69,9 @@ - QFileDialog + MyFileDialog QWidget -
qfiledialog.h
+
dialog_saveas.h
1
diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index c1fe4f4d..c79cc471 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -2716,9 +2716,32 @@ void MainWindow::on_act_Export_triggered() int tiffQuality = dlg.getTiffQuality(); bool isOcr = dlg.isOcr(); - Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality, - tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this); - dlgExport.exec(); + 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 + saveName + saveExt) + { + find = true; + break; + } + } + + if (!find) + { + Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality, + tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this); + dlgExport.exec(); + } + else + { + QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail")); + } } } } diff --git a/modules/base/HGDef.h b/modules/base/HGDef.h index ca91af08..c0deebf1 100644 --- a/modules/base/HGDef.h +++ b/modules/base/HGDef.h @@ -119,6 +119,12 @@ typedef HGUInt HGResult; #endif #endif +#if defined(HG_CMP_MSC) + #define HG_SEP "\\" +#else + #define HG_SEP "/" +#endif + #define HG_DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name #pragma pack(push)