From 1dafa5cb16db5552bdf154fb3ae02b8e9a65562e Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Mon, 15 Nov 2010 18:22:35 +0300 Subject: [PATCH] Allow styling of translate line and word list dependent on the current group by introducing a currentGroup Qt property. To use, create ~/.goldendict/qt-style.css like this: MainWindow #searchPane #translateLine[currentGroup="En"], MainWindow #searchPane #wordList[currentGroup="En"] { background: white; color: black; font-size: 20px; } --- articleview.cc | 27 +++++++++++++-------------- articleview.hh | 2 ++ mainwindow.cc | 24 ++++++++++++++++++++++++ mainwindow.hh | 3 +++ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/articleview.cc b/articleview.cc index 88233496..396e1259 100644 --- a/articleview.cc +++ b/articleview.cc @@ -1183,14 +1183,7 @@ void ArticleView::openSearch() ui.searchText->setProperty( "noResults", false ); // Reload stylesheet - for( QWidget * w = parentWidget(); w; w = w->parentWidget() ) - { - if ( w->styleSheet().size() ) - { - w->setStyleSheet( w->styleSheet() ); - break; - } - } + reloadStyleSheet(); } } @@ -1275,17 +1268,23 @@ void ArticleView::performFindOperation( bool restart, bool backwards ) ui.searchText->setProperty( "noResults", setMark ); // Reload stylesheet - for( QWidget * w = parentWidget(); w; w = w->parentWidget() ) + reloadStyleSheet(); + } +} + +void ArticleView::reloadStyleSheet() +{ + for( QWidget * w = parentWidget(); w; w = w->parentWidget() ) + { + if ( w->styleSheet().size() ) { - if ( w->styleSheet().size() ) - { - w->setStyleSheet( w->styleSheet() ); - break; - } + w->setStyleSheet( w->styleSheet() ); + break; } } } + bool ArticleView::closeSearch() { if ( searchIsOpened ) diff --git a/articleview.hh b/articleview.hh index dd7ee1a8..b236138b 100644 --- a/articleview.hh +++ b/articleview.hh @@ -240,6 +240,8 @@ private: void performFindOperation( bool restart, bool backwards ); + void reloadStyleSheet(); + /// Returns the comma-separated list of dictionary ids which should be muted /// for the given group. If there are none, returns empty string. QString getMutedForGroup( unsigned group ); diff --git a/mainwindow.cc b/mainwindow.cc index b114e126..903e815c 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -664,6 +664,7 @@ void MainWindow::updateGroupList() groupList.fill( groupInstances ); groupList.setCurrentGroup( cfg.lastMainGroupId ); + updateCurrentGroupProperty(); updateDictionaryBar(); @@ -1063,6 +1064,29 @@ void MainWindow::currentGroupChanged( QString const & ) // Update word search results translateInputChanged( ui.translateLine->text() ); + + updateCurrentGroupProperty(); +} + +void MainWindow::updateCurrentGroupProperty() +{ + // We maintain currentGroup property so styles could use that to change + // fonts based on group names + Instances::Group * grp = + groupInstances.findGroup( groupList.getCurrentGroup() ); + + if ( grp && ui.translateLine->property( "currentGroup" ).toString() != + grp->name ) + { + ui.translateLine->setProperty( "currentGroup", grp->name ); + ui.wordList->setProperty( "currentGroup", grp->name ); + QString ss = styleSheet(); + + // Only update stylesheet if it mentions currentGroup, as updating the + // stylesheet is a slow operation + if ( ss.contains("currentGroup") ) + setStyleSheet( ss ); + } } void MainWindow::translateInputChanged( QString const & newValue ) diff --git a/mainwindow.hh b/mainwindow.hh index 879bba81..17e4dd4f 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -136,6 +136,9 @@ private: void mousePressEvent ( QMouseEvent * event ); + void updateCurrentGroupProperty(); + + private slots: void hotKeyActivated( int );