Adds latest migration results
This commit is contained in:
829 files changed
+35074
-70886
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user