Commit 9d98513e authored by Laurent Montel's avatar Laurent Montel 😁

Display page

parent 3316ee98
......@@ -78,6 +78,12 @@ void PrintPreviewDialog::loadFile(const QString &path)
KMessageBox::error(this, i18n("Unable to open file \"%1\"", path), i18n("Open file error"));
return;
}
showPage(0);
}
//TODO
void PrintPreviewDialog::showPage(int index)
{
Poppler::Page *popplerPage = mDoc->page(index);
mPrintPreviewPage->showPage(popplerPage);
delete popplerPage;
}
......@@ -38,6 +38,7 @@ public:
private:
void writeConfig();
void readConfig();
void showPage(int index);
PrintPreviewPageViewer *mPrintPreviewPage;
Poppler::Document *mDoc;
};
......
......@@ -16,13 +16,20 @@
*/
#include "printpreviewpageviewer.h"
#include <poppler-qt5.h>
#include <QLabel>
#include <QApplication>
#include <QDesktopWidget>
using namespace WebEngineViewer;
PrintPreviewPageViewer::PrintPreviewPageViewer(QWidget *parent)
: QScrollArea(parent)
: QScrollArea(parent),
mDpiX(QApplication::desktop()->physicalDpiX()),
mDpiY(QApplication::desktop()->physicalDpiY())
{
mImage = new QLabel(this);
mImage->setObjectName(QStringLiteral("page"));
mImage->resize(0, 0);
......@@ -33,3 +40,15 @@ PrintPreviewPageViewer::~PrintPreviewPageViewer()
{
}
void PrintPreviewPageViewer::showPage(Poppler::Page *page)
{
const QImage image = page->renderToImage(mDpiX, mDpiY);
if (!image.isNull()) {
mImage->resize(image.size());
mImage->setPixmap(QPixmap::fromImage(image));
} else {
mImage->resize(0, 0);
mImage->setPixmap(QPixmap());
}
}
......@@ -21,6 +21,10 @@
#include <QScrollArea>
class QLabel;
namespace Poppler
{
class Page;
}
namespace WebEngineViewer
{
class PrintPreviewPageViewer : public QScrollArea
......@@ -29,7 +33,12 @@ class PrintPreviewPageViewer : public QScrollArea
public:
explicit PrintPreviewPageViewer(QWidget *parent = Q_NULLPTR);
~PrintPreviewPageViewer();
void showPage(Poppler::Page *page);
private:
int mDpiX;
int mDpiY;
QLabel *mImage;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment