1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/GUI/pdfexportdialog.cpp

134 lines
4.6 KiB
C++
Raw Normal View History

2016-05-24 03:01:22 +02:00
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
2016-05-27 22:45:58 +02:00
#include <QDialogButtonBox>
2016-05-24 03:01:22 +02:00
#include <QGroupBox>
#include <QComboBox>
2016-05-25 23:27:07 +02:00
#include <QRadioButton>
2016-05-24 03:01:22 +02:00
#include <QMessageBox>
2016-05-27 22:45:58 +02:00
#include <QTabWidget>
2020-10-06 21:41:23 +02:00
#include "marginswidget.h"
2016-05-24 03:01:22 +02:00
#include "fileselectwidget.h"
2016-05-27 22:45:58 +02:00
#include "units.h"
2020-09-27 00:34:38 +02:00
#include "pdfexportdialog.h"
2016-05-24 03:01:22 +02:00
2020-09-27 00:34:38 +02:00
PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
: QDialog(parent), _export(exp), _units(units)
2016-05-24 03:01:22 +02:00
{
int index;
_fileSelect = new FileSelectWidget();
2018-09-30 11:35:33 +02:00
_fileSelect->setFilter(tr("PDF files") + " (*.pdf);;" + tr("All files")
+ " (*)");
2020-09-27 00:34:38 +02:00
_fileSelect->setFile(_export.fileName);
2016-05-24 03:01:22 +02:00
_paperSize = new QComboBox();
_paperSize->addItem("A2", QPageSize::PageSizeId::A2);
_paperSize->addItem("A3", QPageSize::PageSizeId::A3);
_paperSize->addItem("A4", QPageSize::PageSizeId::A4);
_paperSize->addItem("A5", QPageSize::PageSizeId::A5);
_paperSize->addItem("A6", QPageSize::PageSizeId::A6);
_paperSize->addItem("B3", QPageSize::PageSizeId::B3);
_paperSize->addItem("B4", QPageSize::PageSizeId::B4);
_paperSize->addItem("B5", QPageSize::PageSizeId::B5);
_paperSize->addItem("B6", QPageSize::PageSizeId::B6);
_paperSize->addItem("Tabloid", QPageSize::PageSizeId::Tabloid);
_paperSize->addItem("Legal", QPageSize::PageSizeId::Legal);
_paperSize->addItem("Letter", QPageSize::PageSizeId::Letter);
2020-09-27 00:34:38 +02:00
if ((index = _paperSize->findData(_export.paperSize)) >= 0)
2016-05-25 23:27:07 +02:00
_paperSize->setCurrentIndex(index);
_resolution = new QComboBox();
2018-04-27 19:37:15 +02:00
_resolution->addItem("150 DPI", 150);
_resolution->addItem("300 DPI", 300);
_resolution->addItem("600 DPI", 600);
2020-09-27 00:34:38 +02:00
if ((index = _resolution->findData(_export.resolution)) >= 0)
_resolution->setCurrentIndex(index);
2016-05-25 23:27:07 +02:00
_portrait = new QRadioButton(tr("Portrait"));
_landscape = new QRadioButton(tr("Landscape"));
QHBoxLayout *orientationLayout = new QHBoxLayout();
orientationLayout->addWidget(_portrait);
orientationLayout->addWidget(_landscape);
if (_export.orientation == QPageLayout::Orientation::Portrait)
2016-05-25 23:27:07 +02:00
_portrait->setChecked(true);
else
_landscape->setChecked(true);
2020-10-06 21:41:23 +02:00
_margins = new MarginsFWidget();
_margins->setUnits((units == Metric) ? tr("cm") : tr("in"));
2020-10-06 21:41:23 +02:00
_margins->setSingleStep(0.1);
_margins->setValue((units == Metric)
? _export.margins * MM2CM : _export.margins * MM2IN);
2016-05-27 22:45:58 +02:00
#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("Resolution:"), _resolution);
2016-05-27 22:45:58 +02:00
pageSetupLayout->addRow(tr("Orientation:"), orientationLayout);
2020-10-06 21:41:23 +02:00
pageSetupLayout->addRow(tr("Margins:"), _margins);
2016-05-27 22:45:58 +02:00
#ifdef Q_OS_MAC
QFrame *line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
pageSetupLayout->addRow(line);
pageSetupLayout->addRow(tr("File:"), _fileSelect);
2016-10-12 22:37:40 +02:00
pageSetupLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
2016-05-27 22:45:58 +02:00
#else // Q_OS_MAC
pageSetupBox->setLayout(pageSetupLayout);
#endif // Q_OS_MAC
#ifndef Q_OS_MAC
QGroupBox *outputFileBox = new QGroupBox(tr("Output file"));
2020-10-07 09:04:40 +02:00
QVBoxLayout *outputFileLayout = new QVBoxLayout();
2016-05-27 22:45:58 +02:00
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()));
2016-05-24 03:01:22 +02:00
QVBoxLayout *layout = new QVBoxLayout;
2016-05-27 22:45:58 +02:00
#ifdef Q_OS_MAC
layout->addLayout(pageSetupLayout);
#else // Q_OS_MAC
layout->addWidget(pageSetupBox);
layout->addWidget(outputFileBox);
#endif // Q_OS_MAC
layout->addWidget(buttonBox);
2016-05-24 03:01:22 +02:00
setLayout(layout);
2016-05-27 22:45:58 +02:00
setWindowTitle(tr("Export to PDF"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2016-05-24 03:01:22 +02:00
}
2020-09-27 00:34:38 +02:00
void PDFExportDialog::accept()
2016-05-24 03:01:22 +02:00
{
2020-09-27 00:34:38 +02:00
QString error;
if (!_fileSelect->checkFile(error)) {
QMessageBox::warning(this, tr("Error"), error);
2016-05-24 03:01:22 +02:00
return;
2020-09-27 00:34:38 +02:00
}
2016-05-24 03:01:22 +02:00
QPageLayout::Orientation orientation = _portrait->isChecked()
? QPageLayout::Orientation::Portrait : QPageLayout::Orientation::Landscape;
QPageSize::PageSizeId paperSize = static_cast<QPageSize::PageSizeId>
2016-05-24 03:01:22 +02:00
(_paperSize->itemData(_paperSize->currentIndex()).toInt());
int resolution = _resolution->itemData(_resolution->currentIndex()).toInt();
2016-05-24 03:01:22 +02:00
2020-09-27 00:34:38 +02:00
_export.fileName = _fileSelect->file();
_export.paperSize = paperSize;
_export.resolution = resolution;
_export.orientation = orientation;
2020-10-06 21:41:23 +02:00
_export.margins = (_units == Imperial)
? _margins->value() / MM2IN : _margins->value() / MM2CM;
2016-05-24 03:01:22 +02:00
QDialog::accept();
}