Merge pull request #248 from FeJQ/FluNavigationView-pr

补交漏掉的FluEditableText.qml
This commit is contained in:
zhuzichu 2023-08-18 20:13:00 +08:00 committed by GitHub
commit efd21a5f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 214 additions and 2 deletions

View File

@ -7,6 +7,12 @@ FluObject{
property var navigationView property var navigationView
function rename(item, newName){
if(newName && newName.trim().length>0){
item.title = newName;
}
}
FluPaneItem{ FluPaneItem{
id:item_home id:item_home
count: 9 count: 9
@ -21,11 +27,48 @@ FluObject{
} }
navigationView.push("qrc:/example/qml/page/T_Home.qml") navigationView.push("qrc:/example/qml/page/T_Home.qml")
} }
rightMenu: FluMenu{
property string renameText : "重命名"
id:nav_item_right_menu
enableAnimation: false
width: 120
FluMenuItem{
text: nav_item_right_menu.renameText
visible: true
onClicked: {
item_home.editable = true;
}
}
}
onTitleEdited:function(newText){
rename(item_home,newText)
}
} }
FluPaneItemExpander{ FluPaneItemExpander{
id:item_expander_basic_input
title:lang.basic_input title:lang.basic_input
icon:FluentIcons.CheckboxComposite icon:FluentIcons.CheckboxComposite
rightMenu: FluMenu{
property string renameText : "重命名"
id:nav_item_expander_right_menu
enableAnimation: false
width: 120
FluMenuItem{
text: nav_item_expander_right_menu.renameText
visible: true
onClicked: {
item_expander_basic_input.editable = true;
}
}
}
onTitleEdited:function(newText){ rename(item_expander_basic_input,newText)}
FluPaneItem{ FluPaneItem{
id:item_buttons id:item_buttons
count: 99 count: 99

View File

@ -0,0 +1,91 @@
import QtQuick
import FluentUI
Item {
id:root
property bool editable: false
property string text: ""
property int elide
property color color
property color editBgColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(255/255,255/255,255/255,1)
property color editTextColor: FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
property alias editBgRect : editBackgroundComponent
property alias normalText :normalTextComponent
property alias editableText :editableTextComponent
signal fluTextEdited(var newText)
signal fluLostFocus(bool isActiveFocus)
height:24
function setEditable(value){
editable = value;
}
Keys.onPressed:function(event) {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if(editableTextComponent.text !== "" && editableTextComponent.text !== root.text){
fluTextEdited(editableTextComponent.text)
}
fluLostFocus(false)
}
}
//property alias anchors:normalText.anchors
FluText{
id:normalTextComponent
text: root.text
elide:root.elide
color:root.color
visible: !editable
anchors.fill: parent
lineHeight: height
verticalAlignment: Text.AlignVCenter
}
Rectangle{
id:editBackgroundComponent
width: Math.max(editableText.implicitWidth,20)
height:parent.height
radius: 5
color:editable? editBgColor:"transparent"
visible: editable
TextInput{
id:editableTextComponent
anchors.fill: parent
text:root.text
color:editTextColor
visible: editable
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
font: FluTextStyle.Body
verticalAlignment: Text.AlignVCenter
//focus: editable
onActiveFocusChanged: {
if(editableTextComponent.text !== "" && editableTextComponent.text !== root.text){
fluTextEdited(text)
}
fluLostFocus(activeFocus);
}
}
}
onEditableChanged: {
if(editable){
editableTextComponent.forceActiveFocus()
editableTextComponent.selectAll()
}
}
}

View File

@ -16,6 +16,8 @@ Item {
property int topPadding: 0 property int topPadding: 0
property int navWidth: 300 property int navWidth: 300
property int pageMode: FluNavigationViewType.Stack property int pageMode: FluNavigationViewType.Stack
property FluMenu navItemRightMenu
property FluMenu navItemExpanderRightMenu
signal logoClicked signal logoClicked
id:control id:control
Item{ Item{
@ -161,6 +163,29 @@ Item {
leftMargin: 6 leftMargin: 6
rightMargin: 6 rightMargin: 6
} }
Loader{
id:navItemRightMenuLoader
//anchors.centerIn: parent
sourceComponent: model.rightMenu
}
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: function(mouse){
if (mouse.button === Qt.RightButton) {
if(model.rightMenu){
var rightMenuComponent = model.rightMenu.createObject(navItemRightMenuLoader); // navItemRightMenuLoader
if (rightMenuComponent !== null) {
rightMenuComponent.popup();
}
}
}
}
z:-100
}
onClicked: { onClicked: {
if(d.isCompactAndNotPanel){ if(d.isCompactAndNotPanel){
control_popup.showPopup(Qt.point(50,mapToItem(control,0,0).y),model.children) control_popup.showPopup(Qt.point(50,mapToItem(control,0,0).y),model.children)
@ -289,9 +314,10 @@ Item {
} }
} }
} }
FluText{ FluEditableText{
id:item_title id:item_title
text:model.title text:model.title
editable: model.editable
visible: { visible: {
if(d.isCompactAndNotPanel){ if(d.isCompactAndNotPanel){
return false return false
@ -310,6 +336,17 @@ Item {
} }
return FluTheme.dark ? FluColors.White : FluColors.Grey220 return FluTheme.dark ? FluColors.White : FluColors.Grey220
} }
onFluTextEdited:function(newText) {
if(model.onTitleEdited)
model.onTitleEdited(newText)
}
onFluLostFocus:function(isActiveFocus){
if(!isActiveFocus){
model.editable = false
if(model.onTitleEdited)
model.onTitleEdited(item_title.text)
}
}
} }
} }
} }
@ -350,6 +387,28 @@ Item {
leftMargin: 6 leftMargin: 6
rightMargin: 6 rightMargin: 6
} }
Loader{
id:loader_auto_suggest_boxsssssdd
sourceComponent: model.rightMenu
}
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: function(mouse){
if (mouse.button === Qt.RightButton) {
if(model.rightMenu){
var rightMenuComponent = model.rightMenu.createObject(loader_auto_suggest_boxsssssdd); // loader_auto_suggest_boxsssssdd
if (rightMenuComponent !== null) {
rightMenuComponent.popup();
}
}
}
}
z:-100
}
onClicked: { onClicked: {
if(type === 0){ if(type === 0){
if(model.tapFunc){ if(model.tapFunc){
@ -440,9 +499,10 @@ Item {
} }
} }
} }
FluText{ FluEditableText{
id:item_title id:item_title
text:model.title text:model.title
editable: model.editable
visible: { visible: {
if(d.isCompactAndNotPanel){ if(d.isCompactAndNotPanel){
return false return false
@ -461,6 +521,18 @@ Item {
left:item_icon.right left:item_icon.right
right: item_dot_loader.left right: item_dot_loader.left
} }
onFluTextEdited:function(newText) {
if(model.onTitleEdited)
model.onTitleEdited(newText)
}
onFluLostFocus:function(isActiveFocus){
if(!isActiveFocus){
model.editable = false
if(model.onTitleEdited){
model.onTitleEdited(item_title.text)
}
}
}
} }
Loader{ Loader{
id:item_dot_loader id:item_dot_loader

View File

@ -19,4 +19,7 @@ QtObject {
property int count: 0 property int count: 0
signal tap signal tap
property var tapFunc property var tapFunc
property Component rightMenu
property bool editable
property var onTitleEdited:null
} }

View File

@ -10,4 +10,7 @@ FluObject {
property Component cusIcon property Component cusIcon
property bool isExpand: false property bool isExpand: false
property var parent property var parent
property Component rightMenu
property bool editable
property var onTitleEdited:null
} }