diff options
Diffstat (limited to 'Swift/QtUI/Trellis/QtDynamicGridLayout.cpp')
-rw-r--r-- | Swift/QtUI/Trellis/QtDynamicGridLayout.cpp | 14 |
1 files changed, 14 insertions, 0 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 @@ -5,12 +5,14 @@ */ #include <Swift/QtUI/Trellis/QtDynamicGridLayout.h> #include <cassert> +#include <QApplication> +#include <QEvent> #include <QLayoutItem> #include <QGridLayout> #include <QtDebug> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtTabbable.h> @@ -20,12 +22,13 @@ namespace Swift { QtDynamicGridLayout::QtDynamicGridLayout(QWidget* parent, bool enableDND) : QWidget(parent), dndEnabled_(enableDND) { 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() { } int QtDynamicGridLayout::addTab(QtTabbable* tab, const QString& title) { @@ -100,12 +103,23 @@ 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()); } void QtDynamicGridLayout::setCurrentIndex(int index) { int tabIndex = -1; |