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

Improved PDF export dialog

This commit is contained in:
Martin Tůma 2016-05-25 23:27:07 +02:00
parent 82cbbbb52a
commit 82df1bec0e
8 changed files with 88 additions and 81 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1" language="cs_CZ"> <TS version="2.0" language="cs_CZ">
<context> <context>
<name>ElevationGraph</name> <name>ElevationGraph</name>
<message> <message>
@ -59,76 +59,76 @@
<context> <context>
<name>ExportDialog</name> <name>ExportDialog</name>
<message> <message>
<location filename="../src/exportdialog.cpp" line="21"/> <location filename="../src/exportdialog.cpp" line="20"/>
<source>Export to PDF</source> <source>Export to PDF</source>
<translation>Exportovat do PDF</translation> <translation>Exportovat do PDF</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="24"/> <location filename="../src/exportdialog.cpp" line="23"/>
<source>PDF files (*.pdf);;All files (*)</source> <source>PDF files (*.pdf);;All files (*)</source>
<translation>soubory PDF (*.pdf);;všechny soubory</translation> <translation>Soubory PDF (*.pdf);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="43"/> <location filename="../src/exportdialog.cpp" line="41"/>
<source>Portrait</source> <source>Portrait</source>
<translation>Na výšku</translation> <translation>Na výšku</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="44"/> <location filename="../src/exportdialog.cpp" line="42"/>
<source>Landscape</source> <source>Landscape</source>
<translation>Na šířku</translation> <translation>Na šířku</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="48"/> <location filename="../src/exportdialog.cpp" line="51"/>
<source>Export settings</source> <source>Settings</source>
<translation>Nastavení exportu</translation> <translation>Nastavení</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="50"/> <location filename="../src/exportdialog.cpp" line="53"/>
<source>Page size:</source> <source>Page size:</source>
<translation>Velikost stránky:</translation> <translation>Velikost stránky:</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="51"/> <location filename="../src/exportdialog.cpp" line="54"/>
<source>Orientation</source> <source>Orientation:</source>
<translation>Orientace</translation> <translation>Orientace:</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="52"/> <location filename="../src/exportdialog.cpp" line="55"/>
<source>Output file:</source> <source>Output file:</source>
<translation>Výstupní soubor:</translation> <translation>Výstupní soubor:</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="55"/> <location filename="../src/exportdialog.cpp" line="58"/>
<source>Export</source> <source>Export</source>
<translation>Exportovat</translation> <translation>Exportovat</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="59"/> <location filename="../src/exportdialog.cpp" line="62"/>
<source>Cancel</source> <source>Cancel</source>
<translation>Zrušit</translation> <translation>Zrušit</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="77"/> <location filename="../src/exportdialog.cpp" line="80"/>
<location filename="../src/exportdialog.cpp" line="84"/> <location filename="../src/exportdialog.cpp" line="90"/>
<location filename="../src/exportdialog.cpp" line="91"/> <location filename="../src/exportdialog.cpp" line="95"/>
<source>Error</source> <source>Error</source>
<translation>Chyba</translation> <translation>Chyba</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="77"/> <location filename="../src/exportdialog.cpp" line="80"/>
<source>No output file selected.</source> <source>No output file selected.</source>
<translation>Nebyl zvolen žádný výstupní soubor.</translation> <translation>Nebyl zvolen žádný výstupní soubor.</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="85"/> <location filename="../src/exportdialog.cpp" line="90"/>
<source>The output file is a directory.</source> <source>%1 is a directory.</source>
<translation>Výstupní soubor je adresář.</translation> <translation>%1 je adresář.</translation>
</message> </message>
<message> <message>
<location filename="../src/exportdialog.cpp" line="92"/> <location filename="../src/exportdialog.cpp" line="95"/>
<source>The output file is not writable.</source> <source>%1 is not writable.</source>
<translation>Výstupní soubor není zapisovatelný.</translation> <translation>%1 nelze zapsat.</translation>
</message> </message>
</context> </context>
<context> <context>
@ -211,14 +211,6 @@
<source>Print</source> <source>Print</source>
<translation>Tisknout</translation> <translation>Tisknout</translation>
</message> </message>
<message>
<source>Export</source>
<translation type="vanished">Exportovat</translation>
</message>
<message>
<source>Export as</source>
<translation type="vanished">Exportovat jako</translation>
</message>
<message> <message>
<location filename="../src/gui.cpp" line="228"/> <location filename="../src/gui.cpp" line="228"/>
<source>Load POI file</source> <source>Load POI file</source>
@ -410,7 +402,7 @@
<message> <message>
<location filename="../src/gui.cpp" line="518"/> <location filename="../src/gui.cpp" line="518"/>
<source>GPX files (*.gpx);;All files (*)</source> <source>GPX files (*.gpx);;All files (*)</source>
<translation>soubory GPX (*.gpx);;všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="585"/> <location filename="../src/gui.cpp" line="585"/>
@ -421,7 +413,7 @@
<message> <message>
<location filename="../src/gui.cpp" line="595"/> <location filename="../src/gui.cpp" line="595"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source> <source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="678"/> <location filename="../src/gui.cpp" line="678"/>

