summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@digia.com>2013-03-21 14:09:03 +0100
committerGunnar Sletta <gunnar.sletta@digia.com>2013-03-21 14:20:45 +0100
commit99e03780797c3097004d1ce91980ce9c20322c58 (patch)
treee651f92d35e916a29696dc6068bc8e3161445b85
parent14f3db5ccd9edd72b14dbe650fd93cfeb971e998 (diff)
Testcase for text input
-rw-r--r--basicsuite/Text Input/ScrollBar.qml66
-rw-r--r--basicsuite/Text Input/TextArea.qml88
-rw-r--r--basicsuite/Text Input/TextBase.qml95
-rw-r--r--basicsuite/Text Input/TextField.qml93
-rw-r--r--basicsuite/Text Input/background.pngbin0 -> 34931 bytes
-rw-r--r--basicsuite/Text Input/main.qml122
6 files changed, 464 insertions, 0 deletions
diff --git a/basicsuite/Text Input/ScrollBar.qml b/basicsuite/Text Input/ScrollBar.qml
new file mode 100644
index 0000000..e6a8143
--- /dev/null
+++ b/basicsuite/Text Input/ScrollBar.qml
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Item {
+ property var scrollArea: parent
+
+ width: 6
+ opacity: scrollArea && scrollArea.movingVertically ? 1.0 : 0.0
+ visible: scrollArea && scrollArea.contentHeight >= scrollArea.height
+ anchors { right: parent.right; top: parent.top; bottom: parent.bottom; margins: 2 }
+
+ Behavior on opacity { NumberAnimation { properties: "opacity"; duration: 600 } }
+
+ function size() {
+ var nh = scrollArea.visibleArea.heightRatio * height
+ var ny = scrollArea.visibleArea.yPosition * height
+ return ny > 3 ? Math.min(nh, Math.ceil(height - 3 - ny)) : nh + ny
+ }
+ Rectangle {
+ x: 1
+ y: scrollArea ? Math.max(2, scrollArea.visibleArea.yPosition * parent.height) : 0
+ height: scrollArea ? size() : 0
+ width: parent.width - 2
+ color: Qt.rgba(1.0, 1.0, 1.0, 0.5)
+ radius: 1
+ }
+}
diff --git a/basicsuite/Text Input/TextArea.qml b/basicsuite/Text Input/TextArea.qml
new file mode 100644
index 0000000..cf337f6
--- /dev/null
+++ b/basicsuite/Text Input/TextArea.qml
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+TextBase {
+ id: textArea
+
+ property alias color: textEdit.color
+ property alias text: textEdit.text
+ property alias textWidth: textEdit.width
+ property alias readOnly: textEdit.readOnly
+ property alias inputMethodHints: textEdit.inputMethodHints
+
+ editor: textEdit
+
+ Repeater {
+ model: Math.floor((parent.height - 30) / editor.cursorRectangle.height)
+ Rectangle {
+ x: 8
+ y: (index+1)*editor.cursorRectangle.height+6
+ height: 1; width: textArea.width-24
+ color: Qt.rgba(1.0, 1.0, 1.0, 0.5)
+ }
+ }
+ TextEdit {
+ id: textEdit
+
+ property alias enterKeyText: textArea.enterKeyText
+ property alias enterKeyEnabled: textArea.enterKeyEnabled
+
+ y: 6
+ focus: true
+ color: "#EEEEEE"
+ wrapMode: TextEdit.Wrap
+ cursorVisible: activeFocus
+ height: Math.max(implicitHeight, 60)
+ font.pixelSize: textArea.fontPixelSize
+ selectionColor: Qt.rgba(1.0, 1.0, 1.0, 0.5)
+ selectedTextColor: Qt.rgba(0.0, 0.0, 0.0, 0.8)
+ anchors { left: parent.left; right: parent.right; margins: 12 }
+ cursorDelegate: Rectangle {
+ width: 2
+ opacity: 0.7
+ color: "#EEEEEE"
+ visible: textEdit.activeFocus
+ }
+
+ onActiveFocusChanged: if (!activeFocus) deselect()
+ }
+}
diff --git a/basicsuite/Text Input/TextBase.qml b/basicsuite/Text Input/TextBase.qml
new file mode 100644
index 0000000..a26c6c6
--- /dev/null
+++ b/basicsuite/Text Input/TextBase.qml
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+FocusScope {
+ id: textBase
+
+ property var editor
+ property bool previewTextActive: !editor.activeFocus && text.length === 0
+ property int fontPixelSize: 32
+ property string previewText
+ property string enterKeyText
+ property bool enterKeyEnabled: true
+ property alias mouseParent: mouseArea.parent
+
+ implicitHeight: editor.height + 12
+
+ signal enterKeyClicked
+
+ Keys.onReleased: {
+ if (event.key === Qt.Key_Return)
+ enterKeyClicked()
+ }
+
+ Rectangle {
+ // background
+ radius: 5.0
+ anchors.fill: parent
+ color: Qt.rgba(1.0, 1.0, 1.0, 0.2)
+ border { width: editor.activeFocus ? 2 : 0; color: "#CCCCCC" }
+ }
+ Text {
+ id: previewText
+
+ y: 8
+ color: "#CCCCCC"
+ visible: previewTextActive
+ text: textBase.previewText
+ font.pixelSize: 28
+ anchors { left: parent.left; right: parent.right; margins: 12 }
+
+ }
+ MouseArea {
+ id: mouseArea
+
+ z: 1
+ parent: textBase
+ anchors.fill: parent
+ onClicked: {
+ var positionInEditor = mapToItem(editor, mouseX, mouseY)
+ var cursorPosition = editor.positionAt(positionInEditor.x, positionInEditor.y)
+ editor.cursorPosition = cursorPosition
+ editor.forceActiveFocus()
+ Qt.inputMethod.show()
+ }
+ }
+}
diff --git a/basicsuite/Text Input/TextField.qml b/basicsuite/Text Input/TextField.qml
new file mode 100644
index 0000000..aa6768e
--- /dev/null
+++ b/basicsuite/Text Input/TextField.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+TextBase {
+ id: textField
+
+ property alias color: textInput.color
+ property alias text: textInput.text
+ property alias textWidth: textInput.width
+ property alias readOnly: textInput.readOnly
+ property alias inputMethodHints: textInput.inputMethodHints
+ property alias validator: textInput.validator
+ property alias echoMode: textInput.echoMode
+
+ editor: textInput
+ mouseParent: flickable
+
+ Flickable {
+ id: flickable
+
+ x: 12
+ clip: true
+ width: parent.width-24
+ height: parent.height
+ flickableDirection: Flickable.HorizontalFlick
+ interactive: contentWidth - 4 > width
+
+ contentWidth: textInput.width+2
+ contentHeight: textInput.height
+ TextInput {
+ id: textInput
+
+ property alias enterKeyText: textField.enterKeyText
+ property alias enterKeyEnabled: textField.enterKeyEnabled
+
+ y: 6
+ focus: true
+ color: "#EEEEEE"
+ cursorVisible: activeFocus
+ passwordCharacter: "\u2022"
+ font.pixelSize: textField.fontPixelSize
+ selectionColor: Qt.rgba(1.0, 1.0, 1.0, 0.5)
+ selectedTextColor: Qt.rgba(0.0, 0.0, 0.0, 0.8)
+ width: Math.max(flickable.width, implicitWidth)-2
+ cursorDelegate: Rectangle {
+ width: 2
+ opacity: 0.7
+ color: "#EEEEEE"
+ visible: textInput.activeFocus
+ }
+ onActiveFocusChanged: if (!activeFocus) deselect()
+ }
+ }
+}
diff --git a/basicsuite/Text Input/background.png b/basicsuite/Text Input/background.png
new file mode 100644
index 0000000..d85f6ee
--- /dev/null
+++ b/basicsuite/Text Input/background.png
Binary files differ
diff --git a/basicsuite/Text Input/main.qml b/basicsuite/Text Input/main.qml
new file mode 100644
index 0000000..13bb669
--- /dev/null
+++ b/basicsuite/Text Input/main.qml
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.virtualkeyboard 1.0
+
+Image {
+ source: "background.png"
+
+ Flickable {
+ id: flickable
+
+ property real scrollMarginVertical: 20
+
+ width: parent.width
+ contentWidth: content.width
+ contentHeight: content.height
+ interactive: contentHeight > height
+ height: Qt.inputMethod.keyboardRectangle.y
+ flickableDirection: Flickable.VerticalFlick
+ children: ScrollBar {}
+
+ MouseArea {
+ id: content
+
+ width: flickable.width
+ height: textEditors.height + 24
+
+ onClicked: {
+ if (Qt.inputMethod.inputItem)
+ Qt.inputMethod.inputItem.focus = false
+ }
+
+ Column {
+ id: textEditors
+ spacing: 15
+ x: 12; y: 12
+ width: parent.width - 26
+
+ Text {
+ color: "#EEEEEE"
+ text: "Tap fields to enter text"
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pixelSize: 22
+ }
+ TextField {
+ width: parent.width
+ previewText: "One line field"
+ enterKeyText: "Next"
+ enterKeyEnabled: text.length > 0
+ onEnterKeyClicked: passwordField.focus = true
+ }
+ TextField {
+ id: passwordField
+
+ width: parent.width
+ echoMode: TextInput.PasswordEchoOnEdit
+ previewText: "Password field"
+ inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText
+ enterKeyText: "Next"
+ enterKeyEnabled: text.length > 0
+ onEnterKeyClicked: numberField.focus = true
+ }
+ TextField {
+ id: numberField
+
+ validator: RegExpValidator { regExp: /^[0-9\+\-\#\*\ ]{6,}$/ }
+ width: parent.width
+ previewText: "Phone number field"
+ inputMethodHints: Qt.ImhDialableCharactersOnly
+ enterKeyText: "Next"
+ enterKeyEnabled: text.length > 0
+ onEnterKeyClicked: textArea.focus = true
+ }
+ TextArea {
+ id: textArea
+
+ width: parent.width
+ previewText: "Multiple lines field"
+ height: Math.max(206, implicitHeight)
+ }
+ }
+ }
+ }
+}