summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-08-26 11:48:18 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-08-27 03:42:14 (GMT)
commit928e81b68e0b695662c7ee3dd0bfa409a7ca1ffd (patch)
treed6e02b3a6de3f003c23cc46e4b9687bd990e02ca /examples
parentbaeb25062194c9ddc36c4536662de46b6b09cd68 (diff)
downloadQt-928e81b68e0b695662c7ee3dd0bfa409a7ca1ffd.zip
Qt-928e81b68e0b695662c7ee3dd0bfa409a7ca1ffd.tar.gz
Qt-928e81b68e0b695662c7ee3dd0bfa409a7ca1ffd.tar.bz2
Implement Focus Scope support in GraphicsView
Focus Scopes are an additional focus paradigm, designed to be more suitable for use by declarative UI. With focus scopes, graphics view continues to have a single focused item - this is the single item to which key events are *actually* delivered. To simplify the description that follows, we will say that this element has "global focus". Focus scopes partitions focus into a heirarchy. Each focus scope may have one sub-focused item, which may itself be another focus scope. The sub-focused item is said to be have "scope focus" or its ancestor focus scope. Consequently, any given QGraphicsItem may be globally focused, scope focused (which means it is focused within its ancestor focus scope) or both. A focus scope corresponds to a QGraphicsItem with the ItemIsFocusScope flag set. As graphics view doesn't have a single root item, a "virtual" focus scope is modeled as being the ancestor of all the root items. With focus scopes, when QGraphicsItem::setFocus() is called, the item's ancestors are searched until a focus scope is found (remembering the "virtual" root focus scope is used if there is no *actual* ancestor scope). The item is set as the sub-focused item of the focus scope (becoming focus scoped) and any existing sub-focused item of that focus scope has scope focus removed from it. The item that receives global focus is found by beginning at the "virtual" root focus scope and recursively decending into each item that is scope focused until a leaf (non-focus scope) item is reached. The implementation takes shortcuts here to be slightly more optimal, but the end result should be the same as though this abstract algorithm was evaluated each time. Two manual examples of focus scope are found under examples/declarative/focusscope
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/focusscope/test.qml76
-rw-r--r--examples/declarative/focusscope/test2.qml40
2 files changed, 116 insertions, 0 deletions
diff --git a/examples/declarative/focusscope/test.qml b/examples/declarative/focusscope/test.qml
new file mode 100644
index 0000000..22ffc8d
--- /dev/null
+++ b/examples/declarative/focusscope/test.qml
@@ -0,0 +1,76 @@
+import Qt 4.6
+
+Rectangle {
+ color: "white"
+ width: 800
+ height: 600
+
+ Keys.onDigit9Pressed: print("Error - Root")
+
+ FocusScope {
+ id: MyScope
+ focus: true
+
+ Keys.onDigit9Pressed: print("Error - FocusScope")
+
+ Rectangle {
+ height: 120
+ width: 420
+
+ color: "transparent"
+ border.width: 5
+ border.color: MyScope.focus?"blue":"black"
+
+ Rectangle {
+ id: Item1
+ x: 10; y: 10
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: focus?"blue":"black"
+ Keys.onDigit9Pressed: print("Top Left");
+ KeyNavigation.right: Item2
+ focus: true
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.activeFocus?"red":"transparent"
+ }
+ }
+
+ Rectangle {
+ id: Item2
+ x: 310; y: 10
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: focus?"blue":"black"
+ KeyNavigation.left: Item1
+ Keys.onDigit9Pressed: print("Top Right");
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.activeFocus?"red":"transparent"
+ }
+ }
+ }
+ KeyNavigation.down: Item3
+ }
+
+ Text { x:100; y:170; text: "Blue border indicates scoped focus\nBlack border indicates NOT scoped focus\nRed box indicates active focus\nUse arrow keys to navigate\nPress \"9\" to print currently focused item" }
+
+ Rectangle {
+ id: Item3
+ x: 10; y: 300
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: focus?"blue":"black"
+
+ Keys.onDigit9Pressed: print("Bottom Left");
+ KeyNavigation.up: MyScope
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.activeFocus?"red":"transparent"
+ }
+ }
+
+}
diff --git a/examples/declarative/focusscope/test2.qml b/examples/declarative/focusscope/test2.qml
new file mode 100644
index 0000000..0ac0f5d
--- /dev/null
+++ b/examples/declarative/focusscope/test2.qml
@@ -0,0 +1,40 @@
+import Qt 4.6
+
+Rectangle {
+ color: "white"
+ width: 800
+ height: 600
+
+ Text { text: "All five rectangles should be red" }
+
+ FocusScope {
+ y: 100
+ focus: true
+ Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" }
+
+ FocusScope {
+ y: 100
+ focus: true
+ Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" }
+
+ FocusScope {
+ y: 100
+ focus: true
+ Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" }
+
+ FocusScope {
+ y: 100
+ focus: true
+ Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" }
+
+ FocusScope {
+ y: 100
+ focus: true
+ Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" }
+ }
+ }
+ }
+ }
+ }
+
+}