mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
+ Dictionary bar has now a context menu listing all the dictionaries with
their names.
This commit is contained in:
parent
cb94fbfa41
commit
35af96dfc0
|
@ -1,6 +1,8 @@
|
|||
#include "dictionarybar.hh"
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
using std::vector;
|
||||
|
||||
|
@ -79,9 +81,31 @@ void DictionaryBar::setDictionaries( vector< sptr< Dictionary::Class > >
|
|||
}
|
||||
|
||||
|
||||
void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
|
||||
{
|
||||
QMenu menu( this );
|
||||
|
||||
for( QList< QAction * >::iterator i = dictActions.begin();
|
||||
i != dictActions.end(); ++i )
|
||||
{
|
||||
// We need new action, since the one we have has text elided
|
||||
QAction * action = menu.addAction( (*i)->icon(), (*i)->toolTip() );
|
||||
|
||||
action->setCheckable( true );
|
||||
action->setChecked( (*i)->isChecked() );
|
||||
action->setData( QVariant::fromValue( (void *)*i ) );
|
||||
}
|
||||
QAction * result = menu.exec( event->globalPos() );
|
||||
|
||||
if ( result && result->data().value< void * >() )
|
||||
( ( QAction * )( result->data().value< void * >() ) )->trigger();
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void DictionaryBar::mutedDictionariesChanged()
|
||||
{
|
||||
// printf( "Muted dictionaries changed\n" );
|
||||
//printf( "Muted dictionaries changed\n" );
|
||||
|
||||
// Update actions
|
||||
|
||||
|
@ -178,3 +202,4 @@ void DictionaryBar::actionWasTriggered( QAction * action )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
/// disabled) are taken from the configuration data.
|
||||
void setDictionaries( std::vector< sptr< Dictionary::Class > > const & );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Config::MutedDictionaries & mutedDictionaries;
|
||||
|
@ -32,6 +33,10 @@ private:
|
|||
/// All the actions we have added to the toolbar
|
||||
QList< QAction * > dictActions;
|
||||
|
||||
protected:
|
||||
|
||||
void contextMenuEvent( QContextMenuEvent * event );
|
||||
|
||||
private slots:
|
||||
|
||||
void mutedDictionariesChanged();
|
||||
|
|
Loading…
Reference in a new issue