From 219e2fa7ace74d87fda4ed8c3a2a75005fab10b9 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 27 Aug 2009 14:43:46 +1000 Subject: Fixup 928e81b68e0b695662c7ee3dd0bfa409a7ca1ffd I messed up when I reapplied this patch to the branch head. This also adds an extra test for the case fixed. --- examples/declarative/focusscope/test3.qml | 50 +++++++++++++++++++++++++++++++ src/gui/graphicsview/qgraphicsscene.cpp | 18 ++--------- 2 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 examples/declarative/focusscope/test3.qml diff --git a/examples/declarative/focusscope/test3.qml b/examples/declarative/focusscope/test3.qml new file mode 100644 index 0000000..51fa35a --- /dev/null +++ b/examples/declarative/focusscope/test3.qml @@ -0,0 +1,50 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 800 + height: 600 + + ListModel { + id: Model + ListElement { name: "1" } + ListElement { name: "2" } + ListElement { name: "3" } + ListElement { name: "4" } + ListElement { name: "5" } + ListElement { name: "6" } + ListElement { name: "6" } + ListElement { name: "8" } + ListElement { name: "9" } + } + + Component { + id: VerticalDelegate + FocusScope { + id: Root + width: 50; height: 50; + Keys.onDigit9Pressed: print("Error - " + name) + Rectangle { + focus: true + Keys.onDigit9Pressed: print(name) + width: 50; height: 50; + color: Root.ListView.isCurrentItem?"red":"green" + Text { text: name; anchors.centerIn: parent } + } + } + } + + ListView { + width: 800; height: 50; orientation: "Horizontal" + focus: true + model: Model + delegate: VerticalDelegate + currentItemPositioning: "SnapAuto" + } + + + Text { + y: 100; x: 50 + text: "Currently selected element should be red\nPressing \"9\" should print the number of the currently selected item\nBe sure to scroll all the way to the right, pause, and then all the way to the left." + } +} diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 73dba7b..af137e7 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -602,7 +602,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, QGraphicsItem *oldRootLevelFocusItem = focusItem->d_ptr->rootLevelFocusItem(); - if (oldRootLevelFocusItem != itemRootLevelFocusItem) + if (oldRootLevelFocusItem != itemRootLevelFocusItem) oldRootLevelFocusItem->d_ptr->setItemFocusedInScope(false); focusItem = 0; @@ -2374,22 +2374,10 @@ void QGraphicsScenePrivate::addItem(QGraphicsItem *item, // Ensure that newly added items that have subfocus set, gain // focus automatically if there isn't a focus item already. - if (!focusItem && item->focusItem()) + if (!focusItem && item->focusItem() || + focusScope && !focusScope->d_ptr->focusScopeItem && item->focusItem()) item->focusItem()->setFocus(); - // Ensure that focus scopes set themselves up at add time - if (item->d_ptr->itemIsFocusedInScope) { - if (focusScope && !focusScope->d_ptr->focusScopeItem) { - item->setFocus(); - } else if (!(focusScope && focusScope->d_ptr->focusScopeItem == item) && - !(focusItem && focusItem->d_ptr->rootLevelFocusItem() == item)) { - // We unset the focused in scope variable in this item if: - // It's not scope focused in the closest focus scope, and - // It's not the root-level item for the globally focused item - item->d_ptr->setItemFocusedInScope(false); - } - } - updateInputMethodSensitivityInViews(); } -- cgit v0.12