mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -04:00
Connect PrintAction.
This display a dialog to select the printer and its options. The dialog is awful because it reuses the application stylesheet but it works.
This commit is contained in:
parent
d2e32dbf79
commit
15f1492d96
@ -6,6 +6,8 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QPrintDialog>
|
||||||
|
|
||||||
KiwixApp::KiwixApp(int& argc, char *argv[])
|
KiwixApp::KiwixApp(int& argc, char *argv[])
|
||||||
: QApplication(argc, argv)
|
: QApplication(argc, argv)
|
||||||
@ -97,6 +99,23 @@ void KiwixApp::openZimFile(const QString &zimfile)
|
|||||||
openUrl(QUrl("zim://"+zimId+"/"));
|
openUrl(QUrl("zim://"+zimId+"/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KiwixApp::printPage()
|
||||||
|
{
|
||||||
|
QPrinter* printer = new QPrinter();
|
||||||
|
QPrintDialog printDialog(printer, mp_mainWindow);
|
||||||
|
printDialog.setStyle(nullptr);
|
||||||
|
printDialog.setStyleSheet("");
|
||||||
|
if (printDialog.exec() == QDialog::Accepted) {
|
||||||
|
auto webview = mp_tabWidget->currentWidget();
|
||||||
|
webview->page()->print(printer, [=](bool success) {
|
||||||
|
if (!success) {
|
||||||
|
showMessage("An error has occured while printing.");
|
||||||
|
}
|
||||||
|
delete printer;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KiwixApp::openUrl(const QUrl &url, bool newTab) {
|
void KiwixApp::openUrl(const QUrl &url, bool newTab) {
|
||||||
mp_tabWidget->openUrl(url, newTab);
|
mp_tabWidget->openUrl(url, newTab);
|
||||||
}
|
}
|
||||||
@ -131,7 +150,8 @@ void KiwixApp::createAction()
|
|||||||
|
|
||||||
CREATE_ACTION_ICON(PrintAction, "print", "Print");
|
CREATE_ACTION_ICON(PrintAction, "print", "Print");
|
||||||
SET_SHORTCUT(PrintAction, QKeySequence::Print);
|
SET_SHORTCUT(PrintAction, QKeySequence::Print);
|
||||||
DISABLE_ACTION(PrintAction);
|
connect(mpa_actions[PrintAction], &QAction::triggered,
|
||||||
|
this, &KiwixApp::printPage);
|
||||||
|
|
||||||
CREATE_ACTION(NewTabAction, "New tab");
|
CREATE_ACTION(NewTabAction, "New tab");
|
||||||
SET_SHORTCUT(NewTabAction, QKeySequence::AddTab);
|
SET_SHORTCUT(NewTabAction, QKeySequence::AddTab);
|
||||||
|
@ -65,6 +65,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void openZimFile(const QString& zimfile="");
|
void openZimFile(const QString& zimfile="");
|
||||||
|
void printPage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void createAction();
|
void createAction();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user