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

Display page

parent 3316ee98
...@@ -78,6 +78,12 @@ void PrintPreviewDialog::loadFile(const QString &path) ...@@ -78,6 +78,12 @@ void PrintPreviewDialog::loadFile(const QString &path)
KMessageBox::error(this, i18n("Unable to open file \"%1\"", path), i18n("Open file error")); KMessageBox::error(this, i18n("Unable to open file \"%1\"", path), i18n("Open file error"));
return; 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: ...@@ -38,6 +38,7 @@ public:
private: private:
void writeConfig(); void writeConfig();
void readConfig(); void readConfig();
void showPage(int index);
PrintPreviewPageViewer *mPrintPreviewPage; PrintPreviewPageViewer *mPrintPreviewPage;
Poppler::Document *mDoc; Poppler::Document *mDoc;
}; };
......
...@@ -16,13 +16,20 @@ ...@@ -16,13 +16,20 @@
*/ */
#include "printpreviewpageviewer.h" #include "printpreviewpageviewer.h"
#include <poppler-qt5.h>
#include <QLabel> #include <QLabel>
#include <QApplication>
#include <QDesktopWidget>
using namespace WebEngineViewer; using namespace WebEngineViewer;
PrintPreviewPageViewer::PrintPreviewPageViewer(QWidget *parent) PrintPreviewPageViewer::PrintPreviewPageViewer(QWidget *parent)
: QScrollArea(parent) : QScrollArea(parent),
mDpiX(QApplication::desktop()->physicalDpiX()),
mDpiY(QApplication::desktop()->physicalDpiY())
{ {
mImage = new QLabel(this); mImage = new QLabel(this);
mImage->setObjectName(QStringLiteral("page")); mImage->setObjectName(QStringLiteral("page"));
mImage->resize(0, 0); mImage->resize(0, 0);
...@@ -33,3 +40,15 @@ PrintPreviewPageViewer::~PrintPreviewPageViewer() ...@@ -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 @@ ...@@ -21,6 +21,10 @@
#include <QScrollArea> #include <QScrollArea>
class QLabel; class QLabel;
namespace Poppler
{
class Page;
}
namespace WebEngineViewer namespace WebEngineViewer
{ {
class PrintPreviewPageViewer : public QScrollArea class PrintPreviewPageViewer : public QScrollArea
...@@ -29,7 +33,12 @@ class PrintPreviewPageViewer : public QScrollArea ...@@ -29,7 +33,12 @@ class PrintPreviewPageViewer : public QScrollArea
public: public:
explicit PrintPreviewPageViewer(QWidget *parent = Q_NULLPTR); explicit PrintPreviewPageViewer(QWidget *parent = Q_NULLPTR);
~PrintPreviewPageViewer(); ~PrintPreviewPageViewer();
void showPage(Poppler::Page *page);
private: private:
int mDpiX;
int mDpiY;
QLabel *mImage; 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