From 58484cf70c66da6fef8059b04f15328412fdda1e Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 1 Oct 2012 16:43:00 +0400 Subject: [PATCH] Add Alt+PgDown/PgUp shortcuts to select next/previous group --- groupcombobox.cc | 34 +++++++++++++++++++++++++++++++++- groupcombobox.hh | 3 +++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/groupcombobox.cc b/groupcombobox.cc index 53811f9b..3d8a88b1 100644 --- a/groupcombobox.cc +++ b/groupcombobox.cc @@ -6,7 +6,9 @@ #include GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent ), - popupAction( this ) + popupAction( this ), + selectNextAction( this ), + selectPreviousAction( this ) { setSizeAdjustPolicy( AdjustToContents ); setToolTip( tr( "Choose a Group (Alt+G)" ) ); @@ -16,6 +18,16 @@ GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent ), this, SLOT( popupGroups() ) ); addAction( &popupAction ); + + selectNextAction.setShortcut( QKeySequence( "Alt+PgDown" ) ); + connect( &selectNextAction, SIGNAL( triggered() ), + this, SLOT( selectNextGroup() ) ); + addAction( &selectNextAction ); + + selectPreviousAction.setShortcut( QKeySequence( "Alt+PgUp" ) ); + connect( &selectPreviousAction, SIGNAL( triggered() ), + this, SLOT( selectPreviousGroup() ) ); + addAction( &selectPreviousAction ); } void GroupComboBox::fill( Instances::Groups const & groups ) @@ -97,3 +109,23 @@ void GroupComboBox::popupGroups() { showPopup(); } + +void GroupComboBox::selectNextGroup() +{ + if( count() <= 1 ) + return; + int n = currentIndex() + 1; + if( n >= count() ) + n = 0; + setCurrentIndex( n ); +} + +void GroupComboBox::selectPreviousGroup() +{ + if( count() <= 1 ) + return; + int n = currentIndex() - 1; + if( n < 0 ) + n = count() - 1; + setCurrentIndex( n ); +} diff --git a/groupcombobox.hh b/groupcombobox.hh index 8cf4c085..ec4744a4 100644 --- a/groupcombobox.hh +++ b/groupcombobox.hh @@ -36,10 +36,13 @@ protected: private slots: void popupGroups(); + void selectNextGroup(); + void selectPreviousGroup(); private: QAction popupAction; + QAction selectNextAction, selectPreviousAction; QMap< int, int > shortcuts; };