Move demos to qtdoc repository

These demos use several modules and moving them allows to use for
example Qt Quick Controls 2 in them.

The shared directory should be removed and the examples made
self-contained.

Change-Id: I5dc667d22388651894d7d145b65752bc5c5cf6cf
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Venugopal Shivashankar 2018-06-26 15:53:07 +02:00 committed by Frederik Gladhorn
parent 230db034cf
commit 70ce5f4d3e
349 changed files with 18893 additions and 26 deletions

View File

@ -82,7 +82,7 @@ sourcedirs += \
exampledirs += \
../src \
../snippets \
../../examples/demos
../../examples
# Don't parse files in snippets directory
excludedirs += \

View File

@ -0,0 +1,19 @@
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp
RESOURCES += calqlatr.qrc \
../../shared/shared.qrc
OTHER_FILES = calqlatr.qml \
content/Button.qml \
content/Display.qml \
content/NumberPad.qml \
content/calculator.js \
content/images/paper-edge-left.png \
content/images/paper-edge-right.png \
content/images/paper-grip.png
target.path = $$[QT_INSTALL_EXAMPLES]/demos/calqlatr
INSTALLS += target

View File

@ -0,0 +1,173 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 "content"
import "content/calculator.js" as CalcEngine
Rectangle {
id: window
width: 320
height: 480
focus: true
color: "#272822"
onWidthChanged: controller.reload()
onHeightChanged: controller.reload()
function operatorPressed(operator) {
CalcEngine.operatorPressed(operator)
numPad.buttonPressed()
}
function digitPressed(digit) {
CalcEngine.digitPressed(digit)
numPad.buttonPressed()
}
function isButtonDisabled(op) {
return CalcEngine.disabled(op)
}
Item {
id: pad
width: 180
NumberPad { id: numPad; y: 10; anchors.horizontalCenter: parent.horizontalCenter }
}
AnimationController {
id: controller
animation: ParallelAnimation {
id: anim
NumberAnimation { target: display; property: "x"; duration: 400; from: -16; to: window.width - display.width; easing.type: Easing.InOutQuad }
NumberAnimation { target: pad; property: "x"; duration: 400; from: window.width - pad.width; to: 0; easing.type: Easing.InOutQuad }
SequentialAnimation {
NumberAnimation { target: pad; property: "scale"; duration: 200; from: 1; to: 0.97; easing.type: Easing.InOutQuad }
NumberAnimation { target: pad; property: "scale"; duration: 200; from: 0.97; to: 1; easing.type: Easing.InOutQuad }
}
}
}
Keys.onPressed: {
if (event.key == Qt.Key_0)
digitPressed("0")
else if (event.key == Qt.Key_1)
digitPressed("1")
else if (event.key == Qt.Key_2)
digitPressed("2")
else if (event.key == Qt.Key_3)
digitPressed("3")
else if (event.key == Qt.Key_4)
digitPressed("4")
else if (event.key == Qt.Key_5)
digitPressed("5")
else if (event.key == Qt.Key_6)
digitPressed("6")
else if (event.key == Qt.Key_7)
digitPressed("7")
else if (event.key == Qt.Key_8)
digitPressed("8")
else if (event.key == Qt.Key_9)
digitPressed("9")
else if (event.key == Qt.Key_Plus)
operatorPressed("+")
else if (event.key == Qt.Key_Minus)
operatorPressed("")
else if (event.key == Qt.Key_Asterisk)
operatorPressed("×")
else if (event.key == Qt.Key_Slash)
operatorPressed("÷")
else if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return)
operatorPressed("=")
else if (event.key == Qt.Key_Comma || event.key == Qt.Key_Period)
digitPressed(".")
else if (event.key == Qt.Key_Backspace)
operatorPressed("backspace")
}
Display {
id: display
x: -16
width: window.width - pad.width
height: parent.height
MouseArea {
id: mouseInput
property real startX: 0
property real oldP: 0
property bool rewind: false
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: 50
onPositionChanged: {
var reverse = startX > window.width / 2
var mx = mapToItem(window, mouseInput.mouseX, mouseInput.mouseY).x
var p = Math.abs((mx - startX) / (window.width - display.width))
if (p < oldP)
rewind = reverse ? false : true
else
rewind = reverse ? true : false
controller.progress = reverse ? 1 - p : p
oldP = p
}
onPressed: startX = mapToItem(window, mouseInput.mouseX, mouseInput.mouseY).x
onReleased: {
if (rewind)
controller.completeToBeginning()
else
controller.completeToEnd()
}
}
}
}

View File

@ -0,0 +1,16 @@
import QmlProject 1.1
Project {
mainFile: "calqlatr.qml"
/* Include .qml, .js, and image files from current directory and subdirectories */
QmlFiles {
directory: "."
}
JavaScriptFiles {
directory: "."
}
ImageFiles {
directory: "."
}
}

View File

