+ Printing support implemented.

This commit is contained in:
Konstantin Isakov 2009-05-01 12:20:33 +00:00
parent eee0265ec9
commit 21b2d3b747
11 changed files with 126 additions and 11 deletions

View file

@ -0,0 +1,6 @@
/* This stylesheet is used for printing only, overriding article-style.css */
body
{
background: white;
}

View file

@ -32,6 +32,7 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
// Add a css stylesheet
{
QFile builtInCssFile( ":/article-style.css" );
builtInCssFile.open( QFile::ReadOnly );
QByteArray css = builtInCssFile.readAll();
@ -41,9 +42,27 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
if ( cssFile.open( QFile::ReadOnly ) )
css += cssFile.readAll();
result += "<style type=\"text/css\">\n";
result += "<style type=\"text/css\" media=\"all\">\n";
result += css.data();
result += "</style>\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 += "<style type=\"text/css\" media=\"print\">\n";
result += css.data();
result += "</style>\n";
}
result += "<title>" + Html::escape( Utf8::encode( gd::toWString( word ) ) ) + "</title>";

View file

@ -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?

View file

@ -92,6 +92,9 @@ public:
/// Returns current article's title
QString getTitle();
/// Prints current article
void print( QPrinter * ) const;
signals:
void iconChanged( ArticleView *, QIcon const & icon );

View file

@ -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" );

View file

@ -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 );

BIN
src/icons/print.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -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() ) );

View file

@ -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();
};

View file

@ -65,6 +65,10 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="pageSetup"/>
<addaction name="printPreview"/>
<addaction name="print"/>
<addaction name="separator"/>
<addaction name="saveArticle"/>
<addaction name="separator"/>
<addaction name="actionCloseToTray"/>
@ -300,6 +304,28 @@
<string>F2</string>
</property>
</action>
<action name="print">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/print.png</normaloff>:/icons/print.png</iconset>
</property>
<property name="text">
<string>&amp;Print</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="pageSetup">
<property name="text">
<string>Page Set&amp;up</string>
</property>
</action>
<action name="printPreview">
<property name="text">
<string>Print Preview</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/" >
<file>icons/print.png</file>
<file>icons/arrow.png</file>
<file>icons/prefix.png</file>
<file>icons/pushpin.png</file>
@ -13,6 +14,7 @@
<file>icons/wizard.png</file>
<file>icons/warning.png</file>
<file>article-style.css</file>
<file>article-style-print.css</file>
<file>qt-style.css</file>
<file>icons/icon32_dsl.png</file>
<file>icons/icon32_stardict.png</file>