Commit daf1ce21 authored by Laurent Montel's avatar Laurent Montel 😁

Use printpreviewwidget

parent 143769bd
......@@ -18,6 +18,7 @@ if (WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT)
set(libwebengineviewer_print_SRCS
print/printpreviewdialog.cpp
print/printpreviewpageviewer.cpp
print/printpreviewpagewidget.cpp
)
set(poppler_lib Poppler::Qt5)
endif()
......
ecm_add_test(printpreviewdialogtest.cpp ../printpreviewdialog.cpp ../printpreviewpageviewer.cpp
ecm_add_test(printpreviewdialogtest.cpp ../printpreviewdialog.cpp ../printpreviewpageviewer.cpp ../printpreviewpagewidget.cpp
TEST_NAME printpreviewdialogtest
NAME_PREFIX "webengineviewer-print-"
LINK_LIBRARIES Qt5::Test Qt5::Widgets Qt5::Gui KF5::I18n KF5::WidgetsAddons Poppler::Qt5 KF5::ConfigCore
......@@ -9,3 +9,9 @@ ecm_add_test(printpreviewpageviewertest.cpp ../printpreviewpageviewer.cpp
NAME_PREFIX "webengineviewer-print-"
LINK_LIBRARIES Qt5::Test Qt5::Widgets Qt5::Gui KF5::I18n KF5::WidgetsAddons Poppler::Qt5 KF5::ConfigCore
)
ecm_add_test(printpreviewpagewidgettest.cpp ../printpreviewpagewidget.cpp ../printpreviewpageviewer.cpp
TEST_NAME printpreviewpagewidgettest
NAME_PREFIX "webengineviewer-print-"
LINK_LIBRARIES Qt5::Test Qt5::Widgets Qt5::Gui KF5::I18n KF5::WidgetsAddons Poppler::Qt5 KF5::ConfigCore
)
......@@ -18,7 +18,7 @@
#include "printpreviewdialogtest.h"
#include "../printpreviewdialog.h"
#include "../printpreviewpageviewer.h"
#include "../printpreviewpagewidget.h"
#include <QTest>
#include <QDialogButtonBox>
......@@ -36,8 +36,9 @@ PrintPreviewDialogTest::~PrintPreviewDialogTest()
void PrintPreviewDialogTest::shouldHaveDefaultValue()
{
WebEngineViewer::PrintPreviewDialog dlg;
WebEngineViewer::PrintPreviewPageViewer *page = dlg.findChild<WebEngineViewer::PrintPreviewPageViewer *>(QStringLiteral("printpreviewpage"));
QVERIFY(page);
WebEngineViewer::PrintPreviewPageWidget *widget = dlg.findChild<WebEngineViewer::PrintPreviewPageWidget *>(QStringLiteral("printpreviewwidget"));
QVERIFY(widget);
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
}
......
......@@ -16,11 +16,9 @@
*/
#include "printpreviewdialog.h"
#include "printpreviewpageviewer.h"
#include <poppler-qt5.h>
#include "printpreviewpagewidget.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QVBoxLayout>
#include <KConfigGroup>
#include <KSharedConfig>
......@@ -29,15 +27,14 @@
using namespace WebEngineViewer;
PrintPreviewDialog::PrintPreviewDialog(QWidget *parent)
: QDialog(parent),
mDoc(Q_NULLPTR)
: QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
mPrintPreviewPage = new PrintPreviewPageViewer(this);
mPrintPreviewPage->setObjectName(QStringLiteral("printpreviewpage"));
layout->addWidget(mPrintPreviewPage);
mPrintPreviewWidget = new PrintPreviewPageWidget(this);
mPrintPreviewWidget->setObjectName(QStringLiteral("printpreviewwidget"));
layout->addWidget(mPrintPreviewWidget);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
buttonBox->setObjectName(QStringLiteral("buttonbox"));
layout->addWidget(buttonBox);
......@@ -47,8 +44,6 @@ PrintPreviewDialog::PrintPreviewDialog(QWidget *parent)
PrintPreviewDialog::~PrintPreviewDialog()
{
writeConfig();
delete mDoc;
mDoc = 0;
}
void PrintPreviewDialog::writeConfig()
......@@ -70,20 +65,5 @@ void PrintPreviewDialog::readConfig()
void PrintPreviewDialog::loadFile(const QString &path)
{
if (path.isEmpty()) {
return;
}
mDoc = Poppler::Document::load(path);
if (!mDoc) {
KMessageBox::error(this, i18n("Unable to open file \"%1\"", path), i18n("Open file error"));
return;
}
showPage(0);
}
void PrintPreviewDialog::showPage(int index)
{
Poppler::Page *popplerPage = mDoc->page(index);
mPrintPreviewPage->showPage(popplerPage);
delete popplerPage;
mPrintPreviewWidget->loadFile(path);
}
......@@ -20,13 +20,9 @@
#include <QDialog>
namespace Poppler
{
class Document;
}
namespace WebEngineViewer
{
class PrintPreviewPageViewer;
class PrintPreviewPageWidget;
class PrintPreviewDialog : public QDialog
{
Q_OBJECT
......@@ -38,9 +34,7 @@ public:
private:
void writeConfig();
void readConfig();
void showPage(int index);
PrintPreviewPageViewer *mPrintPreviewPage;
Poppler::Document *mDoc;
PrintPreviewPageWidget *mPrintPreviewWidget;
};
}
......
......@@ -2,6 +2,7 @@ set(printpreviewdialog_gui_test_SRCS
printpreviewdialog_gui.cpp
../printpreviewdialog.cpp
../printpreviewpageviewer.cpp
../printpreviewpagewidget.cpp
)
add_executable(printpreviewdialog_gui ${printpreviewdialog_gui_test_SRCS})
......
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