@ -0,0 +1,12 @@
<RCC>
<qresource prefix="/demos/calqlatr">
<file>calqlatr.qml</file>
<file>content/Button.qml</file>
<file>content/calculator.js</file>
<file>content/Display.qml</file>
<file>content/NumberPad.qml</file>
<file>content/images/paper-edge-left.png</file>
<file>content/images/paper-edge-right.png</file>
<file>content/images/paper-grip.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,104 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 {
id: button
property alias text: textItem.text
property color color: "#eceeea"
property bool operator: false
property bool dimmable: false
property bool dimmed: false
width: 30
height: 50
Text {
id: textItem
font.pixelSize: 48
wrapMode: Text.WordWrap
lineHeight: 0.75
color: (dimmable && dimmed) ? Qt.darker(button.color) : button.color
Behavior on color { ColorAnimation { duration: 120; easing.type: Easing.OutElastic} }
states: [
State {
name: "pressed"
when: mouse.pressed && !dimmed
PropertyChanges {
target: textItem
color: Qt.lighter(button.color)
}
}
]
}
MouseArea {
id: mouse
anchors.fill: parent
anchors.margins: -5
onClicked: {
if (operator)
window.operatorPressed(parent.text)
else
window.digitPressed(parent.text)
}
}
function updateDimmed() {
dimmed = window.isButtonDisabled(button.text)
}
Component.onCompleted: {
numPad.buttonPressed.connect(updateDimmed)
updateDimmed()
}
}

View File

@ -0,0 +1,203 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 QtQuick.Window 2.0
Item {
id: display
property real fontSize: Math.floor(Screen.pixelDensity * 5.0)
property bool enteringDigits: false
property int maxDigits: (width / fontSize) + 1
property string displayedOperand
property string errorString: qsTr("ERROR")
property bool isError: displayedOperand === errorString
function displayOperator(operator)
{
listView.model.append({ "operator": operator, "operand": "" })
enteringDigits = true
listView.positionViewAtEnd()
}
function newLine(operator, operand)
{
displayedOperand = displayNumber(operand)
listView.model.append({ "operator": operator, "operand": displayedOperand })
enteringDigits = false
listView.positionViewAtEnd()
}
function appendDigit(digit)
{
if (!enteringDigits)
listView.model.append({ "operator": "", "operand": "" })
var i = listView.model.count - 1;
listView.model.get(i).operand = listView.model.get(i).operand + digit;
enteringDigits = true
listView.positionViewAtEnd()
}
function setDigit(digit)
{
var i = listView.model.count - 1;
listView.model.get(i).operand = digit;
listView.positionViewAtEnd()
}
function clear()
{
displayedOperand = ""
if (enteringDigits) {
var i = listView.model.count - 1
if (i >= 0)
listView.model.remove(i)
enteringDigits = false
}
}
// Returns a string representation of a number that fits in
// display.maxDigits characters, trying to keep as much precision
// as possible. If the number cannot be displayed, returns an
// error string.
function displayNumber(num) {
if (typeof(num) != "number")
return errorString;
var intNum = parseInt(num);
var intLen = intNum.toString().length;
// Do not count the minus sign as a digit
var maxLen = num < 0 ? maxDigits + 1 : maxDigits;
if (num.toString().length <= maxLen) {
if (isFinite(num))
return num.toString();
return errorString;
}
// Integer part of the number is too long - try
// an exponential notation
if (intNum == num || intLen > maxLen - 3) {
var expVal = num.toExponential(maxDigits - 6).toString();
if (expVal.length <= maxLen)
return expVal;
}
// Try a float presentation with fixed number of digits
var floatStr = parseFloat(num).toFixed(maxDigits - intLen - 1).toString();
if (floatStr.length <= maxLen)
return floatStr;
return errorString;
}
Item {
id: theItem
width: parent.width + 32
height: parent.height
Rectangle {
id: rect
x: 16
color: "white"
height: parent.height
width: display.width - 16
}
Image {
anchors.right: rect.left
source: "images/paper-edge-left.png"
height: parent.height
fillMode: Image.TileVertically
}
Image {
anchors.left: rect.right
source: "images/paper-edge-right.png"
height: parent.height
fillMode: Image.TileVertically
}
Image {
id: grip
source: "images/paper-grip.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
}
ListView {
id: listView
x: 16; y: 30
width: display.width
height: display.height - 50 - y
delegate: Item {
height: display.fontSize * 1.1
width: parent.width
Text {
id: operator
x: 6
font.pixelSize: display.fontSize
color: "#6da43d"
text: model.operator
}
Text {
id: operand
font.pixelSize: display.fontSize
anchors.right: parent.right
anchors.rightMargin: 22
text: model.operand
}
}
model: ListModel { }
}
}
}

View File

