2022-05-03 10:25:52 +00:00
|
|
|
|
#include "dialog_saveas.h"
|
|
|
|
|
#include "ui_dialog_saveas.h"
|
2022-05-13 12:38:58 +00:00
|
|
|
|
#include "dialog_writesettings.h"
|
2023-02-17 01:20:12 +00:00
|
|
|
|
#include "base/HGBase.h"
|
2022-05-03 10:25:52 +00:00
|
|
|
|
#include "HGUIGlobal.h"
|
|
|
|
|
#include "app_cfg.h"
|
2023-02-17 01:20:12 +00:00
|
|
|
|
#include "ocrPdf.h"
|
2022-05-24 05:45:07 +00:00
|
|
|
|
#include <assert.h>
|
2022-07-26 05:44:44 +00:00
|
|
|
|
#include <qabstractproxymodel.h>
|
2022-08-22 06:35:42 +00:00
|
|
|
|
#include <QDateTime>
|
2022-07-26 05:44:44 +00:00
|
|
|
|
|
|
|
|
|
class del_delegate : public QAbstractProxyModel
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
|
|
|
|
Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) :
|
|
|
|
|
QDialog(parent)
|
|
|
|
|
, ui(new Ui::Dialog_SaveAs)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2023-03-08 06:32:31 +00:00
|
|
|
|
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
|
|
|
|
ui->fileDialog->setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
|
ui->fileDialog->setWindowFlags(ui->fileDialog->windowFlags() & ~Qt::Dialog);
|
2022-07-26 05:44:44 +00:00
|
|
|
|
ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
|
|
|
|
|
ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item
|
2022-05-03 10:25:52 +00:00
|
|
|
|
ui->fileDialog->setSizeGripEnabled(false);
|
2023-02-17 01:20:12 +00:00
|
|
|
|
|
|
|
|
|
QString filter = "JPG - JPEG / JFIF(*.jpg)"
|
|
|
|
|
";;BMP - Windows Bitmap(*.bmp)"
|
|
|
|
|
";;PNG - Portable Network Graphics(*.png)"
|
|
|
|
|
";;PPM - Portable PixMap(*.ppm)"
|
|
|
|
|
";;PGM - Portable GreyMap(*.pgm)"
|
|
|
|
|
";;PBM - Portable BitMap(*.pbm)"
|
|
|
|
|
";;TIF - TIFF Revision 6(*.tif)"
|
|
|
|
|
";;PDF - Portable Document Format(*.pdf)"
|
|
|
|
|
";;OFD - Open Fixed-layout Document(*.ofd)"
|
|
|
|
|
";;GIF - Graphics Interchange Format(*.gif)";
|
2023-03-03 04:00:14 +00:00
|
|
|
|
#if 0
|
2023-02-17 01:20:12 +00:00
|
|
|
|
if (!getOcrPath().empty())
|
|
|
|
|
filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
|
2023-03-03 04:00:14 +00:00
|
|
|
|
#elif !defined (x86_64) && !defined (loongarch64)
|
2023-02-17 01:20:12 +00:00
|
|
|
|
filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
|
|
|
|
|
filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)";
|
|
|
|
|
filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
|
2022-07-18 11:17:26 +00:00
|
|
|
|
#endif
|
2022-05-03 10:25:52 +00:00
|
|
|
|
|
2023-02-17 01:20:12 +00:00
|
|
|
|
ui->fileDialog->setNameFilter(filter);
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
|
|
|
|
|
connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close()));
|
|
|
|
|
connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&)));
|
|
|
|
|
|
|
|
|
|
m_suffix = getCfgValue("saveAs", "suffix", 0);
|
2022-11-06 10:13:08 +00:00
|
|
|
|
if (m_suffix > 10)
|
|
|
|
|
m_suffix = 10;
|
2022-05-16 09:00:08 +00:00
|
|
|
|
else if (m_suffix < 0)
|
|
|
|
|
m_suffix = 0;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
|
2022-11-06 10:13:08 +00:00
|
|
|
|
ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix);
|
2022-08-22 06:35:42 +00:00
|
|
|
|
ui->cbox_subFolder->setChecked(false);
|
|
|
|
|
|
|
|
|
|
ui->cbox_subFolder->setChecked(getCfgValue("saveAs", "subFolderByTime", false));
|
2023-03-02 03:21:09 +00:00
|
|
|
|
|
|
|
|
|
ui->label_ocrType->setVisible(false);
|
|
|
|
|
ui->comboBox_ocrType->setVisible(false);
|
|
|
|
|
|
2023-03-03 04:00:14 +00:00
|
|
|
|
#if 0
|
2023-03-02 07:43:58 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-02 03:21:09 +00:00
|
|
|
|
#endif
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dialog_SaveAs::~Dialog_SaveAs()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 10:27:14 +00:00
|
|
|
|
void Dialog_SaveAs::set_current_directory(const QString& dir)
|
|
|
|
|
{
|
|
|
|
|
ui->fileDialog->setDirectory(dir);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
QString Dialog_SaveAs::getSavePath()
|
|
|
|
|
{
|
|
|
|
|
return m_savePath;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 12:38:58 +00:00
|
|
|
|
int Dialog_SaveAs::getJpegQuality()
|
2022-05-03 10:25:52 +00:00
|
|
|
|
{
|
2022-05-13 12:38:58 +00:00
|
|
|
|
return getCfgValue("saveParam", "jpegQuality", 80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Dialog_SaveAs::getTiffCompressionBW()
|
|
|
|
|
{
|
2022-05-13 12:53:53 +00:00
|
|
|
|
return getCfgValue("saveParam", "tiffCompBW", 1);
|
2022-05-13 12:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Dialog_SaveAs::getTiffCompression()
|
|
|
|
|
{
|
2022-05-13 12:53:53 +00:00
|
|
|
|
return getCfgValue("saveParam", "tiffCompClr", 1);
|
2022-05-13 12:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Dialog_SaveAs::getTiffQuality()
|
|
|
|
|
{
|
|
|
|
|
return getCfgValue("saveParam", "tiffQuality", 80);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 09:00:08 +00:00
|
|
|
|
bool Dialog_SaveAs::isOcr()
|
|
|
|
|
{
|
2022-11-06 10:13:08 +00:00
|
|
|
|
return (m_suffix >= 10);
|
2022-05-16 09:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-02 07:43:58 +00:00
|
|
|
|
int Dialog_SaveAs::getOcrLanguageType()
|
|
|
|
|
{
|
|
|
|
|
return ui->comboBox_ocrType->currentIndex();// 0-english, 1-chinese_sim, 2-chinese_tra, 3-japanese, 4-korean...
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
void Dialog_SaveAs::on_dialog_accepted()
|
|
|
|
|
{
|
|
|
|
|
QString extName;
|
|
|
|
|
switch (m_suffix)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
extName = ".jpg";
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
extName = ".bmp";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
extName = ".png";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2022-11-06 10:13:08 +00:00
|
|
|
|
extName = ".ppm";
|
2022-05-03 10:25:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2022-11-06 10:13:08 +00:00
|
|
|
|
extName = ".pgm";
|
2022-05-03 10:25:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2022-11-06 10:13:08 +00:00
|
|
|
|
extName = ".pbm";
|
2022-05-03 10:25:52 +00:00
|
|
|
|
break;
|
2022-05-16 09:00:08 +00:00
|
|
|
|
case 6:
|
2022-11-06 10:13:08 +00:00
|
|
|
|
extName = ".tif";
|
2022-05-16 09:00:08 +00:00
|
|
|
|
break;
|
|
|
|
|
case 7:
|
2022-08-01 08:57:25 +00:00
|
|
|
|
extName = ".pdf";
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
2022-05-16 09:00:08 +00:00
|
|
|
|
extName = ".ofd";
|
|
|
|
|
break;
|
2022-09-02 05:08:51 +00:00
|
|
|
|
case 9:
|
2022-11-06 10:13:08 +00:00
|
|
|
|
extName = ".gif";
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
extName = ".pdf";
|
|
|
|
|
break;
|
|
|
|
|
case 11:
|
|
|
|
|
extName = ".ofd";
|
|
|
|
|
break;
|
|
|
|
|
case 12:
|
2022-09-02 05:08:51 +00:00
|
|
|
|
extName = ".rtf";
|
|
|
|
|
break;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(!extName.isEmpty());
|
|
|
|
|
|
|
|
|
|
QString selectedFile = ui->fileDialog->selectedFiles()[0];
|
|
|
|
|
int pos = selectedFile.lastIndexOf('/');
|
|
|
|
|
if (-1 != pos)
|
|
|
|
|
{
|
|
|
|
|
QString path = selectedFile.left(pos + 1);
|
|
|
|
|
QString name = selectedFile.right(selectedFile.count() - pos - 1);
|
2022-08-22 06:35:42 +00:00
|
|
|
|
|
|
|
|
|
bool checked = ui->cbox_subFolder->isChecked();
|
2022-08-24 03:03:41 +00:00
|
|
|
|
|
2022-08-22 06:35:42 +00:00
|
|
|
|
if(checked)
|
|
|
|
|
{
|
2022-08-24 03:03:41 +00:00
|
|
|
|
QString dirName = NULL;
|
2022-08-22 06:35:42 +00:00
|
|
|
|
dirName = path + QDateTime::currentDateTime().toString("yy-MM-dd hh.mm.ss");
|
|
|
|
|
QDir dir(dirName);
|
|
|
|
|
if(!dir.exists())
|
|
|
|
|
{
|
|
|
|
|
dir.mkdir(dirName);
|
|
|
|
|
}
|
2022-08-24 03:03:41 +00:00
|
|
|
|
path = dirName;
|
2022-08-22 06:35:42 +00:00
|
|
|
|
}
|
2022-08-24 03:03:41 +00:00
|
|
|
|
|
2022-08-12 01:28:30 +00:00
|
|
|
|
if(name.endsWith(extName))
|
2022-08-22 06:35:42 +00:00
|
|
|
|
m_savePath = getStdFileName(path + "/" + name);
|
2022-08-12 01:47:03 +00:00
|
|
|
|
else
|
2022-08-22 06:35:42 +00:00
|
|
|
|
m_savePath = getStdFileName(path + "/" + name + extName);
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 04:00:14 +00:00
|
|
|
|
#if 0
|
2023-03-02 03:21:09 +00:00
|
|
|
|
int ocrLanguage = ui->comboBox_ocrType->currentIndex();
|
|
|
|
|
saveCfgValue("saveAs", "ocrLanguage", ocrLanguage);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
|
saveCfgValue("saveAs", "suffix", m_suffix);
|
2022-08-22 06:35:42 +00:00
|
|
|
|
saveCfgValue("saveAs", "subFolderByTime", ui->cbox_subFolder->isChecked());
|
2022-05-03 10:25:52 +00:00
|
|
|
|
accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog_SaveAs::on_filterSelected(const QString& filterName)
|
|
|
|
|
{
|
|
|
|
|
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
|
2023-03-03 09:57:31 +00:00
|
|
|
|
ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix || 7 == m_suffix || 8 == m_suffix);
|
2023-03-02 03:21:09 +00:00
|
|
|
|
|
2023-03-03 04:00:14 +00:00
|
|
|
|
#if 0
|
2023-03-02 03:21:09 +00:00
|
|
|
|
ui->label_ocrType->setVisible(isOcr());
|
|
|
|
|
ui->comboBox_ocrType->setVisible(isOcr());
|
|
|
|
|
#endif
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dialog_SaveAs::on_btn_option_clicked()
|
|
|
|
|
{
|
2022-05-13 12:38:58 +00:00
|
|
|
|
Dialog_WriteSettings dlg(m_suffix, this);
|
|
|
|
|
dlg.exec();
|
2022-05-03 10:25:52 +00:00
|
|
|
|
}
|