Commit 3316ee98 authored by Laurent Montel's avatar Laurent Montel 😁

Save/load dialog size

parent 6a3cede3
...@@ -82,6 +82,7 @@ target_link_libraries(KF5WebEngineViewer ...@@ -82,6 +82,7 @@ target_link_libraries(KF5WebEngineViewer
KF5::I18n KF5::I18n
KF5::PimCommon KF5::PimCommon
KF5::WidgetsAddons KF5::WidgetsAddons
KF5::ConfigCore
${poppler_lib} ${poppler_lib}
) )
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "../printpreviewdialog.h" #include "../printpreviewdialog.h"
#include "../printpreviewpageviewer.h" #include "../printpreviewpageviewer.h"
#include <QTest> #include <QTest>
#include <QDialogButtonBox>
PrintPreviewDialogTest::PrintPreviewDialogTest(QObject *parent) PrintPreviewDialogTest::PrintPreviewDialogTest(QObject *parent)
: QObject(parent) : QObject(parent)
...@@ -37,6 +38,8 @@ void PrintPreviewDialogTest::shouldHaveDefaultValue() ...@@ -37,6 +38,8 @@ void PrintPreviewDialogTest::shouldHaveDefaultValue()
WebEngineViewer::PrintPreviewDialog dlg; WebEngineViewer::PrintPreviewDialog dlg;
WebEngineViewer::PrintPreviewPageViewer *page = dlg.findChild<WebEngineViewer::PrintPreviewPageViewer *>(QStringLiteral("printpreviewpage")); WebEngineViewer::PrintPreviewPageViewer *page = dlg.findChild<WebEngineViewer::PrintPreviewPageViewer *>(QStringLiteral("printpreviewpage"));
QVERIFY(page); QVERIFY(page);
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
} }
QTEST_MAIN(PrintPreviewDialogTest) QTEST_MAIN(PrintPreviewDialogTest)
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QDialogButtonBox> #include <QDialogButtonBox>
using namespace WebEngineViewer; using namespace WebEngineViewer;
...@@ -36,11 +38,34 @@ PrintPreviewDialog::PrintPreviewDialog(QWidget *parent) ...@@ -36,11 +38,34 @@ PrintPreviewDialog::PrintPreviewDialog(QWidget *parent)
mPrintPreviewPage = new PrintPreviewPageViewer(this); mPrintPreviewPage = new PrintPreviewPageViewer(this);
mPrintPreviewPage->setObjectName(QStringLiteral("printpreviewpage")); mPrintPreviewPage->setObjectName(QStringLiteral("printpreviewpage"));
layout->addWidget(mPrintPreviewPage); layout->addWidget(mPrintPreviewPage);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
buttonBox->setObjectName(QStringLiteral("buttonbox"));
layout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::rejected, this, &PrintPreviewDialog::reject);
} }
PrintPreviewDialog::~PrintPreviewDialog() PrintPreviewDialog::~PrintPreviewDialog()
{ {
writeConfig();
delete mDoc;
mDoc = 0;
}
void PrintPreviewDialog::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "PrintPreviewDialog");
group.writeEntry("Size", size());
group.sync();
}
void PrintPreviewDialog::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "PrintPreviewDialog");
const QSize size = group.readEntry("Size", QSize(500, 300));
if (size.isValid()) {
resize(size);
}
} }
void PrintPreviewDialog::loadFile(const QString &path) void PrintPreviewDialog::loadFile(const QString &path)
......
...@@ -36,6 +36,8 @@ public: ...@@ -36,6 +36,8 @@ public:
void loadFile(const QString &path); void loadFile(const QString &path);
private: private:
void writeConfig();
void readConfig();
PrintPreviewPageViewer *mPrintPreviewPage; PrintPreviewPageViewer *mPrintPreviewPage;
Poppler::Document *mDoc; Poppler::Document *mDoc;
}; };
......
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