From db629b2b0aca1437eca89002331d665a16670695 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jens.bache-wiig@nokia.com> Date: Mon, 16 May 2011 21:35:26 +0200 Subject: [PATCH] Some refactoring of examples --- components/TableView.qml | 1 - examples/Gallery.qml | 1 + examples/ItemViewGallery.qml | 112 ++++++++++++++++++++++++------- examples/{ => content}/Panel.qml | 6 +- 4 files changed, 91 insertions(+), 29 deletions(-) rename examples/{ => content}/Panel.qml (96%) diff --git a/components/TableView.qml b/components/TableView.qml index 3b958df1e..22de87e57 100644 --- a/components/TableView.qml +++ b/components/TableView.qml @@ -95,7 +95,6 @@ FocusScope{ Component { id: standardDelegate Item { - clip: true property int implicitWidth: sizehint.paintedWidth + 4 Text { width: parent.width diff --git a/examples/Gallery.qml b/examples/Gallery.qml index 77f03554b..6f3a73eab 100644 --- a/examples/Gallery.qml +++ b/examples/Gallery.qml @@ -1,5 +1,6 @@ import QtQuick 1.0 import "../components" +import "content" Rectangle { diff --git a/examples/ItemViewGallery.qml b/examples/ItemViewGallery.qml index 906c8082d..ff3565513 100644 --- a/examples/ItemViewGallery.qml +++ b/examples/ItemViewGallery.qml @@ -11,21 +11,21 @@ Rectangle { width: parent.width height: 40 - ContextMenu { - id: editmenu - model: ListModel { - id: menu - ListElement { text: "Copy" } - ListElement { text: "Cut" } - ListElement { text: "Paste" } - } - } MouseArea { anchors.fill: parent acceptedButtons: Qt.RightButton onPressed: editmenu.show(mouseX, mouseY) } + ChoiceList { + id: delegateChooser + enabled: frame.current == 3 ? 1 : 0 + model: delegatemenu + anchors.left: parent.left + anchors.leftMargin: 8 + anchors.verticalCenter: parent.verticalCenter + } + CheckBox { id: enabledCheck text: "Enabled" @@ -39,10 +39,6 @@ Rectangle { QStyleItem{ id: styleitem} color: syspal.window - - - - XmlListModel { id: flickerModel source: "http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&tags=" + "Qt" @@ -76,8 +72,8 @@ Rectangle { ListModel { id: largeModel Component.onCompleted: { - for (var i=0 ; i< 500 ; ++i) - largeModel.append({"name":"Person "+i , "age": Math.round(Math.random()*100)}) + for (var i=0 ; i< 80 ; ++i) + largeModel.append({"name":"Person "+i , "age": Math.round(Math.random()*100), "sex": Math.random()>0.5 ? "Male" : "Female"}) } } @@ -188,6 +184,69 @@ Rectangle { Tab { title: "Custom delegate" + ListModel { + id: delegatemenu + ListElement { text: "Gray" } + ListElement { text: "hover" } + ListElement { text: "Apple" } + ListElement { text: "Coconut" } + } + + + Component { + id: delegate1 + Item { + clip: true + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: itemElideMode + text: itemValue ? itemValue : "" + color: itemForeground + } + } + } + + Component { + id: delegate2 + Item { + height: itemSelected? 60 : 20 + Behavior on height{ NumberAnimation{}} + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: itemElideMode + text: itemValue ? itemValue : "" + color: itemForeground + } + } + } + + Component { + id: delegate3 + Item { + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: itemElideMode + text: itemValue ? itemValue : "" + color: itemForeground + visible: columnIndex == 0 + } + TextInput{ + color:"#333" + anchors.fill: parent + anchors.margins: 4 + visible: columnIndex == 1 + } + } + } TableView { model: largeModel anchors.margins: 12 @@ -207,6 +266,11 @@ Rectangle { caption: "Age" width: 120 } + TableColumn { + property: "sex" + caption: "Sex" + width: 120 + } headerDelegate: Rectangle { color: "#555" @@ -233,16 +297,14 @@ Rectangle { } } - itemDelegate: Item { - clip: true - Text { - width: parent.width - anchors.margins: 4 - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - elide: itemElideMode - text: itemValue ? itemValue : "" - color: itemForeground + itemDelegate: { + switch(delegateChooser.currentIndex) { + case 0: + return delegate1 + case 1: + return delegate2 + case 2: + return delegate3 } } } diff --git a/examples/Panel.qml b/examples/content/Panel.qml similarity index 96% rename from examples/Panel.qml rename to examples/content/Panel.qml index 178643a90..358b5749d 100644 --- a/examples/Panel.qml +++ b/examples/content/Panel.qml @@ -1,5 +1,5 @@ import QtQuick 1.0 -import "../components" +import "../../components" Rectangle { id:root @@ -16,7 +16,7 @@ Rectangle { height:600 BorderImage { id: page - source: "images/page.png" + source: "../images/page.png" y:10; x:50 width: 400; height: 400 border.left: 12; border.top: 12 @@ -39,7 +39,7 @@ Rectangle { BorderImage { id: sidebar - source: "images/panel.png" + source: "../images/panel.png" anchors.left: parent.left anchors.top: parent.top width: show ? 160 : 40 -- GitLab