mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Fixed PNG/PDF export dialogues on Android
This commit is contained in:
parent
209df67380
commit
525f70f15e
@ -5,13 +5,16 @@
|
||||
#include <QFileInfo>
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
#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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user