From 1824d9ab02acd61e74c64a4a161a9f90e93551af Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 23 Oct 2017 17:21:43 +0300 Subject: [PATCH] Change "Add to Favorites" icon if headword is already presented in Favorites --- favoritespanewidget.cc | 29 +++++++++++++++++++++++++++++ favoritespanewidget.hh | 6 ++++++ icons/star.png | Bin 724 -> 477 bytes icons/star_blue.png | Bin 0 -> 942 bytes mainwindow.cc | 22 +++++++++++++++++++++- mainwindow.hh | 4 ++++ resources.qrc | 1 + scanpopup.cc | 14 ++++++++++++-- scanpopup.hh | 4 ++++ 9 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 icons/star_blue.png 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 26d8eb0db81292473b545fa91002bbbc02a30ffd..262c05cc6246e73082b9b1faf112ee8db40d4fed 100644 GIT binary patch delta 415 zcmV;Q0bu^r1>FOXNPhu;NklnMCb$U+U3h)=E29S&)hr9=nI!S!~D)U z_nbL%hyRV^@u^IEW`H5w%CyPi6Q*+vax&<_MjUrlHEPQUFn^5AXtRlD8Mc*}7QVb2 zZ>t&|sHkg{q#oZjbmDiJVWUJ{xSG&i!wR0p`7lmlE@88PdLx56PGAC4ST2bFV6tic z5)W{>pgWI2JhGGRF3w>F_vJM}8%FRE{ml!-HvNk0IEvRoR%P_!4G!UkP|8YN!94CH zH20$BQdOr#dVlaavA!r|+mc#IfSdTCb+>flFus)dX~`7M#Bn>uF=l7)&f-hU&k*CifalyF6D?MCcB@1J0*deoCRUj_0ASjR&QgM-%>gH%+Ihdc zF+6MU0JK|e6XhPfUBPxDl;@L_s5${P8S%(D0C0B=3^Qbwh!go-Q<*;uEw-I5w?zac zcZA_rzz6|fbAPW0>i$0wJv4#yB64h-p>P$kXC~1ER;diqFNjpbrVYLoEjFc3Mm}Uz z#wS3%L+~0Tu0yB$kC$u!;a&wkVG|nFysn8p+$Ni@?3#y*-kyB8?Y>p yz_+4BpCD&(a-X1U(Z^tFgy74Lb@s3uegn|2^${Hr8|*Xy0000Club+%X&A@<@7t+NX*)U< zsHLU0YJo;7HH#l4nhM3}!EXc67!M{UUd$$&P0VuIpoz(@mt7CW%X%<=Y_e+5;I|UJ zh?-!OLKQ7dt;nEaX&p+-(wWyoksyL8375@2$#a_j^Zz{`GXwmuV%few)|Bu4y?Q1! z+zhltNe>>?5~u*yn8CAtNOTn^MYlaM&+DIc zz^G2xoD}UC7E6#a7HpYSfZy*g9WYn9zyXXSh?~8oKA&&NtN~=PZ1t7(m9ZHHCSe-1pWUIDWk2+>!mSySw6({k{QwiTr=tf zDn-MOA9o^PPAZPYoqwGUoIQMKI-l?Uix}uUh2;U6vF^$E13&>3mIp@Wh~M*=_B*Jn ztFtHd&PoM*7BD&~Gk`*Lko60_KA+Dv;|b#WMb!zhybKBe72s16Tk!V!127Hgw{56S z>lP3&Ko;EYw6J6)aKCp(fV9EBec0$E03d#7kCnW>aR07*qoM6N<$g4>*~pa1{> literal 0 HcmV?d00001 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 );