Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/views/kreportsview.cpp
Show All 35 Lines | |||||
36 | #include <QCheckBox> | 36 | #include <QCheckBox> | ||
37 | #include <QMimeData> | 37 | #include <QMimeData> | ||
38 | #include <QIcon> | 38 | #include <QIcon> | ||
39 | #include <QUrlQuery> | 39 | #include <QUrlQuery> | ||
40 | #include <QFileInfo> | 40 | #include <QFileInfo> | ||
41 | #include <QFileDialog> | 41 | #include <QFileDialog> | ||
42 | #include <QLocale> | 42 | #include <QLocale> | ||
43 | #include <QTextCodec> | 43 | #include <QTextCodec> | ||
44 | #include <QWebEngineSettings> | ||||
45 | #include <QPrintDialog> | ||||
44 | 46 | | |||
45 | // ---------------------------------------------------------------------------- | 47 | // ---------------------------------------------------------------------------- | ||
46 | // KDE Includes | 48 | // KDE Includes | ||
47 | 49 | | |||
48 | #include <KHTMLView> | | |||
49 | #include <KConfig> | 50 | #include <KConfig> | ||
50 | #include <KMessageBox> | 51 | #include <KMessageBox> | ||
51 | #include <KRecentDirs> | 52 | #include <KRecentDirs> | ||
53 | #ifdef KF5KHtml_FOUND | ||||
54 | #include <KHTMLPart> | ||||
55 | #include <KHTMLView> | ||||
56 | #endif | ||||
52 | 57 | | |||
53 | // ---------------------------------------------------------------------------- | 58 | // ---------------------------------------------------------------------------- | ||
54 | // Project Includes | 59 | // Project Includes | ||
55 | 60 | | |||
56 | #include <mymoneyfile.h> | 61 | #include <mymoneyfile.h> | ||
57 | #include <mymoneyreport.h> | 62 | #include <mymoneyreport.h> | ||
58 | #include <kmymoneyglobalsettings.h> | 63 | #include <kmymoneyglobalsettings.h> | ||
59 | #include "querytable.h" | 64 | #include "querytable.h" | ||
60 | #include "objectinfotable.h" | 65 | #include "objectinfotable.h" | ||
61 | #include "kreportconfigurationfilterdlg.h" | 66 | #include "kreportconfigurationfilterdlg.h" | ||
62 | #include <icons/icons.h> | 67 | #include <icons/icons.h> | ||
63 | 68 | | |||
64 | using namespace reports; | 69 | using namespace reports; | ||
65 | using namespace Icons; | 70 | using namespace Icons; | ||
66 | 71 | | |||
67 | #define VIEW_LEDGER "ledger" | 72 | #define VIEW_LEDGER "ledger" | ||
68 | #define VIEW_SCHEDULE "schedule" | 73 | #define VIEW_SCHEDULE "schedule" | ||
69 | #define VIEW_WELCOME "welcome" | 74 | #define VIEW_WELCOME "welcome" | ||
70 | #define VIEW_HOME "home" | 75 | #define VIEW_HOME "home" | ||
71 | #define VIEW_REPORTS "reports" | 76 | #define VIEW_REPORTS "reports" | ||
72 | 77 | | |||
73 | /** | 78 | /** | ||
74 | * KReportsView::KReportTab Implementation | 79 | * KReportsView::KReportTab Implementation | ||
75 | */ | 80 | */ | ||
76 | KReportsView::KReportTab::KReportTab(QTabWidget* parent, const MyMoneyReport& report, const QObject* eventHandler): | 81 | KReportsView::KReportTab::KReportTab(QTabWidget* parent, const MyMoneyReport& report, const KReportsView* eventHandler): | ||
77 | QWidget(parent), | 82 | QWidget(parent), | ||
78 | m_tableView(new KHTMLPart(this)), | 83 | m_tableView(new QWebEngineView(this)), | ||
79 | m_chartView(new KReportChartView(this)), | 84 | m_chartView(new KReportChartView(this)), | ||
80 | m_control(new ReportControl(this)), | 85 | m_control(new ReportControl(this)), | ||
81 | m_layout(new QVBoxLayout(this)), | 86 | m_layout(new QVBoxLayout(this)), | ||
82 | m_report(report), | 87 | m_report(report), | ||
83 | m_deleteMe(false), | 88 | m_deleteMe(false), | ||
84 | m_chartEnabled(false), | 89 | m_chartEnabled(false), | ||
85 | m_showingChart(report.isChartByDefault()), | 90 | m_showingChart(report.isChartByDefault()), | ||
86 | m_needReload(true), | 91 | m_needReload(true), | ||
87 | m_table(0) | 92 | m_table(0) | ||
88 | { | 93 | { | ||
89 | m_layout->setSpacing(6); | 94 | m_layout->setSpacing(6); | ||
90 | m_tableView->setFontScaleFactor(KMyMoneyGlobalSettings::fontSizePercentage()); | 95 | m_tableView->setPage(new MyQWebEnginePage(m_tableView)); | ||
96 | m_tableView->setZoomFactor(KMyMoneyGlobalSettings::zoomFactor()); | ||||
91 | 97 | | |||
92 | //set button icons | 98 | //set button icons | ||
93 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::OfficeChartLine])); | 99 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::OfficeChartLine])); | ||
94 | m_control->ui->buttonClose->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentClose])); | 100 | m_control->ui->buttonClose->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentClose])); | ||
95 | m_control->ui->buttonConfigure->setIcon(QIcon::fromTheme(g_Icons[Icon::Configure])); | 101 | m_control->ui->buttonConfigure->setIcon(QIcon::fromTheme(g_Icons[Icon::Configure])); | ||
96 | m_control->ui->buttonCopy->setIcon(QIcon::fromTheme(g_Icons[Icon::EditCopy])); | 102 | m_control->ui->buttonCopy->setIcon(QIcon::fromTheme(g_Icons[Icon::EditCopy])); | ||
97 | m_control->ui->buttonDelete->setIcon(QIcon::fromTheme(g_Icons[Icon::EditDelete])); | 103 | m_control->ui->buttonDelete->setIcon(QIcon::fromTheme(g_Icons[Icon::EditDelete])); | ||
98 | m_control->ui->buttonExport->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentExport])); | 104 | m_control->ui->buttonExport->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentExport])); | ||
99 | m_control->ui->buttonNew->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentNew])); | 105 | m_control->ui->buttonNew->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentNew])); | ||
100 | 106 | | |||
101 | m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 107 | m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
102 | m_chartView->hide(); | 108 | m_chartView->hide(); | ||
103 | m_tableView->view()->hide(); | 109 | m_tableView->hide(); | ||
104 | m_layout->addWidget(m_control); | 110 | m_layout->addWidget(m_control); | ||
105 | m_layout->addWidget(m_tableView->view()); | 111 | m_layout->addWidget(m_tableView); | ||
106 | m_layout->addWidget(m_chartView); | 112 | m_layout->addWidget(m_chartView); | ||
107 | 113 | | |||
108 | connect(m_control->ui->buttonChart, SIGNAL(clicked()), | 114 | connect(m_control->ui->buttonChart, SIGNAL(clicked()), | ||
109 | eventHandler, SLOT(slotToggleChart())); | 115 | eventHandler, SLOT(slotToggleChart())); | ||
110 | 116 | | |||
111 | connect(m_control->ui->buttonConfigure, SIGNAL(clicked()), | 117 | connect(m_control->ui->buttonConfigure, SIGNAL(clicked()), | ||
112 | eventHandler, SLOT(slotConfigure())); | 118 | eventHandler, SLOT(slotConfigure())); | ||
113 | 119 | | |||
114 | connect(m_control->ui->buttonNew, SIGNAL(clicked()), | 120 | connect(m_control->ui->buttonNew, SIGNAL(clicked()), | ||
115 | eventHandler, SLOT(slotDuplicate())); | 121 | eventHandler, SLOT(slotDuplicate())); | ||
116 | 122 | | |||
117 | connect(m_control->ui->buttonCopy, SIGNAL(clicked()), | 123 | connect(m_control->ui->buttonCopy, SIGNAL(clicked()), | ||
118 | eventHandler, SLOT(slotCopyView())); | 124 | eventHandler, SLOT(slotCopyView())); | ||
119 | 125 | | |||
120 | connect(m_control->ui->buttonExport, SIGNAL(clicked()), | 126 | connect(m_control->ui->buttonExport, SIGNAL(clicked()), | ||
121 | eventHandler, SLOT(slotSaveView())); | 127 | eventHandler, SLOT(slotSaveView())); | ||
122 | 128 | | |||
123 | connect(m_control->ui->buttonDelete, SIGNAL(clicked()), | 129 | connect(m_control->ui->buttonDelete, SIGNAL(clicked()), | ||
124 | eventHandler, SLOT(slotDelete())); | 130 | eventHandler, SLOT(slotDelete())); | ||
125 | 131 | | |||
126 | connect(m_control->ui->buttonClose, SIGNAL(clicked()), | 132 | connect(m_control->ui->buttonClose, SIGNAL(clicked()), | ||
127 | eventHandler, SLOT(slotCloseCurrent())); | 133 | eventHandler, SLOT(slotCloseCurrent())); | ||
128 | 134 | | |||
129 | connect(m_tableView->browserExtension(), SIGNAL(openUrlRequest(const QUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &)), | 135 | connect(m_tableView->page(), &QWebEnginePage::urlChanged, | ||
130 | eventHandler, SLOT(slotOpenUrl(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); | 136 | eventHandler, &KReportsView::slotOpenUrl); | ||
131 | 137 | | |||
132 | // if this is a default report, then you can't delete it! | 138 | // if this is a default report, then you can't delete it! | ||
133 | if (report.id().isEmpty()) | 139 | if (report.id().isEmpty()) | ||
134 | m_control->ui->buttonDelete->setEnabled(false); | 140 | m_control->ui->buttonDelete->setEnabled(false); | ||
135 | 141 | | |||
136 | int tabNr = parent->addTab(this, | 142 | int tabNr = parent->addTab(this, | ||
137 | QIcon::fromTheme(g_Icons[Icon::Spreadsheet]), | 143 | QIcon::fromTheme(g_Icons[Icon::Spreadsheet]), | ||
138 | report.name()); | 144 | report.name()); | ||
139 | parent->setTabEnabled(tabNr, true); | 145 | parent->setTabEnabled(tabNr, true); | ||
140 | parent->setCurrentIndex(tabNr); | 146 | parent->setCurrentIndex(tabNr); | ||
141 | 147 | | |||
142 | // get users character set encoding | 148 | // get users character set encoding | ||
143 | m_encoding = QTextCodec::codecForLocale()->name(); | 149 | m_encoding = QTextCodec::codecForLocale()->name(); | ||
144 | } | 150 | } | ||
145 | 151 | | |||
146 | KReportsView::KReportTab::~KReportTab() | 152 | KReportsView::KReportTab::~KReportTab() | ||
147 | { | 153 | { | ||
148 | delete m_table; | 154 | delete m_table; | ||
149 | //This is to prevent a crash on exit with KDE 4.3.2 | | |||
150 | delete m_tableView; | | |||
151 | } | 155 | } | ||
152 | 156 | | |||
153 | void KReportsView::KReportTab::print() | 157 | void KReportsView::KReportTab::print() | ||
154 | { | 158 | { | ||
155 | if (m_tableView && m_tableView->view()) | 159 | if (m_tableView) { | ||
156 | m_tableView->view()->print(); | 160 | #ifdef KF5KHtml_FOUND | ||
161 | KHTMLPart *khtml = new KHTMLPart(this); | ||||
162 | khtml->begin(); | ||||
163 | khtml->write(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name())); | ||||
164 | khtml->end(); | ||||
165 | khtml->view()->print(); | ||||
166 | delete khtml; | ||||
167 | #else | ||||
168 | m_currentPrinter = new QPrinter(); | ||||
169 | QPrintDialog *dialog = new QPrintDialog(m_currentPrinter, this); | ||||
170 | dialog->setWindowTitle(QString()); | ||||
171 | if (dialog->exec() != QDialog::Accepted) { | ||||
172 | delete m_currentPrinter; | ||||
173 | m_currentPrinter = nullptr; | ||||
174 | return; | ||||
175 | } | ||||
176 | m_tableView->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); | ||||
177 | #endif | ||||
178 | } | ||||
157 | } | 179 | } | ||
158 | 180 | | |||
159 | void KReportsView::KReportTab::copyToClipboard() | 181 | void KReportsView::KReportTab::copyToClipboard() | ||
160 | { | 182 | { | ||
161 | QMimeData* pMimeData = new QMimeData(); | 183 | QMimeData* pMimeData = new QMimeData(); | ||
162 | pMimeData->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name(), true)); | 184 | pMimeData->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name(), true)); | ||
163 | QApplication::clipboard()->setMimeData(pMimeData); | 185 | QApplication::clipboard()->setMimeData(pMimeData); | ||
164 | } | 186 | } | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
233 | } | 255 | } | ||
234 | 256 | | |||
235 | void KReportsView::KReportTab::toggleChart() | 257 | void KReportsView::KReportTab::toggleChart() | ||
236 | { | 258 | { | ||
237 | // for now it will just SHOW the chart. In the future it actually has to toggle it. | 259 | // for now it will just SHOW the chart. In the future it actually has to toggle it. | ||
238 | 260 | | |||
239 | if (m_showingChart) { | 261 | if (m_showingChart) { | ||
240 | if (!m_isTableViewValid) { | 262 | if (!m_isTableViewValid) { | ||
241 | m_tableView->begin(); | 263 | m_tableView->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name()), | ||
242 | m_tableView->write(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name())); | 264 | QUrl("file://")); // workaround for access permission to css file | ||
243 | m_tableView->end(); | | |||
244 | } | 265 | } | ||
245 | m_isTableViewValid = true; | 266 | m_isTableViewValid = true; | ||
246 | m_tableView->view()->show(); | 267 | m_tableView->show(); | ||
247 | m_chartView->hide(); | 268 | m_chartView->hide(); | ||
248 | 269 | | |||
249 | m_control->ui->buttonChart->setText(i18n("Chart")); | 270 | m_control->ui->buttonChart->setText(i18n("Chart")); | ||
250 | m_control->ui->buttonChart->setToolTip(i18n("Show the chart version of this report")); | 271 | m_control->ui->buttonChart->setToolTip(i18n("Show the chart version of this report")); | ||
251 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::OfficeChartLine])); | 272 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::OfficeChartLine])); | ||
252 | } else { | 273 | } else { | ||
253 | if (!m_isChartViewValid) | 274 | if (!m_isChartViewValid) | ||
254 | m_table->drawChart(*m_chartView); | 275 | m_table->drawChart(*m_chartView); | ||
255 | m_isChartViewValid = true; | 276 | m_isChartViewValid = true; | ||
256 | m_tableView->view()->hide(); | 277 | m_tableView->hide(); | ||
257 | m_chartView->show(); | 278 | m_chartView->show(); | ||
258 | 279 | | |||
259 | m_control->ui->buttonChart->setText(i18n("Report")); | 280 | m_control->ui->buttonChart->setText(i18n("Report")); | ||
260 | m_control->ui->buttonChart->setToolTip(i18n("Show the report version of this chart")); | 281 | m_control->ui->buttonChart->setToolTip(i18n("Show the report version of this chart")); | ||
261 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::ViewFinancialList])); | 282 | m_control->ui->buttonChart->setIcon(QIcon::fromTheme(g_Icons[Icon::ViewFinancialList])); | ||
262 | } | 283 | } | ||
263 | m_showingChart = ! m_showingChart; | 284 | m_showingChart = ! m_showingChart; | ||
264 | } | 285 | } | ||
▲ Show 20 Lines • Show All 369 Lines • ▼ Show 20 Line(s) | 654 | } else { | |||
634 | m_tocTreeWidget->scrollToTop(); | 655 | m_tocTreeWidget->scrollToTop(); | ||
635 | } | 656 | } | ||
636 | 657 | | |||
637 | setColumnsAlreadyAdjusted(true); | 658 | setColumnsAlreadyAdjusted(true); | ||
638 | 659 | | |||
639 | m_tocTreeWidget->setUpdatesEnabled(true); | 660 | m_tocTreeWidget->setUpdatesEnabled(true); | ||
640 | } | 661 | } | ||
641 | 662 | | |||
642 | void KReportsView::slotOpenUrl(const QUrl &url, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&) | 663 | void KReportsView::slotOpenUrl(const QUrl &url) | ||
643 | { | 664 | { | ||
644 | QString view = url.fileName(); | 665 | QString view = url.fileName(); | ||
666 | if (view.isEmpty()) | ||||
667 | return; | ||||
645 | QString command = QUrlQuery(url).queryItemValue("command"); | 668 | QString command = QUrlQuery(url).queryItemValue("command"); | ||
646 | QString id = QUrlQuery(url).queryItemValue("id"); | 669 | QString id = QUrlQuery(url).queryItemValue("id"); | ||
647 | QString tid = QUrlQuery(url).queryItemValue("tid"); | 670 | QString tid = QUrlQuery(url).queryItemValue("tid"); | ||
648 | 671 | | |||
649 | if (view == VIEW_REPORTS) { | 672 | if (view == VIEW_REPORTS) { | ||
650 | 673 | | |||
651 | if (command.isEmpty()) { | 674 | if (command.isEmpty()) { | ||
652 | // slotRefreshView(); | 675 | // slotRefreshView(); | ||
653 | } else if (command == "print") | 676 | } else if (command == QLatin1String("print")) | ||
654 | slotPrintView(); | 677 | slotPrintView(); | ||
655 | else if (command == "copy") | 678 | else if (command == QLatin1String("copy")) | ||
656 | slotCopyView(); | 679 | slotCopyView(); | ||
657 | else if (command == "save") | 680 | else if (command == QLatin1String("save")) | ||
658 | slotSaveView(); | 681 | slotSaveView(); | ||
659 | else if (command == "configure") | 682 | else if (command == QLatin1String("configure")) | ||
660 | slotConfigure(); | 683 | slotConfigure(); | ||
661 | else if (command == "duplicate") | 684 | else if (command == QLatin1String("duplicate")) | ||
662 | slotDuplicate(); | 685 | slotDuplicate(); | ||
663 | else if (command == "close") | 686 | else if (command == QLatin1String("close")) | ||
664 | slotCloseCurrent(); | 687 | slotCloseCurrent(); | ||
665 | else if (command == "delete") | 688 | else if (command == QLatin1String("delete")) | ||
666 | slotDelete(); | 689 | slotDelete(); | ||
667 | else | 690 | else | ||
668 | qWarning() << i18n("Unknown command '%1' in KReportsView::slotOpenUrl()", qPrintable(command)); | 691 | qWarning() << i18n("Unknown command '%1' in KReportsView::slotOpenUrl()", qPrintable(command)); | ||
669 | 692 | | |||
670 | } else if (view == VIEW_LEDGER) { | 693 | } else if (view == VIEW_LEDGER) { | ||
671 | emit ledgerSelected(id, tid); | 694 | emit ledgerSelected(id, tid); | ||
672 | } else { | 695 | } else { | ||
673 | qWarning() << i18n("Unknown view '%1' in KReportsView::slotOpenUrl()", qPrintable(view)); | 696 | qWarning() << i18n("Unknown view '%1' in KReportsView::slotOpenUrl()", qPrintable(view)); | ||
▲ Show 20 Lines • Show All 1084 Lines • Show Last 20 Lines |