2023-04-08 14:12:11 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
import org.ukui.menu.core 1.0
|
2024-01-04 11:13:41 +08:00
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
2023-12-11 16:13:53 +08:00
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: contain
|
|
|
|
property bool textCenterIn: false
|
|
|
|
property bool editStatus: false
|
|
|
|
property string textEdited: title
|
2024-02-27 15:10:32 +08:00
|
|
|
property string text: editLoader.item.text
|
2024-02-01 18:55:21 +08:00
|
|
|
property real textSize
|
2023-04-08 14:12:11 +08:00
|
|
|
|
2024-01-30 16:16:09 +08:00
|
|
|
signal textEditingFinished(string text)
|
2023-04-08 14:12:11 +08:00
|
|
|
Component {
|
|
|
|
id: unEditText
|
2023-12-11 16:13:53 +08:00
|
|
|
UkuiItems.StyleText {
|
2023-04-08 14:12:11 +08:00
|
|
|
id: textShow
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: contain.textCenterIn ? Text.AlignHCenter : Text.AlignLeft
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: contain.textEdited
|
2024-02-01 18:55:21 +08:00
|
|
|
paletteRole: Platform.Theme.Text
|
|
|
|
font.bold: true
|
|
|
|
font.pointSize: textSize
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: textArea
|
|
|
|
anchors.fill: parent
|
2024-02-01 18:55:21 +08:00
|
|
|
onDoubleClicked: contain.editStatus = true;
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: editText
|
2023-12-11 16:13:53 +08:00
|
|
|
UkuiItems.StyleBackground {
|
2024-01-04 11:13:41 +08:00
|
|
|
radius: Platform.Theme.normalRadius
|
2023-12-11 16:13:53 +08:00
|
|
|
useStyleTransparency: false
|
2023-04-08 14:12:11 +08:00
|
|
|
alpha: textEdit.activeFocus ? 0.04 : 0
|
2024-01-04 11:13:41 +08:00
|
|
|
paletteRole: Platform.Theme.Text
|
2023-04-08 14:12:11 +08:00
|
|
|
border.width: 2
|
|
|
|
borderAlpha: textEdit.activeFocus ? 1 : 0
|
2024-01-04 11:13:41 +08:00
|
|
|
borderColor: Platform.Theme.Highlight
|
2024-02-27 15:10:32 +08:00
|
|
|
property string text: textEdit.text
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
TextInput {
|
|
|
|
id: textEdit
|
|
|
|
clip: true
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 8
|
|
|
|
anchors.right: buttonMouseArea.left
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: contain.textCenterIn ? Text.AlignHCenter : Text.AlignLeft
|
|
|
|
text: contain.textEdited
|
|
|
|
selectByMouse: true
|
|
|
|
maximumLength: 14
|
2024-02-01 18:55:21 +08:00
|
|
|
font.pointSize: textSize
|
2024-07-08 14:00:11 +08:00
|
|
|
font.family: Platform.Theme.fontFamily;
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
onEditingFinished: {
|
2024-01-30 16:16:09 +08:00
|
|
|
// modelManager.getFolderModel().renameFolder(text);
|
2023-04-08 14:12:11 +08:00
|
|
|
contain.textEdited = text;
|
|
|
|
contain.editStatus = false;
|
2024-01-30 16:16:09 +08:00
|
|
|
textEditingFinished(text);
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTextInputColor() {
|
2024-02-01 18:55:21 +08:00
|
|
|
color = Platform.Theme.text();
|
2024-01-18 03:24:01 +08:00
|
|
|
selectionColor = Platform.Theme.highlight();
|
|
|
|
}
|
|
|
|
|
|
|
|
Platform.Theme.onPaletteChanged: {
|
|
|
|
updateTextInputColor();
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
updateTextInputColor();
|
|
|
|
forceActiveFocus();
|
|
|
|
}
|
2024-07-08 17:10:33 +08:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.IBeamCursor
|
|
|
|
enabled: false
|
|
|
|
}
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: buttonMouseArea
|
|
|
|
hoverEnabled: true
|
|
|
|
width: 16; height: width
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 10
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
visible: textEdit.activeFocus
|
|
|
|
|
2024-01-18 03:24:01 +08:00
|
|
|
UkuiItems.Icon {
|
2023-04-08 14:12:11 +08:00
|
|
|
anchors.centerIn: parent
|
|
|
|
width: 16; height: width
|
2024-01-18 03:24:01 +08:00
|
|
|
source: "image://theme/edit-clear-symbolic"
|
2024-02-27 15:10:32 +08:00
|
|
|
mode: UkuiItems.Icon.AutoHighlight
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
2023-04-08 18:42:31 +08:00
|
|
|
textEdit.text = textEdited;
|
2023-04-08 14:12:11 +08:00
|
|
|
contain.editStatus = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: editLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
sourceComponent: contain.editStatus ? editText : unEditText
|
|
|
|
}
|
|
|
|
}
|