#include "dialog_saveas.h" #include "ui_dialog_saveas.h" #include "dialog_writesettings.h" #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);;" "OCR->PDF - Portable Document Format(*.pdf);;" "OCR->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); if (m_suffix > 7) m_suffix = 7; else if (m_suffix < 0) m_suffix = 0; ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix)); ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix); } Dialog_SaveAs::~Dialog_SaveAs() { delete ui; } QString Dialog_SaveAs::getSavePath() { return m_savePath; } int Dialog_SaveAs::getJpegQuality() { 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); } bool Dialog_SaveAs::isOcr() { return (m_suffix >= 6); } 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; case 6: extName = ".pdf"; break; case 7: 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); } void Dialog_SaveAs::on_btn_option_clicked() { Dialog_WriteSettings dlg(m_suffix, this); dlg.exec(); }