code_app/app/scanner/dialog_saveas.cpp

246 lines
6.9 KiB
C++
Raw Normal View History

2022-05-03 10:25:52 +00:00
#include "dialog_saveas.h"
#include "ui_dialog_saveas.h"
#include "dialog_writesettings.h"
2022-05-03 10:25:52 +00:00
#include "HGUIGlobal.h"
#include "app_cfg.h"
#include <assert.h>
#include <qabstractproxymodel.h>
#include <QDateTime>
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);
ui->fileDialog->setAcceptMode(QFileDialog::AcceptSave);
ui->fileDialog->setWindowFlags(ui->fileDialog->windowFlags() & ~Qt::Dialog);
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);
#if defined(OEM_LISICHENG) || defined(x86_64)
2022-07-18 11:17:26 +00:00
ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;"
"BMP - Windows Bitmap(*.bmp);;"
"PNG - Portable Network Graphics(*.png);;"
2022-11-06 10:13:08 +00:00
"PPM - Portable PixMap(*.ppm);;"
"PGM - Portable GreyMap(*.pgm);;"
"PBM - Portable BitMap(*.pbm);;"
2022-07-18 11:17:26 +00:00
"TIF - TIFF Revision 6(*.tif);;"
"PDF - Portable Document Format(*.pdf);;"
2022-08-04 08:31:58 +00:00
"OFD - Open Fixed-layout Document(*.ofd);;"
"GIF - Graphics Interchange Format(*.gif)");
2022-07-18 11:17:26 +00:00
#else
2022-05-03 10:25:52 +00:00
ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;"
"BMP - Windows Bitmap(*.bmp);;"
"PNG - Portable Network Graphics(*.png);;"
2022-11-06 10:13:08 +00:00
"PPM - Portable PixMap(*.ppm);;"
"PGM - Portable GreyMap(*.pgm);;"
"PBM - Portable BitMap(*.pbm);;"
2022-05-03 10:25:52 +00:00
"TIF - TIFF Revision 6(*.tif);;"
"PDF - Portable Document Format(*.pdf);;"
2022-05-16 09:00:08 +00:00
"OFD - Open Fixed-layout Document(*.ofd);;"
"GIF - Graphics Interchange Format(*.gif);;"
2022-05-16 09:00:08 +00:00
"OCR->PDF - Portable Document Format(*.pdf);;"
2022-09-02 05:08:51 +00:00
"OCR->OFD - Open Fixed-layout Document(*.ofd);;"
"OCR->RTF - Rich Text Format(*.rtf)");
2022-07-18 11:17:26 +00:00
#endif
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);
ui->cbox_subFolder->setChecked(false);
ui->cbox_subFolder->setChecked(getCfgValue("saveAs", "subFolderByTime", false));
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;
}
int Dialog_SaveAs::getJpegQuality()
2022-05-03 10:25:52 +00:00
{
return getCfgValue("saveParam", "jpegQuality", 80);
}
int Dialog_SaveAs::getTiffCompressionBW()
{
return getCfgValue("saveParam", "tiffCompBW", 1);
}
int Dialog_SaveAs::getTiffCompression()
{
return getCfgValue("saveParam", "tiffCompClr", 1);
}
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
}
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:
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);
bool checked = ui->cbox_subFolder->isChecked();
2022-08-24 03:03:41 +00:00
if(checked)
{
2022-08-24 03:03:41 +00:00
QString dirName = NULL;
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-24 03:03:41 +00:00
2022-08-12 01:28:30 +00:00
if(name.endsWith(extName))
m_savePath = getStdFileName(path + "/" + name);
2022-08-12 01:47:03 +00:00
else
m_savePath = getStdFileName(path + "/" + name + extName);
2022-05-03 10:25:52 +00:00
}
saveCfgValue("saveAs", "suffix", m_suffix);
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);
2022-11-06 10:13:08 +00:00
ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix);
2022-05-03 10:25:52 +00:00
}
void Dialog_SaveAs::on_btn_option_clicked()
{
Dialog_WriteSettings dlg(m_suffix, this);
dlg.exec();
2022-05-03 10:25:52 +00:00
}