Change "Add to Favorites" icon if headword is already presented in Favorites

This commit is contained in:
Abs62 2017-10-23 17:21:43 +03:00
parent 9ae92bf251
commit 1824d9ab02
9 changed files with 77 additions and 3 deletions

View file

@ -254,6 +254,11 @@ void FavoritesPaneWidget::addHeadword( QString const & path, QString const & hea
m_favoritesModel->addNewHeadword( path, headword ); 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 ) void FavoritesPaneWidget::getDataInXml( QByteArray & dataStr )
{ {
m_favoritesModel->getDataInXml( dataStr ); m_favoritesModel->getDataInXml( dataStr );
@ -973,6 +978,30 @@ bool FavoritesModel::addNewHeadword( const QString & path, const QString & headw
return addHeadword( headword, parentIdx ); 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 FavoritesModel::forceFolder( QString const & name, const QModelIndex & parentIdx )
{ {
QModelIndex idx = findItemInFolder( name, TreeItem::Folder, parentIdx ); QModelIndex idx = findItemInFolder( name, TreeItem::Folder, parentIdx );

View file

@ -51,6 +51,9 @@ public:
// Set interval for periodical save // Set interval for periodical save
void setSaveInterval( unsigned interval ); void setSaveInterval( unsigned interval );
// Return true if headwors is already presented in Favorites
bool isHeadwordPresent( QString const & path, QString const & headword );
signals: signals:
void favoritesItemRequested( QString const & word, QString const & faforitesFolder ); void favoritesItemRequested( QString const & word, QString const & faforitesFolder );
@ -192,6 +195,9 @@ public:
// return false if it already exists there // return false if it already exists there
bool addNewHeadword( QString const & path, QString const & headword ); 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 // Return path in the tree to item
QString pathToItem( QModelIndex const & idx ); QString pathToItem( QModelIndex const & idx );

Binary file not shown.

Before

Width:  |  Height:  |  Size: 724 B

After

Width:  |  Height:  |  Size: 477 B

BIN
icons/star_blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

View file

@ -127,6 +127,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
, ftsIndexing( dictionaries ) , ftsIndexing( dictionaries )
, ftsDlg( 0 ) , ftsDlg( 0 )
, helpWindow( 0 ) , helpWindow( 0 )
, starIcon( ":/icons/star.png" )
, blueStarIcon( ":/icons/star_blue.png" )
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
, gdAskMessage( 0xFFFFFFFF ) , gdAskMessage( 0xFFFFFFFF )
#endif #endif
@ -240,7 +242,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
navToolbar->widgetForAction( navToolbar->addSeparator() )->setObjectName( "separatorBeforeAddToFavorites" ); 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" ); navToolbar->widgetForAction( addToFavorites )->setObjectName( "addToFavoritesButton" );
connect( addToFavorites, SIGNAL( triggered() ), this, SLOT( addCurrentTabToFavorites() ) ); connect( addToFavorites, SIGNAL( triggered() ), this, SLOT( addCurrentTabToFavorites() ) );
@ -1400,6 +1402,9 @@ void MainWindow::makeScanPopup()
connect( scanPopup.get(), SIGNAL( sendWordToFavorites( QString, uint ) ), connect( scanPopup.get(), SIGNAL( sendWordToFavorites( QString, uint ) ),
this, SLOT( addWordToFavorites( QString, uint ) ) ); this, SLOT( addWordToFavorites( QString, uint ) ) );
connect( scanPopup.get(), SIGNAL( isWordPresentedInFavorites( QString, uint ) ),
this, SLOT( isWordPresentedInFavorites( QString, uint ) ) );
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
connect( scanPopup.get(), SIGNAL( isGoldenDictWindow( HWND ) ), connect( scanPopup.get(), SIGNAL( isGoldenDictWindow( HWND ) ),
this, SLOT( isGoldenDictWindow( HWND ) ) ); this, SLOT( isGoldenDictWindow( HWND ) ) );
@ -2639,6 +2644,9 @@ void MainWindow::showTranslationFor( QString const & inWord,
view->showDefinition( inWord, group, dictID ); view->showDefinition( inWord, group, dictID );
// Set icon for "Add to Favorites" action
addToFavorites->setIcon( isWordPresentedInFavorites( inWord, group ) ? blueStarIcon : starIcon );
updatePronounceAvailability(); updatePronounceAvailability();
updateFoundInDictsList(); updateFoundInDictsList();
@ -4467,6 +4475,8 @@ void MainWindow::addCurrentTabToFavorites()
headword.chop( 1 ); headword.chop( 1 );
ui.favoritesPaneWidget->addHeadword( folder, headword ); ui.favoritesPaneWidget->addHeadword( folder, headword );
addToFavorites->setIcon( blueStarIcon );
} }
void MainWindow::addWordToFavorites( QString const & word, unsigned groupId ) 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 ); 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 ) void MainWindow::setGroupByName( QString const & name, bool main_window )
{ {
if( main_window ) if( main_window )

View file

@ -182,6 +182,8 @@ private:
Help::HelpWindow * helpWindow; Help::HelpWindow * helpWindow;
QIcon starIcon, blueStarIcon;
/// Applies the qt's stylesheet, given the style's name. /// Applies the qt's stylesheet, given the style's name.
void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle ); void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle );
@ -439,6 +441,8 @@ private slots:
void addWordToFavorites( QString const & word, unsigned groupId ); void addWordToFavorites( QString const & word, unsigned groupId );
bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
void sendWordToInputLine( QString const & word ); void sendWordToInputLine( QString const & word );
void storeResourceSavePath( QString const & ); void storeResourceSavePath( QString const & );

View file

@ -81,6 +81,7 @@
<file>icons/icon32_slob.png</file> <file>icons/icon32_slob.png</file>
<file>icons/icon32_gls.png</file> <file>icons/icon32_gls.png</file>
<file>icons/star.png</file> <file>icons/star.png</file>
<file>icons/star_blue.png</file>
<file>icons/folder.png</file> <file>icons/folder.png</file>
<file>icons/ontop.png</file> <file>icons/ontop.png</file>
</qresource> </qresource>

View file

@ -53,7 +53,9 @@ ScanPopup::ScanPopup( QWidget * parent,
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ), dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
mouseEnteredOnce( false ), mouseEnteredOnce( false ),
mouseIntercepted( false ), mouseIntercepted( false ),
hideTimer( this ) hideTimer( this ),
starIcon( ":/icons/star.png" ),
blueStarIcon( ":/icons/star_blue.png" )
{ {
ui.setupUi( this ); ui.setupUi( this );
@ -690,9 +692,15 @@ void ScanPopup::showTranslationFor( QString const & inputWord )
{ {
ui.pronounceButton->hide(); ui.pronounceButton->hide();
definition->showDefinition( inputWord, ui.groupList->getCurrentGroup() ); unsigned groupId = ui.groupList->getCurrentGroup();
definition->showDefinition( inputWord, groupId );
definition->focus(); definition->focus();
// Set icon for "Add to Favorites" button
ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( inputWord, groupId ) ?
blueStarIcon : starIcon );
// Add to history // Add to history
emit sendWordToHistory( inputWord.trimmed() ); emit sendWordToHistory( inputWord.trimmed() );
} }
@ -1132,6 +1140,8 @@ void ScanPopup::on_sendWordToFavoritesButton_clicked()
if ( !isVisible() ) if ( !isVisible() )
return; return;
emit sendWordToFavorites( definition->getTitle(), cfg.lastPopupGroupId ); emit sendWordToFavorites( definition->getTitle(), cfg.lastPopupGroupId );
ui.sendWordToFavoritesButton->setIcon( blueStarIcon );
} }
void ScanPopup::switchExpandOptionalPartsMode() void ScanPopup::switchExpandOptionalPartsMode()

View file

@ -73,6 +73,8 @@ signals:
void sendWordToHistory( QString const & word ); void sendWordToHistory( QString const & word );
/// Put translated word into Favorites /// Put translated word into Favorites
void sendWordToFavorites( QString const & word, unsigned groupId ); void sendWordToFavorites( QString const & word, unsigned groupId );
/// Check is word already presented in Favorites
bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
#ifdef HAVE_X11 #ifdef HAVE_X11
/// Interaction with scan flag window /// Interaction with scan flag window
@ -151,6 +153,8 @@ private:
QTimer mouseGrabPollTimer; QTimer mouseGrabPollTimer;
QIcon starIcon, blueStarIcon;
void handleInputWord( QString const & , bool forcePopup = false ); void handleInputWord( QString const & , bool forcePopup = false );
void engagePopup( bool forcePopup, bool giveFocus = false ); void engagePopup( bool forcePopup, bool giveFocus = false );