diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index 0aa9faa5..4e2df204 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -1,6 +1,6 @@ - + ElevationGraph @@ -59,76 +59,76 @@ ExportDialog - + Export to PDF Exportovat do PDF - + PDF files (*.pdf);;All files (*) - soubory PDF (*.pdf);;všechny soubory + Soubory PDF (*.pdf);;Všechny soubory (*) - + Portrait Na výšku - + Landscape Na šířku - - Export settings - Nastavení exportu + + Settings + Nastavení - + Page size: Velikost stránky: - - Orientation - Orientace + + Orientation: + Orientace: - + Output file: Výstupní soubor: - + Export Exportovat - + Cancel Zrušit - - - + + + Error Chyba - + No output file selected. Nebyl zvolen žádný výstupní soubor. - - The output file is a directory. - Výstupní soubor je adresář. + + %1 is a directory. + %1 je adresář. - - The output file is not writable. - Výstupní soubor není zapisovatelný. + + %1 is not writable. + %1 nelze zapsat. @@ -211,14 +211,6 @@ Print Tisknout - - Export - Exportovat - - - Export as - Exportovat jako - Load POI file @@ -410,7 +402,7 @@ GPX files (*.gpx);;All files (*) - soubory GPX (*.gpx);;všechny soubory (*) + Soubory GPX (*.gpx);;Všechny soubory (*) @@ -421,7 +413,7 @@ GPX files (*.gpx);;CSV files (*.csv);;All files (*) - soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*) + Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*) diff --git a/src/exportdialog.cpp b/src/exportdialog.cpp index 33ad30ca..19257a7d 100644 --- a/src/exportdialog.cpp +++ b/src/exportdialog.cpp @@ -4,11 +4,11 @@ #include #include #include +#include #include #include #include #include -#include #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 */; - _paperSize->setCurrentIndex(index); + 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 - (_orientation->itemData(_orientation->currentIndex()).toInt()); + QPrinter::Orientation orientation = _portrait->isChecked() + ? QPrinter::Portrait : QPrinter::Landscape; QPrinter::PaperSize paperSize = static_cast (_paperSize->itemData(_paperSize->currentIndex()).toInt()); diff --git a/src/exportdialog.h b/src/exportdialog.h index fe1fd33d..e4f63db4 100644 --- a/src/exportdialog.h +++ b/src/exportdialog.h @@ -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 diff --git a/src/fileselectwidget.h b/src/fileselectwidget.h index 02ad0e81..ee0901e2 100644 --- a/src/fileselectwidget.h +++ b/src/fileselectwidget.h @@ -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;} diff --git a/src/gui.cpp b/src/gui.cpp index 2e44c22e..f7cdea4d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -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(_trackGraphs->currentWidget()); gv->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh)); } else diff --git a/src/gui.h b/src/gui.h index 22e04c45..4f6f7863 100644 --- a/src/gui.h +++ b/src/gui.h @@ -5,6 +5,7 @@ #include #include #include +#include #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 diff --git a/src/trackview.cpp b/src/trackview.cpp index 1efee1e2..247dc66a 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -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::const_iterator it; diff --git a/src/trackview.h b/src/trackview.h index 1df0ca33..1506f186 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -5,7 +5,6 @@ #include #include #include -#include #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();}