@ -0,0 +1,81 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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
Grid {
columns: 3
columnSpacing: 32
rowSpacing: 16
signal buttonPressed
Button { text: "7" }
Button { text: "8" }
Button { text: "9" }
Button { text: "4" }
Button { text: "5" }
Button { text: "6" }
Button { text: "1" }
Button { text: "2" }
Button { text: "3" }
Button { text: "0" }
Button { text: "."; dimmable: true }
Button { text: " " }
Button { text: "±"; color: "#6da43d"; operator: true; dimmable: true }
Button { text: ""; color: "#6da43d"; operator: true; dimmable: true }
Button { text: "+"; color: "#6da43d"; operator: true; dimmable: true }
Button { text: "√"; color: "#6da43d"; operator: true; dimmable: true }
Button { text: "÷"; color: "#6da43d"; operator: true; dimmable: true }
Button { text: "×"; color: "#6da43d"; operator: true; dimmable: true }
Button { text: "C"; color: "#6da43d"; operator: true }
Button { text: " "; color: "#6da43d"; operator: true }
Button { text: "="; color: "#6da43d"; operator: true; dimmable: true }
}

View File

@ -0,0 +1,161 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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$
**
****************************************************************************/
var curVal = 0
var memory = 0
var lastOp = ""
var previousOperator = ""
var digits = ""
function disabled(op) {
if (digits == "" && !((op >= "0" && op <= "9") || op == "."))
return true
else if (op == '=' && previousOperator.length != 1)
return true
else if (op == "." && digits.toString().search(/\./) != -1) {
return true
} else if (op == "√" && digits.toString().search(/-/) != -1) {
return true
} else {
return false
}
}
function digitPressed(op)
{
if (disabled(op))
return
if (digits.toString().length >= display.maxDigits)
return
if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp == ".") ) {
digits = digits + op.toString()
display.appendDigit(op.toString())
} else {
digits = op
display.appendDigit(op.toString())
}
lastOp = op
}
function operatorPressed(op)
{
if (disabled(op))
return
lastOp = op
if (op == "±") {
digits = Number(digits.valueOf() * -1)
display.setDigit(display.displayNumber(digits))
return
}
if (previousOperator == "+") {
digits = Number(digits.valueOf()) + Number(curVal.valueOf())
} else if (previousOperator == "") {
digits = Number(curVal.valueOf()) - Number(digits.valueOf())
} else if (previousOperator == "×") {
digits = Number(curVal) * Number(digits.valueOf())
} else if (previousOperator == "÷") {
digits = Number(curVal) / Number(digits.valueOf())
}
if (op == "+" || op == "" || op == "×" || op == "÷") {
previousOperator = op
curVal = digits.valueOf()
digits = ""
display.displayOperator(previousOperator)
return
}
if (op == "=") {
display.newLine("=", digits.valueOf())
}
curVal = 0
previousOperator = ""
if (op == "1/x") {
digits = (1 / digits.valueOf()).toString()
} else if (op == "x^2") {
digits = (digits.valueOf() * digits.valueOf()).toString()
} else if (op == "Abs") {
digits = (Math.abs(digits.valueOf())).toString()
} else if (op == "Int") {
digits = (Math.floor(digits.valueOf())).toString()
} else if (op == "√") {
digits = Number(Math.sqrt(digits.valueOf()))
display.newLine("√", digits.valueOf())
} else if (op == "mc") {
memory = 0;
} else if (op == "m+") {
memory += digits.valueOf()
} else if (op == "mr") {
digits = memory.toString()
} else if (op == "m-") {
memory = digits.valueOf()
} else if (op == "backspace") {
digits = digits.toString().slice(0, -1)
display.clear()
display.appendDigit(digits)
} else if (op == "Off") {
Qt.quit();
}
// Reset the state on 'C' operator or after
// an error occurred
if (op == "C" || display.isError) {
display.clear()
curVal = 0
memory = 0
lastOp = ""
digits = ""
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -0,0 +1,195 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\title Qt Quick Demo - Calqlatr
\ingroup qtquickdemos
\example demos/calqlatr
\brief A QML app designed for portrait devices that uses custom components,
animated with AnimationController, and JavaScript for the application logic.
\image qtquick-demo-calqlatr.png
\e{Calqlatr} demonstrates various QML and \l{Qt Quick} features, such as
displaying custom components and using animation to move the components
around in the application view. The application logic is implemented in
JavaScript and the appearance is implemented in QML.
\include examples-run.qdocinc
\section1 Displaying Custom Components
In the Calqlatr application, we use the following custom types that are
each defined in a separate .qml file:
\list
\li Button.qml
\li Display.qml
\li NumberPad.qml
\endlist
To use the custom types, we add an import statement to the main QML file,
calqlatr.qml that imports the folder called \c content where the types are
located:
\code
import "content"
\endcode
We can then display custom components by adding the component types to
any QML file. For example, we use the NumberPad type in calqlatr.qml to
create the number pad of the calculator. We place the type inside an
\l{Item} QML type, which is the base type for all visual items in Qt Quick:
\quotefromfile demos/calqlatr/calqlatr.qml
\skipto Item
\printuntil }
\printuntil }
Further, we use the Button type in the \c NumberPad type to create the
calculator buttons. Button.qml specifies the basic properties for a
button that we can modify for each button instance in NumberPad.qml. For the
digit and separator buttons, we additionally specify the text property using
the property alias \c text that we define in Button.qml.
For the operator buttons, we also specify another color (green) using the
property alias \c color and set the operator property to \c true. We use
the operator property in functions that perform the calculations.
We place the buttons inside a \l{Grid} QML type to position them in a grid:
\quotefromfile demos/calqlatr/content/NumberPad.qml
\skipto Grid
\printuntil /^\}/
Some of the buttons also have a \c dimmable property set, meaning that they
can be visually disabled (dimmed) whenever the calculator engine does not
accept input from that button. As an example, the button for square root
operator is dimmed for negative values.
\section1 Animating Components
We use the Display type to display calculations. In Display.qml, we use
images to make the display component look like a slip of paper that contains
a grip. Users can drag the grip to move the display from left to right.
When users release the grip, the AnimationController QML type that we define
in the calqlatr.qml file finishes running the controlled animation in either
a forwards or a backwards direction. To run the animation, we call either
completeToEnd() or completeToBeginning(), depending on the direction. We do
this in the MouseArea's \c onReleased signal handler, where \c controller
is the id of our AnimationController:
\quotefromfile demos/calqlatr/calqlatr.qml
\skipto MouseArea
\printuntil {
\dots 12
\skipto onReleased
\printuntil }
\printuntil }
Unlike other QML animation types, AnimationController is not driven by
internal timers but by explicitly setting its progress property to a
value between \c 0.0 and \c 1.0.
Inside the AnimationController, we run two NumberAnimation instances in
parallel to move the number pad and the display components simultaneously to
the opposite sides of the view. In addition, we run a SequentialAnimation
instance to scale the number pad during the transition, giving the animation
some depth.
\quotefromfile demos/calqlatr/calqlatr.qml
\skipto AnimationController
\printuntil 1; easing.type
\printuntil }
\printuntil }
\printuntil }
We use the easing curve of the type \c Easing.InOutQuad to accelerate the
motion until halfway and then decelerate it.
In Button.qml, the text colors of the number pad buttons are also animated.
\quotefromfile demos/calqlatr/content/Button.qml
\skipto Text
\printuntil id:
\dots 8
\skipto color:
\printuntil ]
\printuntil }
We use \l {QtQml::Qt::darker()}{Qt.darker()} to darken the color when the
button is dimmed, and \l {QtQml::Qt::lighter()}{Qt.lighter()} to \e {light up}
the button when pressed. The latter is done in a separate \l [QML] {State}
{state} called \e "pressed", which activates when the \c pressed
property of the button's MouseArea is set.
The color changes are animated by defining a \l Behavior on the \c color
property.
In order to dynamically change the \c dimmed property of all the buttons
of the \c NumberPad, we connect its \c buttonPressed signal to the
\c Button's \c updateDimmed() function in Button.qml:
\quotefromfile demos/calqlatr/content/Button.qml
\skipto function updateDimmed() {
\printuntil buttonPressed.connect
\printuntil }
This way, when a button is pressed, all buttons on the \c NumPad
receive a \c buttonPressed signal and are activated or deactivated
according to the state of the calculator engine.
\section1 Performing Calculations
The calculator.js file defines our calculator engine. It contains variables
to store the calculator state, and functions that are called when the
user presses the digit and operator buttons. To use the engine, we
import calculator.js in the calqlatr.qml file as \c CalcEngine:
\code
import "content/calculator.js" as CalcEngine
\endcode
Importing the engine creates a new instance of it. Therefore, we only do it
in the main QML file, \c calqlatr.qml. The root item defined in this file
contains helper functions that allow other types to access the calculator
engine:
\quotefromfile demos/calqlatr/calqlatr.qml
\skipto operatorPressed
\printuntil CalcEngine.disabled
\printuntil }
When users press a digit, the text from the digit appears on the
display. When they press an operator, the appropriate calculation is
performed, and the result can be displayed using the equals (=) operator.
The clear (C) operator resets the calculator engine.
\section1 List of Files
\sa {QML Applications}
*/

