From 525f70f15ed872a4fc6d9fe0c724402d3b0dfb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 7 Aug 2022 22:31:10 +0200 Subject: [PATCH] Fixed PNG/PDF export dialogues on Android --- src/GUI/fileselectwidget.cpp | 28 ++++++++++++++++++---------- src/GUI/fileselectwidget.h | 9 ++++++++- src/GUI/pdfexportdialog.cpp | 2 +- src/GUI/pngexportdialog.cpp | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/GUI/fileselectwidget.cpp b/src/GUI/fileselectwidget.cpp index 6f2de6ab..d3301a52 100644 --- a/src/GUI/fileselectwidget.cpp +++ b/src/GUI/fileselectwidget.cpp @@ -5,13 +5,16 @@ #include #include #include +#include "common/util.h" #include "fileselectwidget.h" FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent) { _edit = new QLineEdit(); -#ifndef Q_OS_ANDROID +#ifdef Q_OS_ANDROID + _edit->setDisabled(true); +#else // Q_OS_ANDROID QFontMetrics fm(QApplication::font()); _edit->setMinimumWidth(fm.averageCharWidth() * (QDir::homePath().length() + 12)); @@ -37,39 +40,44 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent) void FileSelectWidget::browse() { +#ifdef Q_OS_ANDROID + _fileName = QFileDialog::getSaveFileName(this, tr("Select file")); + if (!_fileName.isEmpty()) + _edit->setText(Util::displayName(_fileName)); +#else // Q_OS_ANDROID QFileInfo fi(_edit->text()); QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"), fi.dir().absolutePath(), _filter); - if (!fileName.isEmpty()) _edit->setText(fileName); +#endif // Q_OS_ANDROID } bool FileSelectWidget::checkFile(QString &error) const { - if (_edit->text().isEmpty()) { + if (file().isEmpty()) { error = tr("No output file selected."); return false; } - QFile file(_edit->text()); - QFileInfo fi(file); + QFile f(file()); + QFileInfo fi(f); bool exists = fi.exists(); bool opened = false; if (exists && fi.isDir()) { - error = tr("%1 is a directory.").arg(file.fileName()); + error = tr("%1 is a directory.").arg(f.fileName()); return false; } else if ((exists && !fi.isWritable()) - || !(opened = file.open(QFile::Append))) { - error = tr("%1 is not writable.").arg(file.fileName()); + || !(opened = f.open(QFile::Append))) { + error = tr("%1 is not writable.").arg(f.fileName()); return false; } if (opened) { - file.close(); + f.close(); if (!exists) - file.remove(); + f.remove(); } return true; diff --git a/src/GUI/fileselectwidget.h b/src/GUI/fileselectwidget.h index 619b9c2b..7923f112 100644 --- a/src/GUI/fileselectwidget.h +++ b/src/GUI/fileselectwidget.h @@ -14,9 +14,13 @@ class FileSelectWidget : public QWidget public: FileSelectWidget(QWidget *parent = 0); +#ifdef Q_OS_ANDROID + QString file() const {return _fileName;} +#else // Q_OS_ANDROID QString file() const {return _edit->text();} void setFile(const QString &file) {_edit->setText(file);} void setFilter(const QString &filter) {_filter = filter;} +#endif // Q_OS_ANDROID bool checkFile(QString &error) const; private slots: @@ -29,8 +33,11 @@ private: #else // Q_OS_WIN32 QToolButton *_button; #endif // Q_OS_WIN32 - +#ifdef Q_OS_ANDROID + QString _fileName; +#else // Q_OS_ANDROID QString _filter; +#endif // Q_OS_ANDROID }; #endif // FILESELECTWIDGET_H diff --git a/src/GUI/pdfexportdialog.cpp b/src/GUI/pdfexportdialog.cpp index b4f5a55e..d4aa7ae0 100644 --- a/src/GUI/pdfexportdialog.cpp +++ b/src/GUI/pdfexportdialog.cpp @@ -27,8 +27,8 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent) #ifndef Q_OS_ANDROID _fileSelect->setFilter(tr("PDF files") + " (*.pdf);;" + tr("All files") + " (*)"); -#endif // Q_OS_ANDROID _fileSelect->setFile(_export.fileName); +#endif // Q_OS_ANDROID _paperSize = new QComboBox(); _paperSize->addItem("A2", QPageSize::PageSizeId::A2); diff --git a/src/GUI/pngexportdialog.cpp b/src/GUI/pngexportdialog.cpp index 4aeff14c..c048afce 100644 --- a/src/GUI/pngexportdialog.cpp +++ b/src/GUI/pngexportdialog.cpp @@ -24,8 +24,8 @@ PNGExportDialog::PNGExportDialog(PNGExport &exp, QWidget *parent) #ifndef Q_OS_ANDROID _fileSelect->setFilter(tr("PNG files") + " (*.png);;" + tr("All files") + " (*)"); -#endif // Q_OS_ANDROID _fileSelect->setFile(_export.fileName); +#endif // Q_OS_ANDROID _width = new QSpinBox(); _width->setMinimum(256);