Warning, /education/gcompris/src/core/GCButton.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - GCButton.qml 0002 * 0003 * SPDX-FileCopyrightText: 2020 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 import QtQuick.Controls 2.12 0013 0014 /** 0015 * A QML component representing GCompris' buttons. 0016 * @ingroup components 0017 * 0018 * @inherit QtQuick2.Button 0019 */ 0020 Button { 0021 id: buttonControl 0022 0023 /** 0024 * type:real 0025 * Fixed font size of the label in pt. 0026 * 0027 * Set to a value > 0 for enforcing a fixed font.pointSize for the label, 0028 * that won't be updated with ApplicationSettings.baseFontSize. 0029 * @sa ApplicationSettings.baseFontSize, GCText.fixFontSize 0030 */ 0031 property real fixedFontSize: -1 0032 0033 /** 0034 * type:string 0035 * theme of the button. For now, three themes are accepted: "light" and "dark" and "highContrast" 0036 * 0037 * Default is dark. 0038 */ 0039 property string theme: "dark" 0040 0041 /** 0042 * type:real 0043 * if there is an icon on the right, we need to add a rightMargin for the text label 0044 * 0045 * Default is 0. 0046 */ 0047 property real rightIconSize: 0 0048 0049 /** 0050 * type:var 0051 * existing themes for the button. 0052 * A theme is composed of: 0053 * the colors of the button when selected: selectedColorGradient0 and selectedColorGradient1. 0054 * the colors of the button when not selected: backgroundColorGradient0 and backgroundColorGradient1. 0055 * the button's border color 0056 * the text color 0057 */ 0058 property var themes: { 0059 "dark": { 0060 backgroundColorGradient0: "#23373737", 0061 selectedColorGradient0: "#C03ACAFF", 0062 backgroundColorGradient1: "#13373737", 0063 selectedColorGradient1: "#803ACAFF", 0064 borderColor: "#FF373737", 0065 textColor: "#FF373737" 0066 }, 0067 "light": { 0068 backgroundColorGradient0: "#42FFFFFF", 0069 selectedColorGradient0: "#C03ACAFF", 0070 backgroundColorGradient1: "#23FFFFFF", 0071 selectedColorGradient1: "#803ACAFF", 0072 borderColor: "white", 0073 textColor: "white" 0074 }, 0075 "highContrast": { 0076 backgroundColorGradient0: "#EEFFFFFF", 0077 selectedColorGradient0: "#C03ACAFF", 0078 backgroundColorGradient1: "#AAFFFFFF", 0079 selectedColorGradient1: "#803ACAFF", 0080 borderColor: "white", 0081 textColor: "#FF373737" 0082 }, 0083 "categories": { 0084 backgroundColorGradient0: "#80F6FBFC", 0085 selectedColorGradient0: "#FFF6FBFC", 0086 backgroundColorGradient1: "#80F6FBFC", 0087 selectedColorGradient1: "#FFF6FBFC", 0088 borderColor: "#FF87A6DD", 0089 textColor: "#FF373737" 0090 }, 0091 "settingsButton": { 0092 backgroundColorGradient0: "#bdbed0", 0093 selectedColorGradient0: "#e6e6e6", 0094 backgroundColorGradient1: "#bdbed0", 0095 selectedColorGradient1: "#e6e6e6", 0096 borderColor: selected ? "#ffffffff" : "#00ffffff", 0097 textColor: "#191919" 0098 }, 0099 "noStyle": { 0100 backgroundColorGradient0: "#00FFFFFF", 0101 selectedColorGradient0: "#00FFFFFF", 0102 backgroundColorGradient1: "#00FFFFFF", 0103 selectedColorGradient1: "#00FFFFFF", 0104 borderColor: "#00FFFFFF", 0105 textColor: "#00000000" 0106 } 0107 } 0108 0109 property bool selected: false 0110 0111 property string textSize: "regular" 0112 0113 property var textSizes: { 0114 "regular": { 0115 fontSize: 14, 0116 fontBold: false 0117 }, 0118 "subtitle": { 0119 fontSize: 16, 0120 fontBold: true 0121 }, 0122 "title": { 0123 fontSize: 24, 0124 fontBold: true 0125 } 0126 } 0127 0128 focusPolicy: Qt.NoFocus 0129 0130 background: Rectangle { 0131 border.width: buttonControl.activeFocus ? 4 : 2 0132 border.color: themes[theme].borderColor 0133 radius: 10 0134 gradient: Gradient { 0135 GradientStop { position: 0 ; color: buttonControl.pressed ? themes[theme].selectedColorGradient0 : themes[theme].backgroundColorGradient0 } 0136 GradientStop { position: 1 ; color: buttonControl.pressed ? themes[theme].selectedColorGradient1 : themes[theme].backgroundColorGradient1 } 0137 } 0138 } 0139 contentItem: Item { 0140 id: labelItem 0141 anchors.fill: parent 0142 implicitWidth: labelText.implicitWidth 0143 implicitHeight: labelText.implicitHeight 0144 0145 GCText { 0146 id: labelText 0147 color: themes[theme].textColor 0148 text: buttonControl.text 0149 fontSize: textSizes[textSize].fontSize 0150 font.bold: textSizes[textSize].fontBold 0151 anchors.fill: parent 0152 anchors.leftMargin: 10 0153 anchors.rightMargin: rightIconSize > 0 ? rightIconSize : 10 // if there's a rightIconSize, it must handle the rightMargin 0154 anchors.topMargin: 10 0155 anchors.bottomMargin: 10 0156 horizontalAlignment: Text.AlignHCenter 0157 verticalAlignment: Text.AlignVCenter 0158 wrapMode: Text.WordWrap 0159 fontSizeMode: Text.Fit 0160 0161 Component.onCompleted: { 0162 if (fixedFontSize > 0) { 0163 labelText.fixFontSize = true; 0164 labelText.fontSize = fixedFontSize; 0165 } 0166 } 0167 } 0168 } 0169 }