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
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
31KisPDFImportWidget::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
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
61
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 }
74 }
75}
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
86 }
87}
96
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 }
105}
106
107
109{
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.;
129}
130
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
143{
144 intResolution->blockSignals(true);
145 intResolution->setValue((int)(intWidth->value() / m_maxWidthInch));
146 intResolution->blockSignals(false);
147}
149{
150 intResolution->blockSignals(true);
151 intResolution->setValue((int)(intHeight->value() / m_maxHeightInch));
152 intResolution->blockSignals(false);
153}
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}
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}
173{
174 pixelAspectRatioBtn->blockSignals(true);
175 pixelAspectRatioBtn->setKeepAspectRatio(keep);
176 pixelAspectRatioBtn->blockSignals(false);
177
178 m_keepAspect = keep;
179
180 if (keep)
181 {
183 }
184}
185
const Params2D p
qreal v
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotAspectChanged(bool keep)
Poppler::Document * m_pdfDoc
KisPDFImportWidget(Poppler::Document *pdfDoc, QWidget *parent)
#define dbgFile
Definition kis_debug.h:53