qt6: pdfwidget fixes — replace deprecated layout margin API, adapt Poppler Qt6 unique_ptr API to existing code (use unique_ptr m_doc), fix std::min types
This commit is contained in:
1 parent
58f7124c49
commit
8ef3c1861f
20 files changed
+2459
-21
No files matched your search
@@ -9,6 +9,7 @@
|
||||
#include <QTimer>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
@@ -22,14 +23,15 @@ PDFDocument::PDFDocument(QWidget *parent)
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
{
|
||||
QVBoxLayout *lay = new QVBoxLayout(this);
|
||||
lay->setMargin(0);
|
||||
lay->setContentsMargins(0,0,0,0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
m_pdfLabel = new QWidget(this);
|
||||
m_pdfLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
QVBoxLayout *l = new QVBoxLayout(m_pdfLabel);
|
||||
l->setMargin(l->margin() * 2);
|
||||
l->setSpacing(l->margin());
|
||||
const int innerMargin = 6;
|
||||
l->setContentsMargins(innerMargin, innerMargin, innerMargin, innerMargin);
|
||||
l->setSpacing(innerMargin);
|
||||
l->setSizeConstraint(QLayout::SetFixedSize);
|
||||
|
||||
m_scrollArea = new QScrollArea(this);
|
||||
@@ -45,7 +47,7 @@ PDFDocument::~PDFDocument()
|
||||
{
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
delete m_doc;
|
||||
m_doc.reset();
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QUrl &url)
|
||||
@@ -67,8 +69,7 @@ bool PDFDocument::showPDF(const QString &path)
|
||||
return true;
|
||||
}
|
||||
|
||||
delete m_doc;
|
||||
m_doc = Poppler::Document::load(path);
|
||||
m_doc.reset(Poppler::Document::load(path));
|
||||
if (!m_doc)
|
||||
return false;
|
||||
m_currentPath = path;
|
||||
@@ -80,8 +81,7 @@ bool PDFDocument::showPDF(const QByteArray &pdf)
|
||||
{
|
||||
m_currentPath.clear();
|
||||
|
||||
delete m_doc;
|
||||
m_doc = Poppler::Document::loadFromData(pdf);
|
||||
m_doc.reset(Poppler::Document::loadFromData(pdf));
|
||||
if (!m_doc)
|
||||
return false;
|
||||
|
||||
@@ -113,7 +113,9 @@ bool PDFDocument::showPDFInternal()
|
||||
PDFPage *p = new PDFPage(m_pdfLabel);
|
||||
p->setZoomFactor(m_scaleFactor);
|
||||
p->setRotation(m_rotation);
|
||||
p->setPopplerPage(m_doc->page(i));
|
||||
auto pagePtr = m_doc->page(i);
|
||||
p->setPopplerPage(pagePtr.get());
|
||||
// keep ownership via unique_ptr; PDFPage will not delete the Poppler::Page pointer
|
||||
connect(p, &PDFPage::pageRendered,
|
||||
this, &PDFDocument::onPageRendered);
|
||||
connect(p, &PDFPage::externalLinkClicked,
|
||||
@@ -126,7 +128,7 @@ bool PDFDocument::showPDFInternal()
|
||||
}
|
||||
rebuildRanges();
|
||||
|
||||
m_currentPage = std::min(m_currentPage, m_ranges.count() - 1);
|
||||
m_currentPage = std::min(m_currentPage, static_cast<int>(m_ranges.count() - 1));
|
||||
|
||||
ensureCurPageVisible();
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
|
||||
Reference in new issue
Block a user