2023-05-16 18:06:10 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2025-02-04 15:50:24 +01:00
|
|
|
* Copyright (C) 2022-2025 Tom Zander <tom@flowee.org>
|
2023-05-16 18:06:10 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
import QtQuick
|
|
|
|
|
import "../Flowee" as Flowee
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
2025-02-17 12:44:23 +01:00
|
|
|
implicitHeight: Math.max(editWidget.implicitHeight, ourLabel.contentHeight)
|
2023-05-16 18:06:10 +02:00
|
|
|
property alias text: ourLabel.text
|
|
|
|
|
property bool editable: true
|
2025-02-04 15:50:24 +01:00
|
|
|
baselineOffset: editWidget.baselineOffset
|
2023-05-16 18:06:10 +02:00
|
|
|
|
|
|
|
|
signal edited;
|
|
|
|
|
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
id: ourLabel
|
|
|
|
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: editIcon.left
|
|
|
|
|
anchors.rightMargin: 10
|
|
|
|
|
anchors.baseline: editWidget.baseline
|
|
|
|
|
visible: !editWidget.visible
|
|
|
|
|
}
|
|
|
|
|
Image {
|
|
|
|
|
id: editIcon
|
|
|
|
|
anchors.right: parent.right
|
2025-02-04 15:50:24 +01:00
|
|
|
y: editWidget.baselineOffset - height
|
2023-05-16 22:40:05 +02:00
|
|
|
width: 16
|
|
|
|
|
height: 16
|
2023-05-16 18:06:10 +02:00
|
|
|
smooth: true
|
2023-05-16 22:40:05 +02:00
|
|
|
source: "qrc:/edit-pen" + (Pay.useDarkSkin ? "-light" : "") + ".svg"
|
2023-06-26 22:13:09 +02:00
|
|
|
opacity: {
|
|
|
|
|
if (root.editable == false)
|
|
|
|
|
return 0;
|
|
|
|
|
if (editWidget.visible) // button is disabled.
|
|
|
|
|
return 0.4
|
|
|
|
|
return 1; // enabled
|
|
|
|
|
}
|
2023-05-16 22:00:47 +02:00
|
|
|
visible: opacity > 0
|
2025-02-04 15:50:24 +01:00
|
|
|
enabled: editWidget.visible === false
|
2023-05-16 18:06:10 +02:00
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: -15
|
|
|
|
|
onClicked: {
|
2023-05-16 18:57:23 +02:00
|
|
|
editWidget.visible = !editWidget.visible;
|
2023-05-31 16:23:23 +02:00
|
|
|
if (editWidget.focus)
|
2023-05-16 18:57:23 +02:00
|
|
|
editWidget.forceActiveFocus();
|
2023-05-16 18:06:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-16 22:00:47 +02:00
|
|
|
Behavior on opacity { NumberAnimation { } }
|
2023-05-16 18:06:10 +02:00
|
|
|
}
|
|
|
|
|
Flowee.TextField {
|
|
|
|
|
id: editWidget
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: editIcon.left
|
2025-02-04 15:50:24 +01:00
|
|
|
anchors.rightMargin: 6
|
2023-05-16 18:06:10 +02:00
|
|
|
visible: false
|
2023-05-31 16:23:23 +02:00
|
|
|
focus: visible
|
2023-05-16 18:06:10 +02:00
|
|
|
text: ourLabel.text
|
2023-08-27 18:46:13 +02:00
|
|
|
onEditingFinished: {
|
2023-06-30 22:25:19 +02:00
|
|
|
ourLabel.text = totalText;
|
2023-05-16 18:06:10 +02:00
|
|
|
root.edited();
|
2023-08-27 18:46:13 +02:00
|
|
|
visible = false
|
2023-05-16 18:06:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|