mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support print
This commit is contained in:
parent
cdf3eb537b
commit
07cefdcaec
@ -58,8 +58,11 @@ extern QFile g_logFile;
|
|||||||
|
|
||||||
|
|
||||||
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
||||||
: QMainWindow(p_parent), m_guard(p_guard),
|
: QMainWindow(p_parent),
|
||||||
m_windowOldState(Qt::WindowNoState), m_requestQuit(false)
|
m_guard(p_guard),
|
||||||
|
m_windowOldState(Qt::WindowNoState),
|
||||||
|
m_requestQuit(false),
|
||||||
|
m_printer(NULL)
|
||||||
{
|
{
|
||||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
@ -979,8 +982,6 @@ void VMainWindow::initFileMenu()
|
|||||||
|
|
||||||
fileMenu->addAction(m_exportAsPDFAct);
|
fileMenu->addAction(m_exportAsPDFAct);
|
||||||
|
|
||||||
fileMenu->addSeparator();
|
|
||||||
|
|
||||||
// Print.
|
// Print.
|
||||||
m_printAct = new QAction(VIconUtils::menuIcon(":/resources/icons/print.svg"),
|
m_printAct = new QAction(VIconUtils::menuIcon(":/resources/icons/print.svg"),
|
||||||
tr("&Print"), this);
|
tr("&Print"), this);
|
||||||
@ -989,6 +990,10 @@ void VMainWindow::initFileMenu()
|
|||||||
this, &VMainWindow::printNote);
|
this, &VMainWindow::printNote);
|
||||||
m_printAct->setEnabled(false);
|
m_printAct->setEnabled(false);
|
||||||
|
|
||||||
|
fileMenu->addAction(m_printAct);
|
||||||
|
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
|
||||||
// Themes.
|
// Themes.
|
||||||
initThemeMenu(fileMenu);
|
initThemeMenu(fileMenu);
|
||||||
|
|
||||||
@ -2324,13 +2329,18 @@ void VMainWindow::shortcutsHelp()
|
|||||||
|
|
||||||
void VMainWindow::printNote()
|
void VMainWindow::printNote()
|
||||||
{
|
{
|
||||||
QPrinter printer;
|
if (m_printer
|
||||||
QPrintDialog dialog(&printer, this);
|
|| !m_curFile
|
||||||
|
|| m_curFile->getDocType() != DocType::Markdown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_printer = new QPrinter();
|
||||||
|
QPrintDialog dialog(m_printer, this);
|
||||||
dialog.setWindowTitle(tr("Print Note"));
|
dialog.setWindowTitle(tr("Print Note"));
|
||||||
|
|
||||||
V_ASSERT(m_curTab);
|
V_ASSERT(m_curTab);
|
||||||
|
|
||||||
if (m_curFile->getDocType() == DocType::Markdown) {
|
|
||||||
VMdTab *mdTab = dynamic_cast<VMdTab *>((VEditTab *)m_curTab);
|
VMdTab *mdTab = dynamic_cast<VMdTab *>((VEditTab *)m_curTab);
|
||||||
VWebView *webView = mdTab->getWebViewer();
|
VWebView *webView = mdTab->getWebViewer();
|
||||||
|
|
||||||
@ -2340,9 +2350,15 @@ void VMainWindow::printNote()
|
|||||||
dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
|
dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dialog.exec() != QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
return;
|
webView->page()->print(m_printer, [this](bool p_succ) {
|
||||||
}
|
qDebug() << "print web page callback" << p_succ;
|
||||||
|
delete m_printer;
|
||||||
|
m_printer = NULL;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
delete m_printer;
|
||||||
|
m_printer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ class VButtonWithWidget;
|
|||||||
class VAttachmentList;
|
class VAttachmentList;
|
||||||
class VSnippetList;
|
class VSnippetList;
|
||||||
class VCart;
|
class VCart;
|
||||||
|
class QPrinter;
|
||||||
|
|
||||||
enum class PanelViewState
|
enum class PanelViewState
|
||||||
{
|
{
|
||||||
@ -392,6 +393,8 @@ private:
|
|||||||
|
|
||||||
VWebUtils m_webUtils;
|
VWebUtils m_webUtils;
|
||||||
|
|
||||||
|
QPrinter *m_printer;
|
||||||
|
|
||||||
// Interval of the shared memory timer in ms.
|
// Interval of the shared memory timer in ms.
|
||||||
static const int c_sharedMemTimerInterval;
|
static const int c_sharedMemTimerInterval;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user