View File

@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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$
**
****************************************************************************/
#include "../../shared/shared.h"
DECLARATIVE_EXAMPLE_MAIN(demos/calqlatr/calqlatr)

View File

@ -0,0 +1,14 @@
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp
RESOURCES += clocks.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/demos/clocks
INSTALLS += target
OTHER_FILES += \
clocks.qml \
content/Clock.qml \
content/*.png

View File

@ -0,0 +1,98 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 "content" as Content
Rectangle {
id: root
width: 640; height: 320
color: "#646464"
ListView {
id: clockview
anchors.fill: parent
orientation: ListView.Horizontal
cacheBuffer: 2000
snapMode: ListView.SnapOneItem
highlightRangeMode: ListView.ApplyRange
delegate: Content.Clock { city: cityName; shift: timeShift }
model: ListModel {
ListElement { cityName: "New York"; timeShift: -4 }
ListElement { cityName: "London"; timeShift: 0 }
ListElement { cityName: "Oslo"; timeShift: 1 }
ListElement { cityName: "Mumbai"; timeShift: 5.5 }
ListElement { cityName: "Tokyo"; timeShift: 9 }
ListElement { cityName: "Brisbane"; timeShift: 10 }
ListElement { cityName: "Los Angeles"; timeShift: -8 }
}
}
Image {
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 10
source: "content/arrow.png"
rotation: -90
opacity: clockview.atXBeginning ? 0 : 0.5
Behavior on opacity { NumberAnimation { duration: 500 } }
}
Image {
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
source: "content/arrow.png"
rotation: 90
opacity: clockview.atXEnd ? 0 : 0.5
Behavior on opacity { NumberAnimation { duration: 500 } }
}
}

View File

@ -0,0 +1,8 @@
import QmlProject 1.1
Project {
mainFile: "clocks.qml"
QmlFiles { directory: "." }
JavaScriptFiles { directory: "." }
ImageFiles { directory: "." }
}

View File

@ -0,0 +1,15 @@
<RCC>
<qresource prefix="/demos/clocks">
<file>clocks.qml</file>
<file>content/arrow.png</file>
<file>content/background.png</file>
<file>content/center.png</file>
<file>content/clock-night.png</file>
<file>content/clock.png</file>
<file>content/Clock.qml</file>
<file>content/hour.png</file>
<file>content/minute.png</file>
<file>content/quit.png</file>
<file>content/second.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,150 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 {
id : clock
width: {
if (ListView.view && ListView.view.width >= 200)
return ListView.view.width / Math.floor(ListView.view.width / 200.0);
else
return 200;
}
height: {
if (ListView.view && ListView.view.height >= 240)
return ListView.view.height;
else
return 240;
}
property alias city: cityLabel.text
property int hours
property int minutes
property int seconds
property real shift
property bool night: false
property bool internationalTime: true //Unset for local time
function timeChanged() {
var date = new Date;
hours = internationalTime ? date.getUTCHours() + Math.floor(clock.shift) : date.getHours()
night = ( hours < 7 || hours > 19 )
minutes = internationalTime ? date.getUTCMinutes() + ((clock.shift % 1) * 60) : date.getMinutes()
seconds = date.getUTCSeconds();
}
Timer {
interval: 100; running: true; repeat: true;
onTriggered: clock.timeChanged()
}
Item {
anchors.centerIn: parent
width: 200; height: 240
Image { id: background; source: "clock.png"; visible: clock.night == false }
Image { source: "clock-night.png"; visible: clock.night == true }
Image {
x: 92.5; y: 27
source: "hour.png"
transform: Rotation {
id: hourRotation
origin.x: 7.5; origin.y: 73;
angle: (clock.hours * 30) + (clock.minutes * 0.5)
Behavior on angle {
SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
}
}
}
Image {
x: 93.5; y: 17
source: "minute.png"
transform: Rotation {
id: minuteRotation
origin.x: 6.5; origin.y: 83;
angle: clock.minutes * 6
Behavior on angle {
SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
}
}
}
Image {
x: 97.5; y: 20
source: "second.png"
transform: Rotation {
id: secondRotation
origin.x: 2.5; origin.y: 80;
angle: clock.seconds * 6
Behavior on angle {
SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
}
}
}
Image {
anchors.centerIn: background; source: "center.png"
}
Text {
id: cityLabel
y: 210; anchors.horizontalCenter: parent.horizontalCenter
color: "white"
font.family: "Helvetica"
font.bold: true; font.pixelSize: 16
style: Text.Raised; styleColor: "black"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,127 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\title Qt Quick Demo - Clocks
\ingroup qtquickdemos
\example demos/clocks
\brief A QML clock application that demonstrates using a ListView type to
display data generated by a ListModel and a SpringAnimation type to animate
images.
\image qtquick-demo-clocks-small.png
\e Clocks demonstrates using a ListView type to display data generated by a
ListModel. The delegate used by the model is specified as a custom QML type
that is specified in the Clock.qml file.
JavaScript methods are used to fetch the current time in several cities in
different time zones and QML types are used to display the time on a clock
face with animated clock hands.
\include examples-run.qdocinc
\section1 Displaying Data Generated by List Models
In the clocks.qml file, we use a \l Rectangle type to create the application
main window:
\quotefromfile demos/clocks/clocks.qml
\skipto Rectangle
\printuntil color
We use a ListView type to display a list of the items provided by a
ListModel type:
\printuntil Los Angeles
\printuntil }
\printuntil }
List elements are defined like other QML types except that they contain a
collection of \e role definitions instead of properties. Roles both define
how the data is accessed and include the data itself.
For each list element, we use the \c cityName role to specify the name of a
city and the \c timeShift role to specify a time zone as a positive or
negative offset from UTC (coordinated universal time).
The Clock custom type is used as the ListView's \c delegate, defining the
visual appearance of list items. To use the Clock type, we add an import
statement that imports the folder called \c content where the type is
located:
\quotefromfile demos/clocks/clocks.qml
\skipto content
\printuntil "
We use an \l Image type to display arrows that indicate whether users can
flick the view to see more clocks on the left or right:
\quotefromfile demos/clocks/clocks.qml
\skipto Image
\printuntil /^\}/
We use the \c opacity property to hide the arrows when the list view is
located at the beginning or end of the x axis.
In Clock.qml, we define a \c timeChanged() function in which we use
methods from the JavaScript \c Date object to fetch the current time in
UTC and to adjust it to the correct time zone:
\quotefromfile demos/clocks/content/Clock.qml
\skipto timeChanged
\printuntil }
We use a \l Timer type to update the time at intervals of 100 milliseconds:
\printuntil }
We use \l Image types within an \l Item type to display the time on an
analog clock face. Different images are used for daytime and nighttime
hours:
\printuntil clock-night.png
A \l Rotation transform applied to \l Image types provides a way to rotate
the clock hands. The \c origin property holds the point that stays fixed
relative to the parent as the rest of the item rotates. The \c angle
property determines the angle to rotate the hands in degrees clockwise.
\printuntil center.png
\printuntil }
We use a \l Behavior type on the \c angle property to apply a
SpringAnimation when the time changes. The \c spring and \c damping
properties enable the spring-like motion of the clock hands, and a
\c modulus of \c 360 makes the animation target values wrap around at a
full circle.
We use a \l Text type to display the city name below the clock:
\printuntil }
\sa {QML Applications}
*/

