From ee9eff16cd7024bdbd889bab7612c63bcfe3cbe9 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 25 May 2010 20:56:36 +0100 Subject: Support Ctrl-PgUp/PgDn for switch ing tabs diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index d327e7c..a7698c2 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -51,6 +51,8 @@ void QtChatTabs::addTab(QtTabbable* tab) { connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing())); connect(tab, SIGNAL(windowOpening()), this, SLOT(handleWidgetShown())); connect(tab, SIGNAL(wantsToActivate()), this, SLOT(handleWantsToActivate())); + connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab())); + connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab())); } void QtChatTabs::handleWidgetShown() { @@ -95,6 +97,18 @@ void QtChatTabs::handleTabClosing() { handleTabTitleUpdated(tabs_->currentWidget()); } +void QtChatTabs::handleRequestedPreviousTab() { + int newIndex = tabs_->currentIndex() - 1; + tabs_->setCurrentIndex(newIndex >= 0 ? newIndex : tabs_->count() - 1); +} + +void QtChatTabs::handleRequestedNextTab() { + int newIndex = tabs_->currentIndex() + 1; + tabs_->setCurrentIndex(newIndex < tabs_->count() ? newIndex : 0); + +} + + void QtChatTabs::handleTabCloseRequested(int index) { QWidget* widget = tabs_->widget(index); widget->close(); diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h index 84d9dbc..41d7b2f0 100644 --- a/Swift/QtUI/QtChatTabs.h +++ b/Swift/QtUI/QtChatTabs.h @@ -35,6 +35,9 @@ namespace Swift { void handleTabCloseRequested(int index); void handleWidgetShown(); void handleWantsToActivate(); + void handleRequestedPreviousTab(); + void handleRequestedNextTab(); + private: void checkForFirstShow(); QtTabWidget* tabs_; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 2f85571..544efd3 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -83,10 +83,18 @@ QtChatWindow::~QtChatWindow() { void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { int key = event->key(); Qt::KeyboardModifiers modifiers = event->modifiers(); - if ( - (key == Qt::Key_W && modifiers == Qt::ControlModifier) - ) { + if (key == Qt::Key_W && modifiers == Qt::ControlModifier) { close(); + } else if ( + (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier) + || (key == Qt::Key_Left && modifiers == (Qt::ControlModifier & Qt::ShiftModifier)) + ) { + emit requestPreviousTab(); + } else if ( + (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier) + || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier & Qt::ShiftModifier)) + ) { + emit requestNextTab(); } else { messageLog_->handleKeyPressEvent(event); } diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h index 63bc140..dd87142 100644 --- a/Swift/QtUI/QtTabbable.h +++ b/Swift/QtUI/QtTabbable.h @@ -25,5 +25,7 @@ namespace Swift { void windowClosing(); void windowOpening(); void wantsToActivate(); + void requestPreviousTab(); + void requestNextTab(); }; } diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index a5fe762..451a18c 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -24,7 +24,12 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { emit returnPressed(); } else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier) || (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty()) - || (key == Qt::Key_W && modifiers == Qt::ControlModifier)) { + || (key == Qt::Key_W && modifiers == Qt::ControlModifier) + || (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier) + || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier) + || (key == Qt::Key_Left && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) + || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) + ) { emit unhandledKeyPressEvent(event); } else { QTextEdit::keyPressEvent(event); -- cgit v0.10.2-6-g49f6