summaryrefslogtreecommitdiff
path: root/components/custom/GroupBox.qml
blob: 1c25fa8d1e4b1ee636014f4550c66d4996a6f810 (plain)
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
import QtQuick 2.0

Item {
    id: groupbox

    implicitWidth: adjustToContentSize ? Math.max(200, contentWidth + loader.leftMargin + loader.rightMargin) : 100
    implicitHeight: adjustToContentSize ? contentHeight + loader.topMargin + loader.bottomMargin : 100

    default property alias data: content.data

    property string title
    property bool checkable: false
    property int contentWidth: content.childrenRect.width
    property int contentHeight: content.childrenRect.height
    property double contentOpacity: 1

    property Component background: null
    property Item backgroundItem: loader.item

    property Item checkbox: check
    property alias checked: check.checked
    property bool adjustToContentSize: false // Resizes groupbox to fit contents.
                                             // Note when using this, you cannot anchor children
    Loader {
        id: loader
        anchors.fill: parent
        property int topMargin: title.length > 0 || checkable ? 22 : 4
        property int bottomMargin: 4
        property int leftMargin: 4
        property int rightMargin: 4
        property alias styledItem: groupbox
        sourceComponent: background
    }
    CheckBox {
        id: check
        checked: true
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        height: loader.topMargin
    }
    Item {
        id:content
        z: 1
        focus: true
        opacity: contentOpacity
        anchors.topMargin: loader.topMargin
        anchors.leftMargin: 8
        anchors.rightMargin: 8
        anchors.bottomMargin: 8
        anchors.fill: parent
        enabled: (!checkable || checkbox.checked)
    }
}