View File

@ -4,11 +4,11 @@
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QComboBox> #include <QComboBox>
#include <QRadioButton>
#include <QPushButton> #include <QPushButton>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QMessageBox> #include <QMessageBox>
#include <QLocale>
#include "fileselectwidget.h" #include "fileselectwidget.h"
#include "exportdialog.h" #include "exportdialog.h"
@ -22,33 +22,32 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
_fileSelect = new FileSelectWidget(); _fileSelect = new FileSelectWidget();
_fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)")); _fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)"));
_fileSelect->setFile(QString("%1/export.pdf").arg(QDir::currentPath())); _fileSelect->setFile(_printer->outputFileName());
_paperSize = new QComboBox(); _paperSize = new QComboBox();
_paperSize->addItem("A0", QPrinter::A0);
_paperSize->addItem("A1", QPrinter::A1);
_paperSize->addItem("A2", QPrinter::A2);
_paperSize->addItem("A3", QPrinter::A3); _paperSize->addItem("A3", QPrinter::A3);
_paperSize->addItem("A4", QPrinter::A4); _paperSize->addItem("A4", QPrinter::A4);
_paperSize->addItem("A5", QPrinter::A5); _paperSize->addItem("A5", QPrinter::A5);
_paperSize->addItem("A6", QPrinter::A6);
_paperSize->addItem("Tabloid", QPrinter::Tabloid); _paperSize->addItem("Tabloid", QPrinter::Tabloid);
_paperSize->addItem("Legal", QPrinter::Legal); _paperSize->addItem("Legal", QPrinter::Legal);
_paperSize->addItem("Letter", QPrinter::Letter); _paperSize->addItem("Letter", QPrinter::Letter);
index = (QLocale::system().measurementSystem() == QLocale::ImperialSystem) if ((index = _paperSize->findData(_printer->paperSize())) >= 0)
? 9 /* Letter */ : 4 /* A4 */; _paperSize->setCurrentIndex(index);
_paperSize->setCurrentIndex(index);
_orientation = new QComboBox(); _portrait = new QRadioButton(tr("Portrait"));
_orientation->addItem(tr("Portrait"), QPrinter::Portrait); _landscape = new QRadioButton(tr("Landscape"));
_orientation->addItem(tr("Landscape"), QPrinter::Landscape); QHBoxLayout *orientationLayout = new QHBoxLayout();
index = _printer->orientation() == QPrinter::Portrait ? 0 : 1; orientationLayout->addWidget(_portrait);
_orientation->setCurrentIndex(index); orientationLayout->addWidget(_landscape);
if (_printer->orientation() == QPrinter::Portrait)
_portrait->setChecked(true);
else
_landscape->setChecked(true);
QGroupBox *contentBox = new QGroupBox(tr("Export settings")); QGroupBox *contentBox = new QGroupBox(tr("Settings"));
QFormLayout *contentLayout = new QFormLayout; QFormLayout *contentLayout = new QFormLayout;
contentLayout->addRow(tr("Page size:"), _paperSize); contentLayout->addRow(tr("Page size:"), _paperSize);
contentLayout->addRow(tr("Orientation"), _orientation); contentLayout->addRow(tr("Orientation:"), orientationLayout);
contentLayout->addRow(tr("Output file:"), _fileSelect); contentLayout->addRow(tr("Output file:"), _fileSelect);
contentBox->setLayout(contentLayout); contentBox->setLayout(contentLayout);
@ -73,24 +72,30 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
bool ExportDialog::checkFile() bool ExportDialog::checkFile()
{ {
if (_fileSelect->file().isNull()) { if (_fileSelect->file().isEmpty()) {
QMessageBox::warning(this, tr("Error"), tr("No output file selected.")); QMessageBox::warning(this, tr("Error"), tr("No output file selected."));
return false; return false;
} }
QFileInfo fi(_fileSelect->file()); QFile file(_fileSelect->file());
QFileInfo fi(file);
bool exists = fi.exists();
bool opened = false;
if (fi.isDir()) { if (exists && fi.isDir()) {
QMessageBox::warning(this, tr("Error"), QMessageBox::warning(this, tr("Error"), tr("%1 is a directory.")
tr("The output file is a directory.")); .arg(file.fileName()));
return false;
} else if ((exists && !fi.isWritable())
|| !(opened = file.open(QFile::Append))) {
QMessageBox::warning(this, tr("Error"), tr("%1 is not writable.")
.arg(file.fileName()));
return false; return false;
} }
if (opened) {
QFileInfo di(fi.path()); file.close();
if (!di.isWritable()) { if (!exists)
QMessageBox::warning(this, tr("Error"), file.remove();
tr("The output file is not writable."));
return false;
} }
return true; return true;
@ -101,8 +106,8 @@ void ExportDialog::accept()
if (!checkFile()) if (!checkFile())
return; return;
QPrinter::Orientation orientation = static_cast<QPrinter::Orientation> QPrinter::Orientation orientation = _portrait->isChecked()
(_orientation->itemData(_orientation->currentIndex()).toInt()); ? QPrinter::Portrait : QPrinter::Landscape;
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize> QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize>
(_paperSize->itemData(_paperSize->currentIndex()).toInt()); (_paperSize->itemData(_paperSize->currentIndex()).toInt());

View File

@ -5,6 +5,7 @@
class QPrinter; class QPrinter;
class QComboBox; class QComboBox;
class QRadioButton;
class FileSelectWidget; class FileSelectWidget;
class ExportDialog : public QDialog class ExportDialog : public QDialog
@ -24,7 +25,8 @@ private:
FileSelectWidget *_fileSelect; FileSelectWidget *_fileSelect;
QComboBox *_paperSize; QComboBox *_paperSize;
QComboBox *_orientation; QRadioButton *_portrait;
QRadioButton *_landscape;
}; };
#endif // EXPORTDIALOG_H #endif // EXPORTDIALOG_H

