Skip to content
Permalink
Browse files

Merge PR #2411: MainWindow: allow using F6 to switch between MainWind…

…ow's main widgets.
  • Loading branch information...
mkrautz committed Jul 16, 2016
2 parents 0dcbf54 + 615fe7f commit 10abf3698526d7bae6ff459c1d576e555b2de8dc
Showing with 49 additions and 0 deletions.
  1. +47 −0 src/mumble/MainWindow.cpp
  2. +2 −0 src/mumble/MainWindow.h
@@ -503,6 +503,53 @@ void MainWindow::changeEvent(QEvent *e) {
}
}

void MainWindow::keyPressEvent(QKeyEvent *e) {
// Pressing F6 switches between the main
// window's main widgets, making it easier
// to navigate Mumble's MainWindow with only
// a keyboard.
if (e->key() == Qt::Key_F6) {
focusNextMainWidget();
} else {
QMainWindow::keyPressEvent(e);
}
}

/// focusNextMainWidget switches the focus to the next main
/// widget of the MainWindow.
///
/// This is used to implement behavior where pressing F6
/// switches between major elements of an application.
/// This behavior is for example seen in Windows's (File) Explorer.
///
/// The main widgets are qteLog (the log view), qteChat (chat input bar)
/// and qtvUsers (users tree view).
void MainWindow::focusNextMainWidget() {
QWidget *mainFocusWidgets[] = {
qteLog,
qteChat,
qtvUsers,
};
const int numMainFocusWidgets = sizeof(mainFocusWidgets)/sizeof(mainFocusWidgets[0]);

int currentMainFocusWidgetIndex = -1;

QWidget *w = focusWidget();
for (int i = 0; i < numMainFocusWidgets; i++) {
QWidget *mainFocusWidget = mainFocusWidgets[i];
if (w == mainFocusWidget || w->isAncestorOf(mainFocusWidget)) {
currentMainFocusWidgetIndex = i;
break;
}
}

Q_ASSERT(currentMainFocusWidgetIndex != -1);

int nextMainFocusWidgetIndex = (currentMainFocusWidgetIndex + 1) % numMainFocusWidgets;
QWidget *nextMainFocusWidget = mainFocusWidgets[nextMainFocusWidgetIndex];
nextMainFocusWidget->setFocus();
}

void MainWindow::updateTrayIcon() {
ClientUser *p=ClientUser::get(g.uiSession);

@@ -116,6 +116,7 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
void setOnTop(bool top);
void setShowDockTitleBars(bool doShow);
void updateTrayIcon();
void focusNextMainWidget();
void updateTransmitModeComboBox();
QPair<QByteArray, QImage> openImageFile();

@@ -168,6 +169,7 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
void hideEvent(QHideEvent *e) Q_DECL_OVERRIDE;
void showEvent(QShowEvent *e) Q_DECL_OVERRIDE;
void changeEvent(QEvent* e) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;

QMenu *createPopupMenu() Q_DECL_OVERRIDE;

0 comments on commit 10abf36

Please sign in to comment.
You can’t perform that action at this time.