main
zhuzihcu 2023-03-08 11:46:40 +08:00
parent b3b107c134
commit aadd7475d6
6 changed files with 78 additions and 25 deletions

View File

@ -66,7 +66,7 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
var org = createOrg(10, 3, 5) var org = createOrg(3, 3, 3)
updateData(org) updateData(org)
} }
@ -84,13 +84,13 @@ Item {
FluText{ FluText{
text:{ text:{
if(tree_view.selectionMode === FluTreeView.None){ if(tree_view.selectionMode === FluTreeView.None){
return "FluTreeView.None" return "selectionMode->FluTreeView.None"
} }
if(tree_view.selectionMode === FluTreeView.Single){ if(tree_view.selectionMode === FluTreeView.Single){
return "FluTreeView.Single" return "selectionMode->FluTreeView.Single"
} }
if(tree_view.selectionMode === FluTreeView.Multiple){ if(tree_view.selectionMode === FluTreeView.Multiple){
return "FluTreeView.Multiple" return "selectionMode->FluTreeView.Multiple"
} }
} }
} }

View File

@ -35,8 +35,8 @@ void Fluent::registerTypes(const char *uri){
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTreeView.qml"),uri,major,minor,"FluTreeView"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTreeView.qml"),uri,major,minor,"FluTreeView");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluContentDialog.qml"),uri,major,minor,"FluContentDialog"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluContentDialog.qml"),uri,major,minor,"FluContentDialog");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenu.qml"),uri,major,minor,"FluMenu");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenuItem.qml"),uri,major,minor,"FluMenuItem"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenuItem.qml"),uri,major,minor,"FluMenuItem");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenu.qml"),uri,major,minor,"FluMenu");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTextButton.qml"),uri,major,minor,"FluTextButton"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTextButton.qml"),uri,major,minor,"FluTextButton");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMultiLineTextBox.qml"),uri,major,minor,"FluMultiLineTextBox"); qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMultiLineTextBox.qml"),uri,major,minor,"FluMultiLineTextBox");

View File

