From ed18c9afe795ec1e4542a0d35c5d11dc724fb977 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 3 Mar 2014 17:47:06 +0400 Subject: [PATCH] Add show all groups button to groups dialog --- groups.cc | 38 ++++++++++++++++++++++++++++++++++++++ groups.hh | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/groups.cc b/groups.cc index 6bdb1cfc..a686c400 100644 --- a/groups.cc +++ b/groups.cc @@ -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); +} diff --git a/groups.hh b/groups.hh index 3a7f68a2..5ad5aea1 100644 --- a/groups.hh +++ b/groups.hh @@ -9,6 +9,7 @@ #include "dictionary.hh" #include "groups_widgets.hh" #include +#include 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 );