diff --git a/gpxsee.pro b/gpxsee.pro index 154ff20e..d497e3fd 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -40,7 +40,9 @@ HEADERS += src/config.h \ src/cpuarch.h \ src/settings.h \ src/app.h \ - src/trackinfo.h + src/trackinfo.h \ + src/exportdialog.h \ + src/fileselectwidget.h SOURCES += src/main.cpp \ src/gui.cpp \ src/gpx.cpp \ @@ -68,7 +70,9 @@ SOURCES += src/main.cpp \ src/heartrategraph.cpp \ src/range.cpp \ src/app.cpp \ - src/trackinfo.cpp + src/trackinfo.cpp \ + src/exportdialog.cpp \ + src/fileselectwidget.cpp RESOURCES += gpxsee.qrc TRANSLATIONS = lang/gpxsee_cs.ts macx { diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index 93881291..0aa9faa5 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -56,20 +56,108 @@ Maximum + + ExportDialog + + + Export to PDF + Exportovat do PDF + + + + PDF files (*.pdf);;All files (*) + soubory PDF (*.pdf);;všechny soubory + + + + Portrait + Na výšku + + + + Landscape + Na šířku + + + + Export settings + Nastavení exportu + + + + Page size: + Velikost stránky: + + + + 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ář. + + + + The output file is not writable. + Výstupní soubor není zapisovatelný. + + + + FileSelectWidget + + + Browse... + Procházet... + + + + Select file + Vybrat soubor + + GUI - + GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese - + Open file Otevřít soubor - + Open POI file Otevřít POI soubor @@ -85,36 +173,36 @@ - - + + Keyboard controls Ovládací klávesy - + Close Zavřít - + Reload Znovu načíst - + Show Zobrazit - - + + File Soubor - - + + Data sources Zdroje dat @@ -124,293 +212,291 @@ Tisknout - Export - Exportovat + Exportovat - Export as - Exportovat jako + Exportovat jako - + Load POI file Nahrát POI soubor - + Close POI files Zavřit POI soubory - + Show POIs Zobrazit POI - + Show map Zobrazit mapu - + Clear tile cache Vymazat mezipaměť dlaždic + - - + Next map Následující mapa - + Show graphs Zobrazovat grafy - + Show toolbars Zobrazovat nástrojové lišty - + Metric Metrické - + Imperial Imperiální - + Fullscreen mode Celoobrazovkový režim - + Next Následující - + Previous Předchozí - + Last Poslední - + First První - + Map Mapa - + POI POI - + POI files POI soubory - + Settings Nastavení - + Units Jednotky - + Help Nápověda - + Previous map Předchozí mapa - + Export to PDF Exportovat do PDF - - + + Date Datum - + No GPX files loaded Nejsou načteny žádné GPX soubory - + Elevation Výška - + Speed Rychlost - + Heart rate Tep - + Next file Následující soubor - + Version Verze - + Previous file Předchozí soubor - + First file První soubor - + Last file Poslední soubor - + Append modifier Modifikátor nahradit/přidat - + Map (tiles) source URLs are read on program startup from the following file: URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru: - + The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like: Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad: - + To make GPXSee load a POI file automatically on startup, add the file to the following directory: POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře: - + GPX files (*.gpx);;All files (*) soubory GPX (*.gpx);;všechny soubory (*) - - + + Line: %1 Řádka: %1 - + GPX files (*.gpx);;CSV files (*.csv);;All files (*) soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*) - - + + mi mi - + ft ft - + About GPXSee O aplikaci GPXSee - + Navigation Navigace - + Map sources Mapové zdroje - + POIs POI body - - + + Distance Vzdálenost - + Time Čas - + m m - + %1 tracks Počet tras: %1 - - + + km km - - + + Error Chyba - + Error loading GPX file: %1 Soubor GPX nelze otevřít: %1 - + Error loading POI file: %1 Soubor POI nelze otevřít: diff --git a/src/exportdialog.cpp b/src/exportdialog.cpp new file mode 100644 index 00000000..33ad30ca --- /dev/null +++ b/src/exportdialog.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fileselectwidget.h" +#include "exportdialog.h" + + +ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent) + : QDialog(parent), _printer(printer) +{ + int index; + + setWindowTitle(tr("Export to PDF")); + + _fileSelect = new FileSelectWidget(); + _fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)")); + _fileSelect->setFile(QString("%1/export.pdf").arg(QDir::currentPath())); + + _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); + + _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); + + QGroupBox *contentBox = new QGroupBox(tr("Export settings")); + QFormLayout *contentLayout = new QFormLayout; + contentLayout->addRow(tr("Page size:"), _paperSize); + contentLayout->addRow(tr("Orientation"), _orientation); + contentLayout->addRow(tr("Output file:"), _fileSelect); + contentBox->setLayout(contentLayout); + + QPushButton *exportButton = new QPushButton(tr("Export")); + exportButton->setAutoDefault(true); + exportButton->setDefault(true); + connect(exportButton, SIGNAL(clicked()), this, SLOT(accept())); + QPushButton *cancelButton = new QPushButton(tr("Cancel")); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + QHBoxLayout *buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch(); + buttonsLayout->addWidget(exportButton); + buttonsLayout->addWidget(cancelButton); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(contentBox); + layout->addLayout(buttonsLayout); + + setLayout(layout); +} + +bool ExportDialog::checkFile() +{ + if (_fileSelect->file().isNull()) { + QMessageBox::warning(this, tr("Error"), tr("No output file selected.")); + return false; + } + + QFileInfo fi(_fileSelect->file()); + + if (fi.isDir()) { + QMessageBox::warning(this, tr("Error"), + tr("The output file is a directory.")); + return false; + } + + QFileInfo di(fi.path()); + if (!di.isWritable()) { + QMessageBox::warning(this, tr("Error"), + tr("The output file is not writable.")); + return false; + } + + return true; +} + +void ExportDialog::accept() +{ + if (!checkFile()) + return; + + QPrinter::Orientation orientation = static_cast + (_orientation->itemData(_orientation->currentIndex()).toInt()); + QPrinter::PaperSize paperSize = static_cast + (_paperSize->itemData(_paperSize->currentIndex()).toInt()); + + _printer->setOutputFormat(QPrinter::PdfFormat); + _printer->setOutputFileName(_fileSelect->file()); + _printer->setPaperSize(paperSize); + _printer->setOrientation(orientation); + + QDialog::accept(); +} diff --git a/src/exportdialog.h b/src/exportdialog.h new file mode 100644 index 00000000..fe1fd33d --- /dev/null +++ b/src/exportdialog.h @@ -0,0 +1,30 @@ +#ifndef EXPORTDIALOG_H +#define EXPORTDIALOG_H + +#include + +class QPrinter; +class QComboBox; +class FileSelectWidget; + +class ExportDialog : public QDialog +{ + Q_OBJECT + +public: + ExportDialog(QPrinter *printer, QWidget *parent = 0); + +public slots: + void accept(); + +private: + bool checkFile(); + + QPrinter *_printer; + + FileSelectWidget *_fileSelect; + QComboBox *_paperSize; + QComboBox *_orientation; +}; + +#endif // EXPORTDIALOG_H diff --git a/src/fileselectwidget.cpp b/src/fileselectwidget.cpp new file mode 100644 index 00000000..0df1a6b3 --- /dev/null +++ b/src/fileselectwidget.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include "fileselectwidget.h" + + +FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent) +{ + _edit = new QLineEdit(); + _button = new QPushButton(tr("Browse...")); + connect(_button, SIGNAL(clicked()), this, SLOT(browse())); + + QHBoxLayout *layout = new QHBoxLayout(); + layout->setMargin(0); + layout->addWidget(_edit); + layout->addWidget(_button); + setLayout(layout); +} + +void FileSelectWidget::browse() +{ + QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"), + QDir::currentPath(), _filter); + + if (!fileName.isEmpty()) + _edit->setText(fileName); +} diff --git a/src/fileselectwidget.h b/src/fileselectwidget.h new file mode 100644 index 00000000..02ad0e81 --- /dev/null +++ b/src/fileselectwidget.h @@ -0,0 +1,30 @@ +#ifndef FILESELECTWIDGET_H +#define FILESELECTWIDGET_H + +#include +#include + +class QPushButton; + +class FileSelectWidget : public QWidget +{ + Q_OBJECT + +public: + FileSelectWidget(QWidget *parent = 0); + + QString file() {return _edit->text().isEmpty() ? QString() : _edit->text();} + void setFile(const QString &file) {_edit->setText(file);} + void setFilter(const QString &filter) {_filter = filter;} + +private slots: + void browse(); + +private: + QLineEdit *_edit; + QPushButton *_button; + + QString _filter; +}; + +#endif // FILESELECTWIDGET_H diff --git a/src/gui.cpp b/src/gui.cpp index 7492c199..2e44c22e 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -33,6 +33,7 @@ #include "trackinfo.h" #include "filebrowser.h" #include "cpuarch.h" +#include "exportdialog.h" #include "gui.h" @@ -204,15 +205,11 @@ void GUI::createActions() connect(_printFileAction, SIGNAL(triggered()), this, SLOT(printFile())); addAction(_printFileAction); _exportFileAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)), - tr("Export"), this); + tr("Export to PDF"), this); _exportFileAction->setShortcut(EXPORT_SHORTCUT); _exportFileAction->setActionGroup(_fileActionGroup); connect(_exportFileAction, SIGNAL(triggered()), this, SLOT(exportFile())); addAction(_exportFileAction); - _exportAsAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)), - tr("Export as"), this); - _exportAsAction->setActionGroup(_fileActionGroup); - connect(_exportAsAction, SIGNAL(triggered()), this, SLOT(exportAs())); _closeFileAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)), tr("Close"), this); _closeFileAction->setShortcut(CLOSE_SHORTCUT); @@ -322,7 +319,6 @@ void GUI::createMenus() _fileMenu->addSeparator(); _fileMenu->addAction(_printFileAction); _fileMenu->addAction(_exportFileAction); - _fileMenu->addAction(_exportAsAction); _fileMenu->addSeparator(); _fileMenu->addAction(_reloadFileAction); _fileMenu->addSeparator(); @@ -642,46 +638,28 @@ void GUI::closePOIFiles() void GUI::printFile() { QPrinter printer(QPrinter::HighResolution); - QPrintDialog printDialog(&printer, this); + QPrintDialog dialog(&printer, this); - if (printDialog.exec() == QDialog::Accepted) + if (dialog.exec() == QDialog::Accepted) plot(&printer); } -void GUI::exportAs() -{ - QString fileName = QFileDialog::getSaveFileName(this, tr("Export to PDF"), - QString(), "*.pdf"); - - if (!fileName.isEmpty()) { - exportFile(fileName); - _exportFileName = fileName; - } -} - void GUI::exportFile() -{ - if (_exportFileName.isEmpty()) - emit exportAs(); - else - exportFile(_exportFileName); -} - -void GUI::exportFile(const QString &fileName) { QPrinter printer(QPrinter::HighResolution); - printer.setPageSize(QPrinter::A4); printer.setOrientation(_track->orientation()); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(fileName); + ExportDialog dialog(&printer, this); - plot(&printer); + if (dialog.exec() == QDialog::Accepted) + plot(&printer); } void GUI::plot(QPrinter *printer) { QPainter p(printer); TrackInfo info; + qreal ih, gh, mh; + if (_dateRange.first.isValid()) { if (_dateRange.first == _dateRange.second) { @@ -707,37 +685,26 @@ void GUI::plot(QPrinter *printer) info.insert(tr("Time"), timeSpan(_time)); - qreal ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI; - qreal ih = info.contentSize().height() * ratio; - qreal mh = ih / 2; - -#define GRR(printer) \ - (((printer)->width() > (printer)->height()) \ - ? 0.15 * ((qreal)((printer)->width()) / (qreal)((printer)->height())) \ - : 0.15) -#define TRR(printer) \ - (1.0 - GRR(printer)) - if (info.isEmpty()) { - if (_trackGraphs->isVisible()) - _track->plot(&p, QRectF(0, 0, printer->width(), - (TRR(printer) * printer->height()))); - else - _track->plot(&p, QRectF(0, 0, printer->width(), printer->height())); + ih = 0; + mh = 0; } else { + qreal r = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI; + ih = info.contentSize().height() * r; + mh = ih / 2; info.plot(&p, QRectF(0, 0, printer->width(), ih)); - if (_trackGraphs->isVisible()) - _track->plot(&p, QRectF(0, ih + mh, printer->width(), - (TRR(printer) * printer->height()) - (ih + 2*mh))); - else - _track->plot(&p, QRectF(0, ih + mh, printer->width(), - printer->height() - (ih + mh))); } if (_trackGraphs->isVisible()) { + qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height())); + gh = (printer->width() > printer->height()) + ? 0.15 * r * (printer->height() - ih - 2*mh) + : 0.15 * (printer->height() - ih - 2*mh); GraphView *gv = static_cast(_trackGraphs->currentWidget()); - gv->plot(&p, QRectF(0, TRR(printer) * printer->height(), - printer->width(), printer->height() * GRR(printer))); - } + gv->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh)); + } else + gh = 0; + _track->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() + - (ih + 2*mh + gh))); } void GUI::reloadFile() diff --git a/src/gui.h b/src/gui.h index 2f44713b..22e04c45 100644 --- a/src/gui.h +++ b/src/gui.h @@ -39,7 +39,6 @@ private slots: void dataSources(); void printFile(); void exportFile(); - void exportAs(); void openFile(); void closeAll(); void reloadFile(); @@ -125,7 +124,6 @@ private: QAction *_aboutQtAction; QAction *_printFileAction; QAction *_exportFileAction; - QAction *_exportAsAction; QAction *_openFileAction; QAction *_closeFileAction; QAction *_reloadFileAction; @@ -165,7 +163,6 @@ private: FileBrowser *_browser; QList _files; - QString _exportFileName; Map *_currentMap; int _trackCount;