Warning, /plasma-bigscreen/calamares-bigscreen-branding/bigscreen/keyboarddata/Key.qml is written in an unsupported language. File is not indexed.

0001 /* === This file is part of Calamares - <https://calamares.io> ===
0002  *
0003  *   SPDX-FileCopyrightText: 2021 Anke Boersma <demm@kaosx.us>
0004  *   SPDX-License-Identifier: GPL-3.0-or-later
0005  *
0006  *   Calamares is Free Software: see the License-Identifier above.
0007  *
0008  */
0009 
0010 import QtQuick 2.15
0011 
0012 Item {
0013     id: key
0014 
0015     property string mainLabel: "A"
0016     property var secondaryLabels: [];
0017 
0018     property var iconSource;
0019 
0020     property var keyImageLeft: ""
0021     property var keyImageRight: ""
0022     property var keyImageCenter: ""
0023 
0024     property color keyColor: "#404040"
0025     property color keyPressedColor: "grey"
0026     property int keyBounds: 2
0027     property var keyPressedColorOpacity: 1
0028 
0029     property var mainFontFamily: "Roboto"
0030     property color mainFontColor: "white"
0031     property int mainFontSize: 18
0032 
0033     property var secondaryFontFamily: "Roboto"
0034     property color secondaryFontColor: "white"
0035     property int secondaryFontSize: 10
0036 
0037     property bool secondaryLabelVisible: true
0038 
0039     property bool isChekable;
0040     property bool isChecked;
0041 
0042     property bool upperCase;
0043 
0044     signal clicked()
0045     signal alternatesClicked(string symbol)
0046 
0047     Item {
0048         anchors.fill: parent
0049         anchors.margins: key.keyBounds
0050         visible: key.keyImageLeft != "" || key.keyImageCenter != "" || key.keyImageRight != "" ? 1 : 0
0051         Image {
0052             id: backgroundImage_left
0053             anchors.left: parent.left
0054             height: parent.height
0055             fillMode: Image.PreserveAspectFit
0056             source: key.keyImageLeft
0057         }
0058         Image {
0059             id: backgroundImage_right
0060             anchors.right: parent.right
0061             height: parent.height
0062             fillMode: Image.PreserveAspectFit
0063             source: key.keyImageRight
0064         }
0065         Image {
0066             id: backgroundImage_center
0067             anchors.fill: parent
0068             anchors.leftMargin: backgroundImage_left.width - 1
0069             anchors.rightMargin: backgroundImage_right.width - 1
0070             height: parent.height
0071             fillMode: Image.Stretch
0072             source: key.keyImageCenter
0073         }
0074     }
0075 
0076     Rectangle {
0077         id: backgroundItem
0078         anchors.fill: parent
0079         anchors.margins: key.keyBounds
0080         color: key.isChecked || mouseArea.pressed ? key.keyPressedColor : key.keyColor;
0081         opacity: key.keyPressedColorOpacity
0082     }
0083 
0084     Column
0085     {
0086         anchors.centerIn: backgroundItem
0087 
0088         Text {
0089             id: secondaryLabelsItem
0090             smooth: true
0091             anchors.right: parent.right
0092             visible: true //secondaryLabelVisible
0093             text: secondaryLabels.length > 0 ? secondaryLabels : ""
0094             color: secondaryFontColor
0095 
0096             font.pixelSize: secondaryFontSize
0097             font.weight: Font.Light
0098             font.family: secondaryFontFamily
0099             font.capitalization: upperCase ? Font.AllUppercase :
0100                                                      Font.MixedCase
0101         }
0102 
0103         Row {
0104             anchors.horizontalCenter: parent.horizontalCenter
0105 
0106             Image {
0107                 id: icon
0108                 smooth: true
0109                 anchors.verticalCenter: parent.verticalCenter
0110                 source: iconSource
0111                 //sourceSize.width: key.width * 0.6
0112                 sourceSize.height: key.height * 0.4
0113             }
0114 
0115             Text {
0116                 id: mainLabelItem
0117                 smooth: true
0118                 anchors.verticalCenter: parent.verticalCenter
0119                 text: mainLabel
0120                 color: mainFontColor
0121                 visible: iconSource ? false : true
0122 
0123                 font.pixelSize: mainFontSize
0124                 font.weight: Font.Light
0125                 font.family: mainFontFamily
0126                 font.capitalization: upperCase ? Font.AllUppercase :
0127                                                          Font.MixedCase
0128             }
0129         }
0130     }
0131 
0132     Row {
0133         id: alternatesRow
0134         property int selectedIndex: -1
0135         visible: false
0136         anchors.bottom: backgroundItem.top
0137         anchors.left: backgroundItem.left
0138 
0139         Repeater {
0140             model: secondaryLabels.length
0141 
0142             Rectangle {
0143                 property bool isSelected: alternatesRow.selectedIndex == index
0144                 color: isSelected ? mainLabelItem.color : key.keyPressedColor
0145                 height: backgroundItem.height
0146                 width: backgroundItem.width
0147 
0148                 Text {
0149                     anchors.centerIn: parent
0150                     text: secondaryLabels[ index ]
0151                     font: mainLabelItem.font
0152                     color: isSelected ? key.keyPressedColor : mainLabelItem.color
0153                 }
0154             }
0155         }
0156     }
0157 
0158     MouseArea {
0159         id: mouseArea
0160         anchors.fill: parent
0161         onPressAndHold: alternatesRow.visible = true
0162         onClicked: {
0163             if (key.isChekable) key.isChecked = !key.isChecked
0164             key.clicked()
0165         }
0166 
0167         onReleased: {
0168             alternatesRow.visible = false
0169             if (alternatesRow.selectedIndex > -1)
0170                 key.alternatesClicked(secondaryLabels[alternatesRow.selectedIndex])
0171         }
0172 
0173         onMouseXChanged: {
0174             alternatesRow.selectedIndex =
0175             (mouseY < 0 && mouseX > 0 && mouseY < alternatesRow.width) ?
0176                         Math.floor(mouseX / backgroundItem.width) :
0177                         -1;
0178         }
0179     }
0180 }