Skip to content

Commit

Permalink
Switch between tabs using both Alt+N and Ctrl+N (Cmd+N on Macs).
Browse files Browse the repository at this point in the history
  • Loading branch information
mblsha committed Jan 30, 2010
1 parent 22bb2e9 commit e4376c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
31 changes: 10 additions & 21 deletions src/tabs/tabdlg.cpp
Expand Up @@ -32,6 +32,7 @@
#include <QKeyEvent>
#include <QDropEvent>
#include <QCloseEvent>
#include <QSignalMapper>

#include "psitabwidget.h"
#include "psioptions.h"
Expand Down Expand Up @@ -171,15 +172,16 @@ TabDlg::TabDlg(TabManager* tabManager, QSize size, TabDlgDelegate *delegate)

setShortcuts();

tabSwitcher_ = new QActionGroup(this);
for (int i = 0 ; i <= 9; ++i) {
QAction *act = new QAction(tabSwitcher_);
act->setShortcut(QKeySequence(Qt::ALT + (Qt::Key_0 + i)));
act->setData(i);
tabSwitcher_->addAction(act);
addAction(act);
QSignalMapper* activateTabMapper_ = new QSignalMapper(this);
connect(activateTabMapper_, SIGNAL(mapped(int)), tabWidget_, SLOT(setCurrentPage(int)));
for (int i = 0; i < 10; ++i) {
QAction* action = new QAction(this);
connect(action, SIGNAL(triggered()), activateTabMapper_, SLOT(map()));
action->setShortcuts(QList<QKeySequence>() << QKeySequence(QString("Ctrl+%1").arg(i))
<< QKeySequence(QString("Alt+%1").arg(i)));
activateTabMapper_->setMapping(action, (i > 0 ? i : 10) - 1);
addAction(action);
}
connect(tabSwitcher_, SIGNAL(triggered(QAction *)), SLOT(switchTab(QAction *)));

if (size.isValid()) {
resize(size);
Expand Down Expand Up @@ -772,16 +774,3 @@ void TabDlg::setSimplifiedCaptionEnabled(bool enabled) {
simplifiedCaption_ = enabled;
updateCaption();
}

void TabDlg::switchTab(QAction *act)
{
// data is in 0..9, 0 means 10th tab, but index starts from 0...
int page = act->data().toInt() - 1;
if (page == -1) {
page = 9;
}

if (page < tabWidget_->count()) {
tabWidget_->setCurrentPage(page);
}
}
2 changes: 0 additions & 2 deletions src/tabs/tabdlg.h
Expand Up @@ -118,7 +118,6 @@ public slots:
void optionsUpdate();
void detachTab(TabbableWidget*);
void sendTabTo(TabbableWidget*, TabDlg *);
void switchTab(QAction *act);

signals:
void resized(QSize size);
Expand Down Expand Up @@ -149,7 +148,6 @@ private slots:
QAction *act_close_;
QAction *act_next_;
QAction *act_prev_;
QActionGroup *tabSwitcher_;
TabManager *tabManager_;
QPointer<TabbableWidget> selectedTab_;
bool userManagement_;
Expand Down

0 comments on commit e4376c1

Please sign in to comment.