+ Dictionary bar has now a context menu listing all the dictionaries with

their names.
This commit is contained in:
Konstantin Isakov 2009-10-12 13:58:32 +00:00
parent cb94fbfa41
commit 35af96dfc0
2 changed files with 31 additions and 1 deletions

View file

@ -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 )
}
}
}

View file

@ -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();