printpreviewdialog.cpp 2.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
  Copyright (c) 2016 Montel Laurent <montel@kde.org>

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "printpreviewdialog.h"
Laurent Montel's avatar
Laurent Montel committed
19
#include "printpreviewpagewidget.h"
Laurent Montel's avatar
Laurent Montel committed
20
21
22

#include <KLocalizedString>
#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
23
24
#include <KConfigGroup>
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
25
#include <QDialogButtonBox>
Laurent Montel's avatar
Laurent Montel committed
26
#include <QPushButton>
27
28
29
30

using namespace WebEngineViewer;

PrintPreviewDialog::PrintPreviewDialog(QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
31
    : QDialog(parent)
32
{
Laurent Montel's avatar
Laurent Montel committed
33
34
    QVBoxLayout *layout = new QVBoxLayout;
    setLayout(layout);
35

Laurent Montel's avatar
Laurent Montel committed
36
37
38
    mPrintPreviewWidget = new PrintPreviewPageWidget(this);
    mPrintPreviewWidget->setObjectName(QStringLiteral("printpreviewwidget"));
    layout->addWidget(mPrintPreviewWidget);
Laurent Montel's avatar
Laurent Montel committed
39
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
Laurent Montel's avatar
Laurent Montel committed
40
    QPushButton *printButton = new QPushButton(i18n("Print"));
Laurent Montel's avatar
Laurent Montel committed
41
    printButton->setObjectName(QStringLiteral("printbutton"));
Laurent Montel's avatar
Laurent Montel committed
42
    connect(printButton, &QPushButton::clicked, this, &PrintPreviewDialog::slotPrint);
Laurent Montel's avatar
Laurent Montel committed
43
    buttonBox->addButton(printButton, QDialogButtonBox::ActionRole);
Laurent Montel's avatar
Laurent Montel committed
44
45
46
    buttonBox->setObjectName(QStringLiteral("buttonbox"));
    layout->addWidget(buttonBox);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &PrintPreviewDialog::reject);
47
48
49
50
}

PrintPreviewDialog::~PrintPreviewDialog()
{
Laurent Montel's avatar
Laurent Montel committed
51
52
53
54
55
56
57
58
59
    writeConfig();
}

void PrintPreviewDialog::writeConfig()
{
    KConfigGroup group(KSharedConfig::openConfig(), "PrintPreviewDialog");
    group.writeEntry("Size", size());
    group.sync();
}
60

Laurent Montel's avatar
Laurent Montel committed
61
62
63
64
65
66
67
68
void PrintPreviewDialog::readConfig()
{
    KConfigGroup group(KSharedConfig::openConfig(), "PrintPreviewDialog");

    const QSize size = group.readEntry("Size", QSize(500, 300));
    if (size.isValid()) {
        resize(size);
    }
69
}
70
71
72

void PrintPreviewDialog::loadFile(const QString &path)
{
Laurent Montel's avatar
Laurent Montel committed
73
    mPrintPreviewWidget->loadFile(path);
74
}
Laurent Montel's avatar
Laurent Montel committed
75
76
77
78
79
80
81

void PrintPreviewDialog::slotPrint()
{
    //TODO select page ?
    //mPrintPreviewWidget->print();
    //TODO
}