Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_pdf_import_widget.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2006 Cyrille Berger <cberger@cberger.net>
3
*
4
* SPDX-License-Identifier: GPL-2.0-or-later
5
*/
6
7
#include "
kis_pdf_import_widget.h
"
8
9
#define UNSTABLE_POPPLER_QT4
10
// poppler's headers
11
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
12
#include <poppler-qt5.h>
13
#else
14
#include <poppler-qt6.h>
15
#endif
16
17
// Qt's headers
18
#include <QRadioButton>
19
20
// KDE's headers
21
#include <
kis_debug.h
>
22
23
// For ceil()
24
#include <math.h>
25
26
// For KoAspectButton
27
#include <klocalizedstring.h>
28
29
30
31
KisPDFImportWidget::KisPDFImportWidget
(Poppler::Document* pdfDoc, QWidget * parent)
32
: QWidget(parent)
33
, m_pdfDoc(pdfDoc)
34
, m_keepAspect(true)
35
{
36
setupUi(
this
);
37
m_pages
.push_back(0);
// The first page is selected
38
updateMaxCanvasSize
();
39
40
for
(
int
i = 1; i <=
m_pdfDoc
->numPages(); i++) {
41
listPages->addItem(QString::number(i));
42
}
43
44
connect
(intWidth, SIGNAL(valueChanged(
int
)),
this
, SLOT(
updateHRes
()));
45
connect
(intHeight, SIGNAL(valueChanged(
int
)),
this
, SLOT(
updateHVer
()));
46
connect
(intResolution, SIGNAL(valueChanged(
int
)),
this
, SLOT(
updateResolution
()));
47
connect
(intHeight, SIGNAL(valueChanged(
int
)),
this
, SLOT(
heightAspectRatio
()));
48
connect
(intWidth, SIGNAL(valueChanged(
int
)),
this
, SLOT(
widthAspectRatio
()));
49
connect
(boolAllPages, SIGNAL(toggled(
bool
)),
this
, SLOT(
selectAllPages
(
bool
)));
50
connect
(boolFirstPage, SIGNAL(toggled(
bool
)),
this
, SLOT(
selectFirstPage
(
bool
)));
51
connect
(boolSelectionPage, SIGNAL(toggled(
bool
)),
this
, SLOT(
selectSelectionOfPages
(
bool
)));
52
connect
(listPages, SIGNAL(itemSelectionChanged()),
this
, SLOT(
updateSelectionOfPages
()));
53
connect
(pixelAspectRatioBtn, SIGNAL(keepAspectRatioChanged(
bool
)),
this
, SLOT(
slotAspectChanged
(
bool
)));
54
55
}
56
57
58
KisPDFImportWidget::~KisPDFImportWidget
()
59
{
60
}
61
62
void
KisPDFImportWidget::selectAllPages
(
bool
v
)
63
{
64
if
(
v
) {
65
if
(listPages->selectedItems().count() != 0){
66
listPages->clearSelection();
67
boolAllPages->toggle();
68
}
69
m_pages
.clear();
70
for
(
int
i = 0; i <
m_pdfDoc
->numPages(); i++) {
71
m_pages
.push_back(i);
72
}
73
updateMaxCanvasSize
();
74
}
75
}
76
void
KisPDFImportWidget::selectFirstPage
(
bool
v
)
77
{
78
if
(
v
) {
79
if
(listPages->selectedItems().count() != 0){
80
listPages->clearSelection();
81
boolFirstPage->toggle();
82
}
83
m_pages
.clear();
84
m_pages
.push_back(0);
// The first page is selected
85
updateMaxCanvasSize
();
86
}
87
}
88
void
KisPDFImportWidget::selectSelectionOfPages
(
bool
v
)
89
{
90
if
(
v
) {
91
updateSelectionOfPages
();
92
updateMaxCanvasSize
();
93
}
94
95
}
96
97
void
KisPDFImportWidget::updateSelectionOfPages
()
98
{
99
if
(! boolSelectionPage->isChecked()) boolSelectionPage->toggle();
100
m_pages
.clear();
101
for
(
int
i = 0; i <
m_pdfDoc
->numPages(); i++) {
102
if
(listPages->item(i)->isSelected())
m_pages
.push_back(i);
103
}
104
updateMaxCanvasSize
();
105
}
106
107
108
void
KisPDFImportWidget::updateMaxCanvasSize
()
109
{
110
m_maxWidthInch
= 0.,
m_maxHeightInch
= 0.;
111
for
(
QList<int>::const_iterator
it =
m_pages
.constBegin(); it !=
m_pages
.constEnd(); ++it) {
112
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
113
Poppler::Page *
p
=
m_pdfDoc
->page(*it);
114
#else
115
std::unique_ptr<Poppler::Page>
p
=
m_pdfDoc
->page(*it);
116
#endif
117
QSizeF size =
p
->pageSizeF();
118
if
(size.width() >
m_maxWidthInch
) {
119
m_maxWidthInch
= size.width();
120
}
121
if
(size.height() >
m_maxHeightInch
) {
122
m_maxHeightInch
= size.height();
123
}
124
}
125
m_maxWidthInch
/= 72.;
126
m_maxHeightInch
/= 72.;
127
dbgFile
<<
m_maxWidthInch
<<
""
<<
m_maxHeightInch
;
128
updateResolution
();
129
}
130
131
void
KisPDFImportWidget::updateResolution
()
132
{
133
int
resolution = intResolution->value();
134
intWidth->blockSignals(
true
);
135
intWidth->setValue((
int
) ceil(
m_maxWidthInch
* resolution));
136
intWidth->blockSignals(
false
);
137
intHeight->blockSignals(
true
);
138
intHeight->setValue((
int
) ceil(
m_maxHeightInch
* resolution));
139
intHeight->blockSignals(
false
);
140
}
141
142
void
KisPDFImportWidget::updateHRes
()
143
{
144
intResolution->blockSignals(
true
);
145
intResolution->setValue((
int
)(intWidth->value() /
m_maxWidthInch
));
146
intResolution->blockSignals(
false
);
147
}
148
void
KisPDFImportWidget::updateHVer
()
149
{
150
intResolution->blockSignals(
true
);
151
intResolution->setValue((
int
)(intHeight->value() /
m_maxHeightInch
));
152
intResolution->blockSignals(
false
);
153
}
154
void
KisPDFImportWidget::heightAspectRatio
()
155
{
156
intWidth->blockSignals(
true
);
157
if
(
m_keepAspect
)
158
{
159
intWidth->setValue((
int
) ceil(((intHeight->value() *
m_maxWidthInch
* 1.) /
m_maxHeightInch
* 1.) + 0.5));
160
}
161
intWidth->blockSignals(
false
);
162
}
163
void
KisPDFImportWidget::widthAspectRatio
()
164
{
165
intHeight->blockSignals(
true
);
166
if
(
m_keepAspect
)
167
{
168
intHeight->setValue((
int
) ceil(((intWidth->value() *
m_maxHeightInch
* 1.) /
m_maxWidthInch
* 1.) + 0.5));
169
}
170
intHeight->blockSignals(
false
);
171
}
172
void
KisPDFImportWidget::slotAspectChanged
(
bool
keep)
173
{
174
pixelAspectRatioBtn->blockSignals(
true
);
175
pixelAspectRatioBtn->setKeepAspectRatio(keep);
176
pixelAspectRatioBtn->blockSignals(
false
);
177
178
m_keepAspect
= keep;
179
180
if
(keep)
181
{
182
heightAspectRatio
();
183
}
184
}
185
p
const Params2D p
Definition
KisBezierUtils.cpp:703
v
qreal v
Definition
KisBezierUtils.cpp:702
connect
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisPDFImportWidget::selectFirstPage
void selectFirstPage(bool v)
Definition
kis_pdf_import_widget.cpp:76
KisPDFImportWidget::updateMaxCanvasSize
void updateMaxCanvasSize()
Definition
kis_pdf_import_widget.cpp:108
KisPDFImportWidget::selectSelectionOfPages
void selectSelectionOfPages(bool v)
Definition
kis_pdf_import_widget.cpp:88
KisPDFImportWidget::m_keepAspect
bool m_keepAspect
Definition
kis_pdf_import_widget.h:46
KisPDFImportWidget::updateHRes
void updateHRes()
Definition
kis_pdf_import_widget.cpp:142
KisPDFImportWidget::slotAspectChanged
void slotAspectChanged(bool keep)
Definition
kis_pdf_import_widget.cpp:172
KisPDFImportWidget::selectAllPages
void selectAllPages(bool v)
Definition
kis_pdf_import_widget.cpp:62
KisPDFImportWidget::widthAspectRatio
void widthAspectRatio()
Definition
kis_pdf_import_widget.cpp:163
KisPDFImportWidget::~KisPDFImportWidget
~KisPDFImportWidget()
Definition
kis_pdf_import_widget.cpp:58
KisPDFImportWidget::updateSelectionOfPages
void updateSelectionOfPages()
Definition
kis_pdf_import_widget.cpp:97
KisPDFImportWidget::updateResolution
void updateResolution()
Definition
kis_pdf_import_widget.cpp:131
KisPDFImportWidget::updateHVer
void updateHVer()
Definition
kis_pdf_import_widget.cpp:148
KisPDFImportWidget::heightAspectRatio
void heightAspectRatio()
Definition
kis_pdf_import_widget.cpp:154
KisPDFImportWidget::m_maxWidthInch
double m_maxWidthInch
Definition
kis_pdf_import_widget.h:45
KisPDFImportWidget::m_pages
QList< int > m_pages
Definition
kis_pdf_import_widget.h:44
KisPDFImportWidget::m_pdfDoc
Poppler::Document * m_pdfDoc
Definition
kis_pdf_import_widget.h:43
KisPDFImportWidget::KisPDFImportWidget
KisPDFImportWidget(Poppler::Document *pdfDoc, QWidget *parent)
Definition
kis_pdf_import_widget.cpp:31
KisPDFImportWidget::m_maxHeightInch
double m_maxHeightInch
Definition
kis_pdf_import_widget.h:45
QList
Definition
KisQStringListFwd.h:16
kis_debug.h
dbgFile
#define dbgFile
Definition
kis_debug.h:53
kis_pdf_import_widget.h
plugins
impex
pdf
kis_pdf_import_widget.cpp
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52