-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For now maybe I should give up on trying to integrate TilesGrid and just have tile positions be a config file thing with a custom grid. #253
Comments
Oh, I also need to have this in a Flickable for scrolling. |
This answer might help with drag-and-drop when I'm ready to do that, but I'll need to re-add support for getting indexes from the simple grid unless I can just get the children from it instead: https://stackoverflow.com/a/13970199 Not everything will be used from it though, and I need to re-implement the collision code in a way that doesn't cause a lot of interference and is simple. Here's the answer for archival, it was posted by meolic and is under the CC BY-SA 3.0: In the given solution, there is no problem with function indexAt() and thus explicit calculation of gridArea.index is not needed anymore. I will appreciate any comment on this solution and why these changes are so important. I still think that the original solution is intuitive and I do not understand why it is not working. import QtQuick 1.1
GridView {
id: mainGrid
cellWidth: 165; cellHeight: 95
width: 5*cellWidth; height: 4*cellHeight
model: myModel
delegate: myButton
ListModel {
id: myModel
function createModel() {
for (var i=1; i<=20; i++) {
myModel.append({"display": i, "uid": i})
}
}
Component.onCompleted: {createModel()}
}
Component {
id: myButton
Item {
id: item
width: mainGrid.cellWidth-5; height: mainGrid.cellHeight-5;
Rectangle {
id: box
parent: mainGrid
x: item.x; y: item.y;
width: item.width; height: item.height;
border.width: 1
property int uid: (index >= 0) ? myModel.get(index).uid : -1
Text {
anchors.centerIn: parent
text: display
font.pixelSize: 48
}
states: [
State {
name: "active"; when: gridArea.activeId == box.uid
PropertyChanges {target: box; x: gridArea.mouseX-80; y: gridArea.mouseY-45; z: 10}
}
]
}
}
}
MouseArea {
id: gridArea
anchors.fill: parent
hoverEnabled: true
preventStealing : true
property int index: mainGrid.indexAt(mouseX, mouseY) //item underneath cursor
property int activeId: -1 //uid of active item
property int activeIndex //current position of active item
onPressAndHold: {
activeId = mainGrid.model.get(activeIndex=index).uid
}
onReleased: {
activeId = -1
}
onPositionChanged: {
if (activeId != -1 && index != -1 && index != activeIndex) {
mainGrid.model.move(activeIndex, activeIndex = index, 1)
}
}
}
} " Also, in 2019, Valentin Radu posted this comment to another answer posted by meolic I'll copy after their comment: And here's meolic's other answer, also under CC BY-SA 3.0 (link: https://stackoverflow.com/a/13975952 ) : Any comment on this solution is also very welcome. import QtQuick 1.1
GridView {
id: mainGrid
cellWidth: 165; cellHeight: 95
width: 5*cellWidth; height: 4*cellHeight
model: myModel
delegate: myButton
ListModel {
id: myModel
function createModel() {
for (var i=1; i<=20; i++) {
myModel.append({"display": i})
}
}
Component.onCompleted: {createModel()}
}
Component {
id: myButton
Rectangle {
id: item
z: 1
width: mainGrid.cellWidth-5; height: mainGrid.cellHeight-5;
border.width: 1
Text {
anchors.centerIn: parent
text: display
font.pixelSize: 48
}
}
}
MouseArea {
id: gridArea
anchors.fill: parent
hoverEnabled: true
drag.axis: Drag.XandYAxis
//property int index: mainGrid.indexAt(mouseX,mouseY) //NOT WORKING RELIABLE!
property int mX: (mouseX < 0) ? 0 : ((mouseX < mainGrid.width - mainGrid.cellWidth) ? mouseX : mainGrid.width - mainGrid.cellWidth)
property int mY: (mouseY < 0) ? 0 : ((mouseY < mainGrid.height - mainGrid.cellHeight) ? mouseY : mainGrid.height - mainGrid.cellHeight)
property int index: parseInt(mX/mainGrid.cellWidth) + 5*parseInt(mY/mainGrid.cellHeight) //item underneath cursor
property int activeIndex
onPressAndHold: {
currentIndex = index
currentItem.z = 10
gridArea.drag.target = currentItem
activeIndex = index
}
onReleased: {
currentItem.x = mainGrid.cellWidth * (index % 5)
currentItem.y = mainGrid.cellHeight * parseInt(index / 5)
currentItem.z = 1
currentIndex = -1
gridArea.drag.target = null
}
onPositionChanged: {
if (drag.active && index !== -1 && index !== activeIndex) {
mainGrid.model.move(activeIndex, activeIndex = index, 1)
}
}
}
} " |
TilesGrid is just too hard for me right now.
Here's what I can try: https://stackoverflow.com/a/61804867
I'll have to have a spacing property that's added to the x and y values for when tiles are added if the column and row are greater than 0 (zero). Making sure tiles are moved to the next available space will also be necessary if they're resized, as will moving tiles when unpinning them. The row amount will need to be grabbed from the highest value in the tiles layout config file also, I'm thinking what we can do is there will be a property that's increased if the current tile we're looking at in the config file has a larger row value than that temporary "total rows" variable, and we'll send it back to the main file along with all the tiles in the dict so it can be processed right then, just like I do with the messagebox regarding deprecated tile stuff.
Will need to have the file licensed under the CC BY-SA 3.0 because it's pretty much what I need and I don't foresee it being basically entirely changed like I usually do.
This won't include drag-and-drop support yet, but it's better than nothing.
The text was updated successfully, but these errors were encountered: