Warning, /education/gcompris/src/core/DialogBackground.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - DialogBackground.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 /**
0014  * Base QML component for all full screen dialog screens.
0015  * @ingroup components
0016  *
0017  * Defines the general screen layout used by the following full screen
0018  * dialog elements:
0019  *
0020  * DialogAbout, DialogHelp.
0021  *
0022  * For a general purpose dialog cf. GCDialog.
0023  *
0024  * @inherit QtQuick.Rectangle
0025  */
0026 Rectangle {
0027     id: dialogBackground
0028     color: "#696da3"
0029     z: 1000
0030     focus: visible
0031     property bool isDialog: true
0032     property string title
0033     property string content
0034     property string contentIcon
0035     property alias button0Text: button0.text
0036     signal close
0037     signal start
0038     signal pause
0039     signal play
0040     signal stop
0041     signal button0Hit
0042 
0043     Keys.onPressed: {
0044         if(event.key === Qt.Key_Down) {
0045             scrollItem.down();
0046         } else if(event.key === Qt.Key_Up) {
0047             scrollItem.up();
0048         }
0049     }
0050 
0051     Keys.onEscapePressed: {
0052         dialogBackground.close();
0053     }
0054 
0055     Keys.onReleased: {
0056         if(event.key === Qt.Key_Back) {
0057             dialogBackground.close();
0058             event.accepted = true;
0059         }
0060     }
0061 
0062     onClose: activity.forceActiveFocus();
0063 
0064     Column {
0065         spacing: 10
0066         anchors.top: parent.top
0067         anchors.topMargin: 15
0068         anchors.horizontalCenter: parent.horizontalCenter
0069         width: dialogBackground.width - 30
0070         Rectangle {
0071             id: titleRectangle
0072             color: "#e6e6e6"
0073             radius: 10 * ApplicationInfo.ratio
0074             width: parent.width
0075             height: title.height + 10 * 2
0076 
0077             GCText {
0078                 id: title
0079                 text: dialogBackground.title
0080                 width: titleRectangle.width - 120 * ApplicationInfo.ratio //minus twice the cancel button size
0081                 anchors.horizontalCenter: titleRectangle.horizontalCenter
0082                 anchors.verticalCenter: titleRectangle.verticalCenter
0083                 horizontalAlignment: Text.AlignHCenter
0084                 verticalAlignment: Text.AlignVCenter
0085                 fontSize: 20
0086                 font.weight: Font.DemiBold
0087                 wrapMode: Text.WordWrap
0088             }
0089             // The cancel button
0090             GCButtonCancel {
0091                 id: cancel
0092                 anchors.verticalCenter: titleRectangle.verticalCenter
0093                 anchors.margins: 2 * ApplicationInfo.ratio
0094                 onClose: dialogBackground.close()
0095             }
0096         }
0097         Rectangle {
0098             color: "#bdbed0"
0099             radius: 10 * ApplicationInfo.ratio
0100             width: dialogBackground.width - 30
0101             height: dialogBackground.height - (2 * parent.anchors.topMargin) - titleRectangle.height - parent.spacing
0102             border.color: "white"
0103             border.width: 3 * ApplicationInfo.ratio
0104 
0105             Flickable {
0106                 id: flick
0107                 flickDeceleration: 1500
0108                 anchors.margins: 10 * ApplicationInfo.ratio
0109                 anchors.fill: parent
0110                 contentWidth: textContent.contentWidth
0111                 contentHeight: iconImage.height + button0.height + textContent.contentHeight + 70 * ApplicationInfo.ratio
0112                 flickableDirection: Flickable.VerticalFlick
0113                 clip: true
0114 
0115                 GCButton {
0116                     id: button0
0117                     visible: text != ""
0118                     onClicked: { dialogBackground.button0Hit() }
0119                     width: 150 * ApplicationInfo.ratio
0120                     height: visible ? 40 * ApplicationInfo.ratio : 0
0121                     anchors {
0122                         horizontalCenter: parent.horizontalCenter
0123                         top: parent.top
0124                         topMargin: parent.anchors.margins
0125                     }
0126                     theme: "highContrast"
0127                 }
0128 
0129                 Image {
0130                     id: iconImage
0131                     source: contentIcon
0132                     visible: contentIcon != ""
0133                     width: 100 * ApplicationInfo.ratio
0134                     height: visible ? iconImage.width : 0
0135                     sourceSize.width: iconImage.width
0136                     sourceSize.height: iconImage.width
0137                     anchors.top: button0.bottom
0138                     anchors.margins: parent.anchors.margins
0139                     anchors.horizontalCenter: parent.horizontalCenter
0140                 }
0141 
0142                 GCText {
0143                     id: textContent
0144                     text: style + "<body>" + content + "</body>"
0145                     width: flick.width
0146                     height: flick.height - button0.height
0147                     anchors.top: iconImage.bottom
0148                     anchors.margins: parent.anchors.margins
0149                     fontSize: regularSize
0150                     wrapMode: TextEdit.Wrap
0151                     textFormat: TextEdit.RichText
0152                     property string style: "<head><style>A {color: #191919;}</style></head>"
0153                 }
0154             }
0155             // The scroll buttons
0156             GCButtonScroll {
0157                 id: scrollItem
0158                 anchors.right: parent.right
0159                 anchors.rightMargin: 5 * ApplicationInfo.ratio
0160                 anchors.bottom: flick.bottom
0161                 anchors.bottomMargin: 5 * ApplicationInfo.ratio
0162                 onUp: flick.flick(0, 1000)
0163                 onDown: flick.flick(0, -1000)
0164                 upVisible: flick.atYBeginning ? false : true
0165                 downVisible: flick.atYEnd ? false : true
0166             }
0167         }
0168     }
0169 }