mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Change "Add to Favorites" icon if headword is already presented in Favorites
This commit is contained in:
parent
9ae92bf251
commit
1824d9ab02
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
BIN
icons/star.png
BIN
icons/star.png
Binary file not shown.
Before Width: | Height: | Size: 724 B After Width: | Height: | Size: 477 B |
BIN
icons/star_blue.png
Normal file
BIN
icons/star_blue.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 942 B |
|
@ -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 )
|
||||
|
|
|
@ -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 & );
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
<file>icons/icon32_slob.png</file>
|
||||
<file>icons/icon32_gls.png</file>
|
||||
<file>icons/star.png</file>
|
||||
<file>icons/star_blue.png</file>
|
||||
<file>icons/folder.png</file>
|
||||
<file>icons/ontop.png</file>
|
||||
</qresource>
|
||||
|
|
14
scanpopup.cc
14
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()
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue