#include "dialog_saveas.h" #include "ui_dialog_saveas.h" #include "dialog_savequality.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)"); 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_saveQuality = getCfgValue("saveAs", "quality", 0); m_suffix = getCfgValue("saveAs", "suffix", 0); ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix)); } Dialog_SaveAs::~Dialog_SaveAs() { delete ui; } QString Dialog_SaveAs::getSavePath() { return m_savePath; } int Dialog_SaveAs::getSaveQuality() { return m_saveQuality; } 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", "quality", m_saveQuality); saveCfgValue("saveAs", "suffix", m_suffix); accept(); } void Dialog_SaveAs::on_filterSelected(const QString& filterName) { m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); } void Dialog_SaveAs::on_btn_option_clicked() { Dialog_SaveQuality dlg(m_saveQuality, this); if (dlg.exec()) { m_saveQuality = dlg.getSaveQuality(); } }