Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp
Show All 24 Lines | |||||
25 | #include <QPushButton> | 25 | #include <QPushButton> | ||
26 | #include <QLayout> | 26 | #include <QLayout> | ||
27 | #include <QTabWidget> | 27 | #include <QTabWidget> | ||
28 | #include <QPrinter> | 28 | #include <QPrinter> | ||
29 | #include <QPrintDialog> | 29 | #include <QPrintDialog> | ||
30 | #include <QPointer> | 30 | #include <QPointer> | ||
31 | 31 | | |||
32 | // KDE includes | 32 | // KDE includes | ||
33 | #include <khtmlview.h> | | |||
34 | #include <khtml_part.h> | | |||
35 | #include <KStandardGuiItem> | 33 | #include <KStandardGuiItem> | ||
34 | #ifdef KF5KHtml_FOUND | ||||
35 | #include <KHTMLPart> | ||||
36 | #include <KHTMLView> | ||||
37 | #endif | ||||
36 | 38 | | |||
37 | KReportDlg::KReportDlg(QWidget* parent, const QString& summaryReportHTML, const QString& detailsReportHTML) : QDialog(parent) | 39 | KReportDlg::KReportDlg(QWidget* parent, const QString& summaryReportHTML, const QString& detailsReportHTML) : QDialog(parent) | ||
38 | { | 40 | { | ||
39 | setupUi(this); | 41 | setupUi(this); | ||
40 | m_summaryHTMLPart = new KHTMLPart(m_summaryTab); | 42 | m_summaryHTMLPart = new QWebEngineView(m_summaryTab); | ||
41 | m_summaryLayout->addWidget(m_summaryHTMLPart->view()); | 43 | m_summaryLayout->addWidget(m_summaryHTMLPart); | ||
42 | 44 | | |||
43 | m_detailsHTMLPart = new KHTMLPart(m_detailsTab); | 45 | m_detailsHTMLPart = new QWebEngineView(m_detailsTab); | ||
44 | m_detailsLayout->addWidget(m_detailsHTMLPart->view()); | 46 | m_detailsLayout->addWidget(m_detailsHTMLPart); | ||
45 | 47 | | |||
46 | m_summaryHTMLPart->begin(); | 48 | m_summaryHTMLPart->setHtml(summaryReportHTML, QUrl("file://")); | ||
47 | m_summaryHTMLPart->write(summaryReportHTML); | 49 | m_detailsHTMLPart->setHtml(detailsReportHTML, QUrl("file://")); | ||
48 | m_summaryHTMLPart->end(); | | |||
49 | | ||||
50 | m_detailsHTMLPart->begin(); | | |||
51 | m_detailsHTMLPart->write(detailsReportHTML); | | |||
52 | m_detailsHTMLPart->end(); | | |||
53 | 50 | | |||
54 | QPushButton* printButton = m_buttonBox->addButton(QString(), QDialogButtonBox::ActionRole); | 51 | QPushButton* printButton = m_buttonBox->addButton(QString(), QDialogButtonBox::ActionRole); | ||
55 | KGuiItem::assign(printButton, KStandardGuiItem::print()); | 52 | KGuiItem::assign(printButton, KStandardGuiItem::print()); | ||
56 | 53 | | |||
57 | // signals and slots connections | 54 | // signals and slots connections | ||
58 | connect(printButton, SIGNAL(clicked()), this, SLOT(print())); | 55 | connect(printButton, SIGNAL(clicked()), this, SLOT(print())); | ||
59 | } | 56 | } | ||
60 | 57 | | |||
61 | KReportDlg::~KReportDlg() | 58 | KReportDlg::~KReportDlg() | ||
62 | { | 59 | { | ||
63 | } | 60 | } | ||
64 | 61 | | |||
65 | void KReportDlg::print() | 62 | #ifdef KF5KHtml_FOUND | ||
63 | void KReportDlg::handleHTML(const QString &sHTML) | ||||
66 | { | 64 | { | ||
67 | // create the QPrinter object with default options | 65 | KHTMLPart *khtml = new KHTMLPart(this); | ||
68 | QPrinter printer; | 66 | khtml->begin(); | ||
69 | 67 | khtml->write(sHTML); | |||
70 | // start the print dialog to initialize the QPrinter object | 68 | khtml->end(); | ||
71 | QPointer<QPrintDialog> dlg = new QPrintDialog(&printer, this); | 69 | khtml->view()->print(); | ||
72 | 70 | delete khtml; | |||
73 | if (dlg->exec()) { | 71 | } | ||
74 | // create the painter object | 72 | #endif | ||
75 | QPainter painter(&printer); | | |||
76 | 73 | | |||
74 | void KReportDlg::print() | ||||
75 | { | ||||
76 | #ifdef KF5KHtml_FOUND | ||||
77 | // do the actual painting job | 77 | // do the actual painting job | ||
78 | connect(this, &KReportDlg::getHTML, this, &KReportDlg::handleHTML); | ||||
78 | switch (m_tabWidget->currentIndex()) { | 79 | switch (m_tabWidget->currentIndex()) { | ||
79 | case 0: | 80 | case 0: | ||
80 | m_summaryHTMLPart->paint(&painter, QRect(0, 0, 800, 600)); | 81 | m_summaryHTMLPart->page()->toHtml([this](const QString &result){emit getHTML(result);}); | ||
81 | break; | 82 | break; | ||
82 | case 1: | 83 | case 1: | ||
83 | m_detailsHTMLPart->paint(&painter, QRect(0, 0, 800, 600)); | 84 | m_detailsHTMLPart->page()->toHtml([this](const QString &result){emit getHTML(result);}); | ||
84 | break; | 85 | break; | ||
85 | default: | 86 | default: | ||
86 | qDebug("KReportDlg::print() current page index not handled correctly"); | 87 | qDebug("KReportDlg::print() current page index not handled correctly"); | ||
87 | } | 88 | } | ||
89 | #else | ||||
90 | m_currentPrinter = new QPrinter(); | ||||
91 | QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); | ||||
92 | dialog->setWindowTitle(QString()); | ||||
93 | if (dialog->exec() != QDialog::Accepted) { | ||||
94 | delete m_currentPrinter; | ||||
95 | m_currentPrinter = nullptr; | ||||
96 | return; | ||||
97 | } | ||||
98 | | ||||
99 | // do the actual painting job | ||||
100 | switch (m_tabWidget->currentIndex()) { | ||||
101 | case 0: | ||||
102 | m_summaryHTMLPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); | ||||
103 | break; | ||||
104 | case 1: | ||||
105 | m_detailsHTMLPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); | ||||
106 | break; | ||||
107 | default: | ||||
108 | delete m_currentPrinter; | ||||
109 | m_currentPrinter = nullptr; | ||||
110 | qDebug("KReportDlg::print() current page index not handled correctly"); | ||||
88 | } | 111 | } | ||
89 | delete dlg; | 112 | #endif | ||
90 | } | 113 | } |