diff --git a/favoritespanewidget.cc b/favoritespanewidget.cc index a36ecec3..ded7a2a9 100644 --- a/favoritespanewidget.cc +++ b/favoritespanewidget.cc @@ -254,6 +254,11 @@ void FavoritesPaneWidget::addHeadword( QString const & path, QString const & hea m_favoritesModel->addNewHeadword( path, headword ); } +bool FavoritesPaneWidget::isHeadwordPresent( const QString & path, const QString & headword ) +{ + return m_favoritesModel->isHeadwordPresent( path, headword ); +} + void FavoritesPaneWidget::getDataInXml( QByteArray & dataStr ) { m_favoritesModel->getDataInXml( dataStr ); @@ -973,6 +978,30 @@ bool FavoritesModel::addNewHeadword( const QString & path, const QString & headw return addHeadword( headword, parentIdx ); } +bool FavoritesModel::isHeadwordPresent( const QString & path, const QString & headword ) +{ + QModelIndex idx; + + // Find or create target folder + + QStringList folders = path.split( "/", QString::SkipEmptyParts ); + QStringList::const_iterator it = folders.begin(); + for( ; it != folders.end(); ++it ) + { + idx = findItemInFolder( *it, TreeItem::Folder, idx ); + if( !idx.isValid() ) + break; + } + + if( path.isEmpty() || idx.isValid() ) + { + idx = findItemInFolder( headword, TreeItem::Word, idx ); + return idx.isValid(); + } + + return false; +} + QModelIndex FavoritesModel::forceFolder( QString const & name, const QModelIndex & parentIdx ) { QModelIndex idx = findItemInFolder( name, TreeItem::Folder, parentIdx ); diff --git a/favoritespanewidget.hh b/favoritespanewidget.hh index def54f6b..e2b00ce3 100644 --- a/favoritespanewidget.hh +++ b/favoritespanewidget.hh @@ -51,6 +51,9 @@ public: // Set interval for periodical save void setSaveInterval( unsigned interval ); + // Return true if headwors is already presented in Favorites + bool isHeadwordPresent( QString const & path, QString const & headword ); + signals: void favoritesItemRequested( QString const & word, QString const & faforitesFolder ); @@ -192,6 +195,9 @@ public: // return false if it already exists there bool addNewHeadword( QString const & path, QString const & headword ); + // Return true if headwors is already presented in Favorites + bool isHeadwordPresent( QString const & path, QString const & headword ); + // Return path in the tree to item QString pathToItem( QModelIndex const & idx ); diff --git a/icons/star.png b/icons/star.png index 26d8eb0d..262c05cc 100644 Binary files a/icons/star.png and b/icons/star.png differ diff --git a/icons/star_blue.png b/icons/star_blue.png new file mode 100644 index 00000000..d378a78d Binary files /dev/null and b/icons/star_blue.png differ diff --git a/mainwindow.cc b/mainwindow.cc index 41888ddc..c65acf34 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -127,6 +127,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ): , ftsIndexing( dictionaries ) , ftsDlg( 0 ) , helpWindow( 0 ) +, starIcon( ":/icons/star.png" ) +, blueStarIcon( ":/icons/star_blue.png" ) #ifdef Q_OS_WIN32 , gdAskMessage( 0xFFFFFFFF ) #endif @@ -240,7 +242,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): navToolbar->widgetForAction( navToolbar->addSeparator() )->setObjectName( "separatorBeforeAddToFavorites" ); - addToFavorites = navToolbar->addAction( QIcon( ":/icons/star.png" ), tr( "Add current tab to Favorites" ) ); + addToFavorites = navToolbar->addAction( starIcon, tr( "Add current tab to Favorites" ) ); navToolbar->widgetForAction( addToFavorites )->setObjectName( "addToFavoritesButton" ); connect( addToFavorites, SIGNAL( triggered() ), this, SLOT( addCurrentTabToFavorites() ) ); @@ -1400,6 +1402,9 @@ void MainWindow::makeScanPopup() connect( scanPopup.get(), SIGNAL( sendWordToFavorites( QString, uint ) ), this, SLOT( addWordToFavorites( QString, uint ) ) ); + connect( scanPopup.get(), SIGNAL( isWordPresentedInFavorites( QString, uint ) ), + this, SLOT( isWordPresentedInFavorites( QString, uint ) ) ); + #ifdef Q_OS_WIN32 connect( scanPopup.get(), SIGNAL( isGoldenDictWindow( HWND ) ), this, SLOT( isGoldenDictWindow( HWND ) ) ); @@ -2639,6 +2644,9 @@ 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(); @@ -4467,6 +4475,8 @@ void MainWindow::addCurrentTabToFavorites() headword.chop( 1 ); ui.favoritesPaneWidget->addHeadword( folder, headword ); + + addToFavorites->setIcon( blueStarIcon ); } void MainWindow::addWordToFavorites( QString const & word, unsigned groupId ) @@ -4479,6 +4489,16 @@ void MainWindow::addWordToFavorites( QString const & word, unsigned groupId ) ui.favoritesPaneWidget->addHeadword( folder, word ); } +bool MainWindow::isWordPresentedInFavorites( QString const & word, unsigned groupId ) +{ + QString folder; + Instances::Group const * igrp = groupInstances.findGroup( groupId ); + if( igrp ) + folder = igrp->favoritesFolder; + + return ui.favoritesPaneWidget->isHeadwordPresent( folder, word ); +} + void MainWindow::setGroupByName( QString const & name, bool main_window ) { if( main_window ) diff --git a/mainwindow.hh b/mainwindow.hh index 74d7ee0d..de5ae6a3 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -182,6 +182,8 @@ private: Help::HelpWindow * helpWindow; + QIcon starIcon, blueStarIcon; + /// Applies the qt's stylesheet, given the style's name. void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle ); @@ -439,6 +441,8 @@ private slots: void addWordToFavorites( QString const & word, unsigned groupId ); + bool isWordPresentedInFavorites( QString const & word, unsigned groupId ); + void sendWordToInputLine( QString const & word ); void storeResourceSavePath( QString const & ); diff --git a/resources.qrc b/resources.qrc index 2bfda092..774cf53c 100644 --- a/resources.qrc +++ b/resources.qrc @@ -81,6 +81,7 @@ icons/icon32_slob.png icons/icon32_gls.png icons/star.png + icons/star_blue.png icons/folder.png icons/ontop.png diff --git a/scanpopup.cc b/scanpopup.cc index fc58da6c..9ac58668 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -53,7 +53,9 @@ ScanPopup::ScanPopup( QWidget * parent, dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ), mouseEnteredOnce( false ), mouseIntercepted( false ), - hideTimer( this ) + hideTimer( this ), + starIcon( ":/icons/star.png" ), + blueStarIcon( ":/icons/star_blue.png" ) { ui.setupUi( this ); @@ -690,9 +692,15 @@ void ScanPopup::showTranslationFor( QString const & inputWord ) { ui.pronounceButton->hide(); - definition->showDefinition( inputWord, ui.groupList->getCurrentGroup() ); + unsigned groupId = ui.groupList->getCurrentGroup(); + 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() ); } @@ -1132,6 +1140,8 @@ void ScanPopup::on_sendWordToFavoritesButton_clicked() if ( !isVisible() ) return; emit sendWordToFavorites( definition->getTitle(), cfg.lastPopupGroupId ); + + ui.sendWordToFavoritesButton->setIcon( blueStarIcon ); } void ScanPopup::switchExpandOptionalPartsMode() diff --git a/scanpopup.hh b/scanpopup.hh index 593adc5b..4b7c017f 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -73,6 +73,8 @@ signals: void sendWordToHistory( QString const & word ); /// Put translated word into Favorites void sendWordToFavorites( QString const & word, unsigned groupId ); + /// Check is word already presented in Favorites + bool isWordPresentedInFavorites( QString const & word, unsigned groupId ); #ifdef HAVE_X11 /// Interaction with scan flag window @@ -151,6 +153,8 @@ private: QTimer mouseGrabPollTimer; + QIcon starIcon, blueStarIcon; + void handleInputWord( QString const & , bool forcePopup = false ); void engagePopup( bool forcePopup, bool giveFocus = false );