summaryrefslogtreecommitdiffstats
path: root/examples/declarative/tutorials/contacts/t8
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/tutorials/contacts/t8')
-rw-r--r--examples/declarative/tutorials/contacts/t8/Button.qml33
-rw-r--r--examples/declarative/tutorials/contacts/t8/Contact.qml80
-rw-r--r--examples/declarative/tutorials/contacts/t8/Field.qml54
-rw-r--r--examples/declarative/tutorials/contacts/t8/FieldRemover.qml57
-rw-r--r--examples/declarative/tutorials/contacts/t8/FieldText.qml89
-rw-r--r--examples/declarative/tutorials/contacts/t8/SearchBar.qml16
-rw-r--r--examples/declarative/tutorials/contacts/t8/contacts.qml133
7 files changed, 462 insertions, 0 deletions
diff --git a/examples/declarative/tutorials/contacts/t8/Button.qml b/examples/declarative/tutorials/contacts/t8/Button.qml
new file mode 100644
index 0000000..63c4636
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/Button.qml
@@ -0,0 +1,33 @@
+<Item width="30" height="30" id="button">
+ <properties>
+ <Property name="icon"/>
+ </properties>
+ <signals>
+ <Signal name="clicked"/>
+ </signals>
+ <Rect id="buttonRect" color="lightgreen" anchors.fill="{parent}" radius="5">
+ <Image id="iconImage"
+ src="{button.icon}"
+ anchors.horizontalCenter="{buttonRect.horizontalCenter}"
+ anchors.verticalCenter="{buttonRect.verticalCenter}"/>
+ <MouseRegion id="buttonMouseRegion" anchors.fill="{buttonRect}" onClicked="button.clicked.emit()"/>
+ <states>
+ <State name="pressed" when="{buttonMouseRegion.pressed == true}">
+ <SetProperty target="{buttonRect}" property="color" value="green"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="pressed">
+ <ColorAnimation duration="200"/>
+ </Transition>
+ <Transition fromState="pressed" toState="*">
+ <ColorAnimation duration="1000"/>
+ </Transition>
+ </transitions>
+ </Rect>
+ <opacity>
+ <Behaviour>
+ <NumericAnimation property="opacity" duration="250"/>
+ </Behaviour>
+ </opacity>
+</Item>
diff --git a/examples/declarative/tutorials/contacts/t8/Contact.qml b/examples/declarative/tutorials/contacts/t8/Contact.qml
new file mode 100644
index 0000000..5852b43
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/Contact.qml
@@ -0,0 +1,80 @@
+<Item id="contactDetails" anchors.fill="{parent}">
+ <properties>
+ <Property name="label" onValueChanged="c_label.value = label"/>
+ <Property name="contactid" value=""/>
+ <Property name="phone" onValueChanged="c_phone.value = phone"/>
+ <Property name="email" onValueChanged="c_email.value = email"/>
+ <Property name="mode" value="closed"/>
+ </properties>
+ <signals>
+ <Signal name="open"/>
+ <Signal name="close"/>
+ <Signal name="confirm"/>
+ <Signal name="cancel"/>
+ </signals>
+ <resources>
+ <SqlQuery id="updateContactQuery" connection="{contactDatabase}">
+ <query>UPDATE contacts SET label = :l, email = :e, phone = :p WHERE recid = :r</query>
+ <bindings>
+ <SqlBind name=":r" value="{contactid}"/>
+ <SqlBind name=":l" value="{c_label.value}"/>
+ <SqlBind name=":e" value="{c_email.value}"/>
+ <SqlBind name=":p" value="{c_phone.value}"/>
+ </bindings>
+ </SqlQuery>
+ <SqlQuery id="insertContactQuery" connection="{contactDatabase}">
+ <query>INSERT INTO contacts (label, email, phone) VALUES(:l, :e, :p)</query>
+ <bindings>
+ <SqlBind name=":l" value="{c_label.value}"/>
+ <SqlBind name=":e" value="{c_email.value}"/>
+ <SqlBind name=":p" value="{c_phone.value}"/>
+ </bindings>
+ </SqlQuery>
+ </resources>
+ <Connection sender="{contactDetails}" signal="cancel()">
+ c_label.value = label;
+ c_phone.value = phone;
+ c_email.value = email;
+ contactDetails.close.emit();
+ </Connection>
+ <Connection sender="{contactDetails}" signal="confirm()">
+ if (c_label.value != '') {
+ if (contactid == '') {
+ insertContactQuery.exec();
+ c_label.value = label;
+ c_phone.value = phone;
+ c_email.value = email;
+ } else {
+ updateContactQuery.exec();
+ }
+ contactList.exec();
+ }
+ contactDetails.close.emit();
+ </Connection>
+ <VerticalLayout id="layout" anchors.fill="{parent}" spacing="5" margin="5">
+ <Field id="c_label" label="Name"
+ editable="{mode == 'opened' ? 1 : 0}"
+ anchors.left="{layout.left}" anchors.leftMargin="5"
+ anchors.right="{layout.right}" anchors.rightMargin="5"/>
+ <Field id="c_phone" icon="../shared/pics/phone.png" label="Phone"
+ opacity="0" editable="{mode == 'opened' ? 1 : 0}"
+ anchors.left="{layout.left}" anchors.leftMargin="5"
+ anchors.right="{layout.right}" anchors.rightMargin="5"/>
+ <Field id="c_email" icon="../shared/pics/email.png" label="Email"
+ opacity="0" editable="{mode == 'opened' ? 1 : 0}"
+ anchors.left="{layout.left}" anchors.leftMargin="5"
+ anchors.right="{layout.right}" anchors.rightMargin="5"/>
+ </VerticalLayout>
+ <MouseRegion anchors.fill="{contactDetails}" onClicked="contactDetails.open.emit()" z="{mode=='opened' ? -1 : 1}"/>
+ <states>
+ <State name="opened" when="{mode == 'opened'}">
+ <SetProperty target="{c_phone}" property="opacity" value="1"/>
+ <SetProperty target="{c_email}" property="opacity" value="1"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="opened" reversible="true">
+ <NumericAnimation target="{contactFields}" properties="opacity" duration="200"/>
+ </Transition>
+ </transitions>
+</Item>
diff --git a/examples/declarative/tutorials/contacts/t8/Field.qml b/examples/declarative/tutorials/contacts/t8/Field.qml
new file mode 100644
index 0000000..0191ef8
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/Field.qml
@@ -0,0 +1,54 @@
+<Item height="30" width="200" id="field">
+ <properties>
+ <Property name="value" onValueChanged="fieldText.text=field.value"/>
+ <Property name="icon"/>
+ <Property name="editable" value="0"/>
+ <Property name="label"/>
+ </properties>
+ <Item id="fieldSelector" width="30" height="30"
+ x="0"
+ anchors.top="{parent.top}"
+ anchors.bottom="{parent.bottom}">
+ <Image src="{field.icon}"
+ anchors.verticalCenter="{parent.verticalCenter}"
+ anchors.horizontalCenter="{parent.horizontalCenter}"/>
+ </Item>
+ <FieldText id="fieldText"
+ label="{field.label}"
+ width="{field.width-70}"
+ anchors.left="{fieldSelector.right}"
+ anchors.leftMargin="5"
+ anchors.top="{parent.top}"
+ anchors.bottom="{parent.bottom}"
+ onTextEdited="field.value = fieldText.text"/>
+ <FieldRemover id="fieldRemover"
+ anchors.left="{fieldText.right}"
+ anchors.leftMargin="5"
+ anchors.top="{parent.top}"
+ anchors.bottom="{parent.bottom}"
+ onConfirm="fieldText.text = ''"
+ opacity="{field.editable}"/>
+ <states>
+ <State name="textFill" when="{fieldText.open == 'true'}">
+ <SetProperty target="{fieldText}" property="width" value="{field.width}"/>
+ <SetProperty target="{fieldText}" property="x" value="0"/>
+ <SetProperty target="{fieldRemover}" property="opacity" value="0"/>
+ <SetProperty target="{fieldSelector}" property="opacity" value="0"/>
+ <SetProperty target="{fieldSelector}" property="x" value="{-5-fieldSelector.width}"/>
+ </State>
+ <State name="removerFill" when="{fieldRemover.open == 'true'}">
+ <SetProperty target="{fieldRemover}" property="width" value="{field.width}"/>
+ <SetProperty target="{fieldRemover}" property="x" value="0"/>
+ <SetProperty target="{fieldText}" property="opacity" value="0"/>
+ <SetProperty target="{fieldSelector}" property="opacity" value="0"/>
+ <SetProperty target="{fieldSelector}" property="x" value="{-10-fieldText.width-fieldSelector.width}"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="*">
+ <NumericAnimation target="{fieldSelector}" properties="width,x,opacity" duration="200"/>
+ <NumericAnimation target="{fieldText}" properties="width,x,opacity" duration="200"/>
+ <NumericAnimation target="{fieldRemover}" properties="width,x,opacity" duration="200"/>
+ </Transition>
+ </transitions>
+</Item>
diff --git a/examples/declarative/tutorials/contacts/t8/FieldRemover.qml b/examples/declarative/tutorials/contacts/t8/FieldRemover.qml
new file mode 100644
index 0000000..a7dad64
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/FieldRemover.qml
@@ -0,0 +1,57 @@
+<Item height="30" width="30" id="fieldRemover" clip="true">
+ <properties>
+ <Property name="open" value="false"/>
+ </properties>
+ <signals>
+ <Signal name="confirm"/>
+ </signals>
+ <resources>
+ <Script>
+ function toggle() {
+ if (fieldRemover.state=='opened') {
+ fieldRemover.state='';
+ open='false';
+ Page.mouseGrabbed='false';
+ } else {
+ if (Page.mouseGrabbed != 'true') {
+ fieldRemover.state='opened';
+ open='true';
+ Page.mouseGrabbed='true';
+ }
+ }
+ }
+ </Script>
+ </resources>
+ <Rect id="border" anchors.fill="{parent}" color="red" radius="5"/>
+ <Image id="trashIcon" src="../shared/pics/trash.png"
+ width="22" height="22"
+ anchors.right="{parent.right}" anchors.rightMargin="4"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <Image id="cancelIcon" src="../shared/pics/cancel.png"
+ width="22" height="22" opacity="0"
+ anchors.right="{parent.right}" anchors.rightMargin="4"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <Image id="confirmIcon" src="../shared/pics/ok.png"
+ width="22" height="22" opacity="0"
+ anchors.left="{parent.left}" anchors.leftMargin="4"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <Text id="text" opacity="0" text="Remove" font.bold="true" color="white" hAlign="AlignHCenter"
+ anchors.verticalCenter="{parent.verticalCenter}"
+ anchors.left="{confirmIcon.right}" anchors.leftMargin="4"
+ anchors.right="{cancelIcon.left}" anchors.rightMargin="4"/>
+ <MouseRegion anchors.fill="{confirmIcon}" onClicked="toggle(); fieldRemover.confirm.emit()"/>
+ <MouseRegion anchors.fill="{trashIcon}" onClicked="toggle()"/>
+ <states>
+ <State name="opened">
+ <SetProperty target="{text}" property="opacity" value="1"/>
+ <SetProperty target="{confirmIcon}" property="opacity" value="1"/>
+ <SetProperty target="{cancelIcon}" property="opacity" value="1"/>
+ <SetProperty target="{trashIcon}" property="opacity" value="0"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="opened" reversible="true">
+ <NumericAnimation properties="opacity,x,width" duration="200"/>
+ </Transition>
+ </transitions>
+</Item>
diff --git a/examples/declarative/tutorials/contacts/t8/FieldText.qml b/examples/declarative/tutorials/contacts/t8/FieldText.qml
new file mode 100644
index 0000000..d3a158a
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/FieldText.qml
@@ -0,0 +1,89 @@
+<Item height="30" id="fieldText">
+ <properties>
+ <Property name="open" value="false"/>
+ <Property name="text" value="" onValueChanged="setText(fieldText.text)"/>
+ <Property name="label" value=""/>
+ </properties>
+ <signals>
+ <Signal name="textEdited"/>
+ </signals>
+ <resources>
+ <Script>
+ function start() {
+ if (Page.mouseGrabbed != 'true') {
+ fieldText.state='editing';
+ open='true';
+ Page.mouseGrabbed='true';
+ }
+ }
+ function confirm() {
+ fieldText.text = textEdit.text;
+ fieldText.state='';
+ open='false';
+ Page.mouseGrabbed='false';
+ fieldText.textEdited.emit();
+ }
+ function cancel() {
+ textEdit.text = fieldText.text;
+ fieldText.state='';
+ open='false';
+ Page.mouseGrabbed='false';
+ }
+ function setText(value) {
+ if (textEdit.text != value) {
+ fieldText.state='';
+ open='false';
+ textEdit.text = value;
+ }
+ }
+ </Script>
+ </resources>
+ <Rect id="border" radius="5" anchors.fill="{parent}" color="{field.editable == 1 ? '#202020' : '#000000'}">
+ <TextEdit id="textEdit" vAlign="AlignVCenter" text=""
+ readOnly="true" font.bold="true" wrap="false" color="white"
+ x="5" width="{parent.width-10}"
+ anchors.verticalCenter="{parent.verticalCenter}"
+ />
+ <Text id="textLabel" vAlign="AlignVCenter" hAlign="AlignHCenter"
+ color="#505050" font.italic="true"
+ anchors.fill="{border}" text="{fieldText.label}"
+ opacity="{textEdit.text == '' ? 1 : 0}">
+ <opacity>
+ <Behaviour>
+ <NumericAnimation target="{textLabel}" property="opacity" duration="250"/>
+ </Behaviour>
+ </opacity>
+ </Text>
+ <Image id="cancelIcon" src="../shared/pics/cancel.png"
+ width="22" height="22" opacity="0"
+ anchors.right="{parent.right}" anchors.rightMargin="4"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <Image id="confirmIcon" src="../shared/pics/ok.png"
+ width="22" height="22" opacity="0"
+ anchors.left="{parent.left}" anchors.leftMargin="4"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <MouseRegion anchors.fill="{cancelIcon}" onClicked="cancel()"/>
+ <MouseRegion anchors.fill="{confirmIcon}" onClicked="confirm()"/>
+ <MouseRegion id="editRegion" anchors.fill="{textEdit}" onClicked="start()"/>
+ </Rect>
+ <states>
+ <State name="editing">
+ <SetProperty target="{confirmIcon}" property="opacity" value="1"/>
+ <SetProperty target="{cancelIcon}" property="opacity" value="1"/>
+ <SetProperty target="{border}" property="color" value="white"/>
+ <SetProperty target="{textEdit}" property="color" value="black"/>
+ <SetProperty target="{textEdit}" property="readOnly" value="false"/>
+ <SetProperty target="{textEdit}" property="focus" value="true"/>
+ <SetProperty target="{textEdit}" property="x" value="35"/>
+ <SetProperty target="{editRegion}" property="opacity" value="0"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState='' toState="*" reversible="true">
+ <NumericAnimation target="{textEdit}" properties="x" duration="200"/>
+ <NumericAnimation target="{confirmIcon}" properties="opacity" duration="200"/>
+ <NumericAnimation target="{cancelIcon}" properties="opacity" duration="200"/>
+ <ColorAnimation duration="150"/>
+ </Transition>
+ </transitions>
+</Item>
diff --git a/examples/declarative/tutorials/contacts/t8/SearchBar.qml b/examples/declarative/tutorials/contacts/t8/SearchBar.qml
new file mode 100644
index 0000000..f8e1a6a
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/SearchBar.qml
@@ -0,0 +1,16 @@
+<Item height="30" width="{parent.width}">
+ <properties>
+ <Property name="text" value="{searchEdit.text}"/>
+ </properties>
+ <Rect color="white" anchors.fill="{parent}">
+ <Image id="searchIcon" src="../shared/pics/search.png"
+ anchors.left="{parent.left}" anchors.leftMargin="5"
+ anchors.verticalCenter="{parent.verticalCenter}"/>
+ <TextEdit id="searchEdit" focus="{Page.listShown == 1}"
+ anchors.left="{searchIcon.right}" anchors.right="{parent.right}"
+ anchors.leftMargin="5" anchors.rightMargin="5"
+ anchors.verticalCenter="{parent.verticalCenter}"
+ readOnly="false" wrap="false"/>
+ </Rect>
+</Item>
+
diff --git a/examples/declarative/tutorials/contacts/t8/contacts.qml b/examples/declarative/tutorials/contacts/t8/contacts.qml
new file mode 100644
index 0000000..f76ccfd
--- /dev/null
+++ b/examples/declarative/tutorials/contacts/t8/contacts.qml
@@ -0,0 +1,133 @@
+<Rect id="Page" color="black" width="240" height="320">
+ <properties>
+ <Property name="listShown" value="1"/>
+ <Property name="mode" value="list"/>
+ <Property name="mouseGrabbed" value="false"/>
+ </properties>
+ <resources>
+ <SqlConnection id="contactDatabase" name="qmlConnection" driver="QSQLITE" databaseName="../shared/contacts.sqlite"/>
+ <SqlQuery id="contactList" connection="{contactDatabase}">
+ <query>SELECT recid, label, email, phone FROM contacts WHERE lower(label) LIKE lower(:searchTerm) ORDER BY label, recid</query>
+ <bindings>
+ <SqlBind name=":searchTerm" value="{searchBar.text + '%' }"/>
+ </bindings>
+ </SqlQuery>
+ <Component id="contactDelegate">
+ <Item id="wrapper" x="0" width="{ListView.view.width}" height="34">
+ <Text id="label" x="45" y="12" text="{model.label}" color="white" font.bold="true" width="{parent.width-30}" opacity="{listShown}"/>
+ <Item id="Details" anchors.fill="{wrapper}">
+ <Bind target="{Details.qmlItem}" property="contactid" value="{model.recid}"/>
+ <Bind target="{Details.qmlItem}" property="mode" value="{wrapper.state}"/>
+ <Bind target="{Details.qmlItem}" property="label" value="{model.label}"/>
+ <Bind target="{Details.qmlItem}" property="phone" value="{model.phone}"/>
+ <Bind target="{Details.qmlItem}" property="email" value="{model.email}"/>
+ </Item>
+ <MouseRegion anchors.fill="{label}" opacity="{listShown}">
+ <onClicked>
+ Details.qml = 'Contact.qml';
+ wrapper.state='opened';
+ </onClicked>
+ </MouseRegion>
+ <states>
+ <State name='opened'>
+ <SetProperty target="{wrapper}" property="height" value="{contactListView.height}"/>
+ <SetProperty target="{contactListView}" property="yPosition" value="{wrapper.y}"/>
+ <SetProperty target="{contactListView}" property="locked" value="1"/>
+ <SetProperty target="{Details.qmlItem}" property="mode" value="opened"/>
+ <SetProperty target="{Page}" property="mode" value="editExisting"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition>
+ <NumericAnimation duration="500" properties="yPosition,height,opacity"/>
+ </Transition>
+ </transitions>
+ <Connection sender="{confirmEditButton}" signal="clicked()">
+ if (Details.qmlItem.mode == 'opened' &amp;&amp; Page.mouseGrabbed != 'true') {
+ Details.qmlItem.mode = 'closed';
+ wrapper.state = "";
+ Details.qmlItem.confirm.emit();
+ }
+ </Connection>
+ <Connection sender="{cancelEditButton}" signal="clicked()">
+ if (Details.qmlItem.mode == 'opened' &amp;&amp; Page.mouseGrabbed != 'true') {
+ Details.qmlItem.mode = 'closed';
+ wrapper.state = "";
+ Details.qmlItem.cancel.emit();
+ }
+ </Connection>
+ </Item>
+ </Component>
+ </resources>
+ <Button id="newContactButton" icon="../shared/pics/new.png"
+ anchors.top="{parent.top}" anchors.topMargin="5"
+ anchors.right="{parent.right}" anchors.rightMargin="5"
+ onClicked="newContactItem.label = ''; newContactItem.phone = ''; newContactItem.email = ''; Page.mode = 'editNew'"
+ opacity="{Page.mode == 'list' ? 1 : 0}"/>
+ <Button id="cancelEditButton" icon="../shared/pics/cancel.png"
+ anchors.top="{parent.top}" anchors.topMargin="5"
+ anchors.right="{parent.right}" anchors.rightMargin="5"
+ opacity="{Page.mode == 'list' || Page.mouseGrabbed == 'true' ? 0 : 1}"/>
+ <Button id="confirmEditButton" icon="../shared/pics/ok.png"
+ anchors.top="{parent.top}" anchors.topMargin="5"
+ anchors.left="{parent.left}" anchors.leftMargin="5"
+ opacity="{Page.mode == 'list' || Page.mouseGrabbed == 'true' ? 0 : 1}"/>
+ <FocusRealm id="searchBarRealm"
+ height="30"
+ anchors.bottom="{parent.bottom}"
+ anchors.left="{parent.left}" anchors.right="{parent.right}"
+ focus="{Page.mode == 'list' ? 'true' : 'false'}">
+ <SearchBar id="searchBar" anchors.fill="{parent}">
+ <states>
+ <State name="searchHidden" when="{searchBar.text == '' || Page.listShown == 0}">
+ <SetProperty target="{searchBarRealm}" property="anchors.bottomMargin" value="-30"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="*">
+ <NumericAnimation property="bottomMargin" duration="250"/>
+ </Transition>
+ </transitions>
+ </SearchBar>
+ </FocusRealm>
+ <ListView id="contactListView" model="{contactList}" delegate="{contactDelegate}"
+ anchors.top="{newContactButton.bottom}" anchors.topMargin="10"
+ anchors.left="{parent.left}" anchors.right="{parent.right}"
+ anchors.bottom="{searchBarRealm.top}"
+ clip="true"
+ focus="{Page.mode == 'list' ? 'false' : 'true'}"
+ />
+ <Contact id="newContactItem"
+ mode="opened"
+ anchors.top="{newContactButton.bottom}" anchors.topMargin="10"
+ anchors.left="{parent.left}" anchors.right="{parent.right}"
+ anchors.bottom="{searchBarRealm.top}"
+ onClose="Page.mode='list'"
+ opacity="0"
+ />
+ <Connection sender="{confirmEditButton}" signal="clicked()">
+ if (Page.mode == 'editNew' &amp;&amp; Page.mouseGrabbed != 'true') {
+ newContactItem.confirm.emit()
+ }
+ </Connection>
+ <Connection sender="{cancelEditButton}" signal="clicked()">
+ if (Page.mode == 'editNew' &amp;&amp; Page.mouseGrabbed != 'true') {
+ newContactItem.cancel.emit()
+ }
+ </Connection>
+ <states>
+ <State name="editExistingState" when="{Page.mode == 'editExisting'}">
+ <SetProperty target="{Page}" property="listShown" value="0"/>
+ </State>
+ <State name="editNewState" when="{Page.mode == 'editNew'}">
+ <SetProperty target="{Page}" property="listShown" value="0"/>
+ <SetProperty target="{contactListView}" property="opacity" value="0"/>
+ <SetProperty target="{newContactItem}" property="opacity" value="1"/>
+ </State>
+ </states>
+ <transitions>
+ <Transition fromState="*" toState="*">
+ <NumericAnimation property="opacity" duration="500"/>
+ </Transition>
+ </transitions>
+</Rect>