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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ class FileSelectWidget : public QWidget
public:
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 setFilter(const QString &filter) {_filter = filter;}

View File

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

View File

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

View File

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

View File

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