From 498d33b77d6c5d4d3f34383c00f0e69b57a64825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 27 May 2016 22:45:58 +0200 Subject: [PATCH] PDF export dialog polishing --- gpxsee.pro | 3 +- lang/gpxsee_cs.ts | 241 +++++++++++++++++++++++-------------------- src/exportdialog.cpp | 98 ++++++++++++++---- src/exportdialog.h | 9 +- src/gui.cpp | 18 ++-- src/gui.h | 2 + src/margins.cpp | 9 ++ src/margins.h | 30 ++++++ src/trackview.cpp | 12 +-- src/units.h | 3 +- 10 files changed, 275 insertions(+), 150 deletions(-) create mode 100644 src/margins.cpp create mode 100644 src/margins.h diff --git a/gpxsee.pro b/gpxsee.pro index d497e3fd..8cadab7d 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -42,7 +42,8 @@ HEADERS += src/config.h \ src/app.h \ src/trackinfo.h \ src/exportdialog.h \ - src/fileselectwidget.h + src/fileselectwidget.h \ + src/margins.h SOURCES += src/main.cpp \ src/gui.cpp \ src/gpx.cpp \ diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index f3df1053..b1093e34 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -59,74 +59,89 @@ 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 - - Settings - Nastavení - - - + Page size: Velikost stránky: - + Orientation: Orientace: - - Output file: - Výstupní soubor: + + Page Setup + Nastavení stránky + in + in + + + + mm + mm + + + + Margins: + Okraje: + + + + File: + Soubor: + + + + Output file + Výstupní soubor + + + Export Exportovat - - Cancel - Zrušit - - - - - + + + Error Chyba - + No output file selected. Nebyl zvolen žádný výstupní soubor. - + %1 is a directory. %1 je adresář. - + %1 is not writable. %1 nelze zapsat. @@ -147,353 +162,353 @@ 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 - + Open Otevřít - + Quit Ukončit - - + + Keyboard controls Ovládací klávesy - + Close Zavřít - + Reload Znovu načíst - + Show Zobrazit - - + + File Soubor - - + + Data sources Zdroje dat - - Print - Tisknout - - - + 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 - + + Print... + Tisknout... + + + + Export to PDF... + Exportovat do PDF... + + + 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 (*) - - Track count + + Tracks Počet tras - - + + 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 index e1dbb4cc..53d9c24f 100644 --- a/src/exportdialog.cpp +++ b/src/exportdialog.cpp @@ -1,15 +1,19 @@ -#include #include #include #include +#include +#include #include #include #include #include #include -#include #include +#include +#include +#include #include "fileselectwidget.h" +#include "units.h" #include "exportdialog.h" @@ -18,8 +22,8 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent) { int index; - setWindowTitle(tr("Export to PDF")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + _units = (QLocale::system().measurementSystem() + == QLocale::ImperialSystem) ? QPrinter::Inch : QPrinter::Millimeter; _fileSelect = new FileSelectWidget(); _fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)")); @@ -45,30 +49,78 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent) else _landscape->setChecked(true); - QGroupBox *contentBox = new QGroupBox(tr("Settings")); - QFormLayout *contentLayout = new QFormLayout; - contentLayout->addRow(tr("Page size:"), _paperSize); - contentLayout->addRow(tr("Orientation:"), orientationLayout); - contentLayout->addRow(tr("Output file:"), _fileSelect); - contentBox->setLayout(contentLayout); + qreal top, bottom, left, right; - 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())); + _printer->getPageMargins(&left, &top, &right, &bottom, _units); + QString us = _units == QPrinter::Inch ? tr("in") : tr("mm"); + _topMargin = new QDoubleSpinBox(); + _bottomMargin = new QDoubleSpinBox(); + _leftMargin = new QDoubleSpinBox(); + _rightMargin = new QDoubleSpinBox(); + _topMargin->setValue(top); + _topMargin->setSuffix(UNIT_SPACE + us); + _bottomMargin->setValue(bottom); + _bottomMargin->setSuffix(UNIT_SPACE + us); + _leftMargin->setValue(left); + _leftMargin->setSuffix(UNIT_SPACE + us); + _rightMargin->setValue(right); + _rightMargin->setSuffix(UNIT_SPACE + us); + if (_units == QPrinter::Inch) { + _topMargin->setSingleStep(0.1); + _bottomMargin->setSingleStep(0.1); + _leftMargin->setSingleStep(0.1); + _rightMargin->setSingleStep(0.1); + } - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addStretch(); - buttonsLayout->addWidget(exportButton); - buttonsLayout->addWidget(cancelButton); + QGridLayout *marginsLayout = new QGridLayout(); + marginsLayout->addWidget(_topMargin, 0, 0, 1, 2, Qt::AlignCenter); + marginsLayout->addWidget(_leftMargin, 1, 0, 1, 1, Qt::AlignCenter); + marginsLayout->addWidget(_rightMargin, 1, 1, 1, 1, Qt::AlignCenter); + marginsLayout->addWidget(_bottomMargin, 2, 0, 1, 2, Qt::AlignCenter); + +#ifndef Q_OS_MAC + QGroupBox *pageSetupBox = new QGroupBox(tr("Page Setup")); +#endif // Q_OS_MAC + QFormLayout *pageSetupLayout = new QFormLayout; + pageSetupLayout->addRow(tr("Page size:"), _paperSize); + pageSetupLayout->addRow(tr("Orientation:"), orientationLayout); + pageSetupLayout->addRow(tr("Margins:"), marginsLayout); +#ifdef Q_OS_MAC + QFrame *line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + pageSetupLayout->addRow(line); + pageSetupLayout->addRow(tr("File:"), _fileSelect); +#else // Q_OS_MAC + pageSetupBox->setLayout(pageSetupLayout); +#endif // Q_OS_MAC + +#ifndef Q_OS_MAC + QGroupBox *outputFileBox = new QGroupBox(tr("Output file")); + QHBoxLayout *outputFileLayout = new QHBoxLayout(); + outputFileLayout->addWidget(_fileSelect); + outputFileBox->setLayout(outputFileLayout); +#endif // Q_OS_MAC + + QDialogButtonBox *buttonBox = new QDialogButtonBox(); + buttonBox->addButton(tr("Export"), QDialogButtonBox::AcceptRole); + buttonBox->addButton(QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(contentBox); - layout->addLayout(buttonsLayout); +#ifdef Q_OS_MAC + layout->addLayout(pageSetupLayout); +#else // Q_OS_MAC + layout->addWidget(pageSetupBox); + layout->addWidget(outputFileBox); +#endif // Q_OS_MAC + layout->addWidget(buttonBox); setLayout(layout); + + setWindowTitle(tr("Export to PDF")); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); } bool ExportDialog::checkFile() @@ -116,6 +168,8 @@ void ExportDialog::accept() _printer->setOutputFileName(_fileSelect->file()); _printer->setPaperSize(paperSize); _printer->setOrientation(orientation); + _printer->setPageMargins(_leftMargin->value(), _topMargin->value(), + _rightMargin->value(), _bottomMargin->value(), _units); QDialog::accept(); } diff --git a/src/exportdialog.h b/src/exportdialog.h index e4f63db4..867024b6 100644 --- a/src/exportdialog.h +++ b/src/exportdialog.h @@ -2,11 +2,12 @@ #define EXPORTDIALOG_H #include +#include -class QPrinter; class QComboBox; class QRadioButton; class FileSelectWidget; +class QDoubleSpinBox; class ExportDialog : public QDialog { @@ -23,10 +24,16 @@ private: QPrinter *_printer; + QPrinter::Unit _units; + FileSelectWidget *_fileSelect; QComboBox *_paperSize; QRadioButton *_portrait; QRadioButton *_landscape; + QDoubleSpinBox *_topMargin; + QDoubleSpinBox *_bottomMargin; + QDoubleSpinBox *_leftMargin; + QDoubleSpinBox *_rightMargin; }; #endif // EXPORTDIALOG_H diff --git a/src/gui.cpp b/src/gui.cpp index 3c04fc43..40ca438b 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -90,10 +90,11 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent) readSettings(); - _exportPaperSize = (QLocale::system().measurementSystem() + _exportPaperSize = (QLocale::system().measurementSystem() == QLocale::ImperialSystem) ? QPrinter::Letter : QPrinter::A4; _exportOrientation = QPrinter::Portrait; - _exportFileName = QString("%1/export.pdf").arg(QDir::currentPath()); + _exportFileName = QString("%1/export.pdf").arg(QDir::currentPath()); + _exportMargins = MarginsF(5.0, 5.0, 5.0, 5.0); } GUI::~GUI() @@ -204,12 +205,12 @@ void GUI::createActions() connect(_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); addAction(_openFileAction); _printFileAction = new QAction(QIcon(QPixmap(PRINT_FILE_ICON)), - tr("Print"), this); + tr("Print..."), this); _printFileAction->setActionGroup(_fileActionGroup); connect(_printFileAction, SIGNAL(triggered()), this, SLOT(printFile())); addAction(_printFileAction); _exportFileAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)), - tr("Export to PDF"), this); + tr("Export to PDF..."), this); _exportFileAction->setShortcut(EXPORT_SHORTCUT); _exportFileAction->setActionGroup(_fileActionGroup); connect(_exportFileAction, SIGNAL(triggered()), this, SLOT(exportFile())); @@ -651,16 +652,21 @@ void GUI::printFile() void GUI::exportFile() { QPrinter printer(QPrinter::HighResolution); + printer.setCreator(QString(APP_NAME) + QString(" ") + QString(APP_VERSION)); printer.setOrientation(_exportOrientation); printer.setOutputFileName(_exportFileName); printer.setPaperSize(_exportPaperSize); - printer.setCreator(QString(APP_NAME) + QString(" ") + QString(APP_VERSION)); + printer.setPageMargins(_exportMargins.left(), _exportMargins.top(), + _exportMargins.right(), _exportMargins.bottom(), QPrinter::Millimeter); ExportDialog dialog(&printer, this); if (dialog.exec() == QDialog::Accepted) { _exportFileName = printer.outputFileName(); _exportPaperSize = printer.paperSize(); _exportOrientation = printer.orientation(); + printer.getPageMargins(&(_exportMargins.rleft()), + &(_exportMargins.rtop()), &(_exportMargins.rright()), + &(_exportMargins.rbottom()), QPrinter::Millimeter); plot(&printer); } } @@ -681,7 +687,7 @@ void GUI::plot(QPrinter *printer) info.insert(tr("Date"), QString("%1 - %2") .arg(_dateRange.first.toString(format), _dateRange.second.toString(format))); - info.insert(tr("Track count"), QString::number(_trackCount)); + info.insert(tr("Tracks"), QString::number(_trackCount)); } } if (_distance > 0) { diff --git a/src/gui.h b/src/gui.h index 4f6f7863..697e00a1 100644 --- a/src/gui.h +++ b/src/gui.h @@ -7,6 +7,7 @@ #include #include #include "poi.h" +#include "margins.h" class QMenu; class QToolBar; @@ -179,6 +180,7 @@ private: QString _exportFileName; QPrinter::PaperSize _exportPaperSize; QPrinter::Orientation _exportOrientation; + MarginsF _exportMargins; }; #endif // GUI_H diff --git a/src/margins.cpp b/src/margins.cpp new file mode 100644 index 00000000..70a4b503 --- /dev/null +++ b/src/margins.cpp @@ -0,0 +1,9 @@ +#include "margins.h" + + +QDebug operator<<(QDebug dbg, const MarginsF &margins) +{ + dbg.nospace() << "MarginsF(" << margins.left() << ", " << margins.top() + << ", " << margins.right() << margins.bottom() << ")"; + return dbg.maybeSpace(); +} diff --git a/src/margins.h b/src/margins.h new file mode 100644 index 00000000..693e2f03 --- /dev/null +++ b/src/margins.h @@ -0,0 +1,30 @@ +#ifndef MARGINS_H +#define MARGINS_H + +#include +#include + +class MarginsF +{ +public: + MarginsF() {_left = 0; _top = 0; _right = 0; _bottom = 0;} + MarginsF(qreal left, qreal top, qreal right, qreal bottom) + {_left = left, _top = top; _right = right; _bottom = bottom;} + + qreal left() const {return _left;} + qreal top() const {return _top;} + qreal right() const {return _right;} + qreal bottom() const {return _bottom;} + + qreal &rleft() {return _left;} + qreal &rtop() {return _top;} + qreal &rright() {return _right;} + qreal &rbottom() {return _bottom;} + +private: + qreal _left, _top, _right, _bottom; +}; + +QDebug operator<<(QDebug dbg, const MarginsF &margins); + +#endif // MARGINS_H diff --git a/src/trackview.cpp b/src/trackview.cpp index 247dc66a..ecb32c51 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -354,14 +354,14 @@ void TrackView::plot(QPainter *painter, const QRectF &target) orig = viewport()->rect(); - if (target.width() > target.height()) { - ratio = target.width()/target.height(); - diff = qAbs((orig.height() * ratio) - orig.width()); - adj = orig.adjusted(-diff/2, 0, diff/2, 0); - } else { + if (orig.height() * (target.width() / target.height()) - orig.width() < 0) { ratio = target.height()/target.width(); - diff = qAbs((orig.width() * ratio) - orig.height()); + diff = (orig.width() * ratio) - orig.height(); adj = orig.adjusted(0, -diff/2, 0, diff/2); + } else { + ratio = target.width() / target.height(); + diff = (orig.height() * ratio) - orig.width(); + adj = orig.adjusted(-diff/2, 0, diff/2, 0); } setUpdatesEnabled(false); diff --git a/src/units.h b/src/units.h index c1891bdf..139e9e3d 100644 --- a/src/units.h +++ b/src/units.h @@ -12,13 +12,14 @@ enum Units { #define MS2KMH 3.600000000000 // m/s -> km/h #define MS2MIH 2.236936290000 // m/s -> mi/h #define FT2MI 0.000189393939 // ft -> mi +#define MM2IN 0.039370100000 // mm -> in #define KMINM 1000 // 1 km in m #define MIINFT 5280 // 1 mi in ft #define MIINM 1609.344 // 1mi in m #ifdef Q_OS_WIN32 -#define UNIT_SPACE " " +#define UNIT_SPACE QString(" ") #else // Q_OS_WIN32 #define UNIT_SPACE QString::fromUtf8("\xE2\x80\x89") #endif // Q_OS_WIN32