mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
PDF export dialog polishing
This commit is contained in:
@ -1,15 +1,19 @@
|
||||
#include <QPrinter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGroupBox>
|
||||
#include <QComboBox>
|
||||
#include <QRadioButton>
|
||||
#include <QPushButton>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QTabWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLocale>
|
||||
#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();
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
#define EXPORTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPrinter>
|
||||
|
||||
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
|
||||
|
18
src/gui.cpp
18
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) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QDate>
|
||||
#include <QPrinter>
|
||||
#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
|
||||
|
9
src/margins.cpp
Normal file
9
src/margins.cpp
Normal file
@ -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();
|
||||
}
|
30
src/margins.h
Normal file
30
src/margins.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef MARGINS_H
|
||||
#define MARGINS_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
|
||||
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
|
@ -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);
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user