View File

@ -13,7 +13,7 @@ class FileSelectWidget : public QWidget
public: public:
FileSelectWidget(QWidget *parent = 0); FileSelectWidget(QWidget *parent = 0);
QString file() {return _edit->text().isEmpty() ? QString() : _edit->text();} QString file() {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;}

View File

@ -5,7 +5,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinter>
#include <QPainter> #include <QPainter>
#include <QPaintEngine> #include <QPaintEngine>
#include <QPaintDevice> #include <QPaintDevice>
@ -90,6 +89,11 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
updateTrackView(); updateTrackView();
readSettings(); readSettings();
_exportPaperSize = (QLocale::system().measurementSystem()
== QLocale::ImperialSystem) ? QPrinter::Letter : QPrinter::A4;
_exportOrientation = QPrinter::Portrait;
_exportFileName = QString("%1/export.pdf").arg(QDir::currentPath());
} }
GUI::~GUI() GUI::~GUI()
@ -647,18 +651,24 @@ void GUI::printFile()
void GUI::exportFile() void GUI::exportFile()
{ {
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(_track->orientation()); printer.setOrientation(_exportOrientation);
printer.setOutputFileName(_exportFileName);
printer.setPaperSize(_exportPaperSize);
ExportDialog dialog(&printer, this); ExportDialog dialog(&printer, this);
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted) {
_exportFileName = printer.outputFileName();
_exportPaperSize = printer.paperSize();
_exportOrientation = printer.orientation();
plot(&printer); plot(&printer);
}
} }
void GUI::plot(QPrinter *printer) void GUI::plot(QPrinter *printer)
{ {
QPainter p(printer); QPainter p(printer);
TrackInfo info; TrackInfo info;
qreal ih, gh, mh; qreal ih, gh, mh, ratio;
if (_dateRange.first.isValid()) { if (_dateRange.first.isValid()) {
@ -685,12 +695,12 @@ void GUI::plot(QPrinter *printer)
info.insert(tr("Time"), timeSpan(_time)); info.insert(tr("Time"), timeSpan(_time));
ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI;
if (info.isEmpty()) { if (info.isEmpty()) {
ih = 0; ih = 0;
mh = 0; mh = 0;
} else { } else {
qreal r = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI; ih = info.contentSize().height() * ratio;
ih = info.contentSize().height() * r;
mh = ih / 2; mh = ih / 2;
info.plot(&p, QRectF(0, 0, printer->width(), ih)); info.plot(&p, QRectF(0, 0, printer->width(), ih));
} }
@ -699,6 +709,7 @@ void GUI::plot(QPrinter *printer)
gh = (printer->width() > printer->height()) gh = (printer->width() > printer->height())
? 0.15 * r * (printer->height() - ih - 2*mh) ? 0.15 * r * (printer->height() - ih - 2*mh)
: 0.15 * (printer->height() - ih - 2*mh); : 0.15 * (printer->height() - ih - 2*mh);
gh = qMax(gh, ratio * 150);
GraphView *gv = static_cast<GraphView*>(_trackGraphs->currentWidget()); GraphView *gv = static_cast<GraphView*>(_trackGraphs->currentWidget());
gv->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh)); gv->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
} else } else

