Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/printcheck/printcheck.cpp
Show All 14 Lines | |||||
15 | * GNU General Public License for more details. * | 15 | * GNU General Public License for more details. * | ||
16 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/> * | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "printcheck.h" | 21 | #include "printcheck.h" | ||
22 | 22 | | |||
23 | #include "config-kmymoney.h" | ||||
24 | | ||||
23 | // QT includes | 25 | // QT includes | ||
24 | #include <QAction> | 26 | #include <QAction> | ||
27 | #include <QWebEngineView> | ||||
28 | #include <QPrintDialog> | ||||
25 | 29 | | |||
26 | // KDE includes | 30 | // KDE includes | ||
27 | #include <KActionCollection> | 31 | #include <KActionCollection> | ||
28 | #include <KPluginInfo> | 32 | #include <KPluginInfo> | ||
29 | #include <khtmlview.h> | | |||
30 | #include <khtml_part.h> | | |||
31 | #include <QStandardPaths> | 33 | #include <QStandardPaths> | ||
34 | #include <KLocalizedString> | ||||
35 | #ifdef KF5KHtml_FOUND | ||||
36 | #include <KHTMLPart> | ||||
37 | #include <KHTMLView> | ||||
38 | #endif | ||||
32 | 39 | | |||
33 | // KMyMoney includes | 40 | // KMyMoney includes | ||
34 | #include "mymoneyfile.h" | 41 | #include "mymoneyfile.h" | ||
35 | #include "pluginloader.h" | 42 | #include "pluginloader.h" | ||
36 | 43 | | |||
37 | #include "numbertowords.h" | 44 | #include "numbertowords.h" | ||
38 | #include "pluginsettings.h" | 45 | #include "pluginsettings.h" | ||
39 | 46 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
112 | { | 119 | { | ||
113 | d->m_printedTransactionIdList.append(selectedTransaction.transaction().id()); | 120 | d->m_printedTransactionIdList.append(selectedTransaction.transaction().id()); | ||
114 | } | 121 | } | ||
115 | 122 | | |||
116 | void KMMPrintCheckPlugin::slotPrintCheck() | 123 | void KMMPrintCheckPlugin::slotPrintCheck() | ||
117 | { | 124 | { | ||
118 | MyMoneyFile* file = MyMoneyFile::instance(); | 125 | MyMoneyFile* file = MyMoneyFile::instance(); | ||
119 | MyMoneyMoneyToWordsConverter converter; | 126 | MyMoneyMoneyToWordsConverter converter; | ||
120 | KHTMLPart *htmlPart = new KHTMLPart(static_cast<QWidget*>(0)); | 127 | QWebEngineView *htmlPart = new QWebEngineView(); | ||
121 | KMyMoneyRegister::SelectedTransactions::const_iterator it; | 128 | KMyMoneyRegister::SelectedTransactions::const_iterator it; | ||
122 | for (it = d->m_transactions.constBegin(); it != d->m_transactions.constEnd(); ++it) { | 129 | for (it = d->m_transactions.constBegin(); it != d->m_transactions.constEnd(); ++it) { | ||
123 | if (!canBePrinted(*it)) | 130 | if (!canBePrinted(*it)) | ||
124 | continue; // skip this check since it was already printed | 131 | continue; // skip this check since it was already printed | ||
125 | 132 | | |||
126 | QString checkHTML = d->m_checkTemplateHTML; | 133 | QString checkHTML = d->m_checkTemplateHTML; | ||
127 | MyMoneySecurity currency = file->currency(file->account((*it).split().accountId()).currencyId()); | 134 | MyMoneySecurity currency = file->currency(file->account((*it).split().accountId()).currencyId()); | ||
128 | MyMoneyInstitution institution = file->institution(file->account((*it).split().accountId()).institutionId()); | 135 | MyMoneyInstitution institution = file->institution(file->account((*it).split().accountId()).institutionId()); | ||
Show All 20 Lines | |||||
149 | checkHTML.replace("$PAYEE_CITY", file->payee((*it).split().payeeId()).city()); | 156 | checkHTML.replace("$PAYEE_CITY", file->payee((*it).split().payeeId()).city()); | ||
150 | checkHTML.replace("$PAYEE_POSTCODE", file->payee((*it).split().payeeId()).postcode()); | 157 | checkHTML.replace("$PAYEE_POSTCODE", file->payee((*it).split().payeeId()).postcode()); | ||
151 | checkHTML.replace("$PAYEE_STATE", file->payee((*it).split().payeeId()).state()); | 158 | checkHTML.replace("$PAYEE_STATE", file->payee((*it).split().payeeId()).state()); | ||
152 | checkHTML.replace("$AMOUNT_STRING", converter.convert((*it).split().shares().abs())); | 159 | checkHTML.replace("$AMOUNT_STRING", converter.convert((*it).split().shares().abs())); | ||
153 | checkHTML.replace("$AMOUNT_DECIMAL", MyMoneyUtils::formatMoney((*it).split().shares().abs(), currency)); | 160 | checkHTML.replace("$AMOUNT_DECIMAL", MyMoneyUtils::formatMoney((*it).split().shares().abs(), currency)); | ||
154 | checkHTML.replace("$MEMO", (*it).split().memo()); | 161 | checkHTML.replace("$MEMO", (*it).split().memo()); | ||
155 | 162 | | |||
156 | // print the check | 163 | // print the check | ||
157 | htmlPart->begin(); | 164 | htmlPart->setHtml(checkHTML, QUrl("file://")); | ||
158 | htmlPart->write(checkHTML); | 165 | #ifdef KF5KHtml_FOUND | ||
159 | htmlPart->end(); | 166 | KHTMLPart *khtml = new KHTMLPart(); | ||
160 | htmlPart->view()->print(); | 167 | khtml->begin(); | ||
168 | khtml->write(checkHTML); | ||||
169 | khtml->end(); | ||||
170 | khtml->view()->print(); | ||||
171 | delete khtml; | ||||
172 | #else | ||||
173 | m_currentPrinter = new QPrinter(); | ||||
174 | QPointer<QPrintDialog> dialog = new QPrintDialog(m_currentPrinter); | ||||
175 | dialog->setWindowTitle(QString()); | ||||
176 | if (dialog->exec() != QDialog::Accepted) { | ||||
177 | delete m_currentPrinter; | ||||
178 | m_currentPrinter = nullptr; | ||||
179 | continue; | ||||
180 | } else { | ||||
181 | htmlPart->page()->print(m_currentPrinter, [=] (bool) {delete m_currentPrinter; m_currentPrinter = nullptr;}); | ||||
182 | } | ||||
183 | delete dialog; | ||||
184 | #endif | ||||
161 | 185 | | |||
162 | // mark the transaction as printed | 186 | // mark the transaction as printed | ||
163 | markAsPrinted(*it); | 187 | markAsPrinted(*it); | ||
164 | } | 188 | } | ||
165 | 189 | | |||
166 | PluginSettings::setPrintedChecks(d->m_printedTransactionIdList); | 190 | PluginSettings::setPrintedChecks(d->m_printedTransactionIdList); | ||
191 | delete htmlPart; | ||||
167 | } | 192 | } | ||
168 | 193 | | |||
169 | void KMMPrintCheckPlugin::slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions) | 194 | void KMMPrintCheckPlugin::slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions) | ||
170 | { | 195 | { | ||
171 | d->m_transactions = transactions; | 196 | d->m_transactions = transactions; | ||
172 | bool actionEnabled = false; | 197 | bool actionEnabled = false; | ||
173 | // enable/disable the action depending if there are transactions selected or not | 198 | // enable/disable the action depending if there are transactions selected or not | ||
174 | // and whether they can be printed or not | 199 | // and whether they can be printed or not | ||
Show All 27 Lines |