diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,15 @@ set(OPT_KF5_COMPONENTS ${OPT_KF5_COMPONENTS} Gpgmepp) endif() -find_package(Qt5 5.6 REQUIRED COMPONENTS Core DBus Widgets Svg Sql Xml Test PrintSupport) +find_package(Qt5 5.6 REQUIRED COMPONENTS Core DBus Widgets Svg Sql Xml Test PrintSupport WebEngineWidgets) + +#to be deleted when QWebEngine 5.8 will be better spread across distros +if(Qt5WebEngineWidgets_VERSION VERSION_LESS 5.8.0) + find_package(KF5KHtml 5.2 REQUIRED) +endif() + find_package(KF5 5.2 REQUIRED - COMPONENTS Archive CoreAddons Config ConfigWidgets I18n KHtml Completion KCMUtils ItemModels ItemViews Service Wallet IconThemes XmlGui TextWidgets Notifications KIO + COMPONENTS Archive CoreAddons Config ConfigWidgets I18n Completion KCMUtils ItemModels ItemViews Service Wallet IconThemes XmlGui TextWidgets Notifications KIO OPTIONAL_COMPONENTS ${OPT_KF5_COMPONENTS} ) find_package(LibAlkimia 6.0.0 REQUIRED) @@ -272,6 +278,7 @@ nice_yesno("USE_QT_DESIGNER") nice_yesno("USE_MODELTEST") nice_yesno("DOXYGEN_FOUND") +nice_yesno("KF5KHtml_FOUND") message(" -------- KMyMoney ${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX} -------- @@ -293,6 +300,9 @@ iCalendar export plugin: ${nice_LIBICAL_FOUND} SQLCipher plugin: ${nice_ENABLE_SQLCIPHER} + +KHTML printing: ${nice_KF5KHtml_FOUND} + -------------------------------------------- diff --git a/config-kmymoney.h.cmake b/config-kmymoney.h.cmake --- a/config-kmymoney.h.cmake +++ b/config-kmymoney.h.cmake @@ -20,3 +20,5 @@ #cmakedefine KMM_ADDRESSBOOK_FOUND 1 #cmakedefine KF5Activities_FOUND 1 + +#cmakedefine KF5KHtml_FOUND 0 diff --git a/kmymoney/CMakeLists.txt b/kmymoney/CMakeLists.txt --- a/kmymoney/CMakeLists.txt +++ b/kmymoney/CMakeLists.txt @@ -125,7 +125,7 @@ kmm_plugin Qt5::Core Qt5::Sql - KF5::KHtml + Qt5::WebEngineWidgets KF5::Archive KF5::ConfigGui KF5::WidgetsAddons diff --git a/kmymoney/dialogs/settings/ksettingshomedecl.ui b/kmymoney/dialogs/settings/ksettingshomedecl.ui --- a/kmymoney/dialogs/settings/ksettingshomedecl.ui +++ b/kmymoney/dialogs/settings/ksettingshomedecl.ui @@ -1,227 +1,231 @@ - - - - - KSettingsHomeDecl - - - - 0 - 0 - 659 - 414 - - - - Homepage Settings - - - - - - - - - - - 20 - 20 - - - - QSizePolicy::Fixed - - - Qt::Vertical - - - - - - - Up - - - - - - - Down - - - - - - - - 21 - 70 - - - - QSizePolicy::Expanding - - - Qt::Vertical - - - - - - - - - - 80 - 21 - - - - QSizePolicy::Expanding - - - Qt::Horizontal - - - - - - - - 5 - 1 - 0 - 0 - - - - Selected entries are shown on the home page of the application.<p> + + KSettingsHomeDecl + + + + 0 + 0 + 659 + 520 + + + + Homepage Settings + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Up + + + + + + + Down + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 21 + 70 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 80 + 21 + + + + + + + + + 0 + 0 + + + + Selected entries are shown on the home page of the application.<p> Use the buttons and checkboxes to customize the layout of the home page. - - - Qt::AlignTop - - - true - - - - - - - - - - - - - - - - - + + + Qt::AlignTop + + + true + + + + + + + + + + + + + + + + + + + Homepage/Summary page scaling + + + + + + Zoom factor: + + + false + + - - - - Homepage/Summary page font scaling - - - - - - Percentage of default font size: - - - false - - - - - - - Remember font size when leaving the program if manually changed with mouse-wheel - - - - - - - 100 - - - 1 - - - 1000 - - - - - - - - 40 - 20 - - - - QSizePolicy::Expanding - - - Qt::Horizontal - - - - - + + + + Remember zoom factor when leaving the program if manually changed with mouse-wheel + + - - - - Account information display - - - - - - Show Account Limit Information - - - - - - - Show balance-status of mapped online accounts - - - - - - - Show number of not marked transactions per account [!M] - - - - - - - Show number of cleared transactions per account [C] - - - - - - - Show number of not reconciled (not marked + cleared) transactions per account [!R] - - - - - + + + + 0.250000000000000 + + + 5.000000000000000 + + + 0.050000000000000 + + + 1.000000000000000 + + - - - + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + + Account information display + + + + + + Show Account Limit Information + + + + + + + Show balance-status of mapped online accounts + + + + + + + Show number of not marked transactions per account [!M] + + + + + + + Show number of cleared transactions per account [C] + + + + + + + Show number of not reconciled (not marked + cleared) transactions per account [!R] + + + + + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+
+ +
diff --git a/kmymoney/kmymoney.kcfg b/kmymoney/kmymoney.kcfg --- a/kmymoney/kmymoney.kcfg +++ b/kmymoney/kmymoney.kcfg @@ -160,12 +160,12 @@ 8,1,2,3,4,5,6,7,-9,10 - - - 100 + + + 1.00 - - + + true diff --git a/kmymoney/plugins/printcheck/CMakeLists.txt b/kmymoney/plugins/printcheck/CMakeLists.txt --- a/kmymoney/plugins/printcheck/CMakeLists.txt +++ b/kmymoney/plugins/printcheck/CMakeLists.txt @@ -11,11 +11,17 @@ add_library(kmm_printcheck MODULE ${kmm_printcheck_PART_SRCS}) target_link_libraries(kmm_printcheck - KF5::KHtml + KF5::I18n + Qt5::WebEngineWidgets kmm_mymoney kmm_plugin ) +#to be deleted when QWebEngine 5.8 will be better spread across distros +if(KF5KHtml_FOUND) + target_link_libraries(kmm_printcheck KF5::KHtml) +endif() + install(TARGETS kmm_printcheck DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney/") @@ -43,7 +49,11 @@ kcoreaddons_desktop_to_json(kcm_kmm_printcheck kcm_kmm_printcheck.desktop) target_link_libraries(kcm_kmm_printcheck - KF5::KHtml + KF5::I18n + KF5::ConfigWidgets + Qt5::WebEngineWidgets + KF5::Completion + KF5::KIOWidgets KF5::CoreAddons ) diff --git a/kmymoney/plugins/printcheck/kcm_printcheck.h b/kmymoney/plugins/printcheck/kcm_printcheck.h --- a/kmymoney/plugins/printcheck/kcm_printcheck.h +++ b/kmymoney/plugins/printcheck/kcm_printcheck.h @@ -22,6 +22,7 @@ #include #include +#include #include "ui_pluginsettingsdecl.h" class QStringList; @@ -39,7 +40,7 @@ void returnPressed(const QString& url); private: - KHTMLPart* m_checkTemplatePreviewHTMLPart; + QWebEngineView* m_checkTemplatePreviewHTMLPart; }; class KCMPrintCheck : public KCModule diff --git a/kmymoney/plugins/printcheck/kcm_printcheck.cpp b/kmymoney/plugins/printcheck/kcm_printcheck.cpp --- a/kmymoney/plugins/printcheck/kcm_printcheck.cpp +++ b/kmymoney/plugins/printcheck/kcm_printcheck.cpp @@ -27,21 +27,18 @@ #include // KDE includes -#include -#include -#include #include #include "pluginsettings.h" PluginSettingsWidget::PluginSettingsWidget(QWidget* parent) : QWidget(parent) { setupUi(this); - m_checkTemplatePreviewHTMLPart = new KHTMLPart(m_previewFrame); + m_checkTemplatePreviewHTMLPart = new QWebEngineView(m_previewFrame); QVBoxLayout *layout = new QVBoxLayout; m_previewFrame->setLayout(layout); - layout->addWidget(m_checkTemplatePreviewHTMLPart->view()); + layout->addWidget(m_checkTemplatePreviewHTMLPart); connect(kcfg_checkTemplateFile, SIGNAL(urlSelected(QUrl)), this, SLOT(urlSelected(QUrl))); @@ -52,13 +49,13 @@ void PluginSettingsWidget::urlSelected(const QUrl &url) { if (!url.isEmpty()) - m_checkTemplatePreviewHTMLPart->openUrl(url); + m_checkTemplatePreviewHTMLPart->load(url); } void PluginSettingsWidget::returnPressed(const QString& url) { if (!url.isEmpty()) - m_checkTemplatePreviewHTMLPart->openUrl(QUrl::fromUserInput(url)); + m_checkTemplatePreviewHTMLPart->load(QUrl::fromUserInput(url)); } K_PLUGIN_FACTORY_WITH_JSON(KCMPrintCheckFactory, "kcm_kmm_printcheck.json", registerPlugin();) diff --git a/kmymoney/plugins/printcheck/printcheck.h b/kmymoney/plugins/printcheck/printcheck.h --- a/kmymoney/plugins/printcheck/printcheck.h +++ b/kmymoney/plugins/printcheck/printcheck.h @@ -26,6 +26,7 @@ #include "mymoneyaccount.h" #include "mymoneykeyvaluecontainer.h" #include "selectedtransaction.h" +#include class QStringList; class KPluginInfo; @@ -56,6 +57,7 @@ private: struct Private; std::unique_ptr d; + QPrinter *m_currentPrinter; }; #endif // PRINTCHECK_H diff --git a/kmymoney/plugins/printcheck/printcheck.cpp b/kmymoney/plugins/printcheck/printcheck.cpp --- a/kmymoney/plugins/printcheck/printcheck.cpp +++ b/kmymoney/plugins/printcheck/printcheck.cpp @@ -20,15 +20,22 @@ #include "printcheck.h" +#include "config-kmymoney.h" + // QT includes #include +#include +#include // KDE includes #include #include -#include -#include #include +#include +#ifdef KF5KHtml_FOUND +#include +#include +#endif // KMyMoney includes #include "mymoneyfile.h" @@ -117,7 +124,7 @@ { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyMoneyToWordsConverter converter; - KHTMLPart *htmlPart = new KHTMLPart(static_cast(0)); + QWebEngineView *htmlPart = new QWebEngineView(); KMyMoneyRegister::SelectedTransactions::const_iterator it; for (it = d->m_transactions.constBegin(); it != d->m_transactions.constEnd(); ++it) { if (!canBePrinted(*it)) @@ -154,16 +161,34 @@ checkHTML.replace("$MEMO", (*it).split().memo()); // print the check - htmlPart->begin(); - htmlPart->write(checkHTML); - htmlPart->end(); - htmlPart->view()->print(); + htmlPart->setHtml(checkHTML, QUrl("file://")); +#ifdef KF5KHtml_FOUND + KHTMLPart *khtml = new KHTMLPart(); + khtml->begin(); + khtml->write(checkHTML); + khtml->end(); + khtml->view()->print(); + delete khtml; +#else + m_currentPrinter = new QPrinter(); + QPointer dialog = new QPrintDialog(m_currentPrinter); + dialog->setWindowTitle(QString()); + if (dialog->exec() != QDialog::Accepted) { + delete m_currentPrinter; + m_currentPrinter = nullptr; + continue; + } else { + htmlPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); + } + delete dialog; +#endif // mark the transaction as printed markAsPrinted(*it); } PluginSettings::setPrintedChecks(d->m_printedTransactionIdList); + delete htmlPart; } void KMMPrintCheckPlugin::slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions) diff --git a/kmymoney/plugins/reconciliationreport/CMakeLists.txt b/kmymoney/plugins/reconciliationreport/CMakeLists.txt --- a/kmymoney/plugins/reconciliationreport/CMakeLists.txt +++ b/kmymoney/plugins/reconciliationreport/CMakeLists.txt @@ -14,11 +14,16 @@ add_library(kmm_reconciliationreport MODULE ${kmm_reconciliationreport_PART_SRCS}) target_link_libraries(kmm_reconciliationreport - KF5::KHtml + Qt5::WebEngineWidgets Qt5::PrintSupport kmm_mymoney kmm_plugin ) +#to be deleted when QWebEngine 5.8 will be better spread across distros +if(KF5KHtml_FOUND) + target_link_libraries(kmm_reconciliationreport KF5::KHtml) +endif() + install(TARGETS kmm_reconciliationreport DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney/") diff --git a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.h b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.h --- a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.h +++ b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.h @@ -21,6 +21,9 @@ #ifndef KRECONCILIATIONREPORTDLG_H #define KRECONCILIATIONREPORTDLG_H +#include +#include "config-kmymoney.h" + #include "ui_kreconciliationreportdlgdecl.h" class KHTMLPart; @@ -35,10 +38,18 @@ protected slots: void print(); + #ifdef KF5KHtml_FOUND + void handleHTML(const QString &sHTML); + #endif private: - KHTMLPart* m_summaryHTMLPart; - KHTMLPart* m_detailsHTMLPart; + QWebEngineView *m_summaryHTMLPart; + QWebEngineView *m_detailsHTMLPart; + QPrinter *m_currentPrinter; +signals: + #ifdef KF5KHtml_FOUND + void getHTML(QString sHTML); + #endif }; #endif diff --git a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp --- a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp +++ b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp @@ -30,26 +30,23 @@ #include // KDE includes -#include -#include #include +#ifdef KF5KHtml_FOUND +#include +#include +#endif KReportDlg::KReportDlg(QWidget* parent, const QString& summaryReportHTML, const QString& detailsReportHTML) : QDialog(parent) { setupUi(this); - m_summaryHTMLPart = new KHTMLPart(m_summaryTab); - m_summaryLayout->addWidget(m_summaryHTMLPart->view()); + m_summaryHTMLPart = new QWebEngineView(m_summaryTab); + m_summaryLayout->addWidget(m_summaryHTMLPart); - m_detailsHTMLPart = new KHTMLPart(m_detailsTab); - m_detailsLayout->addWidget(m_detailsHTMLPart->view()); + m_detailsHTMLPart = new QWebEngineView(m_detailsTab); + m_detailsLayout->addWidget(m_detailsHTMLPart); - m_summaryHTMLPart->begin(); - m_summaryHTMLPart->write(summaryReportHTML); - m_summaryHTMLPart->end(); - - m_detailsHTMLPart->begin(); - m_detailsHTMLPart->write(detailsReportHTML); - m_detailsHTMLPart->end(); + m_summaryHTMLPart->setHtml(summaryReportHTML, QUrl("file://")); + m_detailsHTMLPart->setHtml(detailsReportHTML, QUrl("file://")); QPushButton* printButton = m_buttonBox->addButton(QString(), QDialogButtonBox::ActionRole); KGuiItem::assign(printButton, KStandardGuiItem::print()); @@ -62,29 +59,55 @@ { } -void KReportDlg::print() +#ifdef KF5KHtml_FOUND +void KReportDlg::handleHTML(const QString &sHTML) { - // create the QPrinter object with default options - QPrinter printer; - - // start the print dialog to initialize the QPrinter object - QPointer dlg = new QPrintDialog(&printer, this); - - if (dlg->exec()) { - // create the painter object - QPainter painter(&printer); + KHTMLPart *khtml = new KHTMLPart(this); + khtml->begin(); + khtml->write(sHTML); + khtml->end(); + khtml->view()->print(); + delete khtml; +} +#endif +void KReportDlg::print() +{ +#ifdef KF5KHtml_FOUND // do the actual painting job + connect(this, &KReportDlg::getHTML, this, &KReportDlg::handleHTML); switch (m_tabWidget->currentIndex()) { case 0: - m_summaryHTMLPart->paint(&painter, QRect(0, 0, 800, 600)); + m_summaryHTMLPart->page()->toHtml([this](const QString &result){emit getHTML(result);}); break; case 1: - m_detailsHTMLPart->paint(&painter, QRect(0, 0, 800, 600)); + m_detailsHTMLPart->page()->toHtml([this](const QString &result){emit getHTML(result);}); break; default: qDebug("KReportDlg::print() current page index not handled correctly"); } +#else + m_currentPrinter = new QPrinter(); + QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); + dialog->setWindowTitle(QString()); + if (dialog->exec() != QDialog::Accepted) { + delete m_currentPrinter; + m_currentPrinter = nullptr; + return; + } + + // do the actual painting job + switch (m_tabWidget->currentIndex()) { + case 0: + m_summaryHTMLPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); + break; + case 1: + m_detailsHTMLPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); + break; + default: + delete m_currentPrinter; + m_currentPrinter = nullptr; + qDebug("KReportDlg::print() current page index not handled correctly"); } - delete dlg; + #endif } diff --git a/kmymoney/views/CMakeLists.txt b/kmymoney/views/CMakeLists.txt --- a/kmymoney/views/CMakeLists.txt +++ b/kmymoney/views/CMakeLists.txt @@ -65,7 +65,12 @@ add_library(views STATIC ${libviews_a_SOURCES}) -target_link_libraries(views PUBLIC KChart KF5::KIOFileWidgets KF5::Notifications KF5::Archive KF5::KHtml Qt5::Sql Alkimia::alkimia) +target_link_libraries(views PUBLIC KChart KF5::KIOFileWidgets KF5::Notifications KF5::Archive KF5::TextWidgets Qt5::Sql Qt5::WebEngineWidgets Alkimia::alkimia) + +#to be deleted when QWebEngine 5.8 will be better spread across distros +if(KF5KHtml_FOUND) + target_link_libraries(views PRIVATE KF5::KHtml) +endif() if(KF5Activities_FOUND) target_link_libraries(views PRIVATE KF5::Activities) diff --git a/kmymoney/views/khomeview.h b/kmymoney/views/khomeview.h --- a/kmymoney/views/khomeview.h +++ b/kmymoney/views/khomeview.h @@ -25,12 +25,12 @@ // QT Includes #include +#include +#include // ---------------------------------------------------------------------------- // KDE Includes -#include - // ---------------------------------------------------------------------------- // Project Includes @@ -62,6 +62,7 @@ ~KHomeView(); protected: + virtual void wheelEvent(QWheelEvent *event); void showPayments(); void showPaymentEntry(const MyMoneySchedule&, int cnt = 1); void showAccounts(paymentTypeE type, const QString& hdr); @@ -89,16 +90,14 @@ public slots: - void slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browArgs); + void slotOpenUrl(const QUrl &url); void slotLoadView(); /** * Print the current view */ void slotPrintView(); - void slotZoomView(int); - signals: void ledgerSelected(const QString& id, const QString& transaction); void scheduleSelected(const QString& id); @@ -136,6 +135,8 @@ * Calculate the forecast balance after a payment has been made */ MyMoneyMoney forecastPaymentBalance(const MyMoneyAccount& acc, const MyMoneyMoney& payment, QDate& paymentDate); + + QPrinter *m_currentPrinter; }; #endif diff --git a/kmymoney/views/khomeview.cpp b/kmymoney/views/khomeview.cpp --- a/kmymoney/views/khomeview.cpp +++ b/kmymoney/views/khomeview.cpp @@ -38,20 +38,23 @@ #include #include #include +#include // ---------------------------------------------------------------------------- // KDE Includes #include -#include #include #include #include #include #include #include #include -#include +#ifdef KF5KHtml_FOUND +#include +#include +#endif // ---------------------------------------------------------------------------- // Project Includes @@ -96,12 +99,12 @@ */ typedef QMap dailyBalances; - KHTMLPart* m_part; - QString m_html; - bool m_showAllSchedules; - bool m_needReload; - MyMoneyForecast m_forecast; - MyMoneyMoney m_total; + QWebEngineView *m_view; + QString m_html; + bool m_showAllSchedules; + bool m_needReload; + MyMoneyForecast m_forecast; + MyMoneyMoney m_total; /** * Hold the last valid size of the net worth graph * for the times when the needed size can't be computed. @@ -136,35 +139,41 @@ KMyMoneyViewBase(parent, name, i18n("Home")), d(new Private) { - d->m_part = new KHTMLPart(this); - d->m_part->setOnlyLocalReferences(true); - addWidget(d->m_part->view()); + d->m_view = new QWebEngineView(this); + d->m_view->setPage(new MyQWebEnginePage(d->m_view)); + addWidget(d->m_view); - d->m_part->begin(); - d->m_part->write(KWelcomePage::welcomePage()); - d->m_part->end(); - - // we are going to handle the zoom view signal to change the font scale - connect(d->m_part->view(), SIGNAL(zoomView(int)), this, SLOT(slotZoomView(int))); - disconnect(d->m_part->view(), SIGNAL(zoomView(int)), d->m_part, SLOT(slotZoomView(int))); - - connect(d->m_part->browserExtension(), SIGNAL(openUrlRequest(const QUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &)), - this, SLOT(slotOpenUrl(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); + d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); + connect(d->m_view->page(), &QWebEnginePage::urlChanged, + this, &KHomeView::slotOpenUrl); } KHomeView::~KHomeView() { // if user wants to remember the font size, store it here - if (KMyMoneyGlobalSettings::rememberFontSize()) { - KMyMoneyGlobalSettings::setFontSizePercentage(d->m_part->fontScaleFactor()); + if (KMyMoneyGlobalSettings::rememberZoomFactor()) { + KMyMoneyGlobalSettings::setZoomFactor(d->m_view->zoomFactor()); KMyMoneyGlobalSettings::self()->save(); } - //This is to prevent a crash on exit with KDE 4.3.2 - delete d->m_part; delete d; } +void KHomeView::wheelEvent(QWheelEvent* event) +{ + // Zoom text on Ctrl + Scroll + if (event->modifiers() & Qt::CTRL) { + qreal factor = d->m_view->zoomFactor(); + if (event->delta() > 0) + factor += 0.1; + else if (event->delta() < 0) + factor -= 0.1; + d->m_view->setZoomFactor(factor); + event->accept(); + return; + } +} + void KHomeView::slotLoadView() { d->m_needReload = true; @@ -188,29 +197,36 @@ void KHomeView::slotPrintView() { - if (d->m_part && d->m_part->view()) - d->m_part->view()->print(); -} - -void KHomeView::slotZoomView(int delta) -{ - const int fontScaleStepping = 10; - if (delta > 0) - d->m_part->setFontScaleFactor(d->m_part->fontScaleFactor() + fontScaleStepping); - else - d->m_part->setFontScaleFactor(d->m_part->fontScaleFactor() - fontScaleStepping); + if (d->m_view) { +#ifdef KF5KHtml_FOUND + KHTMLPart *khtml = new KHTMLPart(this); + khtml->begin(); + khtml->write(d->m_html); + khtml->end(); + khtml->view()->print(); + delete khtml; +#else + m_currentPrinter = new QPrinter(); + QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); + dialog->setWindowTitle(QString()); + if (dialog->exec() != QDialog::Accepted) { + delete m_currentPrinter; + m_currentPrinter = nullptr; + return; + } + d->m_view->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); +#endif + } } void KHomeView::loadView() { - d->m_part->setFontScaleFactor(KMyMoneyGlobalSettings::fontSizePercentage()); + d->m_view->setZoomFactor(KMyMoneyGlobalSettings::zoomFactor()); QList list; MyMoneyFile::instance()->accountList(list); if (list.count() == 0) { - d->m_part->begin(); - d->m_part->write(KWelcomePage::welcomePage()); - d->m_part->end(); + d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); } else { //clear the forecast flag so it will be reloaded d->m_forecast.setForecastDone(false); @@ -285,9 +301,7 @@ d->m_html += "
"; d->m_html += footer; - d->m_part->begin(); - d->m_part->write(d->m_html); - d->m_part->end(); + d->m_view->setHtml(d->m_html, QUrl("file://")); } } @@ -1153,26 +1167,28 @@ return QStringLiteral(""); } -void KHomeView::slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&) +void KHomeView::slotOpenUrl(const QUrl &url) { QString protocol = url.scheme(); QString view = url.fileName(); + if (view.isEmpty()) + return; QUrlQuery query(url); QString id = query.queryItemValue("id"); QString mode = query.queryItemValue("mode"); - if (protocol == "http") { + if (protocol == QLatin1String("http")) { QDesktopServices::openUrl(url); - } else if (protocol == "mailto") { + } else if (protocol == QLatin1String("mailto")) { QDesktopServices::openUrl(url); } else { KXmlGuiWindow* mw = KMyMoneyUtils::mainWindow(); Q_CHECK_PTR(mw); if (view == VIEW_LEDGER) { emit ledgerSelected(id, QString()); } else if (view == VIEW_SCHEDULE) { - if (mode == "enter") { + if (mode == QLatin1String("enter")) { emit scheduleSelected(id); QTimer::singleShot(0, mw->actionCollection()->action(kmymoney->s_Actions[Action::ScheduleEnter]), SLOT(trigger())); } else if (mode == QLatin1String("edit")) { @@ -1185,26 +1201,21 @@ d->m_showAllSchedules = true; loadView(); - } else if (mode == "reduced") { + } else if (mode == QLatin1String("reduced")) { d->m_showAllSchedules = false; loadView(); } } else if (view == VIEW_REPORTS) { emit reportSelected(id); } else if (view == VIEW_WELCOME) { - if (mode == "whatsnew") { - d->m_part->begin(); - d->m_part->write(KWelcomePage::whatsNewPage()); - d->m_part->end(); - } else { - d->m_part->begin(); - d->m_part->write(KWelcomePage::welcomePage()); - d->m_part->end(); - } + if (mode == QLatin1String("whatsnew")) + d->m_view->setHtml(KWelcomePage::whatsNewPage(), QUrl("file://")); + else + d->m_view->setHtml(KWelcomePage::welcomePage(), QUrl("file://")); - } else if (view == "action") { + } else if (view == QLatin1String("action")) { QTimer::singleShot(0, mw->actionCollection()->action(id), SLOT(trigger())); } else if (view == VIEW_HOME) { QList list; diff --git a/kmymoney/views/kmymoneyview.h b/kmymoney/views/kmymoneyview.h --- a/kmymoney/views/kmymoneyview.h +++ b/kmymoney/views/kmymoneyview.h @@ -28,6 +28,7 @@ #include #include #include +#include // ---------------------------------------------------------------------------- // KDE Includes @@ -669,4 +670,15 @@ Private* const d; }; + +class MyQWebEnginePage : public QWebEnginePage +{ + Q_OBJECT + +public: + MyQWebEnginePage(QObject* parent = nullptr) : QWebEnginePage(parent){} + +protected: + bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool); +}; #endif diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -41,6 +41,7 @@ #include #include #include +#include // ---------------------------------------------------------------------------- // KDE Includes @@ -2147,3 +2148,10 @@ { return d->m_viewLayout; } + +bool MyQWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool) +{ + if (type == NavigationTypeLinkClicked) + emit urlChanged(url); + return false; +} diff --git a/kmymoney/views/kreportsview.h b/kmymoney/views/kreportsview.h --- a/kmymoney/views/kreportsview.h +++ b/kmymoney/views/kreportsview.h @@ -33,11 +33,12 @@ #include #include #include +#include +#include // ---------------------------------------------------------------------------- // KDE Includes -#include #include #include @@ -61,6 +62,7 @@ #include "tocitemreport.h" class MyMoneyReport; +class MyQWebEnginePage; /** * Displays a page where reports can be placed. @@ -85,10 +87,11 @@ class KReportTab: public QWidget { private: - QPointer m_tableView; - reports::KReportChartView* m_chartView; - ReportControl* m_control; - QVBoxLayout* m_layout; + QWebEngineView *m_tableView; + reports::KReportChartView *m_chartView; + ReportControl *m_control; + QVBoxLayout *m_layout; + QPrinter *m_currentPrinter; MyMoneyReport m_report; bool m_deleteMe; bool m_chartEnabled; @@ -104,7 +107,7 @@ QByteArray m_encoding; public: - KReportTab(QTabWidget* parent, const MyMoneyReport& report, const QObject* eventHandler); + KReportTab(QTabWidget* parent, const MyMoneyReport& report, const KReportsView *eventHandler); ~KReportTab(); const MyMoneyReport& report() const { return m_report; @@ -133,9 +136,6 @@ } void showEvent(QShowEvent * event); void loadTab(); - KParts::BrowserExtension* browserExtenstion() const { - return m_tableView->browserExtension(); - } }; /** @@ -205,7 +205,7 @@ void setColumnsAlreadyAdjusted(bool adjusted); public slots: - void slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments& browArgs); + void slotOpenUrl(const QUrl &url); void slotLoadView(); void slotPrintView(); diff --git a/kmymoney/views/kreportsview.cpp b/kmymoney/views/kreportsview.cpp --- a/kmymoney/views/kreportsview.cpp +++ b/kmymoney/views/kreportsview.cpp @@ -41,14 +41,19 @@ #include #include #include +#include +#include // ---------------------------------------------------------------------------- // KDE Includes -#include #include #include #include +#ifdef KF5KHtml_FOUND +#include +#include +#endif // ---------------------------------------------------------------------------- // Project Includes @@ -73,9 +78,9 @@ /** * KReportsView::KReportTab Implementation */ -KReportsView::KReportTab::KReportTab(QTabWidget* parent, const MyMoneyReport& report, const QObject* eventHandler): +KReportsView::KReportTab::KReportTab(QTabWidget* parent, const MyMoneyReport& report, const KReportsView* eventHandler): QWidget(parent), - m_tableView(new KHTMLPart(this)), + m_tableView(new QWebEngineView(this)), m_chartView(new KReportChartView(this)), m_control(new ReportControl(this)), m_layout(new QVBoxLayout(this)), @@ -87,7 +92,8 @@ m_table(0) { m_layout->setSpacing(6); - m_tableView->setFontScaleFactor(KMyMoneyGlobalSettings::fontSizePercentage()); + m_tableView->setPage(new MyQWebEnginePage(m_tableView)); + m_tableView->setZoomFactor(KMyMoneyGlobalSettings::zoomFactor()); //set button icons m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::OfficeChartLine])); @@ -100,9 +106,9 @@ m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_chartView->hide(); - m_tableView->view()->hide(); + m_tableView->hide(); m_layout->addWidget(m_control); - m_layout->addWidget(m_tableView->view()); + m_layout->addWidget(m_tableView); m_layout->addWidget(m_chartView); connect(m_control->ui->buttonChart, SIGNAL(clicked()), @@ -126,8 +132,8 @@ connect(m_control->ui->buttonClose, SIGNAL(clicked()), eventHandler, SLOT(slotCloseCurrent())); - connect(m_tableView->browserExtension(), SIGNAL(openUrlRequest(const QUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &)), - eventHandler, SLOT(slotOpenUrl(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); + connect(m_tableView->page(), &QWebEnginePage::urlChanged, + eventHandler, &KReportsView::slotOpenUrl); // if this is a default report, then you can't delete it! if (report.id().isEmpty()) @@ -146,14 +152,30 @@ KReportsView::KReportTab::~KReportTab() { delete m_table; - //This is to prevent a crash on exit with KDE 4.3.2 - delete m_tableView; } void KReportsView::KReportTab::print() { - if (m_tableView && m_tableView->view()) - m_tableView->view()->print(); + if (m_tableView) { +#ifdef KF5KHtml_FOUND + KHTMLPart *khtml = new KHTMLPart(this); + khtml->begin(); + khtml->write(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name())); + khtml->end(); + khtml->view()->print(); + delete khtml; +#else + m_currentPrinter = new QPrinter(); + QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); + dialog->setWindowTitle(QString()); + if (dialog->exec() != QDialog::Accepted) { + delete m_currentPrinter; + m_currentPrinter = nullptr; + return; + } + m_tableView->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); +#endif + } } void KReportsView::KReportTab::copyToClipboard() @@ -238,12 +260,11 @@ if (m_showingChart) { if (!m_isTableViewValid) { - m_tableView->begin(); - m_tableView->write(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name())); - m_tableView->end(); + m_tableView->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name()), + QUrl("file://")); // workaround for access permission to css file } m_isTableViewValid = true; - m_tableView->view()->show(); + m_tableView->show(); m_chartView->hide(); m_control->ui->buttonChart->setText(i18n("Chart")); @@ -253,7 +274,7 @@ if (!m_isChartViewValid) m_table->drawChart(*m_chartView); m_isChartViewValid = true; - m_tableView->view()->hide(); + m_tableView->hide(); m_chartView->show(); m_control->ui->buttonChart->setText(i18n("Report")); @@ -639,30 +660,32 @@ m_tocTreeWidget->setUpdatesEnabled(true); } -void KReportsView::slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&) +void KReportsView::slotOpenUrl(const QUrl &url) { QString view = url.fileName(); + if (view.isEmpty()) + return; QString command = QUrlQuery(url).queryItemValue("command"); QString id = QUrlQuery(url).queryItemValue("id"); QString tid = QUrlQuery(url).queryItemValue("tid"); if (view == VIEW_REPORTS) { if (command.isEmpty()) { // slotRefreshView(); - } else if (command == "print") + } else if (command == QLatin1String("print")) slotPrintView(); - else if (command == "copy") + else if (command == QLatin1String("copy")) slotCopyView(); - else if (command == "save") + else if (command == QLatin1String("save")) slotSaveView(); - else if (command == "configure") + else if (command == QLatin1String("configure")) slotConfigure(); - else if (command == "duplicate") + else if (command == QLatin1String("duplicate")) slotDuplicate(); - else if (command == "close") + else if (command == QLatin1String("close")) slotCloseCurrent(); - else if (command == "delete") + else if (command == QLatin1String("delete")) slotDelete(); else qWarning() << i18n("Unknown command '%1' in KReportsView::slotOpenUrl()", qPrintable(command));