Add show all groups button to groups dialog

This commit is contained in:
Abs62 2014-03-03 17:47:06 +04:00
parent 55e9dc6a38
commit ed18c9afe7
2 changed files with 44 additions and 0 deletions

View file

@ -26,6 +26,21 @@ Groups::Groups( QWidget * parent,
ui.searchLine->applyTo( ui.dictionaries );
addAction( ui.searchLine->getFocusAction() );
groupsListMenu = new QMenu( tr( "Group tabs" ), ui.groups );
groupsListButton = new QToolButton( ui.groups );
groupsListButton->setAutoRaise( true );
groupsListButton->setIcon( QIcon( ":/icons/windows-list.png" ) );
groupsListButton->setMenu( groupsListMenu );
groupsListButton->setToolTip( tr( "Open groups list" ) );
groupsListButton->setPopupMode( QToolButton::InstantPopup );
ui.groups->setCornerWidget( groupsListButton );
groupsListButton->setFocusPolicy( Qt::ClickFocus );
connect(groupsListMenu, SIGNAL( aboutToShow() ), this, SLOT( fillGroupsMenu() ) );
connect(groupsListMenu, SIGNAL( triggered( QAction * ) ),
this, SLOT( switchToGroup( QAction * ) ) );
// Populate groups' widget
ui.groups->populate( groups, dicts, ui.dictionaries->getCurrentDictionaries() );
@ -205,4 +220,27 @@ void Groups::showDictInfo( QPoint const & pos )
}
}
void Groups::fillGroupsMenu()
{
groupsListMenu->clear();
for( int i = 0; i < ui.groups->count(); i++ )
{
QAction * act = groupsListMenu->addAction( ui.groups->tabText( i ) );
act->setData( i );
if (ui.groups->currentIndex() == i)
{
QFont f( act->font() );
f.setBold( true );
act->setFont( f );
}
}
if( groupsListMenu->actions().size() > 1 )
groupsListMenu->setActiveAction( groupsListMenu->actions().at( ui.groups->currentIndex() ) );
}
void Groups::switchToGroup( QAction * act )
{
int idx = act->data().toInt();
ui.groups->setCurrentIndex(idx);
}

View file

@ -9,6 +9,7 @@
#include "dictionary.hh"
#include "groups_widgets.hh"
#include <QToolButton>
#include <QMenu>
class Groups: public QWidget
{
@ -35,6 +36,9 @@ private:
std::vector< sptr< Dictionary::Class > > const & dicts;
Config::Groups groups;
QToolButton * groupsListButton;
QMenu * groupsListMenu;
// Reacts to the event that the number of groups is possibly changed
void countChanged();
@ -47,6 +51,8 @@ private slots:
void removeFromGroup();
void addAutoGroups();
void showDictInfo( const QPoint & pos );
void fillGroupsMenu();
void switchToGroup( QAction * act );
signals:
void showDictionaryInfo( QString const & id );