From e483886bcfcf7252af9ac7cc89de15f912bf69da Mon Sep 17 00:00:00 2001 From: axis Date: Tue, 9 Mar 2010 15:32:05 +0100 Subject: Fixed a bug where a proxy widget received FocusIn over and over. This also fixed the issue where an input panel would not be requested by the widget, because it thought it was being focused over and over, instead of focused, and then clicked (focus followed by click is default input panel popup behavior on Symbian). AutoTest: Included and passed RevBy: yoann RevBy: Jan-Arve --- src/gui/graphicsview/qgraphicsproxywidget.cpp | 5 ++++- src/gui/graphicsview/qgraphicsproxywidget_p.h | 1 + src/gui/kernel/qwidget.cpp | 2 ++ tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 12 ++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp index a39ccfd..483eb62 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.cpp +++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp @@ -1315,6 +1315,8 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event) return; } + d->proxyIsGivingFocus = true; + switch (event->reason()) { case Qt::TabFocusReason: { if (QWidget *focusChild = d->findFocusChild(0, true)) @@ -1328,10 +1330,11 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event) default: if (d->widget && d->widget->focusWidget()) { d->widget->focusWidget()->setFocus(event->reason()); - return; } break; } + + d->proxyIsGivingFocus = false; } /*! diff --git a/src/gui/graphicsview/qgraphicsproxywidget_p.h b/src/gui/graphicsview/qgraphicsproxywidget_p.h index 60eb058..8aed363 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget_p.h +++ b/src/gui/graphicsview/qgraphicsproxywidget_p.h @@ -118,6 +118,7 @@ public: quint32 styleChangeMode : 2; quint32 paletteChangeMode : 2; quint32 focusFromWidgetToProxy : 1; + quint32 proxyIsGivingFocus : 1; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index b5ccb3e..cd943cd 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -6123,6 +6123,8 @@ void QWidget::setFocus(Qt::FocusReason reason) previousProxyFocus = topData->proxyWidget->widget()->focusWidget(); if (previousProxyFocus && previousProxyFocus->focusProxy()) previousProxyFocus = previousProxyFocus->focusProxy(); + if (previousProxyFocus == this && !topData->proxyWidget->d_func()->proxyIsGivingFocus) + return; } } #endif diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 17311e2..23b3458 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3513,6 +3513,18 @@ void tst_QGraphicsProxyWidget::clickFocus() QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); QVERIFY(!proxy->hasFocus()); QVERIFY(!proxy->widget()->hasFocus()); + + // Multiple clicks should only result in one FocusIn. + proxy->widget()->setFocusPolicy(Qt::StrongFocus); + scene.setFocusItem(0); + QVERIFY(!proxy->hasFocus()); + QVERIFY(!proxy->widget()->hasFocus()); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + QVERIFY(proxy->hasFocus()); + QVERIFY(proxy->widget()->hasFocus()); + QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 1); + QCOMPARE(proxySpy.counts[QEvent::FocusIn], 1); } } -- cgit v0.12