View File

@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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$
**
****************************************************************************/
#include "../../shared/shared.h"
DECLARATIVE_EXAMPLE_MAIN(demos/clocks/clocks)

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -4,7 +4,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -4,7 +4,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -4,7 +4,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -4,7 +4,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -4,7 +4,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -50,7 +50,7 @@
/*!
\example coffee
\example demos/coffee
\title Coffee Machine Example
\ingroup examples-tutorials
@ -71,12 +71,12 @@
and \c animation2 in CoffeeButton.qml. On the right side, you will see
the coffee blend you selected.
\snippet coffee/CoffeeButton.qml 0
\snippet demos/coffee/CoffeeButton.qml 0
It also triggers cappuccinoButton.onClicked(), which sets the default
mix for the coffee type selected:
\snippet coffee/SideBar.qml 0
\snippet demos/coffee/SideBar.qml 0
\borderedimage coffee_machine_selection.png
\caption Coffee blend cappuccino
@ -86,7 +86,7 @@
If you click "Brew me a cup", choosingCoffee.brewButtonSelection.onClicked
is triggered:
\snippet coffee/ApplicationFlow.qml 0
\snippet demos/coffee/ApplicationFlow.qml 0
On the right side of the screen, you will see two sliders, one for
the amount of milk, and one for sugar. They will have default values,
@ -97,18 +97,18 @@
If you click on \c Brew, \c choosingCoffee.brewButton.onClicked() is triggered,
which displays a screen with the message "Please insert cup into tray".
\snippet coffee/ApplicationFlow.qml 2
\snippet demos/coffee/ApplicationFlow.qml 2
\borderedimage coffee_machine_emptycup.png
Clicking on \c Continue starts the brewing of the coffee type you
selected.
\snippet coffee/ApplicationFlow.qml 1
\snippet demos/coffee/ApplicationFlow.qml 1
The brewing process is defined as follows in \c Brewing.qml:
\snippet coffee/Brewing.qml 0
\snippet demos/coffee/Brewing.qml 0
After completion, the application returns to the start screen.
*/

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage

