mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 13:24:05 +00:00
+ Printing support implemented.
This commit is contained in:
parent
eee0265ec9
commit
21b2d3b747
6
src/article-style-print.css
Normal file
6
src/article-style-print.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* This stylesheet is used for printing only, overriding article-style.css */
|
||||
|
||||
body
|
||||
{
|
||||
background: white;
|
||||
}
|
|
@ -31,20 +31,39 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
|
||||
|
||||
// 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 += "<style type=\"text/css\">\n";
|
||||
result += css.data();
|
||||
result += "</style>\n";
|
||||
if ( cssFile.open( QFile::ReadOnly ) )
|
||||
css += cssFile.readAll();
|
||||
|
||||
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>";
|
||||
|
||||
// This doesn't seem to be much of influence right now, but we'll keep
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
|
||||
/// Returns current article's title
|
||||
QString getTitle();
|
||||
|
||||
/// Prints current article
|
||||
void print( QPrinter * ) const;
|
||||
|
||||
signals:
|
||||
|
||||
|
|
|
@ -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" );
|
||||
|
|
|
@ -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
BIN
src/icons/print.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -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() ) );
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@
|
|||
<property name="title">
|
||||
<string>&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>&Print</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+P</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="pageSetup">
|
||||
<property name="text">
|
||||
<string>Page Set&up</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="printPreview">
|
||||
<property name="text">
|
||||
<string>Print Preview</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue