diff --git a/src/article-style-print.css b/src/article-style-print.css
new file mode 100644
index 00000000..04350276
--- /dev/null
+++ b/src/article-style-print.css
@@ -0,0 +1,6 @@
+/* This stylesheet is used for printing only, overriding article-style.css */
+
+body
+{
+ background: white;
+}
diff --git a/src/article_maker.cc b/src/article_maker.cc
index 6927b639..ed3a4056 100644
--- a/src/article_maker.cc
+++ b/src/article_maker.cc
@@ -31,20 +31,39 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
"";
// Add a css stylesheet
-
- QFile builtInCssFile( ":/article-style.css" );
- builtInCssFile.open( QFile::ReadOnly );
- QByteArray css = builtInCssFile.readAll();
-
- QFile cssFile( Config::getUserCssFileName() );
- if ( cssFile.open( QFile::ReadOnly ) )
- css += cssFile.readAll();
+ {
+ QFile builtInCssFile( ":/article-style.css" );
+ builtInCssFile.open( QFile::ReadOnly );
+ QByteArray css = builtInCssFile.readAll();
+
+ QFile cssFile( Config::getUserCssFileName() );
- result += "\n";
+ if ( cssFile.open( QFile::ReadOnly ) )
+ css += cssFile.readAll();
+
+ result += "\n";
+ }
+ // Add print-only css
+
+ {
+ QFile builtInCssFile( ":/article-style-print.css" );
+ builtInCssFile.open( QFile::ReadOnly );
+ QByteArray css = builtInCssFile.readAll();
+
+ QFile cssFile( Config::getUserCssPrintFileName() );
+
+ if ( cssFile.open( QFile::ReadOnly ) )
+ css += cssFile.readAll();
+
+ result += "\n";
+ }
+
result += "
" + Html::escape( Utf8::encode( gd::toWString( word ) ) ) + "";
// This doesn't seem to be much of influence right now, but we'll keep
diff --git a/src/articleview.cc b/src/articleview.cc
index 06d7dce6..ea63155a 100644
--- a/src/articleview.cc
+++ b/src/articleview.cc
@@ -310,6 +310,11 @@ QString ArticleView::getTitle()
return ui.definition->page()->currentFrame()->title();
}
+void ArticleView::print( QPrinter * printer ) const
+{
+ ui.definition->print( printer );
+}
+
void ArticleView::contextMenuRequested( QPoint const & pos )
{
// Is that a link? Is there a selection?
diff --git a/src/articleview.hh b/src/articleview.hh
index 4b51a538..a4dc134f 100644
--- a/src/articleview.hh
+++ b/src/articleview.hh
@@ -91,6 +91,9 @@ public:
/// Returns current article's title
QString getTitle();
+
+ /// Prints current article
+ void print( QPrinter * ) const;
signals:
diff --git a/src/config.cc b/src/config.cc
index 04758a2f..27a99a15 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -751,6 +751,11 @@ QString getUserCssFileName() throw( exError )
return getHomeDir().filePath( "article-style.css" );
}
+QString getUserCssPrintFileName() throw( exError )
+{
+ return getHomeDir().filePath( "article-style-print.css" );
+}
+
QString getUserQtCssFileName() throw( exError )
{
return getHomeDir().filePath( "qt-style.css" );
diff --git a/src/config.hh b/src/config.hh
index d88ec08d..bfc2e1df 100644
--- a/src/config.hh
+++ b/src/config.hh
@@ -241,6 +241,9 @@ QString getIndexDir() throw( exError );
/// Returns the user .css file name.
QString getUserCssFileName() throw( exError );
+/// Returns the user .css file name used for printing only.
+QString getUserCssPrintFileName() throw( exError );
+
/// Returns the user .css file name for the Qt interface customization.
QString getUserQtCssFileName() throw( exError );
diff --git a/src/icons/print.png b/src/icons/print.png
new file mode 100644
index 00000000..ba7c02dc
Binary files /dev/null and b/src/icons/print.png differ
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 07bed335..340c3f05 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -61,6 +61,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
navBack = navToolbar->addAction( QIcon( ":/icons/previous.png" ), tr( "Back" ) );
navForward = navToolbar->addAction( QIcon( ":/icons/next.png" ), tr( "Forward" ) );
+ navToolbar->addAction( ui.print );
navToolbar->addAction( ui.saveArticle );
enableScanPopup = navToolbar->addAction( QIcon( ":/icons/wizard.png" ), tr( "Scan Popup" ) );
@@ -1220,6 +1221,44 @@ void MainWindow::on_actionCloseToTray_activated()
toggleMainWindow( !cfg.preferences.enableTrayIcon );
}
+void MainWindow::on_pageSetup_activated()
+{
+ QPageSetupDialog dialog( &printer, this );
+
+ dialog.exec();
+}
+
+void MainWindow::on_printPreview_activated()
+{
+ QPrintPreviewDialog dialog( &printer, this );
+
+ connect( &dialog, SIGNAL( paintRequested( QPrinter * ) ),
+ this, SLOT( printPreviewPaintRequested( QPrinter * ) ) );
+
+ dialog.exec();
+}
+
+void MainWindow::on_print_activated()
+{
+ QPrintDialog dialog( &printer, this );
+
+ dialog.setWindowTitle( tr( "Print Article") );
+
+ if ( dialog.exec() != QDialog::Accepted )
+ return;
+
+ ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
+
+ view.print( &printer );
+}
+
+void MainWindow::printPreviewPaintRequested( QPrinter * printer )
+{
+ ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
+
+ view.print( printer );
+}
+
void MainWindow::on_saveArticle_activated()
{
ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
diff --git a/src/mainwindow.hh b/src/mainwindow.hh
index 354bd02e..f20dbbb2 100644
--- a/src/mainwindow.hh
+++ b/src/mainwindow.hh
@@ -72,6 +72,8 @@ private:
// release, if enabled
sptr< QNetworkReply > latestReleaseReply;
+ QPrinter printer; // The printer we use for all printing operations
+
/// Creates, destroys or otherwise updates tray icon, according to the
/// current configuration and situation.
void updateTrayIcon();
@@ -190,6 +192,11 @@ private slots:
void on_actionCloseToTray_activated();
+ void on_pageSetup_activated();
+ void on_printPreview_activated();
+ void on_print_activated();
+ void printPreviewPaintRequested( QPrinter * );
+
void on_saveArticle_activated();
};
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index bd03813a..72fef3ba 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -65,6 +65,10 @@
&File
+
+
+
+
@@ -300,6 +304,28 @@
F2
+
+
+
+ :/icons/print.png:/icons/print.png
+
+
+ &Print
+
+
+ Ctrl+P
+
+
+
+
+ Page Set&up
+
+
+
+
+ Print Preview
+
+
diff --git a/src/resources.qrc b/src/resources.qrc
index 0694781e..32df5431 100644
--- a/src/resources.qrc
+++ b/src/resources.qrc
@@ -1,5 +1,6 @@
+ icons/print.png
icons/arrow.png
icons/prefix.png
icons/pushpin.png
@@ -13,6 +14,7 @@
icons/wizard.png
icons/warning.png
article-style.css
+ article-style-print.css
qt-style.css
icons/icon32_dsl.png
icons/icon32_stardict.png