main.qml 2.77 KB
Newer Older
Michael Winkelmann's avatar
Michael Winkelmann committed
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
import QtQuick 2.11
import QtQuick.Window 2.11

import QtQuick.Controls 2.4

Window {
    id: window
    visible: true
    width: 720
    height: 480
    title: qsTr("Example")

    GridView {
        anchors.fill: parent

        model: [
            {
                icon: Icons.ic_play_arrow_48px,
                color: "red"
            },
            {
                icon: Icons.ic_play_circle_fill_48px,
                color: "orange"
            },
            {
                icon: Icons.ic_pause_48px,
                color: "yellow"
            },
            {
                icon: Icons.ic_headset_48px,
                color: "lime"
            },
            {
                icon: Icons.ic_audiotrack_48px,
                color: "aqua"
            },
            {
                icon: Icons.ic_battery_unknown_48px,
                color: "blue"
            },
            {
                icon: Icons.ic_block_48px,
                color: "fuchsia"
            },
            {
                icon: Icons.ic_play_arrow_48px,
                color: "red"
            },
            {
                icon: Icons.ic_play_circle_fill_48px,
                color: "orange"
            },
            {
                icon: Icons.ic_pause_48px,
                color: "yellow"
            },
            {
                icon: Icons.ic_headset_48px,
                color: "lime"
            },
            {
                icon: Icons.ic_audiotrack_48px,
                color: "aqua"
            },
            {
                icon: Icons.ic_battery_unknown_48px,
                color: "blue"
            },
            {
                icon: Icons.ic_block_48px,
                color: "fuchsia"
            }
        ]

        delegate: Button {
            id: button
            width: 96
            height: 96
            checkable: true

            text: modelData.icon
            font.pixelSize: 48
            font.family: 'icons'

            background: Image {
                cache: false
                anchors.fill: button
                id: image

                // Generate a string for image provider from given color in model
                function imageString() {
                    var s = 'image://gradients/';
                    var f = button.down ? 1.4 : 1.0;
                    s += Qt.darker(modelData.color,f) + "-" + Qt.darker(modelData.color,f*1.5);
                    if (button.checked) {
                        s += "-" + Qt.lighter(modelData.color,f);
                    }
                    console.log(s);
                    return s;
                }

                fillMode: Image.Stretch
                sourceSize.width: width
                sourceSize.height: height
                source: imageString()
            }
        }
    }
}