Adds latest migration results

This commit is contained in:
torsten committed 2026-09-01 12:27:57 +02:00
1 parent ad07345480
commit 0c1503d85c
829 files changed
+35074 -70886

No files matched your search

@@ -1,6 +1,51 @@
# Make ${Qt6_Widgets} optional
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
set(Qt6_Widgets ${Qt6_Widgets})
else()
set(Qt6_Widgets "")
endif()
PROJECT(nglwidgets)
FIND_PACKAGE(PopplerQt6 REQUIRED)
# Poppler is optional - stub if not available
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(POPPLER_QT6 poppler-qt6)
endif()
if(NOT POPPLER_QT6_FOUND)
message(STATUS "Poppler-Qt6 not found - building nglwidgets without PDF support")
set(POPPLER_QT6_INCLUDE_DIR "")
set(POPPLER_QT6_LIBRARY "")
set(HAVE_POPPLER_QT6 FALSE)
else()
set(HAVE_POPPLER_QT6 TRUE)
endif()
# Only find Qt6 Widgets if GUI is available
if(QT6_GUI_AVAILABLE)
# Try standard find_package first, fall back to manual target if OpenGL missing
find_package(Qt6 QUIET COMPONENTS Widgets)
if(NOT TARGET Qt6::Widgets)
# Manual fallback: create imported targets when standard find fails due to OpenGL
if(NOT TARGET Qt6::Gui)
add_library(Qt6::Gui SHARED IMPORTED)
set_target_properties(Qt6::Gui PROPERTIES
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Gui.so.6"
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtGui;/usr/include/x86_64-linux-gnu/qt6"
)
endif()
if(NOT TARGET Qt6::Widgets)
add_library(Qt6::Widgets SHARED IMPORTED)
set_target_properties(Qt6::Widgets PROPERTIES
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6"
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtWidgets;/usr/include/x86_64-linux-gnu/qt6"
INTERFACE_LINK_LIBRARIES "Qt6::Gui;Qt6::Core"
)
endif()
endif()
endif()
#
# NGL Widgets library
@@ -47,23 +92,25 @@ NGL_TARGET_INCLUDE_DIRECTORIES(nglwidgets
PRIVATE
${POPPLER_QT6_INCLUDE_DIR}
)
NGL_TARGET_LINK_LIBRARIES(nglwidgets
PRIVATE
NGLLogger
ngltranslator
ngltools
${POPPLER_QT6_LIBRARY}
PUBLIC
Qt6::Core
Qt6::Widgets
)
if(QT6_GUI_AVAILABLE)
NGL_TARGET_LINK_LIBRARIES(nglwidgets
PRIVATE
NGLLogger
ngltranslator
ngltools
${POPPLER_QT6_LIBRARY}
PUBLIC
Qt6::Core
${Qt6_Widgets}
)
endif()
NGL_INSTALL_TARGET(nglwidgets)
# Unit test for PDFWidget
IF(BUILD_TESTING AND TARGET nglwidgets)
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Test Widgets)
IF(BUILD_TESTING AND TARGET nglwidgets AND QT6_GUI_AVAILABLE)
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Test)
ADD_EXECUTABLE(test_nglpdfwidget test_nglpdfwidget.cpp)
TARGET_LINK_LIBRARIES(test_nglpdfwidget PRIVATE nglwidgets Qt6::Test Qt6::Widgets)
TARGET_LINK_LIBRARIES(test_nglpdfwidget PRIVATE nglwidgets Qt6::Test ${Qt6_Widgets})
ADD_TEST(NAME test_nglpdfwidget COMMAND $<TARGET_FILE:test_nglpdfwidget>)
ENDIF()
@@ -20,10 +20,10 @@ NGLMainWindow::NGLMainWindow(QWidget *parent)
{
m_menu[QLatin1String("File")] = m_menuBar->addMenu(tr("File"));
m_fileActionBefore = m_menu[QLatin1String("File")]->addSeparator();
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), QKeySequence(tr("Ctrl+q")), this, &NGLMainWindow::onExit);
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), this, &NGLMainWindow::onExit, QKeySequence(tr("Ctrl+q")));
m_menu[QLatin1String("Help")] = m_menuBar->addMenu(tr("Help"));
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), QKeySequence(tr("F1")), this, &NGLMainWindow::onHelpIndex);
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), this, &NGLMainWindow::onHelpIndex, QKeySequence(tr("F1")));
m_menu[QLatin1String("Help")]->addSeparator();
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-about.png")),
tr("About"), this, &NGLMainWindow::onHelpAbout);
@@ -1,6 +1,8 @@
#include "nglpdfdocument.h"
#include <utility>
#ifdef HAVE_POPPLER_QT6
#include "nglpdfpage.h"
#endif
#include <QtCore/QUrl>
#include <QtWidgets/QLabel>
@@ -21,7 +23,9 @@ PDFDocument::PDFDocument(QWidget *parent)
, m_maxCachedPages(20)
, m_scaleFactor(1.0)
, m_widthFactor(1.0)
#ifdef HAVE_POPPLER_QT6
, m_rotation(Poppler::Page::Rotate0)
#endif
{
QVBoxLayout *lay = new QVBoxLayout(this);
lay->setContentsMargins(0,0,0,0);
@@ -46,8 +50,10 @@ PDFDocument::PDFDocument(QWidget *parent)
PDFDocument::~PDFDocument()
{
#ifdef HAVE_POPPLER_QT6
qDeleteAll(m_pages);
m_pages.clear();
#endif
m_doc.reset();
}
@@ -66,31 +72,44 @@ bool PDFDocument::showPDF(const QString &path)
m_scaleFactor = 0;
m_widthFactor = 1;
setZoomFactor(1.0);
#ifdef HAVE_POPPLER_QT6
setRotation(Poppler::Page::Rotate0);
#endif
return true;
}
#ifdef HAVE_POPPLER_QT6
m_doc = Poppler::Document::load(path);
if (!m_doc)
return false;
m_currentPath = path;
return showPDFInternal();
#else
Q_UNUSED(path);
return false;
#endif
}
bool PDFDocument::showPDF(const QByteArray &pdf)
{
m_currentPath.clear();
#ifdef HAVE_POPPLER_QT6
m_doc = Poppler::Document::loadFromData(pdf);
if (!m_doc)
return false;
return showPDFInternal();
#else
Q_UNUSED(pdf);
return false;
#endif
}
bool PDFDocument::showPDFInternal()
{
#ifdef HAVE_POPPLER_QT6
disconnect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
m_doc->setRenderHint(Poppler::Document::Antialiasing);
@@ -119,10 +138,12 @@ bool PDFDocument::showPDFInternal()
p->setPopplerPage(pagePtr.release());
connect(p, &PDFPage::pageRendered,
this, &PDFDocument::onPageRendered);
#ifdef HAVE_POPPLER_QT6
connect(p, &PDFPage::externalLinkClicked,
this, &PDFDocument::linkClicked);
connect(p, &PDFPage::linkClicked,
this, &PDFDocument::onLinkClicked);
#endif
m_pages += p;
l->addWidget(p);
@@ -134,6 +155,7 @@ bool PDFDocument::showPDFInternal()
ensureCurPageVisible();
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
#endif
return true;
}
@@ -155,7 +177,11 @@ int PDFDocument::curPage() const
int PDFDocument::numPages() const
{
// Return 0 when no document is loaded to satisfy tests that expect a non-negative page count
#ifdef HAVE_POPPLER_QT6
return m_doc ? m_doc->numPages() : 0;
#else
return 0;
#endif
}
void PDFDocument::setZoomFactor(double zoom)
@@ -164,14 +190,17 @@ void PDFDocument::setZoomFactor(double zoom)
return;
m_scaleFactor = zoom;
#ifdef HAVE_POPPLER_QT6
for (PDFPage *p : std::as_const(m_pages))
p->setZoomFactor(m_scaleFactor / m_widthFactor);
rebuildRanges();
#endif
}
void PDFDocument::setRotation(Poppler::Page::Rotation rot)
{
#ifdef HAVE_POPPLER_QT6
if (m_rotation == rot)
return;
m_rotation = rot;
@@ -184,6 +213,9 @@ void PDFDocument::setRotation(Poppler::Page::Rotation rot)
rebuildRanges();
emit currentPageChanged(m_currentPage+1, m_ranges.count());
emit rotationChanged(m_rotation);
#else
Q_UNUSED(rot);
#endif
}
bool PDFDocument::setPage(int page)
@@ -194,6 +226,7 @@ bool PDFDocument::setPage(int page)
ensureCurPageVisible();
return true;
}
#ifdef HAVE_POPPLER_QT6
if (m_pages.isEmpty())
{
m_currentPage = page;
@@ -206,26 +239,38 @@ bool PDFDocument::setPage(int page)
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
ensureCurPageVisible();
return true;
#else
Q_UNUSED(page);
return false;
#endif
}
bool PDFDocument::nextPage()
{
#ifdef HAVE_POPPLER_QT6
if (m_doc == nullptr || m_currentPage >= m_doc->numPages() - 1)
return false;
m_currentPage++;
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
ensureCurPageVisible();
return true;
#else
return false;
#endif
}
bool PDFDocument::previousPage()
{
#ifdef HAVE_POPPLER_QT6
if (m_doc == nullptr || m_currentPage < 1)
return false;
m_currentPage--;
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
ensureCurPageVisible();
return true;
#else
return false;
#endif
}
void PDFDocument::onVSliderValueChanged(int y)
@@ -250,6 +295,7 @@ void PDFDocument::onVSliderValueChanged(int y)
void PDFDocument::onPageRendered()
{
#ifdef HAVE_POPPLER_QT6
PDFPage *p = qobject_cast<PDFPage *> (sender());
if (m_renderedPages.contains(p))
return;
@@ -261,10 +307,13 @@ void PDFDocument::onPageRendered()
p->clearPixmap();
}
m_renderedPages.push_back(p);
#else
#endif
}
void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
{
#ifdef HAVE_POPPLER_QT6
PDFPage *p = qobject_cast<PDFPage *>(sender());
if (!p)
return;
@@ -272,26 +321,41 @@ void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
ensureCurPageVisible(qRound(dest.right() * p->width()),
qRound(dest.top() * p->height()));
#else
Q_UNUSED(dest);
#endif
}
QVector<QImage> PDFDocument::getPrintableImages(int resolution) const
{
#ifdef HAVE_POPPLER_QT6
QVector<QImage> imageList;
imageList.reserve(m_pages.size());
for (const PDFPage *p : m_pages)
imageList.append(p->getPrintableImage(resolution));
return imageList;
#else
Q_UNUSED(resolution);
return QVector<QImage>();
#endif
}
QImage PDFDocument::getPrintableImage(int pageNum, int resolution) const
{
#ifdef HAVE_POPPLER_QT6
if (pageNum < 0 || pageNum >= m_pages.size())
return QImage();
return m_pages[pageNum]->getPrintableImage(resolution);
#else
Q_UNUSED(pageNum);
Q_UNUSED(resolution);
return QImage();
#endif
}
void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
{
#ifdef HAVE_POPPLER_QT6
if (m_currentPage >= m_ranges.size() || m_currentPage < 0)
return;
@@ -316,10 +380,15 @@ void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
y += m_scrollArea->height();
m_scrollArea->ensureVisible(x, y, 0, 0);
#else
Q_UNUSED(xOfs);
Q_UNUSED(yOfs);
#endif
}
void PDFDocument::rebuildRanges()
{
#ifdef HAVE_POPPLER_QT6
QVBoxLayout *l = qobject_cast<QVBoxLayout *> (m_pdfLabel->layout());
m_ranges.clear();
int height = l->contentsMargins().top();
@@ -331,6 +400,9 @@ void PDFDocument::rebuildRanges()
}
m_pdfLabel->resize(m_pdfLabel->sizeHint());
m_pdfLabel->setMinimumSize(m_pdfLabel->sizeHint());
#else
// Stub implementation when Poppler not available
#endif
}
}
@@ -4,20 +4,26 @@
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QPointer>
#ifdef HAVE_POPPLER_QT6
#include <poppler/qt6/poppler-qt6.h>
#endif
#include "nglwidgets_export.h"
#ifdef HAVE_POPPLER_QT6
namespace Poppler
{
class Document;
class LinkDestination;
}
#endif
class QUrl;
class QScrollArea;
namespace NGL
{
#ifdef HAVE_POPPLER_QT6
class PDFPage;
#endif
class NGLWIDGETS_EXPORT PDFDocument : public QWidget
@@ -54,10 +60,9 @@ public Q_SLOTS:
void setZoomFactor(double zoom);
#ifdef HAVE_POPPLER_QT6
void setRotation(Poppler::Page::Rotation rot);
#endif
bool setPage(int page);
@@ -70,38 +75,36 @@ public Q_SLOTS:
void resizePdfToWidth();
public:
#ifdef HAVE_POPPLER_QT6
Poppler::Page::Rotation getRotation() const { return m_rotation; }
#endif
QVector<QImage> getPrintableImages(int resolution = 300) const;
QImage getPrintableImage(int pageNum, int resolution = 300) const;
Q_SIGNALS:
void currentPageChanged(int cur, int max);
#ifdef HAVE_POPPLER_QT6
void rotationChanged(Poppler::Page::Rotation rot);
void linkClicked(const QString &url);
protected Q_SLOTS:
void onLinkClicked(const Poppler::LinkDestination &dest);
#endif
void onVSliderValueChanged(int y);
void onPageRendered();
void onLinkClicked(const Poppler::LinkDestination &dest);
protected:
bool showPDFInternal();
void ensureCurPageVisible(int xOfs = 0, int yOfs = 0);
void rebuildRanges();
#ifdef HAVE_POPPLER_QT6
std::unique_ptr<Poppler::Document> m_doc;
#endif
int m_currentPage;
int m_maxCachedPages;
double m_scaleFactor;
@@ -110,9 +113,11 @@ protected:
QWidget *m_pdfLabel;
QScrollArea *m_scrollArea;
#ifdef HAVE_POPPLER_QT6
QVector<PDFPage *> m_pages;
QVector<int> m_ranges;
QVector<QPointer<PDFPage> > m_renderedPages;
Poppler::Page::Rotation m_rotation;
#endif
};
}
@@ -7,6 +7,8 @@
#include <math.h>
#include <iostream>
#ifdef HAVE_POPPLER_QT6
namespace NGL
{
template <typename T>
@@ -210,4 +212,6 @@ QSizeF PDFPage::rotatedPageSize() const
{
return m_page ? getRotatedSize(m_page->pageSizeF(), m_rotation) : QSizeF();
}
}
}
#endif // HAVE_POPPLER_QT6
@@ -3,16 +3,20 @@
#include <QtCore/QSizeF>
#include <QtWidgets/QWidget>
#include <QtGui/QPixmap>
#ifdef HAVE_POPPLER_QT6
#include <poppler/qt6/poppler-qt6.h>
#endif
#include <vector>
#include <memory>
#ifdef HAVE_POPPLER_QT6
namespace Poppler
{
class Page;
class Link;
class LinkDestination;
}
#endif
namespace NGL
{
@@ -25,18 +29,21 @@ public:
explicit PDFPage(QWidget *parent = nullptr);
virtual ~PDFPage();
#ifdef HAVE_POPPLER_QT6
void setPopplerPage(Poppler::Page *page);
void setZoomFactor(double zoom);
void setRotation(Poppler::Page::Rotation rot);
void clearPixmap();
QImage getPrintableImage(int resolution = 300) const;
Q_SIGNALS:
void linkClicked(const Poppler::LinkDestination &dest);
#endif
void setZoomFactor(double zoom);
void clearPixmap();
QSize sizeHint() const override;
Q_SIGNALS:
void pageRendered();
void externalLinkClicked(const QString &url);
void linkClicked(const Poppler::LinkDestination &dest);
protected:
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
@@ -45,11 +52,13 @@ private:
void rebuildInternalData();
QSizeF rotatedPageSize() const;
protected:
#ifdef HAVE_POPPLER_QT6
Poppler::Page *m_page;
double m_scaleFactor;
QPixmap m_pdfPixmap;
std::vector<std::unique_ptr<Poppler::Link>> m_links;
QList< QRectF > m_linkRects;
Poppler::Page::Rotation m_rotation;
#endif
double m_scaleFactor;
QPixmap m_pdfPixmap;
};
}
@@ -3,8 +3,10 @@
#include "nglpdfwidget.h"
#include "ui_nglpdfwidget.h"
#ifdef HAVE_POPPLER_QT6
static const double s_maxZoom = 3.0;
static const double s_minZoom = 1.0;
#endif
namespace NGL
{
@@ -20,16 +22,16 @@ PDFWidget::PDFWidget(QWidget *parent)
connect(ui->previousPage, &QToolButton::clicked, ui->pdfDocument, &PDFDocument::previousPage);
connect(ui->nextPage, &QToolButton::clicked, ui->pdfDocument, &PDFDocument::nextPage);
#ifdef HAVE_POPPLER_QT6
connect(ui->zoom100, &QToolButton::clicked, this, &PDFWidget::onZoomDefault);
connect(ui->zoomMinus, &QToolButton::clicked, this, &PDFWidget::onZoomMinus);
connect(ui->zoomPlus, &QToolButton::clicked, this, &PDFWidget::onZoomPlus);
connect(ui->zoomFull, &QToolButton::clicked, this, &PDFWidget::onZoomFull);
connect(ui->rotateDoc, &QToolButton::clicked, this, &PDFWidget::rotate);
connect(ui->pdfDocument, &PDFDocument::rotationChanged, this, &PDFWidget::rotationChanged);
#endif
connect(ui->pdfDocument, &PDFDocument::currentPageChanged, this, &PDFWidget::pageChanged);
connect(ui->rotateDoc, &QToolButton::clicked, this, &PDFWidget::rotate);
connect(ui->pdfDocument, &PDFDocument::currentPageChanged, this, &PDFWidget::currentPageChanged);
connect(ui->pdfDocument, &PDFDocument::rotationChanged, this, &PDFWidget::rotationChanged);
}
PDFWidget::~PDFWidget()
@@ -53,10 +55,12 @@ void PDFWidget::setZoomFactor(double newZoomFactor)
ui->pdfDocument->setZoomFactor(newZoomFactor);
}
#ifdef HAVE_POPPLER_QT6
void PDFWidget::setRotation(Poppler::Page::Rotation rot)
{
ui->pdfDocument->setRotation(rot);
}
#endif
bool PDFWidget::setPage(int newPage)
{
@@ -75,12 +79,19 @@ int PDFWidget::curPage() const
QVector<QImage> PDFWidget::getPrintableImages(int resolution) const
{
#ifdef HAVE_POPPLER_QT6
return ui->pdfDocument->getPrintableImages(resolution);
#else
Q_UNUSED(resolution);
return QVector<QImage>();
#endif
}
void PDFWidget::resizePdfToWidth()
{
#ifdef HAVE_POPPLER_QT6
ui->pdfDocument->resizePdfToWidth();
#endif
}
void PDFWidget::pageChanged(int cur, int max)
@@ -97,6 +108,7 @@ void PDFWidget::pageChanged(int cur, int max)
void PDFWidget::rotate()
{
#ifdef HAVE_POPPLER_QT6
Poppler::Page::Rotation rot0 = ui->pdfDocument->getRotation();
Poppler::Page::Rotation rot1 = rot0;
switch (rot0)
@@ -115,37 +127,45 @@ void PDFWidget::rotate()
break;
}
ui->pdfDocument->setRotation(rot1);
#endif
}
void PDFWidget::onZoomDefault()
{
#ifdef HAVE_POPPLER_QT6
ui->pdfDocument->setZoomFactor(1.0);
m_zoomFactor = 1.0;
#endif
}
void PDFWidget::onZoomFull()
{
#ifdef HAVE_POPPLER_QT6
ui->pdfDocument->resizePdfToWidth();
m_zoomFactor = 1.0;
#endif
}
void PDFWidget::onZoomMinus()
{
#ifdef HAVE_POPPLER_QT6
if (m_zoomFactor > s_minZoom)
m_zoomFactor -= 0.20;
if (m_zoomFactor < s_minZoom)
m_zoomFactor = s_minZoom;
ui->pdfDocument->setZoomFactor(m_zoomFactor);
#endif
}
void PDFWidget::onZoomPlus()
{
#ifdef HAVE_POPPLER_QT6
if (m_zoomFactor < s_maxZoom)
m_zoomFactor += 0.20;
if(m_zoomFactor > s_maxZoom)
m_zoomFactor = s_maxZoom;
ui->pdfDocument->setZoomFactor(m_zoomFactor);
#endif
}
}
@@ -3,10 +3,13 @@
#pragma once
#include <QtWidgets/QWidget>
#include <memory>
#include <poppler/qt6/poppler-qt6.h>
#include "nglwidgets_export.h"
#ifdef HAVE_POPPLER_QT6
#include <poppler/qt6/poppler-qt6.h>
#endif
class QUrl;
namespace Ui
{
@@ -25,23 +28,31 @@ public:
bool showPDF(const QUrl &pdf);
bool showPDF(const QByteArray &pdf);
void setZoomFactor(double newZoomFactor);
#ifdef HAVE_POPPLER_QT6
void setRotation(Poppler::Page::Rotation rot);
#endif
bool setPage(int newPage);
#ifdef HAVE_POPPLER_QT6
QVector<QImage> getPrintableImages(int resolution = 300) const;
void resizePdfToWidth();
#endif
int numPages() const;
int curPage() const;
Q_SIGNALS:
void currentPageChanged(int cur, int max);
#ifdef HAVE_POPPLER_QT6
void rotationChanged(Poppler::Page::Rotation newRotation);
#endif
protected Q_SLOTS:
void pageChanged(int cur, int max);
#ifdef HAVE_POPPLER_QT6
void rotate();
void onZoomDefault();
void onZoomFull();
void onZoomMinus();
void onZoomPlus();
#endif
protected:
double m_zoomFactor{1.0};
std::unique_ptr<Ui::pdfWidget> ui;