2023-03-28 09:38:39 +08:00
|
|
|
import QtQuick 2.12
|
2023-02-14 09:34:15 +08:00
|
|
|
import QtQuick.Layouts 1.12
|
2023-03-28 09:38:39 +08:00
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
import org.ukui.menu.core 1.0
|
2023-12-11 16:13:53 +08:00
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2024-01-18 03:24:01 +08:00
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
2023-02-14 09:34:15 +08:00
|
|
|
|
2023-03-31 16:08:10 +08:00
|
|
|
MouseArea {
|
|
|
|
id: control
|
2023-04-07 10:00:56 +08:00
|
|
|
property bool editStatus: false
|
2023-04-08 14:12:11 +08:00
|
|
|
property bool truncate: false
|
2023-05-04 15:09:52 +08:00
|
|
|
property bool isSelect: false
|
2023-03-31 16:08:10 +08:00
|
|
|
hoverEnabled: true
|
2023-12-05 09:22:08 +08:00
|
|
|
|
|
|
|
ToolTip {
|
|
|
|
property bool isVisible: !editStatus && truncate && control.containsMouse
|
|
|
|
id: tip
|
|
|
|
x: mouseX + 15
|
|
|
|
y: mouseY + 15
|
|
|
|
text: name
|
|
|
|
visible: !editStatus && truncate && control.containsMouse
|
|
|
|
delay: 500
|
|
|
|
}
|
|
|
|
onPositionChanged: {
|
|
|
|
if (tip.isVisible) {
|
|
|
|
if (tip.visible) {
|
|
|
|
tip.hide();
|
|
|
|
} else {
|
|
|
|
tip.show(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
states: State {
|
|
|
|
when: control.activeFocus
|
|
|
|
PropertyChanges {
|
|
|
|
target: controlBase
|
2024-01-18 03:24:01 +08:00
|
|
|
borderColor: Platform.Theme.Highlight
|
2023-08-14 11:15:54 +08:00
|
|
|
border.width: 2
|
2023-04-26 17:04:22 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-23 11:54:17 +08:00
|
|
|
|
2024-01-04 11:13:41 +08:00
|
|
|
UkuiItems.StyleBackground {
|
2023-04-26 17:04:22 +08:00
|
|
|
id: controlBase
|
2023-03-28 09:38:39 +08:00
|
|
|
anchors.fill: parent
|
2024-01-04 11:13:41 +08:00
|
|
|
radius: Platform.Theme.minRadius
|
|
|
|
useStyleTransparency: false
|
2023-05-04 15:09:52 +08:00
|
|
|
alpha: isSelect ? 0.55 : control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00
|
2023-02-14 09:34:15 +08:00
|
|
|
|
2023-04-03 15:58:05 +08:00
|
|
|
RowLayout {
|
2023-03-31 16:08:10 +08:00
|
|
|
anchors.fill: parent
|
2023-04-03 15:58:05 +08:00
|
|
|
anchors.leftMargin: 12
|
2023-03-31 16:08:10 +08:00
|
|
|
spacing: 12
|
2023-04-07 10:00:56 +08:00
|
|
|
|
2023-04-03 15:58:05 +08:00
|
|
|
FolderIcon {
|
|
|
|
rows: 2; columns: 2
|
|
|
|
spacing: 2; padding: 2
|
|
|
|
icons: icon
|
2024-01-04 11:13:41 +08:00
|
|
|
alpha: 0.12; radius: Platform.Theme.minRadius
|
2023-04-03 15:58:05 +08:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
Layout.preferredWidth: 32
|
|
|
|
Layout.preferredHeight: 32
|
|
|
|
}
|
|
|
|
|
2023-04-07 10:00:56 +08:00
|
|
|
Item {
|
|
|
|
id: renameArea
|
2023-04-03 15:58:05 +08:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2023-04-07 10:00:56 +08:00
|
|
|
|
2023-04-08 14:12:11 +08:00
|
|
|
Component {
|
|
|
|
id: unEditText
|
2024-01-04 11:13:41 +08:00
|
|
|
UkuiItems.StyleText {
|
2023-04-08 14:12:11 +08:00
|
|
|
id: textShow
|
2023-04-07 10:00:56 +08:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
2023-04-08 14:12:11 +08:00
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: name
|
2023-05-24 14:43:37 +08:00
|
|
|
onWidthChanged: {
|
2023-04-08 14:12:11 +08:00
|
|
|
control.truncate = textShow.truncated
|
2023-04-07 10:00:56 +08:00
|
|
|
}
|
|
|
|
}
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
|
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: textChange.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: textChange.activeFocus ? 1 : 0
|
2024-01-04 11:13:41 +08:00
|
|
|
borderColor: Platform.Theme.Highlight
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
TextInput {
|
|
|
|
id: textChange
|
|
|
|
text: name
|
|
|
|
clip: true
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 8
|
|
|
|
anchors.right: buttonMouseArea.left
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
selectByMouse: true
|
|
|
|
maximumLength: 14
|
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
function editStatusEnd() {
|
2023-04-08 14:12:11 +08:00
|
|
|
control.editStatus = false;
|
2023-05-23 11:54:17 +08:00
|
|
|
control.focus = true;
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTextInputColor() {
|
2024-01-18 03:24:01 +08:00
|
|
|
color = Platform.Theme.text();
|
|
|
|
selectionColor = Platform.Theme.highlight();
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
onEditingFinished: {
|
|
|
|
modelManager.getAppModel().renameFolder(id, text);
|
|
|
|
textChange.editStatusEnd();
|
|
|
|
}
|
2024-01-18 03:24:01 +08:00
|
|
|
|
|
|
|
Platform.Theme.onPaletteChanged: {
|
|
|
|
updateTextInputColor();
|
|
|
|
}
|
|
|
|
|
2023-04-08 14:12:11 +08:00
|
|
|
Component.onCompleted: {
|
|
|
|
updateTextInputColor();
|
|
|
|
forceActiveFocus();
|
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
}
|
|
|
|
|
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: textChange.activeFocus
|
|
|
|
|
2024-01-09 10:08:53 +08:00
|
|
|
UkuiItems.Icon {
|
2023-04-08 14:12:11 +08:00
|
|
|
anchors.centerIn: parent
|
|
|
|
width: 16; height: width
|
2024-01-09 10:08:53 +08:00
|
|
|
source: "edit-clear-symbolic"
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
textChange.text = name;
|
2023-05-23 11:54:17 +08:00
|
|
|
textChange.editStatusEnd();
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
2023-04-07 10:00:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 14:12:11 +08:00
|
|
|
Loader {
|
|
|
|
id: editLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
sourceComponent: editStatus ? editText : unEditText
|
|
|
|
}
|
2023-04-03 15:58:05 +08:00
|
|
|
}
|
2023-02-14 09:34:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|