更改重命名区域加载逻辑
This commit is contained in:
parent
bb7a5d1b0a
commit
af4077b47c
|
@ -7,8 +7,9 @@ import org.ukui.menu.core 1.0
|
|||
MouseArea {
|
||||
id: control
|
||||
property bool editStatus: false
|
||||
property bool truncate: false
|
||||
hoverEnabled: true
|
||||
ToolTip.visible: textShow.truncated && textShow.visible && control.containsMouse
|
||||
ToolTip.visible: editStatus && truncate && control.containsMouse
|
||||
ToolTip.text: name
|
||||
|
||||
StyleBackground {
|
||||
|
@ -36,18 +37,23 @@ MouseArea {
|
|||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
Component {
|
||||
id: unEditText
|
||||
StyleText {
|
||||
id: textShow
|
||||
anchors.fill: parent
|
||||
visible: !control.editStatus
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
elide: Text.ElideRight
|
||||
text: name
|
||||
Component.onCompleted: {
|
||||
control.truncate = textShow.truncated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: editText
|
||||
AppControls2.StyleBackground {
|
||||
anchors.fill: parent
|
||||
radius: 6
|
||||
useStyleTransparent: false
|
||||
alpha: textChange.activeFocus ? 0.04 : 0
|
||||
|
@ -59,15 +65,12 @@ MouseArea {
|
|||
TextInput {
|
||||
id: textChange
|
||||
text: name
|
||||
visible: control.editStatus
|
||||
focus: false
|
||||
clip: true
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 8
|
||||
anchors.right: buttonMouseArea.left
|
||||
anchors.rightMargin: 8
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
activeFocusOnPress: false
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
selectByMouse: true
|
||||
maximumLength: 14
|
||||
|
@ -85,6 +88,7 @@ MouseArea {
|
|||
Component.onCompleted: {
|
||||
updateTextInputColor();
|
||||
themePalette.styleColorChanged.connect(updateTextInputColor);
|
||||
forceActiveFocus();
|
||||
}
|
||||
|
||||
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
|
||||
|
@ -114,15 +118,13 @@ MouseArea {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: editLoader
|
||||
anchors.fill: parent
|
||||
sourceComponent: editStatus ? editText : unEditText
|
||||
}
|
||||
}
|
||||
onEditStatusChanged: {
|
||||
if (editStatus) {
|
||||
textChange.forceActiveFocus();
|
||||
textChange.focus = true;
|
||||
}
|
||||
else {
|
||||
textChange.focus = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,108 +123,9 @@ SwipeView {
|
|||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: contain
|
||||
property bool editStatus: false
|
||||
EditText {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
AppControls2.StyleText {
|
||||
id: textShow
|
||||
visible: !contain.editStatus
|
||||
anchors.fill: parent
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
elide: Text.ElideRight
|
||||
text: title
|
||||
}
|
||||
|
||||
AppControls2.StyleBackground {
|
||||
anchors.fill: parent
|
||||
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
|
||||
visible: contain.editStatus
|
||||
clip: true
|
||||
focus: false
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 8
|
||||
anchors.right: buttonMouseArea.left
|
||||
anchors.rightMargin: 8
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
activeFocusOnPress: false
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: title
|
||||
selectByMouse: true
|
||||
maximumLength: 14
|
||||
|
||||
onEditingFinished: {
|
||||
modelManager.getFolderModel().renameFolder(text);
|
||||
textShow.text = text;
|
||||
contain.editStatus = false;
|
||||
}
|
||||
|
||||
function updateTextInputColor() {
|
||||
color = themePalette.paletteColor(Palette.Text);
|
||||
selectionColor = themePalette.paletteColor(Palette.Highlight);
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
updateTextInputColor();
|
||||
themePalette.styleColorChanged.connect(updateTextInputColor);
|
||||
}
|
||||
|
||||
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: textArea
|
||||
anchors.fill: textEdit
|
||||
onDoubleClicked: {
|
||||
contain.editStatus = true;
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
textEdit.text = title;
|
||||
contain.editStatus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
onEditStatusChanged: {
|
||||
if (editStatus) {
|
||||
textEdit.z = 2;
|
||||
textEdit.forceActiveFocus();
|
||||
textEdit.focus = true;
|
||||
}
|
||||
else {
|
||||
textEdit.z = 0;
|
||||
textEdit.focus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
Component {
|
||||
id: unEditText
|
||||
AppControls2.StyleText {
|
||||
id: textShow
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: contain.textCenterIn ? Text.AlignHCenter : Text.AlignLeft
|
||||
elide: Text.ElideRight
|
||||
text: contain.textEdited
|
||||
|
||||
MouseArea {
|
||||
id: textArea
|
||||
anchors.fill: parent
|
||||
onDoubleClicked: {
|
||||
contain.editStatus = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
onEditingFinished: {
|
||||
modelManager.getFolderModel().renameFolder(text);
|
||||
contain.textEdited = text;
|
||||
contain.editStatus = false;
|
||||
}
|
||||
|
||||
function updateTextInputColor() {
|
||||
color = themePalette.paletteColor(Palette.Text);
|
||||
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"
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
textEdit.text = title;
|
||||
contain.editStatus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: editLoader
|
||||
anchors.fill: parent
|
||||
sourceComponent: contain.editStatus ? editText : unEditText
|
||||
}
|
||||
}
|
|
@ -33,5 +33,6 @@
|
|||
<file>AppUI/SelectionPage.qml</file>
|
||||
<file>AppUI/AppPageContent.qml</file>
|
||||
<file>AppUI/PluginSelectMenu.qml</file>
|
||||
<file>AppUI/EditText.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in New Issue