Skip to content

Commit

Permalink
feat(printDialog): set output file name
Browse files Browse the repository at this point in the history
Change-Id: I095ca4180c688e2bd187a7a1a00c76bad2f26572
  • Loading branch information
rekols committed Sep 14, 2018
1 parent a4c404b commit 8d7d077
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions editor/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,10 +1215,21 @@ void Window::popupPrintDialog()
{
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this);
connect(&preview, &QPrintPreviewDialog::paintRequested, this,
[=] (QPrinter *printer) {
getActiveEditor()->textEditor->print(printer);
});

TextEditor *editor = getActiveEditor()->textEditor;
const QString &filePath = editor->filepath;
const QString &fileDir = QFileInfo(filePath).dir().absolutePath();

if (fileDir == m_blankFileDir) {
printer.setOutputFileName(QString("%1/%2.pdf").arg(QDir::homePath(), m_tabbar->getActiveTabName()));
} else {
printer.setOutputFileName(QString("%1/%2.pdf").arg(fileDir, QFileInfo(filePath).baseName()));
}

connect(&preview, &QPrintPreviewDialog::paintRequested, this, [=] (QPrinter *printer) {
getActiveEditor()->textEditor->print(printer);
});

preview.exec();
}

Expand Down

0 comments on commit 8d7d077

Please sign in to comment.