aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2011-08-16 11:48:14 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-18 00:24:09 +0200
commit74f3a67fe80fecf7ba2fd76e1758b6c0f68ce918 (patch)
tree1f50ac2696414113387da29de3213c9ed494ec68 /examples
parentdc5644758a2cdbe67111e3471488b89b1ddddd8c (diff)
Add attached properties to the positioners.
Added an attached property type to the base positioner class. This allows items within a positioner (Row, Column, Grid, Flow) to determine their index inside the positioner, as well as whether they are the first or last items. Non-visible items are ignored, as in the positioner layout objects themselves. It may be useful to expand this in the future to contain more information specific to the positioner, for example row/column for Grid. Task-number: QTBUG-19211 Change-Id: I10a8c9ca5528dd12811125cae8a9b4d2e3747972 Reviewed-on: http://codereview.qt.nokia.com/2983 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/positioners/positioners-attachedproperties.qml66
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/declarative/positioners/positioners-attachedproperties.qml b/examples/declarative/positioners/positioners-attachedproperties.qml
new file mode 100644
index 0000000000..49638683e4
--- /dev/null
+++ b/examples/declarative/positioners/positioners-attachedproperties.qml
@@ -0,0 +1,66 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 100
+
+ // Create row with four rectangles, the fourth one is hidden
+ Row {
+ id: row
+
+ Rectangle {
+ id: red
+ color: "red"
+ width: 100
+ height: 100
+
+ // When mouse is clicked, display the values of the positioner
+ MouseArea {
+ anchors.fill: parent
+ onClicked: row.showInfo(red.Positioner)
+ }
+ }
+
+ Rectangle {
+ id: green
+ color: "green"
+ width: 100
+ height: 100
+
+ // When mouse is clicked, display the values of the positioner
+ MouseArea {
+ anchors.fill: parent
+ onClicked: row.showInfo(green.Positioner)
+ }
+ }
+
+ Rectangle {
+ id: blue
+ color: "blue"
+ width: 100
+ height: 100
+
+ // When mouse is clicked, display the values of the positioner
+ MouseArea {
+ anchors.fill: parent
+ onClicked: row.showInfo(blue.Positioner)
+ }
+ }
+
+ // This rectangle is not visible, so it doesn't have a positioner value
+ Rectangle {
+ color: "black"
+ width: 100
+ height: 100
+ visible: false
+ }
+
+ // Print the index of the child item in the positioner and convenience
+ // properties showing if it's the first or last item.
+ function showInfo(positioner) {
+ console.log("Item Index = " + positioner.index)
+ console.log(" isFirstItem = " + positioner.isFirstItem)
+ console.log(" isLastItem = " + positioner.isLastItem)
+ }
+ }
+}