Warning, /education/kanagram/src/ui/Blackboard.qml is written in an unsupported language. File is not indexed.

0001 /***************************************************************************
0002  *   This file is part of the Kanagram project                             *
0003  *   Copyright 2014 Debjit Mondal <debjitmondal05@gmail.com>               *
0004  *   Copyright 2014 Jeremy Whiting <jpwhiting@kde.org>                     *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, write to the                         *
0018  *   Free Software Foundation, Inc.,                                       *
0019  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0020  ***************************************************************************/
0021 
0022 import QtQuick
0023 import QtQuick.Controls
0024 
0025 Rectangle {
0026 
0027     id: blackboard
0028     radius: 4
0029     property alias showHintTimeInterval: hintButton.countDownTimerValue
0030     property alias activeTimer: scoreTimer.running
0031 
0032     signal showWiki
0033     signal nextAnagram
0034 
0035     function wikiClosed() {
0036         wikiButton.wikiLinkActivated = false
0037         if (activeTimer) {
0038             kanagramGame.answerRevealed();
0039         }
0040         revealButton.countDownTimerValue = 2
0041         showAnswerTimer.repeat = true
0042         showAnswerTimer.start()
0043     }
0044 
0045     function letterButtonClicked(index) {
0046         kanagramGame.moveLetterToUserAnswer(index);
0047         checkSolved();
0048     }
0049 
0050     Item {
0051         width: parent.width
0052         height: parent.height
0053 
0054         Image {
0055             id: background
0056             smooth: true
0057             anchors.fill: parent
0058             source: "images/chalkboard.png"
0059         }
0060     }
0061 
0062     Item {
0063         id: categoryBar
0064         anchors.top: parent.top
0065         width: parent.width
0066         height: Math.min(parent.height / 5, 4 * categoryName.height)
0067         Rectangle {
0068             anchors.fill: parent
0069             opacity: .25
0070             color: "black"
0071         }
0072 
0073         ToolButton {
0074             height: categoryBar.height
0075             width: categoryBar.height
0076             id: nextVocabularyButton
0077             anchors {
0078                 verticalCenter: categoryBar.verticalCenter
0079                 right: categoryBar.right
0080                 rightMargin: parent.width / 20
0081             }
0082             action: Action {
0083                 shortcut: "PgDown"
0084                 onTriggered: {
0085                     kanagramGame.nextVocabulary();
0086                     nextAnagram();
0087                 }
0088                 text: i18n("Next Vocabulary")
0089             }
0090             Image {
0091                 source: "icons/right-arrow.png"
0092                 anchors.fill: parent
0093                 anchors.margins: 4
0094                 fillMode: Image.PreserveAspectFit
0095             }
0096             background: Rectangle { color: "transparent" }
0097         }
0098 
0099         Text {
0100             id: categoryName
0101             anchors {
0102                 verticalCenter: categoryBar.verticalCenter
0103                 horizontalCenter: categoryBar.horizontalCenter
0104             }
0105             color: "white"
0106             text: kanagramGame.title
0107             font.pixelSize: Math.min(parent.width / 19.5, 32)
0108         }
0109 
0110         ToolButton {
0111             id: previousVocabularyButton
0112             height: categoryBar.height
0113             width: categoryBar.height
0114             anchors {
0115                 verticalCenter: categoryBar.verticalCenter
0116                 left: categoryBar.left
0117                 leftMargin: parent.width / 20
0118             }
0119             action: Action {
0120                 shortcut: "PgUp"
0121                 onTriggered: {
0122                     kanagramGame.previousVocabulary();
0123                     nextAnagram();
0124                 }
0125                 text: i18n("Previous Vocabulary")
0126             }
0127             Image {
0128                 source: "icons/left-arrow.png"
0129                 anchors.fill: parent
0130                 anchors.margins: 4
0131                 fillMode: Image.PreserveAspectFit
0132             }
0133             background: Rectangle { color: "transparent" }
0134         }
0135     }
0136 
0137     Item {
0138         id: optionsBar
0139         width: parent.width
0140         height: categoryBar.height
0141         anchors.bottom: parent.bottom
0142         Rectangle {
0143             anchors.fill: parent
0144             opacity: .25
0145             color: "black"
0146         }
0147 
0148         ToolButton {
0149             id: scoreButton
0150             height: optionsBar.height
0151             width: optionsBar.height
0152             anchors {
0153                 verticalCenter: optionsBar.verticalCenter
0154                 left: optionsBar.left
0155             }
0156             property int countDownTimerValue: 0
0157             property bool flagToggleTimer: false
0158             action: Action {
0159                 id: scoreAction
0160                 shortcut: "Ctrl+S"
0161                 onTriggered: {
0162                     if (!scoreButton.flagToggleTimer) {
0163                         scoreButton.countDownTimerValue = kanagramGame.scoreTime();
0164                         scoreTimer.repeat = true;
0165                         scoreTimer.start();
0166                         kanagramGame.resetTotalScore();
0167                         scoreSection.opacity = 0.35;
0168                         score.opacity = 1;
0169                     } else {
0170                         scoreButton.countDownTimerValue = 1
0171                     }
0172                     scoreButton.flagToggleTimer = !scoreButton.flagToggleTimer;
0173                 }
0174                 text: i18n("Start Timer");
0175             }
0176             Image {
0177                 source: "icons/timer.png"
0178                 anchors.fill: parent
0179                 anchors.margins: 4
0180                 fillMode: Image.PreserveAspectFit
0181             }
0182             background: Rectangle { color: "transparent" }
0183         }
0184 
0185         ToolButton {
0186             id: hintButton
0187             action: Action {
0188                 id: hintAction
0189                 shortcut: "Ctrl+H"
0190                 onTriggered: {
0191                     hintButton.countDownTimerValue = kanagramGame.hintHideTime()
0192                     hintTimer.repeat = true
0193                     hintTimer.start()
0194                 }
0195                 text: i18n("Show Hint")
0196             }
0197             width: optionsBar.height
0198             height: optionsBar.height
0199             property int countDownTimerValue: 0
0200             anchors {
0201                 verticalCenter: optionsBar.verticalCenter
0202                 horizontalCenter: optionsBar.horizontalCenter
0203             }
0204             Image {
0205                 source: "icons/hint.png"
0206                 anchors.fill: parent
0207                 anchors.margins: 4
0208                 fillMode: Image.PreserveAspectFit
0209             }
0210             background: Rectangle { color: "transparent" }
0211         }
0212 
0213         Action {
0214             id: revealAction
0215             shortcut: "Ctrl+R"
0216             onTriggered: {
0217                 kanagramGame.revealWord();
0218                 if (blackboard.activeTimer) {
0219                     kanagramGame.answerRevealed();
0220                 }
0221                 revealButton.countDownTimerValue = 2
0222                 showAnswerTimer.repeat = true
0223                 showAnswerTimer.start()
0224             }
0225             text: i18n("Reveal Word")
0226         }
0227 
0228         ToolButton {
0229             id: revealButton
0230             action: revealAction
0231             width: optionsBar.height
0232             height: optionsBar.height
0233             anchors {
0234                 verticalCenter: optionsBar.verticalCenter
0235                 right: optionsBar.right
0236             }
0237             property int countDownTimerValue: 0
0238             Image {
0239                 source: "icons/reveal.png"
0240                 anchors.fill: parent
0241                 anchors.margins: 4
0242                 fillMode: Image.PreserveAspectFit
0243             }
0244             background: Rectangle { color: "transparent" }
0245         }
0246 
0247         Rectangle {
0248             id: timerSection
0249             width: blackboard.width / 9
0250             height: blackboard.height / 7
0251             anchors {
0252                 top: blackboard.top
0253                 topMargin: blackboard.height / 7
0254                 right: blackboard.left
0255                 rightMargin: blackboard.width / 68.5
0256             }
0257             color: "black"
0258             opacity: 0
0259         }
0260     }
0261 
0262     Text {
0263         id: timeRemaining
0264         anchors {
0265             verticalCenter: timerSection.verticalCenter
0266             horizontalCenter: timerSection.horizontalCenter
0267         }
0268         opacity: 0
0269         text: i18n(" ")
0270         color: "white"
0271         font.pixelSize: parent.width / 32
0272     }
0273 
0274     Rectangle {
0275         id: hintSection
0276         width: parent.width / 3
0277         height: parent.height / 3
0278         opacity: 0
0279         color: "black"
0280         anchors {
0281             verticalCenter: blackboard.verticalCenter
0282             right: blackboard.left
0283             rightMargin: blackboard.width / 70
0284             leftMargin: blackboard.width / 70
0285         }
0286     }
0287 
0288    Grid {
0289         id: currentWordGrid;
0290         anchors {
0291             centerIn: parent;
0292         }
0293         spacing: 5;
0294         columns: 10;
0295         Repeater {
0296             model: kanagramGame.anagram
0297             LetterButton {
0298                 text: modelData
0299                 onClicked: letterButtonClicked( index );
0300             }
0301         }
0302     }
0303 
0304     Rectangle {
0305         id: wikiSection
0306         width: parent.width / 9
0307         height: parent.height / 7
0308         opacity: 0
0309         // FIXME: Set to visible false to avoid crash in WebView
0310         visible: false
0311         color: "black"
0312         anchors {
0313             verticalCenter: hintSection.verticalCenter
0314             right: hintSection.left
0315         }
0316     }
0317 
0318     Text {
0319         id: anagramHint
0320         anchors {
0321             verticalCenter: hintSection.verticalCenter
0322             horizontalCenter: hintSection.horizontalCenter
0323         }
0324         color: "white"
0325         width: hintSection.width
0326         wrapMode: Text.WordWrap
0327         text: kanagramGame.hint
0328         opacity: 0
0329         font.pixelSize: hintSection.width / 10
0330     }
0331 
0332     Image {
0333         id: wikiButton
0334         smooth: true
0335         height: wikiSection.height / 2
0336         anchors {
0337             verticalCenter: wikiSection.verticalCenter
0338             horizontalCenter: wikiSection.horizontalCenter
0339         }
0340         source: "icons/wikipedia.png"
0341         opacity: 0
0342         // FIXME: Set to visible false to avoid crash in WebView
0343         visible: false
0344         fillMode: Image.PreserveAspectFit
0345         property bool wikiLinkActivated: false
0346 
0347         MouseArea {
0348             anchors.fill: parent
0349             hoverEnabled: true
0350             onEntered: wikiButton.state = "onEntered"
0351             onExited: wikiButton.state = "onExited"
0352             onClicked: {
0353                 wikiButton.wikiLinkActivated = true
0354                 showWiki()
0355             }
0356         }
0357 
0358         states: State {
0359             name: "onEntered"
0360             PropertyChanges {
0361                 target: wikiText
0362                 opacity: 1
0363             }
0364         }
0365         State {
0366             name: "onExited"
0367         }
0368 
0369         transitions: Transition {
0370             PropertyAnimation {
0371                 properties: "x,y,opacity"
0372                 easing.type: Easing.Linear
0373                 easing.amplitude: 5.0
0374                 easing.period: 1
0375             }
0376         }
0377     }
0378 
0379     Text {
0380         id: wikiText
0381         anchors {
0382             bottom: hintSection.bottom
0383             horizontalCenter: hintSection.horizontalCenter
0384         }
0385         color: "white"
0386         text: i18n("Show Wiki Content")
0387         opacity: 0
0388         font.pixelSize: parent.width / 55
0389     }
0390 
0391     Rectangle {
0392         id: scoreSection
0393         width: blackboard.width / 5
0394         height: blackboard.height / 7
0395         anchors {
0396             bottom: blackboard.bottom
0397             bottomMargin: blackboard.height / 7
0398             right: blackboard.left
0399             rightMargin: blackboard.width / 68.5
0400         }
0401         color: "black"
0402         opacity: 0
0403     }
0404 
0405     Text {
0406         id: score
0407         anchors {
0408             verticalCenter: scoreSection.verticalCenter
0409             horizontalCenter: scoreSection.horizontalCenter
0410         }
0411         color: "white"
0412         text: kanagramGame.currentPlayer == 1 ? i18n("Score : ") + kanagramGame.score : i18n("Score : ") + kanagramGame.score2
0413         opacity: 0
0414         font.pixelSize: parent.width / 40
0415     }
0416 
0417     Timer {
0418         id: hintTimer
0419         interval: 1000
0420         repeat: true
0421         running: false
0422         triggeredOnStart: false
0423 
0424         onTriggered: {
0425             if (--hintButton.countDownTimerValue == 0) {
0426                 hintSection.opacity = 0
0427                 wikiSection.opacity = 0
0428                 anagramHint.opacity = 0
0429                 wikiText.opacity = 0
0430                 wikiButton.opacity = 0
0431                 stop()
0432             } else {
0433                 hintSection.opacity = 0.35
0434                 wikiSection.opacity = 0.35
0435                 wikiButton.opacity = 1
0436                 anagramHint.opacity = 1
0437             }
0438         }
0439     }
0440 
0441     Timer {
0442         id: scoreTimer
0443         interval: 1000
0444         repeat: true
0445         running: false
0446         triggeredOnStart: false
0447 
0448         onTriggered: {
0449 
0450             if (!wikiButton.wikiLinkActivated) {
0451                 if (--scoreButton.countDownTimerValue == 0) {
0452                     stop()
0453                     timerSection.opacity = 0
0454                     timeRemaining.opacity = 0
0455                     scoreTimer.running = false
0456 
0457                     if(!(kanagramGame.singlePlayerMode())) {
0458                         if((kanagramGame.getPlayerNumber())==1) {
0459                             kanagramGame.setPlayerNumber(2);
0460                             score2Box.visible = true;
0461                             showTurnText.visible = true;
0462                             score2BoxText.visible = false;
0463                         }
0464 
0465                         else {
0466                             kanagramGame.setPlayerNumber(1);
0467                             score2Box.visible = true;
0468                             showTurnText.visible = false;
0469                             score2BoxText.visible = true;
0470                         }
0471                 }
0472 
0473                 } else {
0474                     scoreTimer.running = true
0475                     timerSection.opacity = 0.35
0476                     if (scoreButton.countDownTimerValue > 9) {
0477                         timeRemaining.text = '00:' + scoreButton.countDownTimerValue
0478                     } else {
0479                         timeRemaining.text = '00:0' + scoreButton.countDownTimerValue
0480                     }
0481                     timeRemaining.opacity = 1
0482                 }
0483             }
0484         }
0485     }
0486 
0487     Item {
0488         id: score2Box
0489         anchors {
0490             top: blackboard.top
0491             topMargin: 150
0492             left: blackboard.left
0493             leftMargin: 130
0494         }
0495         visible: false
0496 
0497         Rectangle {
0498             id: score2Button
0499             width: blackboard.width / 2
0500             height: blackboard.height / 5
0501             MouseArea {
0502                 anchors.fill: parent
0503             }
0504             radius: 8
0505             color: "black"
0506         }
0507 
0508         Text {
0509             id: score2BoxText
0510             anchors {
0511                 verticalCenter: score2Button.verticalCenter
0512                 horizontalCenter: score2Button.horizontalCenter
0513             }
0514             color: "white"
0515             text: i18n(" Player 1 : ") + kanagramGame.score + i18n("\n Player 2 : ") + kanagramGame.score2 + i18n("\n Close dialog for new game ")
0516         }
0517 
0518         Text {
0519             id: showTurnText
0520             anchors {
0521                 verticalCenter: score2Button.verticalCenter
0522                 horizontalCenter: score2Button.horizontalCenter
0523             }
0524             color: "white"
0525             text: i18n(" Time Up. \n Player 2's Turn")
0526         }
0527 
0528         ToolButton {
0529             id: closeButton
0530             action: closeAction
0531             width: score2Button.width / 6
0532             height: score2Button.height / 2
0533             anchors {
0534                 top: score2Button.top
0535                 right: score2Button.right
0536             }
0537 
0538             Image {
0539                 source: "icons/close.png"
0540                 anchors.fill: parent
0541                 anchors.margins: 4
0542                 fillMode: Image.PreserveAspectFit
0543             }
0544             background: Rectangle { color: "transparent" }
0545         }
0546 
0547         Action {
0548             id: closeAction
0549             onTriggered: {
0550                 score2Box.visible = false;
0551             }
0552             text: i18n("Close")
0553         }
0554     }
0555 
0556     Timer {
0557         id: showAnswerTimer
0558         interval: 1000
0559         repeat: true
0560         running: false
0561         triggeredOnStart: false
0562 
0563         onTriggered: {
0564             if (--revealButton.countDownTimerValue == 0) {
0565                 kanagramGame.nextAnagram();
0566                 if (kanagramGame.hintHideTime())
0567                     blackboard.showHintTimeInterval = 1
0568                 stop()
0569             }
0570         }
0571     }
0572 }