Warning, /education/gcompris/src/core/IntroMessage.qml is written in an unsupported language. File is not indexed.
0001 /*GCompris - IntroMessage.qml
0002 *
0003 * SPDX-FileCopyrightText: 2015 Siddhesh suthar <siddhesh.it@gmail.com>
0004 *
0005 * Authors:
0006 *
0007 * Siddhesh suthar <siddhesh.it@gmail.com>
0008 * Sagar Chand Agarwal <atomsagar@gmail.com>
0009 *
0010 * SPDX-License-Identifier: GPL-3.0-or-later
0011 */
0012
0013 import QtQuick 2.12
0014 import GCompris 1.0
0015
0016 /**
0017 * A QML component for multi activity introduction in GCompris.
0018 *
0019 * Use IntroMessage when you want to present an introductory message to the
0020 * user, that provides background information or gameplay hints.
0021 *
0022 * Contains the following basic layout elements: Introduction text (intro), a
0023 * skip and an @c Next button to leave the introduction or navigate through it.
0024 * The introDone signal is emitted when the introduction has finished and can
0025 * be used to prepare the start of the activity.
0026 *
0027 * @ingroup components
0028 * @inherit QtQuick.Item
0029 */
0030
0031 Item {
0032 id: message
0033
0034 focus: true
0035 anchors.fill: parent
0036 visible: index == -1 ? false : true
0037
0038 /**
0039 * Emitted when the index of intro is equal to its length
0040 * or when skipButton is clicked.
0041 */
0042 signal introDone
0043
0044 /**
0045 * The index of the intro array.
0046 *
0047 * Set to -1 to hide the IntroMessage item.
0048 */
0049 property int index: 0
0050
0051 /**
0052 * The texts array used as introduction.
0053 *
0054 * It has to be filled by the user when defining an IntroMessage item.
0055 */
0056 property var intro
0057
0058 property int textContainerWidth: 0.9 * parent.width
0059 property int textContainerHeight: 0.75 * parent.height - nextButton.height
0060
0061 Keys.onPressed: {
0062 if(event.key === Qt.Key_Left && previousButton.visible) {
0063 previousButton.clicked();
0064 } else if(event.key === Qt.Key_Right && nextButton.visible) {
0065 nextButton.clicked();
0066 } else if(event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
0067 skipButton.clicked();
0068 } else if(event.key === Qt.Key_Space) {
0069 if(nextButton.visible) {
0070 nextButton.clicked();
0071 } else {
0072 skipButton.clicked();
0073 }
0074 }
0075 event.accepted = true;
0076 }
0077
0078 Keys.onEscapePressed: {
0079 skipButton.clicked();
0080 event.accepted = true;
0081 }
0082
0083 Keys.onReleased: {
0084 if(event.key === Qt.Key_Back) {
0085 skipButton.clicked();
0086 event.accepted = true;
0087 }
0088 }
0089
0090 // to avoid clicking on the activity
0091 MouseArea {
0092 anchors.fill: parent
0093 }
0094
0095 Rectangle {
0096 id: introTextContainer
0097 width: introText.width + 20
0098 height: introText.height + 2
0099 anchors.top: introText.top
0100 anchors.horizontalCenter: introText.horizontalCenter
0101 opacity: 0.9
0102 color: "white"
0103 border.color: "#87A6DD"
0104 border.width: 6
0105 radius: 10
0106 }
0107
0108 GCText {
0109 id: introText
0110 anchors {
0111 horizontalCenter: parent.horizontalCenter
0112 top: parent.top
0113 topMargin: 10
0114 }
0115 width: textContainerWidth
0116 height: textContainerHeight
0117 horizontalAlignment: Text.AlignHCenter
0118 verticalAlignment: Text.AlignVCenter
0119 color: "black"
0120 minimumPixelSize: 10
0121 wrapMode: Text.WordWrap
0122 fontSizeMode: Text.Fit
0123 text: parent.index == -1 ? "" : parent.intro[parent.index]
0124 }
0125
0126 IntroButton {
0127 id: previousButton
0128 width: parent.width / 4
0129 height: 90
0130 z: 5
0131 anchors.right: nextButton.left
0132 anchors.topMargin: 15
0133 anchors.rightMargin: 15
0134 anchors.top: introTextContainer.bottom
0135 visible: index != 0
0136
0137 text: qsTr("Previous")
0138
0139 onClicked: --index;
0140 }
0141
0142 IntroButton {
0143 id: nextButton
0144 width: parent.width / 4
0145 height: 90
0146 z: 5
0147 anchors.right: skipButton.left
0148 anchors.topMargin: 15
0149 anchors.rightMargin: 15
0150 anchors.top: introTextContainer.bottom
0151 visible: index != (intro.length - 1)
0152
0153 text: qsTr("Next")
0154
0155 onClicked: index++;
0156 }
0157
0158 IntroButton {
0159 id: skipButton
0160 width: parent.width / 4
0161 height: 90
0162 z: 5
0163 anchors.right: parent.right
0164 anchors.rightMargin: 15
0165 anchors.topMargin: 15
0166 anchors.top: introTextContainer.bottom
0167
0168 text: nextButton.visible ? qsTr("Skip") : qsTr("Start")
0169
0170 onClicked: {
0171 index = -1;
0172 message.introDone();
0173 }
0174 }
0175 }