mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
+ Implement switchable display styles. For now 'Default' and 'Lingvo'.
This commit is contained in:
parent
c94e98d1c9
commit
8c40c6d50a
30
src/article-style-st-lingvo.css
Normal file
30
src/article-style-st-lingvo.css
Normal file
|
@ -0,0 +1,30 @@
|
|||
body
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
text-decoration: none;
|
||||
color: darkblue;
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Dictionary's name heading */
|
||||
.gddictname
|
||||
{
|
||||
border: 1px dotted black; padding: 0.2em; padding-left: 0.5em;
|
||||
margin-top: 1.2em; margin-bottom: 0.1em; font-weight: bold; font-size: 14px;
|
||||
background: #87CEEB;
|
||||
}
|
||||
|
||||
/* The 'From ' string which preceeds dictionary name in the heading */
|
||||
.gdfromprefix
|
||||
{
|
||||
display: none;
|
||||
}
|
||||
|
|
@ -16,14 +16,21 @@ using std::set;
|
|||
using std::list;
|
||||
|
||||
ArticleMaker::ArticleMaker( vector< sptr< Dictionary::Class > > const & dictionaries_,
|
||||
vector< Instances::Group > const & groups_ ):
|
||||
vector< Instances::Group > const & groups_,
|
||||
QString const & displayStyle_ ):
|
||||
dictionaries( dictionaries_ ),
|
||||
groups( groups_ )
|
||||
groups( groups_ ),
|
||||
displayStyle( displayStyle_ )
|
||||
{
|
||||
}
|
||||
|
||||
void ArticleMaker::setDisplayStyle( QString const & st )
|
||||
{
|
||||
displayStyle = st;
|
||||
}
|
||||
|
||||
std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
||||
QString const & icon )
|
||||
QString const & icon ) const
|
||||
{
|
||||
string result =
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
|
@ -37,6 +44,14 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
builtInCssFile.open( QFile::ReadOnly );
|
||||
QByteArray css = builtInCssFile.readAll();
|
||||
|
||||
if ( displayStyle.size() )
|
||||
{
|
||||
// Load an additional stylesheet
|
||||
QFile builtInCssFile( QString( ":/article-style-st-%1.css" ).arg( displayStyle ) );
|
||||
builtInCssFile.open( QFile::ReadOnly );
|
||||
css += builtInCssFile.readAll();
|
||||
}
|
||||
|
||||
QFile cssFile( Config::getUserCssFileName() );
|
||||
|
||||
if ( cssFile.open( QFile::ReadOnly ) )
|
||||
|
@ -76,7 +91,8 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string ArticleMaker::makeNotFoundBody( QString const & word, QString const & group )
|
||||
std::string ArticleMaker::makeNotFoundBody( QString const & word,
|
||||
QString const & group )
|
||||
{
|
||||
|
||||
return string( "<div class=\"gdnotfound\"><p>" ) +
|
||||
|
|
|
@ -19,6 +19,8 @@ class ArticleMaker: public QObject
|
|||
std::vector< sptr< Dictionary::Class > > const & dictionaries;
|
||||
std::vector< Instances::Group > const & groups;
|
||||
|
||||
QString displayStyle;
|
||||
|
||||
public:
|
||||
|
||||
/// On construction, a reference to all dictionaries and a reference all
|
||||
|
@ -26,7 +28,12 @@ public:
|
|||
/// references, and as such, any changes to them would reflect on the results
|
||||
/// of the inquiries, altthough those changes are perfectly legal.
|
||||
ArticleMaker( std::vector< sptr< Dictionary::Class > > const & dictionaries,
|
||||
std::vector< Instances::Group > const & groups );
|
||||
std::vector< Instances::Group > const & groups,
|
||||
QString const & displayStyle );
|
||||
|
||||
/// Sets the display style to use for any new requests. This affects the
|
||||
/// choice of the stylesheet file.
|
||||
void setDisplayStyle( QString const & );
|
||||
|
||||
/// Looks up the given word within the given group, and creates a full html
|
||||
/// page text containing its definition.
|
||||
|
@ -43,7 +50,7 @@ public:
|
|||
private:
|
||||
|
||||
/// Makes everything up to and including the opening body tag.
|
||||
static std::string makeHtmlHeader( QString const & word, QString const & icon );
|
||||
std::string makeHtmlHeader( QString const & word, QString const & icon ) const;
|
||||
|
||||
/// Makes the html body for makeNotFoundTextFor()
|
||||
static std::string makeNotFoundBody( QString const & word, QString const & group );
|
||||
|
|
|
@ -77,6 +77,10 @@ public:
|
|||
void focus()
|
||||
{ ui.definition->setFocus( Qt::ShortcutFocusReason ); }
|
||||
|
||||
/// Reloads the view
|
||||
void reload()
|
||||
{ ui.definition->reload(); }
|
||||
|
||||
/// Returns true if there's an audio reference on the page, false otherwise.
|
||||
bool hasSound();
|
||||
|
||||
|
|
|
@ -379,6 +379,7 @@ Class load() throw( exError )
|
|||
if ( !preferences.isNull() )
|
||||
{
|
||||
c.preferences.interfaceLanguage = preferences.namedItem( "interfaceLanguage" ).toElement().text();
|
||||
c.preferences.displayStyle = preferences.namedItem( "displayStyle" ).toElement().text();
|
||||
c.preferences.newTabsOpenAfterCurrentOne = ( preferences.namedItem( "newTabsOpenAfterCurrentOne" ).toElement().text() == "1" );
|
||||
c.preferences.newTabsOpenInBackground = ( preferences.namedItem( "newTabsOpenInBackground" ).toElement().text() == "1" );
|
||||
c.preferences.enableTrayIcon = ( preferences.namedItem( "enableTrayIcon" ).toElement().text() == "1" );
|
||||
|
@ -650,6 +651,10 @@ void save( Class const & c ) throw( exError )
|
|||
opt.appendChild( dd.createTextNode( c.preferences.interfaceLanguage ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "displayStyle" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.displayStyle ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "newTabsOpenAfterCurrentOne" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.newTabsOpenAfterCurrentOne ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -129,6 +129,7 @@ struct HotKey
|
|||
struct Preferences
|
||||
{
|
||||
QString interfaceLanguage; // Empty value corresponds to system default
|
||||
QString displayStyle; // Empty value corresponds to the default one
|
||||
bool newTabsOpenAfterCurrentOne;
|
||||
bool newTabsOpenInBackground;
|
||||
bool enableTrayIcon;
|
||||
|
|
14
src/main.cc
14
src/main.cc
|
@ -68,19 +68,7 @@ int main( int argc, char ** argv )
|
|||
app.installTranslator( &translator );
|
||||
|
||||
// Apply qt stylesheet
|
||||
{
|
||||
QFile builtInCssFile( ":/qt-style.css" );
|
||||
builtInCssFile.open( QFile::ReadOnly );
|
||||
QByteArray css = builtInCssFile.readAll();
|
||||
|
||||
// Try loading a style sheet if there's one
|
||||
QFile cssFile( Config::getUserQtCssFileName() );
|
||||
|
||||
if ( cssFile.open( QFile::ReadOnly ) )
|
||||
css += cssFile.readAll();
|
||||
|
||||
app.setStyleSheet( css );
|
||||
}
|
||||
MainWindow::applyQtStyleSheet( cfg.preferences.displayStyle );
|
||||
|
||||
MainWindow m( cfg );
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
trayIconMenu( this ),
|
||||
addTab( this ),
|
||||
cfg( cfg_ ),
|
||||
articleMaker( dictionaries, groupInstances ),
|
||||
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle ),
|
||||
articleNetMgr( this, dictionaries, articleMaker ),
|
||||
dictNetMgr( this ),
|
||||
wordFinder( this ),
|
||||
|
@ -275,6 +275,28 @@ MainWindow::~MainWindow()
|
|||
Config::save( cfg );
|
||||
}
|
||||
|
||||
void MainWindow::applyQtStyleSheet( QString const & displayStyle )
|
||||
{
|
||||
QFile builtInCssFile( ":/qt-style.css" );
|
||||
builtInCssFile.open( QFile::ReadOnly );
|
||||
QByteArray css = builtInCssFile.readAll();
|
||||
|
||||
if ( displayStyle.size() )
|
||||
{
|
||||
// Load an additional stylesheet
|
||||
QFile builtInCssFile( QString( ":/qt-style-st-%1.css" ).arg( displayStyle ) );
|
||||
builtInCssFile.open( QFile::ReadOnly );
|
||||
css += builtInCssFile.readAll();
|
||||
}
|
||||
|
||||
// Try loading a style sheet if there's one
|
||||
QFile cssFile( Config::getUserQtCssFileName() );
|
||||
|
||||
if ( cssFile.open( QFile::ReadOnly ) )
|
||||
css += cssFile.readAll();
|
||||
|
||||
qApp->setStyleSheet( css );
|
||||
}
|
||||
|
||||
void MainWindow::updateTrayIcon()
|
||||
{
|
||||
|
@ -619,7 +641,24 @@ void MainWindow::editPreferences()
|
|||
|
||||
if ( preferences.exec() == QDialog::Accepted )
|
||||
{
|
||||
cfg.preferences = preferences.getPreferences();
|
||||
Config::Preferences p = preferences.getPreferences();
|
||||
|
||||
// See if we need to reapply stylesheets
|
||||
if ( cfg.preferences.displayStyle != p.displayStyle )
|
||||
{
|
||||
applyQtStyleSheet( p.displayStyle );
|
||||
articleMaker.setDisplayStyle( p.displayStyle );
|
||||
|
||||
for( int x = 0; x < ui.tabWidget->count(); ++x )
|
||||
{
|
||||
ArticleView & view =
|
||||
dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) );
|
||||
|
||||
view.reload();
|
||||
}
|
||||
}
|
||||
|
||||
cfg.preferences = p;
|
||||
|
||||
enableScanPopup->setVisible( cfg.preferences.enableScanPopup );
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
MainWindow( Config::Class & cfg );
|
||||
~MainWindow();
|
||||
|
||||
/// Applies the qt's stylesheet, given the style's name.
|
||||
static void applyQtStyleSheet( QString const & displayStyle );
|
||||
|
||||
private:
|
||||
|
||||
QSystemTrayIcon * trayIcon;
|
||||
|
|
|
@ -47,6 +47,16 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
|||
break;
|
||||
}
|
||||
|
||||
ui.displayStyle->addItem( QIcon( ":/icons/programicon.png" ), tr( "Default" ), QString() );
|
||||
ui.displayStyle->addItem( QIcon( ":/icons/icon32_dsl.png" ), tr( "Lingvo" ), QString( "lingvo" ) );
|
||||
|
||||
for( int x = 0; x < ui.displayStyle->count(); ++x )
|
||||
if ( ui.displayStyle->itemData( x ).toString() == p.displayStyle )
|
||||
{
|
||||
ui.displayStyle->setCurrentIndex( x );
|
||||
break;
|
||||
}
|
||||
|
||||
ui.newTabsOpenAfterCurrentOne->setChecked( p.newTabsOpenAfterCurrentOne );
|
||||
ui.newTabsOpenInBackground->setChecked( p.newTabsOpenInBackground );
|
||||
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
|
||||
|
@ -130,6 +140,10 @@ Config::Preferences Preferences::getPreferences()
|
|||
ui.interfaceLanguage->itemData(
|
||||
ui.interfaceLanguage->currentIndex() ).toString();
|
||||
|
||||
p.displayStyle =
|
||||
ui.displayStyle->itemData(
|
||||
ui.displayStyle->currentIndex() ).toString();
|
||||
|
||||
p.newTabsOpenAfterCurrentOne = ui.newTabsOpenAfterCurrentOne->isChecked();
|
||||
p.newTabsOpenInBackground = ui.newTabsOpenInBackground->isChecked();
|
||||
p.enableTrayIcon = ui.enableTrayIcon->isChecked();
|
||||
|
|
1926
src/preferences.ui
1926
src/preferences.ui
File diff suppressed because it is too large
Load diff
6
src/qt-style-st-lingvo.css
Normal file
6
src/qt-style-st-lingvo.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
MainWindow #searchPane #translateLine, MainWindow #searchPane #wordList,
|
||||
ArticleView #definition
|
||||
{
|
||||
background: white;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
MainWindow #searchPane #translateLine, MainWindow #searchPane #wordList
|
||||
MainWindow #searchPane #translateLine, MainWindow #searchPane #wordList,
|
||||
ArticleView #definition
|
||||
{
|
||||
background: #fefdeb;
|
||||
}
|
||||
|
|
|
@ -34,5 +34,7 @@
|
|||
<file>icons/configure.png</file>
|
||||
<file>icons/book.png</file>
|
||||
<file>icons/bookcase.png</file>
|
||||
<file>qt-style-st-lingvo.css</file>
|
||||
<file>article-style-st-lingvo.css</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in a new issue