From 77c9a4c3e21e8f7da5f477662c4a9e80b0acad34 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Tue, 7 Nov 2017 17:46:59 +0300 Subject: [PATCH] Fix "Add to Favorites" icon changing --- mainwindow.cc | 46 ++++++++++++++++++++++++---------------------- mainwindow.hh | 2 ++ scanpopup.cc | 17 ++++++++++++----- scanpopup.hh | 2 ++ 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index 7fbcd476..f61c891b 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -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 ); } diff --git a/mainwindow.hh b/mainwindow.hh index 9305987a..d1cd1848 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -249,6 +249,8 @@ private: void showDictionaryHeadwords( QWidget * owner, Dictionary::Class * dict ); + QString unescapeTabHeader( QString const & header ); + private slots: void hotKeyActivated( int ); diff --git a/scanpopup.cc b/scanpopup.cc index 9ac58668..aed999b0 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -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 ); +} diff --git a/scanpopup.hh b/scanpopup.hh index 4b7c017f..95e15011 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -223,6 +223,8 @@ private slots: void alwaysOnTopClicked( bool checked ); + void titleChanged( ArticleView *, QString const & title ); + #ifdef HAVE_X11 void delayShow(); #endif