View File

@ -1,6 +1,20 @@
TEMPLATE = subdirs
qtHaveModule(quick) {
SUBDIRS += coffee
}
SUBDIRS += \
samegame \
calqlatr \
clocks \
tweetsearch \
maroon \
photosurface \
stocqt
qtHaveModule(quickcontrols2) {
SUBDIRS += coffee
}
qtHaveModule(xmlpatterns) {
SUBDIRS += rssnews photoviewer
}
}

View File

@ -0,0 +1,100 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 "logic.js" as Logic
Item {
id: container
width: 64
height: 64
property alias source: img.source
property int index
property int row: 0
property int col: 0
property int towerType
property bool canBuild: true
property Item gameCanvas: parent.parent.parent
signal clicked()
Image {
id: img
opacity: (canBuild && gameCanvas.coins >= Logic.towerData[towerType-1].cost) ? 1.0 : 0.4
}
Text {
anchors.right: parent.right
font.pointSize: 14
font.bold: true
color: "#ffffff"
text: Logic.towerData[towerType - 1].cost
}
MouseArea {
anchors.fill: parent
onClicked: {
Logic.buildTower(towerType, col, row)
container.clicked()
}
}
Image {
visible: col == index && row != 0
source: "gfx/dialog-pointer.png"
anchors.top: parent.bottom
anchors.topMargin: 4
anchors.horizontalCenter: parent.horizontalCenter
}
Image {
visible: col == index && row == 0
source: "gfx/dialog-pointer.png"
rotation: 180
anchors.bottom: parent.top
anchors.bottomMargin: 6
anchors.horizontalCenter: parent.horizontalCenter
}
}

View File

