forked from cloose/CuteMarkEd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportpdfdialog.cpp
More file actions
98 lines (83 loc) · 3.39 KB
/
exportpdfdialog.cpp
File metadata and controls
98 lines (83 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright 2013 Christian Loose <christian.loose@hamburg.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "exportpdfdialog.h"
#include "ui_exportpdfdialog.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QPrinter>
ExportPdfDialog::ExportPdfDialog(const QString &fileName, QWidget *parent) :
QDialog(parent),
ui(new Ui::ExportPdfDialog)
{
ui->setupUi(this);
// change button text of standard Ok button
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
okButton->setText("Export PDF");
if (!fileName.isEmpty()) {
QFileInfo info(fileName);
QString exportFileName = info.absoluteFilePath().replace(info.suffix(), "pdf");
ui->exportToLineEdit->setText(exportFileName);
}
// fill paper size combobox
ui->paperSizeComboBox->addItem(tr("A4 (210 x 297 mm, 8.26 x 11.69 inches)"), QPrinter::A4);
ui->paperSizeComboBox->addItem(tr("Letter (8.5 x 11 inches, 215.9 x 279.4 mm)"), QPrinter::Letter);
ui->paperSizeComboBox->addItem(tr("Legal (8.5 x 14 inches, 215.9 x 355.6 mm)"), QPrinter::Legal);
ui->paperSizeComboBox->addItem(tr("A3 (297 x 420 mm)"), QPrinter::A3);
ui->paperSizeComboBox->addItem(tr("A5 (148 x 210 mm)"), QPrinter::A5);
ui->paperSizeComboBox->addItem(tr("A6 (105 x 148 mm)"), QPrinter::A6);
ui->paperSizeComboBox->addItem(tr("B4 (250 x 353 mm)"), QPrinter::B4);
ui->paperSizeComboBox->addItem(tr("B5 (176 x 250 mm, 6.93 x 9.84 inches)"), QPrinter::B5);
// initialize Ok button state
exportToTextChanged(fileName);
}
ExportPdfDialog::~ExportPdfDialog()
{
delete ui;
}
QPrinter *ExportPdfDialog::printer()
{
QString fileName = ui->exportToLineEdit->text();
QPrinter::Orientation orientation;
if (ui->portraitRadioButton->isChecked()) {
orientation = QPrinter::Portrait;
} else {
orientation = QPrinter::Landscape;
}
QVariant v = ui->paperSizeComboBox->itemData(ui->paperSizeComboBox->currentIndex());
QPrinter::PaperSize size = (QPrinter::PaperSize)v.toInt();
QPrinter *p = new QPrinter();
p->setOutputFileName(fileName);
p->setOutputFormat(QPrinter::PdfFormat);
p->setOrientation(orientation);
p->setPaperSize(size);
return p;
}
void ExportPdfDialog::exportToTextChanged(const QString &text)
{
// only enable ok button if a filename was provided
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
okButton->setEnabled(!text.isEmpty());
}
void ExportPdfDialog::chooseFileButtonClicked()
{
QString fileName = ui->exportToLineEdit->text();
fileName = QFileDialog::getSaveFileName(this, tr("Export to PDF..."), fileName,
tr("PDF Files (*.pdf);;All Files (*)"));
if (!fileName.isEmpty()) {
ui->exportToLineEdit->setText(fileName);
}
}