@ -8,6 +8,7 @@ Item {
property bool checked: false property bool checked: false
property string text: "Check Box" property string text: "Check Box"
property var checkClicked property var checkClicked
property bool hovered: mouse_area.containsMouse
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height

View File

@ -1,8 +0,0 @@
import QtQuick 2.15
Item {
property string name
property bool expanded: false
property list<FluTreeItem> children
}

View File

@ -31,6 +31,8 @@ Rectangle {
ListElement{ ListElement{
text: "根节点" text: "根节点"
expanded:true expanded:true
key:"123456"
multipSelected:false
items:[] items:[]
} }
} }
@ -66,7 +68,7 @@ Rectangle {
property real level: (mapToItem(list_root,0,0).x+list_root.contentX)/0.001 property real level: (mapToItem(list_root,0,0).x+list_root.contentX)/0.001
property var text: model.text??"Item" property var text: model.text??"Item"
property bool isItems : (model.items !== undefined) && (model.items.count !== 0) property bool hasChild : (model.items !== undefined) && (model.items.count !== 0)
property var items: model.items??[] property var items: model.items??[]
property var expanded: model.expanded??true property var expanded: model.expanded??true
property int width_hint: calculateWidth() property int width_hint: calculateWidth()
@ -99,12 +101,12 @@ Rectangle {
if(item_layout.singleSelected && selectionMode === FluTreeView.Single){ if(item_layout.singleSelected && selectionMode === FluTreeView.Single){
return Qt.rgba(62/255,62/255,62/255,1) return Qt.rgba(62/255,62/255,62/255,1)
} }
return (item_layout_mouse.containsMouse || item_layout_expanded.hovered)?Qt.rgba(62/255,62/255,62/255,1):Qt.rgba(50/255,50/255,50/255,1) return (item_layout_mouse.containsMouse || item_layout_expanded.hovered || item_layout_checkbox.hovered)?Qt.rgba(62/255,62/255,62/255,1):Qt.rgba(50/255,50/255,50/255,1)
}else{ }else{
if(item_layout.singleSelected && selectionMode === FluTreeView.Single){ if(item_layout.singleSelected && selectionMode === FluTreeView.Single){
return Qt.rgba(244/255,244/255,244/255,1) return Qt.rgba(244/255,244/255,244/255,1)
} }
return (item_layout_mouse.containsMouse || item_layout_expanded.hovered)?Qt.rgba(244/255,244/255,244/255,1):Qt.rgba(253/255,253/255,253/255,1) return (item_layout_mouse.containsMouse || item_layout_expanded.hovered || item_layout_checkbox.hovered)?Qt.rgba(244/255,244/255,244/255,1):Qt.rgba(253/255,253/255,253/255,1)
} }
} }
@ -160,14 +162,67 @@ Rectangle {
} }
FluCheckBox{ FluCheckBox{
id:item_layout_checkbox
text:"" text:""
checked: multipElement.includes(itemModel) checked: itemModel.multipSelected
visible: selectionMode === FluTreeView.Multiple visible: selectionMode === FluTreeView.Multiple
checkClicked:function(){ checkClicked:function(){
if(checked){ if(hasChild){
multipElement = multipElement.filter((value) => value !== itemModel)
}else{ }else{
multipElement = [...multipElement,itemModel] itemModel.multipSelected = !itemModel.multipSelected
const stack = [tree_model.get(0)];
const result = [];
while (stack.length > 0) {
const curr = stack.pop();
result.unshift(curr);
if (curr.items) {
for(var i=0 ; i<curr.items.count ; i++){
stack.push(curr.items.get(i));
}
}
}
for(var j=0 ; j<result.length ; j++){
var item = result[j]
if((item.items !== undefined) && (item.items.count !== 0)){
console.debug(item.index)
var items = item.items
for(var k=0 ; k<items.count ; k++){
if(items.get(k).multipSelected === false){
items.setProperty(k,"multipSelected",false)
break
}
items.setProperty(k,"multipSelected",true)
}
}
}
// const stack = [tree_model.get(0)];
// while (stack.length > 0) {
// const node = stack.pop();
// for (var i = 0 ; i <node.items.count; i i--) {
// const item = node.items.get(i)
// if((item.items !== undefined) && (item.items.count !== 0)){
// console.debug(item.text)
// var items = item.items
// for(var j=0 ; j<items.count ; j++){
// if(items.get(j).multipSelected === false){
// node.items.setProperty(i,"multipSelected",false)
// break
// }
// node.items.setProperty(i,"multipSelected",true)
// }
// }
// stack.push(item);
// }
// }
} }
} }
} }
@ -176,9 +231,9 @@ Rectangle {
id:item_layout_expanded id:item_layout_expanded
color:"#00000000" color:"#00000000"
icon:item_layout.expanded?FluentIcons.FA_angle_down:FluentIcons.FA_angle_right icon:item_layout.expanded?FluentIcons.FA_angle_down:FluentIcons.FA_angle_right
opacity: item_layout.isItems opacity: item_layout.hasChild
onClicked: { onClicked: {
if(!item_layout.isItems){ if(!item_layout.hasChild){
item_layout_rect.onClickItem() item_layout_rect.onClickItem()
return return
} }
@ -198,7 +253,7 @@ Rectangle {
Item{ Item{
id:item_sub id:item_sub
visible: { visible: {
if(!isItems){ if(!hasChild){
return false return false
} }
return item_layout.expanded??false return item_layout.expanded??false
@ -249,8 +304,14 @@ Rectangle {
} }
function createItem(text="Title",expanded=true,items=[]){ function createItem(text="Title",expanded=true,items=[]){
return {text:text,expanded:expanded,items:items}; return {text:text,expanded:expanded,items:items,key:uniqueRandom(),multipSelected:false};
} }
function uniqueRandom() {
var timestamp = Date.now();
var random = Math.floor(Math.random() * 1000000);
return timestamp.toString() + random.toString();
}
} }

View File

@ -34,6 +34,5 @@
<file>controls/FluTextButton.qml</file> <file>controls/FluTextButton.qml</file>
<file>controls/FluContentDialog.qml</file> <file>controls/FluContentDialog.qml</file>
<file>controls/FluTreeView.qml</file> <file>controls/FluTreeView.qml</file>
<file>controls/FluTreeItem.qml</file>
</qresource> </qresource>
</RCC> </RCC>