@ -0,0 +1,250 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 "logic.js" as Logic
import "towers" as Towers
Item {
id: grid
property int squareSize: 64
property int rows: 6
property int cols: 4
property Item canvas: grid
property int score: 0
property int coins: 100
property int lives: 3
property int waveNumber: 0
property int waveProgress: 0
property var towers
property var mobs
property bool gameRunning: false
property bool gameOver: false
property bool errored: false
property string errorString: ""
width: cols * squareSize
height: rows * squareSize
function freshState() {
lives = 3
coins = 100
score = 0
waveNumber = 0
waveProgress = 0
gameOver = false
gameRunning = false
towerMenu.shown = false
helpButton.comeBack();
}
Text {
id: errorText // Mostly for debug purposes
text: errorString
visible: errored
color: "red"
font.pixelSize: 18
wrapMode: Text.WordWrap
width: parent.width / 1.2
height: parent.height / 1.2
anchors.centerIn: parent
z: 1000
}
Timer {
interval: 16
running: true
repeat: true
onTriggered: Logic.tick()
}
MouseArea {
id: ma
anchors.fill: parent
onClicked: {
if (towerMenu.visible)
towerMenu.finish()
else
towerMenu.open(mouse.x, mouse.y)
}
}
Image {
id: towerMenu
visible: false
z: 1500
scale: 0.9
opacity: 0.7
property int dragDistance: 16
property int targetRow: 0
property int targetCol: 0
property bool shown: false
property bool towerExists: false
function finish() {
shown = false
}
function open(xp,yp) {
if (!grid.gameRunning)
return
targetRow = Logic.row(yp)
targetCol = Logic.col(xp)
if (targetRow == 0)
towerMenu.y = (targetRow + 1) * grid.squareSize
else
towerMenu.y = (targetRow - 1) * grid.squareSize
towerExists = (grid.towers[Logic.towerIdx(targetCol, targetRow)] != null)
shown = true
helpButton.goAway();
}
states: State {
name: "shown"; when: towerMenu.shown && !grid.gameOver
PropertyChanges { target: towerMenu; visible: true; scale: 1; opacity: 1 }
}
transitions: Transition {
PropertyAction { property: "visible" }
NumberAnimation { properties: "opacity,scale"; duration: 500; easing.type: Easing.OutElastic }
}
x: -32
source: "gfx/dialog.png"
Row {
id: buttonRow
height: 100
anchors.centerIn: parent
spacing: 8
BuildButton {
row: towerMenu.targetRow; col: towerMenu.targetCol
anchors.verticalCenter: parent.verticalCenter
towerType: 1; index: 0
canBuild: !towerMenu.towerExists
source: "gfx/dialog-melee.png"
onClicked: towerMenu.finish()
}
BuildButton {
row: towerMenu.targetRow; col: towerMenu.targetCol
anchors.verticalCenter: parent.verticalCenter
towerType: 2; index: 1
canBuild: !towerMenu.towerExists
source: "gfx/dialog-shooter.png"
onClicked: towerMenu.finish()
}
BuildButton {
row: towerMenu.targetRow; col: towerMenu.targetCol
anchors.verticalCenter: parent.verticalCenter
towerType: 3; index: 2
canBuild: !towerMenu.towerExists
source: "gfx/dialog-bomb.png"
onClicked: towerMenu.finish()
}
BuildButton {
row: towerMenu.targetRow; col: towerMenu.targetCol
anchors.verticalCenter: parent.verticalCenter
towerType: 4; index: 3
canBuild: !towerMenu.towerExists
source: "gfx/dialog-factory.png"
onClicked: towerMenu.finish()
}
}
}
Keys.onPressed: { // Cheat Codes while Testing
if (event.key == Qt.Key_Up && (event.modifiers & Qt.ShiftModifier))
grid.coins += 10;
if (event.key == Qt.Key_Left && (event.modifiers & Qt.ShiftModifier))
grid.lives += 1;
if (event.key == Qt.Key_Down && (event.modifiers & Qt.ShiftModifier))
Logic.gameState.waveProgress += 1000;
if (event.key == Qt.Key_Right && (event.modifiers & Qt.ShiftModifier))
Logic.endGame();
}
Image {
id: helpButton
z: 1010
source: "gfx/button-help.png"
function goAway() {
helpMA.enabled = false;
helpButton.opacity = 0;
}
function comeBack() {
helpMA.enabled = true;
helpButton.opacity = 1;
}
Behavior on opacity { NumberAnimation {} }
MouseArea {
id: helpMA
anchors.fill: parent
onClicked: {helpImage.visible = true; helpButton.visible = false;}
}
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
}
Image {
id: helpImage
z: 1010
source: "gfx/help.png"
anchors.fill: parent
visible: false
MouseArea {
anchors.fill: parent
onClicked: helpImage.visible = false;
}
}
}

View File

