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 AppControls2 1.0 as AppControls2
|
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: contain
|
|
|
|
property bool textCenterIn: false
|
|
|
|
property bool editStatus: false
|
|
|
|
property string textEdited: title
|
2023-04-08 18:42:31 +08:00
|
|
|
property bool isFullScreenFolder: false
|
2023-05-15 17:28:48 +08:00
|
|
|
property real textInputSize: 14
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: unEditText
|
|
|
|
AppControls2.StyleText {
|
|
|
|
id: textShow
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: contain.textCenterIn ? Text.AlignHCenter : Text.AlignLeft
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: contain.textEdited
|
2023-04-08 18:42:31 +08:00
|
|
|
paletteRole: isFullScreenFolder ? Palette.HighlightedText : Palette.Text
|
|
|
|
font.bold: !isFullScreenFolder
|
2023-05-15 17:28:48 +08:00
|
|
|
font.pointSize: isFullScreenFolder ? textUltra : systemFontSize
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: textArea
|
|
|
|
anchors.fill: parent
|
2023-05-15 17:28:48 +08:00
|
|
|
onDoubleClicked: {
|
|
|
|
contain.editStatus = true;
|
|
|
|
contain.textInputSize = textShow.font.pointSize;
|
|
|
|
}
|
2023-04-08 14:12:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: editText
|
|
|
|
AppControls2.StyleBackground {
|
|
|
|
radius: 6
|
|
|
|
useStyleTransparent: false
|
|
|
|
alpha: textEdit.activeFocus ? 0.04 : 0
|
|
|
|
paletteRole: Palette.Text
|
|
|
|
border.width: 2
|
|
|
|
borderAlpha: textEdit.activeFocus ? 1 : 0
|
|
|
|
borderColor: Palette.Highlight
|
|
|
|
|
|
|
|
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
|
2023-04-08 18:42:31 +08:00
|
|
|
font.bold: !isFullScreenFolder
|
2023-05-15 17:28:48 +08:00
|
|
|
font.pointSize: contain.textInputSize
|
2023-04-08 14:12:11 +08:00
|
|
|
|
|
|
|
onEditingFinished: {
|
|
|
|
modelManager.getFolderModel().renameFolder(text);
|
|
|
|
contain.textEdited = text;
|
|
|
|
contain.editStatus = false;
|
|
|
|
}
|
|
|
|
|
2023-04-08 18:42:31 +08:00
|
|
|
property int textColor: isFullScreenFolder ? Palette.HighlightedText : Palette.Text
|
2023-04-08 14:12:11 +08:00
|
|
|
function updateTextInputColor() {
|
2023-04-08 18:42:31 +08:00
|
|
|
color = themePalette.paletteColor(textColor);
|
2023-04-08 14:12:11 +08:00
|
|
|
selectionColor = themePalette.paletteColor(Palette.Highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
updateTextInputColor();
|
|
|
|
themePalette.styleColorChanged.connect(updateTextInputColor);
|
|
|
|
forceActiveFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: buttonMouseArea
|
|
|
|
hoverEnabled: true
|
|
|
|
width: 16; height: width
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 10
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
visible: textEdit.activeFocus
|
|
|
|
|
|
|
|
ThemeIcon {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: 16; height: width
|
|
|
|
source: "image://appicon/edit-clear-symbolic"
|
2023-04-08 18:42:31 +08:00
|
|
|
highLight: isFullScreenFolder
|
|
|
|
autoHighLight: !isFullScreenFolder
|
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
|
|
|
|
}
|
|
|
|
}
|