Fix "Add to Favorites" icon changing

This commit is contained in:
Abs62 2017-11-07 17:46:59 +03:00
parent 65be9f2f8a
commit 77c9a4c3e2
4 changed files with 40 additions and 27 deletions

View file

@ -1723,6 +1723,10 @@ void MainWindow::titleChanged( ArticleView * view, QString const & title )
}
ui.tabWidget->setTabText( ui.tabWidget->indexOf( view ), escaped );
// Set icon for "Add to Favorites" action
addToFavorites->setIcon( isWordPresentedInFavorites( title, cfg.lastMainGroupId ) ? blueStarIcon : starIcon );
updateWindowTitle();
}
@ -1787,6 +1791,10 @@ void MainWindow::tabSwitched( int )
if ( from > 0)
mruList.move( from, 0 );
}
// Set icon for "Add to Favorites" action
QString headword = ui.tabWidget->tabText( ui.tabWidget->currentIndex() );
addToFavorites->setIcon( isWordPresentedInFavorites( unescapeTabHeader( headword ), cfg.lastMainGroupId ) ? blueStarIcon : starIcon );
}
void MainWindow::tabMenuRequested(QPoint pos)
@ -2653,9 +2661,6 @@ void MainWindow::showTranslationFor( QString const & inWord,
view->showDefinition( inWord, group, dictID );
// Set icon for "Add to Favorites" action
addToFavorites->setIcon( isWordPresentedInFavorites( inWord, group ) ? blueStarIcon : starIcon );
updatePronounceAvailability();
updateFoundInDictsList();
@ -4466,6 +4471,20 @@ void MainWindow::showFTSIndexingName( QString const & name )
mainStatusBar->setBackgroundMessage( tr( "Now indexing for full-text search: " ) + name );
}
QString MainWindow::unescapeTabHeader(QString const & header )
{
// Reset table header to original headword
QString escaped = header;
escaped.replace( "&&", "&" );
if( escaped.startsWith( QChar( 0x202E ) ) )
escaped = escaped.mid( 1 );
if( escaped.endsWith( QChar( 0x202C ) ) )
escaped.chop( 1 );
return escaped;
}
void MainWindow::addCurrentTabToFavorites()
{
QString folder;
@ -4475,15 +4494,7 @@ void MainWindow::addCurrentTabToFavorites()
QString headword = ui.tabWidget->tabText( ui.tabWidget->currentIndex() );
// Reset table header to original headword
headword.replace( "&&", "&" );
if( headword.startsWith( QChar( 0x202E ) ) )
headword = headword.mid( 1 );
if( headword.endsWith( QChar( 0x202C ) ) )
headword.chop( 1 );
ui.favoritesPaneWidget->addHeadword( folder, headword );
ui.favoritesPaneWidget->addHeadword( folder, unescapeTabHeader( headword ) );
addToFavorites->setIcon( blueStarIcon );
}
@ -4508,16 +4519,7 @@ void MainWindow::addAllTabsToFavorites()
for( int i = 0; i < ui.tabWidget->count(); i++ )
{
QString headword = ui.tabWidget->tabText( i );
// Reset table header to original headword
headword.replace( "&&", "&" );
if( headword.startsWith( QChar( 0x202E ) ) )
headword = headword.mid( 1 );
if( headword.endsWith( QChar( 0x202C ) ) )
headword.chop( 1 );
ui.favoritesPaneWidget->addHeadword( folder, headword );
ui.favoritesPaneWidget->addHeadword( folder, unescapeTabHeader( headword ) );
}
addToFavorites->setIcon( blueStarIcon );
}

View file

@ -249,6 +249,8 @@ private:
void showDictionaryHeadwords( QWidget * owner, Dictionary::Class * dict );
QString unescapeTabHeader( QString const & header );
private slots:
void hotKeyActivated( int );

View file

@ -234,6 +234,9 @@ ScanPopup::ScanPopup( QWidget * parent,
connect( definition, SIGNAL( statusBarMessage( QString const &, int, QPixmap const & ) ),
this, SLOT( showStatusBarMessage( QString const &, int, QPixmap const & ) ) );
connect( definition, SIGNAL( titleChanged( ArticleView *, QString const & ) ),
this, SLOT( titleChanged( ArticleView *, QString const & ) ) );
#ifdef HAVE_X11
connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ),
this, SLOT( clipboardChanged( QClipboard::Mode ) ) );
@ -696,11 +699,6 @@ void ScanPopup::showTranslationFor( QString const & inputWord )
definition->showDefinition( inputWord, groupId );
definition->focus();
// Set icon for "Add to Favorites" button
ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( inputWord, groupId ) ?
blueStarIcon : starIcon );
// Add to history
emit sendWordToHistory( inputWord.trimmed() );
}
@ -1203,3 +1201,12 @@ void ScanPopup::alwaysOnTopClicked( bool checked )
show();
}
}
void ScanPopup::titleChanged( ArticleView *, QString const & title )
{
unsigned groupId = ui.groupList->getCurrentGroup();
// Set icon for "Add to Favorites" button
ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( title, groupId ) ?
blueStarIcon : starIcon );
}

View file

@ -223,6 +223,8 @@ private slots:
void alwaysOnTopClicked( bool checked );
void titleChanged( ArticleView *, QString const & title );
#ifdef HAVE_X11
void delayShow();
#endif