BabeGrid.qml 1.99 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3
import QtQuick.Controls 2.2
import QtQuick 2.9

Camilo Higuita's avatar
Camilo Higuita committed
4
Pane
Camilo Higuita's avatar
Camilo Higuita committed
5
{
Camilo Higuita's avatar
Camilo Higuita committed
6
    property int albumSize : 150
Camilo Higuita's avatar
Camilo Higuita committed
7 8
    property int albumSpacing: 20
    property int borderRadius : 4
9
    property alias gridModel: gridModel
Camilo Higuita's avatar
Camilo Higuita committed
10
    property alias grid: grid
Camilo Higuita's avatar
Camilo Higuita committed
11 12 13 14 15
    signal albumCoverClicked(string album, string artist)

    width: 500
    height: 400

Camilo Higuita's avatar
Camilo Higuita committed
16
    id: gridPage
Camilo Higuita's avatar
Camilo Higuita committed
17 18

    ListModel {id: gridModel}
Camilo Higuita's avatar
Camilo Higuita committed
19 20 21 22

    GridView
    {
        id: grid
Camilo Higuita's avatar
Camilo Higuita committed
23

Camilo Higuita's avatar
fixes  
Camilo Higuita committed
24
        width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
Camilo Higuita's avatar
Camilo Higuita committed
25 26 27
        height: parent.height

        anchors.horizontalCenter: parent.horizontalCenter
Camilo Higuita's avatar
Camilo Higuita committed
28

Camilo Higuita's avatar
Camilo Higuita committed
29
        cellWidth: albumSize + albumSpacing
Camilo Higuita's avatar
Camilo Higuita committed
30
        cellHeight:  parseInt(albumSize+(albumSize*0.6))
Camilo Higuita's avatar
Camilo Higuita committed
31

Camilo Higuita's avatar
Camilo Higuita committed
32
        focus: true
33
        model: gridModel
Camilo Higuita's avatar
Camilo Higuita committed
34

35 36 37 38 39 40 41 42
//        highlight: Rectangle
//        {
//            id: highlight
//            width: albumSize
//            height: albumSize
//            color: "lightsteelblue"
//            radius: borderRadius
//        }
Camilo Higuita's avatar
Camilo Higuita committed
43

Camilo Higuita's avatar
fixes  
Camilo Higuita committed
44 45 46 47 48
        //        onWidthChanged:
        //        {
        //            var amount = parseInt(grid.width/(albumSize+albumSpacing),10)
        //            var leftSpace = parseInt(grid.width-(amount*albumSize), 10)
        //            var size = parseInt(albumSize+(parseInt(leftSpace/amount, 10)), 10)
Camilo Higuita's avatar
Camilo Higuita committed
49

Camilo Higuita's avatar
fixes  
Camilo Higuita committed
50
        //            size = size > albumSize+albumSpacing ? size : albumSize+albumSpacing
Camilo Higuita's avatar
Camilo Higuita committed
51

Camilo Higuita's avatar
fixes  
Camilo Higuita committed
52 53 54
        //            grid.cellWidth = size
        //            //            grid.cellHeight = size
        //        }
Camilo Higuita's avatar
Camilo Higuita committed
55 56 57 58

        delegate: BabeAlbum
        {
            id: delegate
Camilo Higuita's avatar
Camilo Higuita committed
59

Camilo Higuita's avatar
Camilo Higuita committed
60 61 62 63 64 65 66 67
            Connections
            {
                target: delegate
                onAlbumClicked:
                {
                    var album = grid.model.get(index).album
                    var artist = grid.model.get(index).artist
                    albumCoverClicked(album, artist)
Camilo Higuita's avatar
Camilo Higuita committed
68 69
                    grid.currentIndex = index
                    console.log("current index is: ", grid.currentIndex)
Camilo Higuita's avatar
Camilo Higuita committed
70 71 72
                }
            }
        }
73

Camilo Higuita's avatar
Camilo Higuita committed
74
        ScrollBar.vertical: ScrollBar{}
Camilo Higuita's avatar
Camilo Higuita committed
75
    }
Camilo Higuita's avatar
Camilo Higuita committed
76

Camilo Higuita's avatar
Camilo Higuita committed
77
}