diff options
Diffstat (limited to 'Swift/QtUI/Trellis')
-rw-r--r-- | Swift/QtUI/Trellis/QtDynamicGridLayout.cpp | 14 | ||||
-rw-r--r-- | Swift/QtUI/Trellis/QtDynamicGridLayout.h | 4 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp index e0bfa33..cc3208b 100644 --- a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp +++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp @@ -8,6 +8,8 @@ #include <cassert> +#include <QApplication> +#include <QEvent> #include <QLayoutItem> #include <QGridLayout> #include <QtDebug> @@ -23,6 +25,7 @@ QtDynamicGridLayout::QtDynamicGridLayout(QWidget* parent, bool enableDND) : QWid gridLayout_ = new QGridLayout(this); setContentsMargins(0,0,0,0); setDimensions(QSize(1,1)); + connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*,QWidget*))); } QtDynamicGridLayout::~QtDynamicGridLayout() { @@ -103,6 +106,17 @@ int QtDynamicGridLayout::indexOf(const QWidget* widget) const { return -1; } +void QtDynamicGridLayout::handleApplicationFocusChanged(QWidget*, QWidget* newFocus) { + if (newFocus) { + if (isAncestorOf(newFocus)) { + QtTabbable *newTab = dynamic_cast<QtTabbable*>(newFocus->parentWidget()); + if (newTab) { + onCurrentIndexChanged(currentIndex()); + } + } + } +} + int QtDynamicGridLayout::currentIndex() const { return indexOf(currentWidget()); } diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.h b/Swift/QtUI/Trellis/QtDynamicGridLayout.h index 3b798bd..616ee5e 100644 --- a/Swift/QtUI/Trellis/QtDynamicGridLayout.h +++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -47,6 +47,7 @@ namespace Swift { signals: void tabCloseRequested(int index); + void onCurrentIndexChanged(int newIndex); public slots: void setDimensions(const QSize& dim); @@ -62,6 +63,7 @@ namespace Swift { private slots: void handleTabCloseRequested(int index); void handleTabCurrentChanged(int index); + void handleApplicationFocusChanged(QWidget* oldFocus, QWidget* newFocus); private: void moveTab(QtTabWidget* tabWidget, int oldIndex, int newIndex); |