Skip to content

Commit

Permalink
Add the ability to export notes to a PDF file. It is still primitive,…
Browse files Browse the repository at this point in the history
… but

it works in limited circumstances.
  • Loading branch information
baumgarr committed Jan 31, 2017
1 parent 764c03e commit 7c971bd
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gui/nmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ void NMainMenuBar::setupFileMenu() {

fileMenu->addSeparator();

exportNoteAction = new QAction(tr("&Export Notes"), this);
exportNoteAction->setToolTip(tr("Export selected notes to a file"));
exportNoteAction = new QAction(tr("&Export to NixNote Export"), this);
exportNoteAction->setToolTip(tr("Export selected notes to a NNEX file"));
connect(exportNoteAction, SIGNAL(triggered()), parent, SLOT(noteExport()));
setupShortcut(exportNoteAction, QString("File_Note_Export"));
fileMenu->addAction(exportNoteAction);

exportAsPdfAction = new QAction(tr("&Export Notes as PDF"), this);
exportAsPdfAction->setToolTip(tr("Export selected notes to a PDF file"));
connect(exportAsPdfAction, SIGNAL(triggered()), parent, SLOT(exportAsPdf()));
setupShortcut(exportAsPdfAction, QString("File_Note_Export_Pdf"));
fileMenu->addAction(exportAsPdfAction);

importNoteAction = new QAction(tr("&Import Notes"), this);
importNoteAction->setToolTip(tr("Import notes from an export file"));
connect(importNoteAction, SIGNAL(triggered()), parent, SLOT(noteImport()));
Expand Down
1 change: 1 addition & 0 deletions gui/nmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class NMainMenuBar : public QMenuBar
QAction *restoreDatabaseAction;
QAction *backupDatabaseAction;
QAction *exportNoteAction;
QAction *exportAsPdfAction;
QAction *importNoteAction;
QAction *accountDialogAction;
QAction *pauseIndexingAction;
Expand Down
90 changes: 89 additions & 1 deletion nixnote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ NixNote::NixNote(QWidget *parent) : QMainWindow(parent)
//QDesktopServices::setUrlHandler("evernote", this, "showDesktopUrl");
remoteQuery = new RemoteQuery();

// Initialize pdfExportWindow to null. We don't fully set this up in case the person requests it.
pdfExportWindow = NULL;

// Setup file watcher
importManager = new FileWatcherManager(this);
Expand Down Expand Up @@ -3776,7 +3778,8 @@ void NixNote::presentationModeOff() {




// Check to see if plugins are avaialble and they match
// the correct version expected. Load them if possible.
void NixNote::loadPlugins() {
webcamPluginAvailable = false;

Expand Down Expand Up @@ -3816,3 +3819,88 @@ void NixNote::loadPlugins() {
}
}
}



// Export selected notes as PDF files.
void NixNote::exportAsPdf() {


QList<qint32> lids;
noteTableView->getSelectedLids(lids);

if (pdfExportWindow == NULL) {
pdfExportWindow = new QWebView();
connect(pdfExportWindow, SIGNAL(loadFinished(bool)), this, SLOT(exportAsPdfReady(bool)));
}


if (lids.size() <= 0) {
QString file = "/home/randy/test.pdf";

if (file == "")
return;
QList<qint32> lids;
noteTableView->getSelectedLids(lids);

QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setResolution(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(file);

printer.setDocName(tabWindow->currentBrowser()->noteTitle.text());
tabWindow->currentBrowser()->editor->print(&printer);
QMessageBox::information(0, tr("NixNote"), tr("Export complete"));

return;
}

NoteTable noteTable(global.db);
QByteArray content;
content.clear();
NoteFormatter formatter;

QProgressDialog *progress = new QProgressDialog(0);
progress->setMinimum(0);
progress->setWindowTitle(tr("Exporting Notes as PDF"));
progress->setLabelText(tr("Exporting notes as PDF"));
progress->setMaximum(lids.size());
progress->setVisible(true);
progress->setWindowModality(Qt::ApplicationModal);
progress->setCancelButton(0);
progress->show();
for (int i=0; i<lids.size(); i++) {
Note n;
noteTable.get(n,lids[i],true,false);
formatter.setNote(n,false);
if (n.title.isSet())
content.append("<h2>"+n.title+"</h2>");
content.append(formatter.rebuildNoteHTML());
if (i<lids.size()-1)
content.append("<p style=\"page-break-after:always;\"></p>");
progress->setValue(i);
}

progress->hide();
delete progress;
pdfExportWindow->setHtml(content);
return;
}


// Slot called when notes that were exported as PDF files are ready to be printed
void NixNote::exportAsPdfReady(bool) {
QString file = QFileDialog::getSaveFileName(0,tr("PDF Export"), "","*.pdf");

if (file == "")
return;

QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setResolution(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(file);
pdfExportWindow->print(&printer);
QMessageBox::information(0, tr("NixNote"), tr("Export complete"));
}
3 changes: 3 additions & 0 deletions nixnote.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class NixNote : public QMainWindow
NewScreenNote=3
};

QWebView *pdfExportWindow;
DatabaseConnection *db; // The database connection
NTableView *noteTableView;
NSearchView *searchTreeView;
Expand Down Expand Up @@ -302,6 +303,8 @@ public slots:
void presentationModeOn();
void presentationModeOff();
void indexFinished(bool finished);
void exportAsPdf();
void exportAsPdfReady(bool);

signals:
void syncRequested();
Expand Down
1 change: 1 addition & 0 deletions shortcuts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ File_Print Ctrl+P // Print
File_Selective_Sync // Selective sync setup
File_Empty_Trash // Purge all delete notes
File_Exit Ctrl+Q // I'm outahere
File_Note_Export_Pdf // Export selected notes as a PDF

Edit_Search_Find Ctrl+F // Search only within the current note
Edit_Search_Find_Next Ctrl+G // Find the next occurrence within the current note
Expand Down

0 comments on commit 7c971bd

Please sign in to comment.