@ -0,0 +1,125 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 QtQuick.Particles 2.0
import "logic.js" as Logic
Item {
id: gameOverScreen
width: 320
height: 400
property GameCanvas gameCanvas
Image {
id: img
source: "gfx/text-gameover.png"
anchors.centerIn: parent
}
ParticleSystem {
anchors.fill: parent
ImageParticle {
id: cloud
source: "gfx/cloud.png"
alphaVariation: 0.25
opacity: 0.25
}
Wander {
xVariance: 100;
pace: 1;
}
Emitter {
id: cloudLeft
width: 160
height: 160
anchors.right: parent.left
emitRate: 0.5
lifeSpan: 12000
velocity: PointDirection{ x: 64; xVariation: 2; yVariation: 2 }
size: 160
}
Emitter {
id: cloudRight
width: 160
height: 160
anchors.left: parent.right
emitRate: 0.5
lifeSpan: 12000
velocity: PointDirection{ x: -64; xVariation: 2; yVariation: 2 }
size: 160
}
}
Text {
visible: gameCanvas != undefined
text: "You saved " + gameCanvas.score + " fishes!"
anchors.top: img.bottom
anchors.topMargin: 12
anchors.horizontalCenter: parent.horizontalCenter
font.bold: true
color: "#000000"
opacity: 0.5
}
Image {
source: "gfx/button-play.png"
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
MouseArea {
anchors.fill: parent
onClicked: gameCanvas.gameOver = false//This will actually trigger the state change in main.qml
}
}
}

View File

@ -0,0 +1,94 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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 {
height: childrenRect.height
// Display the number of lives
Row {
anchors.left: parent.left
anchors.leftMargin: 10
spacing: 5
Repeater {
id: rep
model: Math.min(10, canvas.lives)
delegate: Image { source: "gfx/lifes.png" }
}
}
// Display the number of fishes saved
Row {
anchors.right: points.left
anchors.rightMargin: 20
spacing: 5
Image { source: "gfx/scores.png" }
Text {
text: canvas.score
font.bold: true
}
}
// Display the number of coins
Row {
id: points
anchors.right: parent.right
anchors.rightMargin: 10
spacing: 5
Image { source: "gfx/points.png" }
Text {
id: pointsLabel
text: canvas.coins
font.bold: true
}
}
}

View File

@ -0,0 +1,121 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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
// This is the first screen.
// It shows the logo and emit a startButtonClicked signal
// when the user press the "PLAY" button.
Item {
id: newGameScreen
width: 320
height: 480
signal startButtonClicked
Image {
source: "gfx/logo.png"
anchors.top: parent.top
anchors.topMargin: 60
}
Image {
source: "gfx/logo-fish.png"
anchors.top: parent.top
SequentialAnimation on x {
loops: Animation.Infinite
NumberAnimation { from: x + 148; to: x + 25; duration: 2000; easing.type: Easing.InOutQuad }
NumberAnimation { from: x + 25; to: x + 148; duration: 1600; easing.type: Easing.InOutQuad }
}
SequentialAnimation on anchors.topMargin {
loops: Animation.Infinite
NumberAnimation { from: 100; to: 60; duration: 1600; easing.type: Easing.InOutQuad }
NumberAnimation { from: 60; to: 100; duration: 2000; easing.type: Easing.InOutQuad }
}
}
Image {
source: "gfx/logo-bubble.png"
anchors.top: parent.top
SequentialAnimation on x {
loops: Animation.Infinite
NumberAnimation { from: x + 140; to: x + 40; duration: 2000; easing.type: Easing.InOutQuad }
NumberAnimation { from: x + 40; to: x + 140; duration: 1600; easing.type: Easing.InOutQuad }
}
SequentialAnimation on anchors.topMargin {
loops: Animation.Infinite
NumberAnimation { from: 100; to: 60; duration: 1600; easing.type: Easing.InOutQuad }
NumberAnimation { from: 60; to: 100; duration: 2000; easing.type: Easing.InOutQuad }
}
SequentialAnimation on width {
loops: Animation.Infinite
NumberAnimation { from: 140; to: 160; duration: 1000; easing.type: Easing.InOutQuad }
NumberAnimation { from: 160; to: 140; duration: 800; easing.type: Easing.InOutQuad }
}
SequentialAnimation on height {
loops: Animation.Infinite
NumberAnimation { from: 150; to: 140; duration: 800; easing.type: Easing.InOutQuad }
NumberAnimation { from: 140; to: 150; duration: 1000; easing.type: Easing.InOutQuad }
}
}
Image {
source: "gfx/button-play.png"
anchors.bottom: parent.bottom
anchors.bottomMargin: 60
MouseArea {
anchors.fill: parent
onClicked: newGameScreen.startButtonClicked()
}
}
}

View File

@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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
//Proxies a SoundEffect if QtMultimedia is installed
Item {
id: container
property QtObject effect: Qt.createQmlObject("import QtMultimedia 5.0; SoundEffect{ source: '" + container.source + "'; muted: Qt.application.state != Qt.ApplicationActive }", container);
property url source: ""
onSourceChanged: if (effect != null) effect.source = source;
function play() {
if (effect != null)
effect.play();
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 911 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Some files were not shown because too many files have changed in this diff Show More