View File

@ -5,6 +5,7 @@
#include <QString> #include <QString>
#include <QList> #include <QList>
#include <QDate> #include <QDate>
#include <QPrinter>
#include "poi.h" #include "poi.h"
class QMenu; class QMenu;
@ -174,6 +175,10 @@ private:
int _frameStyle; int _frameStyle;
bool _showGraphs; bool _showGraphs;
QString _exportFileName;
QPrinter::PaperSize _exportPaperSize;
QPrinter::Orientation _exportOrientation;
}; };
#endif // GUI_H #endif // GUI_H

View File

@ -380,12 +380,6 @@ void TrackView::plot(QPainter *painter, const QRectF &target)
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
enum QPrinter::Orientation TrackView::orientation() const
{
return (sceneRect().width() > sceneRect().height())
? QPrinter::Landscape : QPrinter::Portrait;
}
void TrackView::clearPOI() void TrackView::clearPOI()
{ {
QHash<Waypoint, WaypointItem*>::const_iterator it; QHash<Waypoint, WaypointItem*>::const_iterator it;

View File

@ -5,7 +5,6 @@
#include <QVector> #include <QVector>
#include <QHash> #include <QHash>
#include <QList> #include <QList>
#include <QPrinter>
#include "units.h" #include "units.h"
#include "palette.h" #include "palette.h"
#include "waypoint.h" #include "waypoint.h"
@ -35,7 +34,6 @@ public:
void setUnits(enum Units units); void setUnits(enum Units units);
void plot(QPainter *painter, const QRectF &target); void plot(QPainter *painter, const QRectF &target);
enum QPrinter::Orientation orientation() const;
int trackCount() const {return _paths.count();} int trackCount() const {return _paths.count();}
int waypointCount() const {return _locations.count();} int waypointCount() const {return _locations.count();}