code_app/app/scanner/dialog_saveas.cpp

119 lines
3.0 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"
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->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)");
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);
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix);
2022-05-03 10:25:52 +00:00
}
Dialog_SaveAs::~Dialog_SaveAs()
{
delete ui;
}
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", "tiffCompressionBW", 1);
}
int Dialog_SaveAs::getTiffCompression()
{
return getCfgValue("saveParam", "tiffCompression", 1);
}
int Dialog_SaveAs::getTiffQuality()
{
return getCfgValue("saveParam", "tiffQuality", 80);
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:
extName = ".tif";
break;
case 4:
extName = ".pdf";
break;
case 5:
extName = ".ofd";
break;
}
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);
pos = name.lastIndexOf('.');
if (-1 != pos)
name = name.left(pos);
m_savePath = getStdFileName(path + name + extName);
}
saveCfgValue("saveAs", "suffix", m_suffix);
accept();
}
void Dialog_SaveAs::on_filterSelected(const QString& filterName)
{
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
ui->btn_option->setEnabled(0 == m_suffix || 3 == 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
}