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

0001 /* GCompris - DialogActivityConfig.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Johnny Jazeix <jazeix@gmail.com>
0004  *
0005  * Authors:
0006  *   Johnny Jazeix <jazeix@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 /**
0014  * A QML component for a full screen configuration dialog.
0015  * @ingroup components
0016  *
0017  * All user editable settings are presented to the user in a
0018  * DialogActivityConfig dialog. The global configuration can be accessed
0019  * through the Bar in the main menu, activity specific configuration from the
0020  * respective activity.
0021  *
0022  * All config items that are shown in this dialog are persisted
0023  * using ApplicationSettings.
0024  *
0025  * For an example have a look at Menu.qml.
0026  *
0027  * For more details on how to add configuration to an activity cf.
0028  * [the wiki](https://gcompris.net/wiki/Qt_Quick_development_process#Adding_a_configuration_for_a_specific_activity)
0029  *
0030  * @sa ApplicationSettings
0031  * @inherit QtQuick.Item
0032  */
0033 Rectangle {
0034     id: dialogActivityContent
0035     visible: false
0036     focus: visible
0037 
0038     /* Public interface: */
0039 
0040     /**
0041      * type:object
0042      * The content object as loaded dynamically.
0043      */
0044     property alias configItem: loader.item
0045 
0046     /**
0047      * type:Component
0048      * Content component which holds the visual presentation of the
0049      * config settings in the QML scene.
0050      */
0051     property Component content
0052 
0053     /**
0054      * type:string
0055      * The name of the activity in case of per-activity config.
0056      *
0057      * Will be autogenerated unless set by the caller.
0058      */
0059     property string activityName: ""
0060 
0061     /**
0062      * type:object
0063      * Map containing all settings as key/value-pairs.
0064      *
0065      * Will be populated from ApplicationSettings.loadActivityConfiguration
0066      * and can be passed to ApplicationSettings.saveActivityConfiguration.
0067      */
0068     property var dataToSave
0069 
0070     property var dataValidationFunc: null
0071 
0072     /// @cond INTERNAL_DOCS
0073 
0074     property bool isDialog: true
0075 
0076     /**
0077      * type:string
0078      * Title of the configuration dialog.
0079      * Global configuration name is "Configuration".
0080      * For activities, it is "activity name configuration".
0081     */
0082     readonly property string title: {
0083         if(activityName != "")
0084         qsTr("%1 configuration").arg(activityInfo.title)
0085         else
0086         qsTr("Configuration")
0087     }
0088     property alias active: loader.active
0089     property alias loader: loader
0090     property QtObject activityInfo: ActivityInfoTree.currentActivity
0091 
0092     property ActivityBase currentActivity
0093 
0094     /// @endcond
0095 
0096     /**
0097      * Emitted when the config dialog has been closed.
0098      */
0099     signal close
0100 
0101     /**
0102      * Emitted when the config dialog has been started.
0103      */
0104     signal start
0105 
0106     /**
0107      * Emitted when the settings are to be saved.
0108      *
0109      * The actual persisting of the settings in the settings file is done by
0110      * DialogActivityConfig. The activity has to take care to update its
0111      * internal state.
0112      */
0113     signal saveData
0114 
0115     /**
0116      * Emitted when the config settings have been loaded.
0117      */
0118     signal loadData
0119 
0120     signal stop
0121 
0122     color: "#696da3"
0123 
0124     Keys.onPressed: {
0125         if(event.key === Qt.Key_Down) {
0126             scrollItem.down();
0127         } else if(event.key === Qt.Key_Up) {
0128             scrollItem.up();
0129         } else if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
0130             apply.close();
0131         }
0132     }
0133 
0134     Keys.onEscapePressed: {
0135         dialogActivityContent.close();
0136     }
0137 
0138     Keys.onReleased: {
0139         if(event.key === Qt.Key_Back) {
0140             dialogActivityContent.close();
0141             event.accepted = true;
0142         }
0143     }
0144 
0145     onClose: activity.forceActiveFocus();
0146 
0147     function getInitialConfiguration() {
0148         if(activityName == "") {
0149             activityName = activityInfo.name.split('/')[0];
0150         }
0151         dataToSave = ApplicationSettings.loadActivityConfiguration(activityName)
0152         loadData()
0153     }
0154 
0155     function saveDatainConfiguration() {
0156         saveData()
0157         ApplicationSettings.saveActivityConfiguration(activityName, dataToSave)
0158     }
0159 
0160     Column {
0161         visible: dialogActivityContent.active
0162         spacing: 10
0163         anchors.top: parent.top
0164         anchors.topMargin: 15
0165         anchors.horizontalCenter: parent.horizontalCenter
0166         width: dialogActivityContent.width - 30
0167         Rectangle {
0168             id: titleRectangle
0169             color: "#e6e6e6"
0170             radius: 10 * ApplicationInfo.ratio
0171             width: parent.width
0172             height: title.height + 10 * 2
0173 
0174             // The apply button
0175             GCButtonCancel {
0176                 id: apply
0177                 apply: true
0178                 anchors.verticalCenter: titleRectangle.verticalCenter
0179                 anchors.margins: 2 * ApplicationInfo.ratio
0180                 onClose: {
0181                     if (dialogActivityContent.dataValidationFunc && !
0182                         dialogActivityContent.dataValidationFunc()) {
0183                         console.log("Configuration data is invalid, not saving!");
0184                     return;
0185                         }
0186                         saveData()
0187                         if(activityName != "") {
0188                             ApplicationSettings.saveActivityConfiguration(activityName, dataToSave)
0189                         }
0190                         dialogActivityContent.close()
0191                 }
0192             }
0193 
0194             GCText {
0195                 id: title
0196                 text: dialogActivityContent.title
0197                 width: titleRectangle.width - 120 * ApplicationInfo.ratio //minus twice the apply button size
0198                 height: 50 * ApplicationInfo.ratio
0199                 anchors.horizontalCenter: titleRectangle.horizontalCenter
0200                 anchors.verticalCenter: titleRectangle.verticalCenter
0201                 horizontalAlignment: Text.AlignHCenter
0202                 verticalAlignment: Text.AlignVCenter
0203                 fontSizeMode: Text.Fit
0204                 minimumPointSize: 7
0205                 fontSize: largeSize
0206                 font.weight: Font.DemiBold
0207                 wrapMode: Text.WordWrap
0208             }
0209         }
0210 
0211         Rectangle {
0212             color: "#bdbed0"
0213             radius: 10 * ApplicationInfo.ratio
0214             width: dialogActivityContent.width - 30
0215             height: dialogActivityContent.height - (2 * parent.anchors.topMargin) - titleRectangle.height - parent.spacing
0216             border.color: "white"
0217             border.width: 3 * ApplicationInfo.ratio
0218 
0219             Flickable {
0220                 id: flick
0221                 flickDeceleration: 1500
0222                 anchors.margins: 10 * ApplicationInfo.ratio
0223                 anchors.fill: parent
0224                 flickableDirection: Flickable.VerticalFlick
0225                 clip: true
0226                 contentHeight: contentItem.childrenRect.height + 40 * ApplicationInfo.ratio
0227                 Loader {
0228                     id: loader
0229                     active: false
0230                     sourceComponent: dialogActivityContent.content
0231                     property alias rootItem: dialogActivityContent
0232                 }
0233             }
0234 
0235             // The scroll buttons
0236             GCButtonScroll {
0237                 id: scrollItem
0238                 anchors.right: parent.right
0239                 anchors.rightMargin: 5 * ApplicationInfo.ratio
0240                 anchors.bottom: flick.bottom
0241                 anchors.bottomMargin: 5 * ApplicationInfo.ratio
0242                 onUp: flick.flick(0, 1000)
0243                 onDown: flick.flick(0, -1000)
0244                 upVisible: flick.atYBeginning ? false : true
0245                 downVisible: flick.atYEnd ? false : true
0246             }
0247         }
0248     }
0249 }