More GridViews drag and drop
-
Hi everybody,
I have a problem. Code below imagine gridview PLATFORM and under the one is the second gridview imagine TRAINS ... And I need to move items from TRAINS into the PLATFORM by Drag and drop. The problem is, that I use IndexAt and it works only in one MouseArea. Please help, if somebody knows:@//importQtQuick1.0
importQtQuick1.1
Rectangle{
id:rectangle1
width:1024
height:768
color:"#1fdbc8"
MouseArea{
id:mouse11
anchors.fill:parent
drag.filterChildren:trueListModel{
id:platformList
ListElement{
name:"Platform1"
iColor:"gray"
iVisible:true
}
ListElement{
iColor:"gray"
iBorder:2
}
ListElement{
iColor:"gray"
iBorder:2
}
ListElement{
iColor:"gray"
iBorder:2
}
ListElement{
iColor:"gray"
iBorder:2
}
}ListModel{
id:trainList
ListElement{
name:"Train1"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train2"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train3"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train4"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train5"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train6"
iColor:"white"
iVisible:true
}
ListElement{
name:"Train7"
iColor:"white"
iVisible:true
}
}Component{
id:platformDelegate
Item{
width:grid1.cellWidth
height:grid1.cellHeightRectangle{
id:prvek1
width:grid1.cellWidth
height:grid1.cellHeight
color:iColor
visible:iVisible
border.width:iBorder
Text{
width:parent.width
horizontalAlignment:Text.AlignHCenter
font.pixelSize:20
text:name
}
}
}
}Component{
id:trainDelegate
Item{
width:grid3.cellWidth
height:grid3.cellHeightRectangle{
id:prvek3
state:"inactive"
//anchors.centerIn:parent
width:grid3.cellWidth-10
height:grid3.cellHeight-10
radius:10
color:iColor
visible:iVisible
Text{
width:parent.width
horizontalAlignment:Text.AlignHCenter
font.pixelSize:20
text:name
}
}states:[
State{
name:"inDrag"
when:index==grid3.firstIndexDrag
PropertyChanges{target:prvek3;parent:container3}
PropertyChanges{target:prvek3;border.width:2}
PropertyChanges{target:prvek3;anchors.centerIn:undefined}
PropertyChanges{target:prvek3;x:coords2.mouseX-prvek3.width/2}
PropertyChanges{target:prvek3;y:coords2.mouseY-prvek3.height/2}},
State{
name:"inactive"
when:(grid3.firstIndexDrag==-1)||(grid.firstIndexDrag==index)
PropertyChanges{target:prvek3;border.width:10}
PropertyChanges{target:prvek3;border.width:0}
}
]
}
}GridView{
propertyintfID1:-1//FIRSTINDEXDRAG
id:grid1
interactive:false
cellWidth:parent.width/4
cellHeight:height/5height:parent.height/4
width:parent.width/4model:platformList
delegate:platformDelegateItem{
id:container1
anchors.fill:parent
}MouseArea{
id:coords1
anchors.fill:parent
onReleased:{
varnewIndex=grid1.indexAt(mouseX,mouseY);
varoldIndex=grid1.fID1;
if(grid1.fID1!=-1&&newIndex!=-1){
if(newIndex>oldIndex&&grid3.firstIndexDrag){
platformList.add(newIndex);
platformList.move(oldIndex,newIndex-1,1);
}
else{
platformList.move(oldIndex,newIndex,1);
platformList.insert(newIndex+1,{"iColor":"gray","iVisible":true});
}
}
}
onPressed:{
grid1.fID1=grid1.indexAt(mouseX,mouseY);
grid1.fID1=grid1.indexAt(mouseX,mouseY)
}
}
}GridView{
propertyintfirstIndexDrag:-1
id:grid3
interactive:false
cellWidth:grid1.cellWidth
cellHeight:grid1.cellHeightanchors.bottom:parent.bottom
model:trainList
delegate:trainDelegate
flow:GridView.TopToBottom
height:parent.height/4
width:parent.widthItem{
id:container3
anchors.fill:parent
}MouseArea{
id:coords2
anchors.fill:parent
//hoverEnabled:true
onReleased:{
varnewIndex=grid3.indexAt(mouseX,mouseY);
varoldIndex=grid3.firstIndexDrag;if(grid3.firstIndexDrag!=-1&&newIndex!=-1&&newIndex!=oldIndex){
if(newIndex>oldIndex){
trainList.move(oldIndex,newIndex-1,1);
trainList.move(newIndex,oldIndex,1)
}else{
trainList.move(oldIndex,newIndex,1);
trainList.move(newIndex+1,oldIndex,1);
}
}
grid3.firstIndexDrag=-1;
grid1.fID1=grid1.indexAt(mouseX,mouseY)
grid3.firstIndexDrag=grid3.indexAt(mouseX,mouseY)
}
onPressed:{
grid3.firstIndexDrag=grid3.indexAt(mouseX,mouseY);
}
}
}
}
}
@