ukui-menu/qml/AppControls2/FolderItem.qml

164 lines
5.5 KiB
QML
Raw Normal View History

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
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
2023-02-14 09:34:15 +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
property bool isSelect: false
hoverEnabled: true
UkuiItems.Tooltip {
anchors.fill: parent
mainText: name
posFollowCursor: true
margin: 6
visible: !editStatus && truncate
}
onPositionChanged: {
if (tip.isVisible) {
if (tip.visible) {
tip.hide();
} else {
tip.show(name);
}
}
}
states: State {
when: control.activeFocus
PropertyChanges {
target: controlBase
borderColor: Platform.Theme.Highlight
border.width: 2
}
}
UkuiItems.StyleBackground {
id: controlBase
2023-03-28 09:38:39 +08:00
anchors.fill: parent
radius: Platform.Theme.minRadius
useStyleTransparency: false
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 {
anchors.fill: parent
2023-04-03 15:58:05 +08:00
anchors.leftMargin: 12
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
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
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
UkuiItems.StyleBackground {
radius: Platform.Theme.normalRadius
useStyleTransparency: false
2023-04-08 14:12:11 +08:00
alpha: textChange.activeFocus ? 0.04 : 0
paletteRole: Platform.Theme.Text
2023-04-08 14:12:11 +08:00
border.width: 2
borderAlpha: textChange.activeFocus ? 1 : 0
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
function editStatusEnd() {
2023-04-08 14:12:11 +08:00
control.editStatus = false;
control.focus = true;
2023-04-08 14:12:11 +08:00
}
function updateTextInputColor() {
color = Platform.Theme.text();
selectionColor = Platform.Theme.highlight();
2023-04-08 14:12:11 +08:00
}
onEditingFinished: {
modelManager.getAppModel().renameFolder(id, text);
textChange.editStatusEnd();
}
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;
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
}
}
}