90 lines
1.8 KiB
QML
90 lines
1.8 KiB
QML
import QtGraphicalEffects 1.0
|
|
import QtQuick 2.7
|
|
import QtQuick.Controls 2.4
|
|
import QtQuick.Controls.Material 2.0
|
|
import QtQuick.Layouts 1.3
|
|
|
|
|
|
Item {
|
|
id: root
|
|
height: lbl.visible ? lbl.height : txt.height + (gcd.os == "android" ? btn.height + 3 : 0) //lbl.height
|
|
implicitHeight: height //lbl.height
|
|
|
|
property alias text: lbl.text
|
|
signal updated
|
|
|
|
Text { // DISPLAY THE TEXT IN READONLY MODE
|
|
id: lbl
|
|
fontSizeMode: Text.HorizontalFit
|
|
font.pixelSize: 36
|
|
minimumPixelSize: 8
|
|
horizontalAlignment: Text.AlignHCenter
|
|
textFormat: Text.PlainText
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
}
|
|
|
|
Image {
|
|
id: img
|
|
anchors.left: lbl.right
|
|
anchors.leftMargin: 3
|
|
source: "qrc:/qml/images/fontawesome/solid/edit.svg"
|
|
height: 16
|
|
sourceSize.height: 16
|
|
}
|
|
|
|
|
|
MouseArea {
|
|
anchors.fill: lbl
|
|
|
|
|
|
onClicked: {
|
|
lbl.visible = img.visible = false
|
|
txt.visible = true
|
|
if (gcd.os == "android") btn.visible = true
|
|
txt.text = lbl.text
|
|
txt.selectAll()
|
|
txt.focus = true
|
|
}
|
|
}
|
|
|
|
TextEdit { // MAKE IT AN EDITOR WHEN EDITING
|
|
id: txt
|
|
text: root.text
|
|
visible: false
|
|
selectByMouse: true
|
|
font.pixelSize: lbl.font.pixelSize
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
if (!activeFocus) {
|
|
save()
|
|
}
|
|
}
|
|
|
|
Keys.onReturnPressed: {
|
|
if (event.modifiers == Qt.NoModifier) {
|
|
save()
|
|
}
|
|
}
|
|
|
|
function save() {
|
|
root.text = txt.text
|
|
txt.visible = btn.visible = false
|
|
lbl.visible = img.visible = true
|
|
root.updated(txt.text)
|
|
}
|
|
}
|
|
|
|
SimpleButton {
|
|
id: btn
|
|
anchors.top: txt.bottom
|
|
anchors.topMargin: 3
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
visible: false
|
|
text: qsTr("Update")
|
|
|
|
|
|
onClicked: txt.save()
|
|
}
|
|
} |