Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Qt6: make impex/pdf build with Qt5 and Qt6

Halla Rempt01a2c93a7a50
diff --git a/plugins/impex/pdf/kis_pdf_import.cpp b/plugins/impex/pdf/kis_pdf_import.cpp
index e2c4548cc4..01eedd6d42 100644
--- a/plugins/impex/pdf/kis_pdf_import.cpp
+++ b/plugins/impex/pdf/kis_pdf_import.cpp
@@ -1,3 +1,4 @@
+
/*
* SPDX-FileCopyrightText: 2006 Cyrille Berger <[email protected]>
*
@@ -7,10 +8,10 @@
#include "kis_pdf_import.h"
// poppler's headers
-#if QT_VERSION_MAJOR == 6
-#include <poppler-qt6.h>
-#else
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <poppler-qt5.h>
+#else
+#include <poppler-qt6.h>
#endif
// Qt's headers
@@ -59,8 +60,11 @@ KisPDFImport::~KisPDFImport()
KisImportExportErrorCode KisPDFImport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP /*configuration*/)
{
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ Poppler::Document* pdoc = Poppler::Document::loadFromData(io->readAll());
+#else
std::unique_ptr<Poppler::Document> pdoc = Poppler::Document::loadFromData(io->readAll());
-
+#endif
if (!pdoc) {
dbgFile << "Error when reading the PDF";
return ImportExportCodes::ErrorWhileReading;
@@ -84,13 +88,21 @@ KisImportExportErrorCode KisPDFImport::convert(KisDocument *document, QIODevice
kdb->setCaption(i18n("PDF Import Options"));
kdb->setModal(false);
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ KisPDFImportWidget* wdg = new KisPDFImportWidget(pdoc, kdb);
+#else
KisPDFImportWidget* wdg = new KisPDFImportWidget(pdoc.get(), kdb);
+#endif
+
kdb->setMainWidget(wdg);
{
KisCursorOverrideHijacker cursorHijacker;
if (kdb->exec() == QDialog::Rejected) {
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ delete pdoc;
+#endif
delete kdb;
return ImportExportCodes::Cancelled;
}
@@ -110,8 +122,11 @@ KisImportExportErrorCode KisPDFImport::convert(KisDocument *document, QIODevice
i18n("Page %1", *it + 1),
quint8_MAX);
-
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ Poppler::Page* page = pdoc->page(*it);
+#else
std::unique_ptr<Poppler::Page> page = pdoc->page(*it);
+#endif
QImage img = page->renderToImage(wdg->intResolution->value(), wdg->intResolution->value(), 0, 0, width, height);
layer->paintDevice()->convertFromQImage(img, 0, 0, 0);
@@ -121,7 +136,9 @@ KisImportExportErrorCode KisPDFImport::convert(KisDocument *document, QIODevice
}
document->setCurrentImage(image);
-
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ delete pdoc;
+#endif
delete kdb;
return ImportExportCodes::OK;
}
diff --git a/plugins/impex/pdf/kis_pdf_import_widget.cpp b/plugins/impex/pdf/kis_pdf_import_widget.cpp
index 328a815e59..f08ae33433 100644
--- a/plugins/impex/pdf/kis_pdf_import_widget.cpp
+++ b/plugins/impex/pdf/kis_pdf_import_widget.cpp
@@ -8,7 +8,11 @@
#define UNSTABLE_POPPLER_QT4
// poppler's headers
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+#include <poppler-qt5.h>
+#else
#include <poppler-qt6.h>
+#endif
// Qt's headers
#include <QRadioButton>
@@ -105,7 +109,11 @@ void KisPDFImportWidget::updateMaxCanvasSize()
{
m_maxWidthInch = 0., m_maxHeightInch = 0.;
for (QList<int>::const_iterator it = m_pages.constBegin(); it != m_pages.constEnd(); ++it) {
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ Poppler::Page *p = m_pdfDoc->page(*it);
+#else
std::unique_ptr<Poppler::Page> p = m_pdfDoc->page(*it);
+#endif
QSizeF size = p->pageSizeF();
if (size.width() > m_maxWidthInch) {
m_maxWidthInch = size.width();