1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| import QtQuick 2.0
Image {
id: anImage
source: "testImage"
// Lorsque l'image est chargé, on appel la fonction addElement
Component.onCompleted: listModel.addElement(anImage.width, anImage.height, gridView.cellWidth, gridView.cellHeight)
ListModel {
id: listModel
// Fonction qui ajoute un élément en fonction de la taille de l'image et d'une cellule.
function addElement(width, height, cellWidth, cellHeight)
{
var nbElementsByRow = width/cellWidth
var nbElementsByCol = height/cellHeight
console.log("nbElementsByRow: " + nbElementsByRow)
console.log("nbElementsByCol: " + nbElementsByCol)
for (var i=0; i<nbElementsByRow; ++i)
{
for (var j=0; j<nbElementsByCol; ++j)
{
listModel.append({"name": i + "_" + j})
}
}
}
}
GridView {
id: gridView
width: anImage.width
height: anImage.height
anchors.top: parent.top // je ne pense pas que tous ces anchors soient nécessaires... Je veux juste que la grille ne change pas de position
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
cellWidth: 50
cellHeight: 50
model: listModel;
delegate: Item {
id: content
x: 0
height: 50
Column {
Rectangle {
width: 50
height: 50
border.color: "black"
border.width: 1
color: "#00FFFFFF"
MouseArea {
id: up
anchors.top: parent.top
width: parent.width
height: 2
hoverEnabled: true
property variant prevPosition
onEntered: {
cursorShape = Qt.SizeVerCursor
}
onExited: {
cursorShape = Qt.ArrowCursor
}
onPressed: {
prevPosition = Qt.point(mouseX, mouseY);
}
onPositionChanged: {
if (pressedButtons == Qt.LeftButton)
{
var dy = (mouseY - prevPosition.y)/2.0
parent.height += dy
}
}
} // MouseArea up
MouseArea {
id: right
anchors.right: parent.right
width: 2
height: parent.height
hoverEnabled: true
property variant prevPosition
onEntered: {
cursorShape = Qt.SizeHorCursor
}
onExited: {
cursorShape = Qt.ArrowCursor
}
onPressed: {
prevPosition = Qt.point(mouseX, mouseY);
}
onPositionChanged: {
if (pressedButtons == Qt.LeftButton)
{
var dx = (mouseX - prevPosition.x)/2.0
parent.width += dx
}
}
} // MouseArea right
}
}
}
}
} |
Partager