Add Alt+PgDown/PgUp shortcuts to select next/previous group

This commit is contained in:
Abs62 2012-10-01 16:43:00 +04:00
parent 8cc13b98b9
commit 58484cf70c
2 changed files with 36 additions and 1 deletions

View file

@ -6,7 +6,9 @@
#include <QShortcutEvent> #include <QShortcutEvent>
GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent ), GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent ),
popupAction( this ) popupAction( this ),
selectNextAction( this ),
selectPreviousAction( this )
{ {
setSizeAdjustPolicy( AdjustToContents ); setSizeAdjustPolicy( AdjustToContents );
setToolTip( tr( "Choose a Group (Alt+G)" ) ); setToolTip( tr( "Choose a Group (Alt+G)" ) );
@ -16,6 +18,16 @@ GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent ),
this, SLOT( popupGroups() ) ); this, SLOT( popupGroups() ) );
addAction( &popupAction ); 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 ) void GroupComboBox::fill( Instances::Groups const & groups )
@ -97,3 +109,23 @@ void GroupComboBox::popupGroups()
{ {
showPopup(); 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 );
}

View file

@ -36,10 +36,13 @@ protected:
private slots: private slots:
void popupGroups(); void popupGroups();
void selectNextGroup();
void selectPreviousGroup();
private: private:
QAction popupAction; QAction popupAction;
QAction selectNextAction, selectPreviousAction;
QMap< int, int > shortcuts; QMap< int, int > shortcuts;
}; };