diff --git a/src/activities/question_and_answer/Question_and_answer.qml b/src/activities/question_and_answer/Question_and_answer.qml --- a/src/activities/question_and_answer/Question_and_answer.qml +++ b/src/activities/question_and_answer/Question_and_answer.qml @@ -134,6 +134,7 @@ Item { id: questionItem state: "short" + property alias text: sampleAnswer.text GCText { id: questionText text: items.questions[index] @@ -145,36 +146,75 @@ height: questionsGrid.cellHeight fontSizeMode: Text.Fit } - TextField { - id: answerText - height: bar.height * 0.4 - width: questionsGrid.cellWidth * 0.30 + GCText { + id: sampleAnswer + visible: false + height: getHeight() + width: questionsGrid.cellWidth * 0.3 + wrapMode: Text.WordWrap + color: "white" + fontSize: tinySize + function getHeight() { + if(text.length > 20) { + if(contentHeight > questionsGrid.cellHeight * 0.8) { + return questionsGrid.cellHeight * 0.8 + } else { + return contentHeight * 1.1 + } + } else { + return bar.height * 0.4 + } + } + } + Rectangle { + id: answerRectangle + border.color: "black" + border.width: 5 + radius: 10 anchors.left: questionText.right - anchors.leftMargin: questionsGrid.cellWidth * 0.1 - anchors.verticalCenter: questionText.verticalCenter - activeFocusOnPress: true - readOnly: !items.editAnswers - onVisibleChanged: text = "" - horizontalAlignment: TextInput.AlignHCenter - font.pixelSize: 24 - style: TextFieldStyle { - textColor: "black" - background: Rectangle { - radius: 5 - color: "transparent" - implicitWidth: bar.height * 0.9 - implicitHeight: 130/800*parent.width - border.color: "#333" - border.width: 2 + width: getWidth() + height: sampleAnswer.height * 0.8 + property alias cellWidth: questionText.width + property real cellHeight: questionsGrid.cellHeight + property alias text: questionItem.text + color: "transparent" + function getWidth() { + if(sampleAnswer.contentWidth < questionsGrid.cellWidth * 0.3) { + if(sampleAnswer.contentWidth < questionsGrid.cellWidth * 0.1) + return questionsGrid.cellWidth * 0.1 + else + return sampleAnswer.contentWidth * 1.2 + } else { + return questionsGrid.cellWidth * 0.3 } } + TextArea { + id: answerText + width: parent.width + height: parent.height + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + anchors.topMargin: 20 + activeFocusOnPress: true + readOnly: !items.editAnswers + horizontalAlignment: TextInput.AlignHCenter + implicitWidth: bar.height * 0.9 + implicitHeight: 130/800*parent.width + text: answerRectangle.text + font.pixelSize: 24 + backgroundVisible: false + + onTextChanged:{ + answerRectangle.text = answerText.text + } - onActiveFocusChanged: { - if (!items.levelStarted && items.buttonType != "restart") { - items.levelStarted = true - items.startFinishButton.visibility = true - items.editAnswers = true - answerText.focus = true + onActiveFocusChanged: { + if (!items.levelStarted && items.buttonType != "restart") { + items.levelStarted = true + items.startFinishButton.visibility = true + items.editAnswers = true + answerText.focus = true + } } } } @@ -184,7 +224,7 @@ height: 50 visible: items.showAnswerStatus fillMode: Image.PreserveAspectFit - source: (answerText.text).trim() === items.answers[index] ? + source: (answerRectangle.text).trim() === items.answers[index] ? "qrc:/gcompris/src/activities/question_and_answer/resource/right.svg" : "qrc:/gcompris/src/activities/photo_hunter/resource/wrong.svg" } @@ -200,18 +240,16 @@ height: questionsGrid.cellHeight } PropertyChanges { - target: answerText - height: bar.height * 0.4 - width: questionsGrid.cellWidth * 0.30 + target: answerRectangle anchors.left: questionText.right + anchors.leftMargin: 50 anchors.verticalCenter: questionText.verticalCenter - anchors.top: undefined anchors.horizontalCenter: undefined } PropertyChanges { target: question_image anchors.verticalCenter: questionText.verticalCenter - anchors.left: answerText.right + anchors.left: answerRectangle.right anchors.top: questionText.top } }, @@ -224,9 +262,7 @@ height: questionsGrid.cellHeight * 0.3 } PropertyChanges { - target: answerText - height: bar.height * 0.4 - width: questionsGrid.cellWidth * 0.30 + target: answerRectangle anchors.top: questionText.bottom anchors.horizontalCenter: questionText.horizontalCenter anchors.verticalCenter: undefined @@ -234,9 +270,9 @@ } PropertyChanges { target: question_image - anchors.left: answerText.right - anchors.top: answerText.top - anchors.verticalCenter: answerText.verticalCenter + anchors.left: answerRectangle.right + anchors.top: answerRectangle.top + anchors.verticalCenter: answerRectangle.verticalCenter } } ] diff --git a/src/activities/question_and_answer/question_and_answer.js b/src/activities/question_and_answer/question_and_answer.js --- a/src/activities/question_and_answer/question_and_answer.js +++ b/src/activities/question_and_answer/question_and_answer.js @@ -132,6 +132,7 @@ nextLevel() previousLevel() resetButtonVisibility() + clearAnswerAreas() restartingLevel = false } @@ -162,7 +163,14 @@ } items.longestQuestion = longestText } - +function clearAnswerAreas() { + var answers = items.questionsGrid.contentItem.children + for(var child in answers) { + if(typeof answers[child].text !== 'undefined') { + answers[child].text = "" + } + } +} function initializeSubActivity(index) { currentActivityIndex = index currentLevel = 0 @@ -173,6 +181,7 @@ items.allQuestions = dataset["questions"] setLongestQuestion() initLevel() + clearAnswerAreas() } function launchMenuScreen() { diff --git a/src/activities/question_and_answer/resource/dataset.json b/src/activities/question_and_answer/resource/dataset.json new file mode 100644 --- /dev/null +++ b/src/activities/question_and_answer/resource/dataset.json @@ -0,0 +1,16 @@ +{ + "data": [ + { + "category": "Multiplication", + "category_image_src": "qrc:/gcompris/src/activities/algebra_by/algebra_by.svg" + }, + { + "category": "Addition", + "category_image_src": "qrc:/gcompris/src/activities/algebra_plus/algebra_plus.svg" + }, + { + "category": "Sample Questions", + "category_image_src": "qrc:/gcompris/src/activities/algebra_plus/algebra_plus.svg" + } + ] +} diff --git a/src/activities/question_and_answer/resource/datasetDetails.json b/src/activities/question_and_answer/resource/datasetDetails.json deleted file mode 100644 --- a/src/activities/question_and_answer/resource/datasetDetails.json +++ /dev/null @@ -1,19 +0,0 @@ - - { - "data": [ - { - "category": "Multiplication", - "category_image_src": "qrc:/gcompris/src/activities/algebra_by/algebra_by.svg", - }, - - { - "category": "Addition", - "category_image_src": "qrc:/gcompris/src/activities/algebra_plus/algebra_plus.svg", - }, - - { - "category": "Sample Questions", - "category_image_src": "qrc:/gcompris/src/activities/algebra_plus/algebra_plus.svg", - } - ] -}