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;
}
This commit is contained in:
Konstantin Isakov 2010-11-15 18:22:35 +03:00
parent e1c9748d88
commit 1dafa5cb16
4 changed files with 42 additions and 14 deletions

View file

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

View file

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

View file

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

View file

@ -136,6 +136,9 @@ private:
void mousePressEvent ( QMouseEvent * event );
void updateCurrentGroupProperty();
private slots:
void hotKeyActivated( int );