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

Save/load dialog size

parent 6a3cede3
......@@ -82,6 +82,7 @@ target_link_libraries(KF5WebEngineViewer
KF5::I18n
KF5::PimCommon
KF5::WidgetsAddons
KF5::ConfigCore
${poppler_lib}
)
......
......@@ -20,6 +20,7 @@
#include "../printpreviewdialog.h"
#include "../printpreviewpageviewer.h"
#include <QTest>
#include <QDialogButtonBox>
PrintPreviewDialogTest::PrintPreviewDialogTest(QObject *parent)
: QObject(parent)
......@@ -37,6 +38,8 @@ void PrintPreviewDialogTest::shouldHaveDefaultValue()
WebEngineViewer::PrintPreviewDialog dlg;
WebEngineViewer::PrintPreviewPageViewer *page = dlg.findChild<WebEngineViewer::PrintPreviewPageViewer *>(QStringLiteral("printpreviewpage"));
QVERIFY(page);
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
}
QTEST_MAIN(PrintPreviewDialogTest)
......@@ -22,6 +22,8 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <QVBoxLayout>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QDialogButtonBox>
using namespace WebEngineViewer;
......@@ -36,11 +38,34 @@ PrintPreviewDialog::PrintPreviewDialog(QWidget *parent)
mPrintPreviewPage = new PrintPreviewPageViewer(this);
mPrintPreviewPage->setObjectName(QStringLiteral("printpreviewpage"));
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()
{
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)
......
......@@ -36,6 +36,8 @@ public:
void loadFile(const QString &path);
private:
void writeConfig();
void readConfig();
PrintPreviewPageViewer *mPrintPreviewPage;
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