1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Fixed PNG/PDF export dialogues on Android

This commit is contained in:
Martin Tůma 2022-08-07 22:31:10 +02:00
parent 209df67380
commit 525f70f15e
4 changed files with 28 additions and 13 deletions

View File

@ -5,13 +5,16 @@
#include <QFileInfo> #include <QFileInfo>
#include <QApplication> #include <QApplication>
#include <QFontMetrics> #include <QFontMetrics>
#include "common/util.h"
#include "fileselectwidget.h" #include "fileselectwidget.h"
FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent) FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
{ {
_edit = new QLineEdit(); _edit = new QLineEdit();
#ifndef Q_OS_ANDROID #ifdef Q_OS_ANDROID
_edit->setDisabled(true);
#else // Q_OS_ANDROID
QFontMetrics fm(QApplication::font()); QFontMetrics fm(QApplication::font());
_edit->setMinimumWidth(fm.averageCharWidth() * (QDir::homePath().length() _edit->setMinimumWidth(fm.averageCharWidth() * (QDir::homePath().length()
+ 12)); + 12));
@ -37,39 +40,44 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
void FileSelectWidget::browse() 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()); QFileInfo fi(_edit->text());
QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"), QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"),
fi.dir().absolutePath(), _filter); fi.dir().absolutePath(), _filter);
if (!fileName.isEmpty()) if (!fileName.isEmpty())
_edit->setText(fileName); _edit->setText(fileName);
#endif // Q_OS_ANDROID
} }
bool FileSelectWidget::checkFile(QString &error) const bool FileSelectWidget::checkFile(QString &error) const
{ {
if (_edit->text().isEmpty()) { if (file().isEmpty()) {
error = tr("No output file selected."); error = tr("No output file selected.");
return false; return false;
} }
QFile file(_edit->text()); QFile f(file());
QFileInfo fi(file); QFileInfo fi(f);
bool exists = fi.exists(); bool exists = fi.exists();
bool opened = false; bool opened = false;
if (exists && fi.isDir()) { if (exists && fi.isDir()) {
error = tr("%1 is a directory.").arg(file.fileName()); error = tr("%1 is a directory.").arg(f.fileName());
return false; return false;
} else if ((exists && !fi.isWritable()) } else if ((exists && !fi.isWritable())
|| !(opened = file.open(QFile::Append))) { || !(opened = f.open(QFile::Append))) {
error = tr("%1 is not writable.").arg(file.fileName()); error = tr("%1 is not writable.").arg(f.fileName());
return false; return false;
} }
if (opened) { if (opened) {
file.close(); f.close();
if (!exists) if (!exists)
file.remove(); f.remove();
} }
return true; return true;

View File

@ -14,9 +14,13 @@ class FileSelectWidget : public QWidget
public: public:
FileSelectWidget(QWidget *parent = 0); FileSelectWidget(QWidget *parent = 0);
#ifdef Q_OS_ANDROID
QString file() const {return _fileName;}
#else // Q_OS_ANDROID
QString file() const {return _edit->text();} QString file() const {return _edit->text();}
void setFile(const QString &file) {_edit->setText(file);} void setFile(const QString &file) {_edit->setText(file);}
void setFilter(const QString &filter) {_filter = filter;} void setFilter(const QString &filter) {_filter = filter;}
#endif // Q_OS_ANDROID
bool checkFile(QString &error) const; bool checkFile(QString &error) const;
private slots: private slots:
@ -29,8 +33,11 @@ private:
#else // Q_OS_WIN32 #else // Q_OS_WIN32
QToolButton *_button; QToolButton *_button;
#endif // Q_OS_WIN32 #endif // Q_OS_WIN32
#ifdef Q_OS_ANDROID
QString _fileName;
#else // Q_OS_ANDROID
QString _filter; QString _filter;
#endif // Q_OS_ANDROID
}; };
#endif // FILESELECTWIDGET_H #endif // FILESELECTWIDGET_H

View File

@ -27,8 +27,8 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
_fileSelect->setFilter(tr("PDF files") + " (*.pdf);;" + tr("All files") _fileSelect->setFilter(tr("PDF files") + " (*.pdf);;" + tr("All files")
+ " (*)"); + " (*)");
#endif // Q_OS_ANDROID
_fileSelect->setFile(_export.fileName); _fileSelect->setFile(_export.fileName);
#endif // Q_OS_ANDROID
_paperSize = new QComboBox(); _paperSize = new QComboBox();
_paperSize->addItem("A2", QPageSize::PageSizeId::A2); _paperSize->addItem("A2", QPageSize::PageSizeId::A2);

View File

@ -24,8 +24,8 @@ PNGExportDialog::PNGExportDialog(PNGExport &exp, QWidget *parent)
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
_fileSelect->setFilter(tr("PNG files") + " (*.png);;" + tr("All files") _fileSelect->setFilter(tr("PNG files") + " (*.png);;" + tr("All files")
+ " (*)"); + " (*)");
#endif // Q_OS_ANDROID
_fileSelect->setFile(_export.fileName); _fileSelect->setFile(_export.fileName);
#endif // Q_OS_ANDROID
_width = new QSpinBox(); _width = new QSpinBox();
_width->setMinimum(256); _width->setMinimum(256);