summaryrefslogtreecommitdiffstats
path: root/templates/GroupBox.qml
blob: 4b196c3405882379df0c33c8c6def521c49cb4d6 (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
55
56
57
58
59
60
61
62
import QtQuick
import QtQuick.Controls.impl
import QtQuick.Templates as T

T.GroupBox {
    id: control

    implicitWidth: Math.max(implicitBackgroundWidth
                            + leftInset + rightInset,
                            contentWidth + leftPadding + rightPadding)
    implicitHeight: Math.max(implicitBackgroundHeight
                            + topInset + bottomInset,
                            contentHeight + topPadding + bottomPadding)

    readonly property real __deltaY: (__config.background.y - __config.label.y) || 0
    readonly property real __deltaX: (__config.background.x - __config.label.x) || 0
    spacing: (__deltaY - __config.label.height) || 0

    topPadding: (__config.topPadding || 0) + (spacing >= 0 ? (label.height + spacing) : __deltaY)
    bottomPadding: __config.bottomPadding || 0
    leftPadding: (__config.leftPadding || 0) + (__deltaX >= 0 ? __deltaX : 0)
    rightPadding: __config.rightPadding || 0

    topInset: __deltaY > 0 ? __deltaY : 0
    bottomInset: -__config.bottomInset || 0
    leftInset: __deltaX > 0 ? __deltaX : 0
    rightInset: -__config.rightInset || 0

    readonly property string __currentState: [
        !control.enabled && "disabled",
        control.enabled && control.hovered && "hovered",
    ].filter(Boolean).join("_") || "normal"
    readonly property var __config: Config.controls.groupbox[__currentState] || {}

    label: T.Label {
        x: control.__deltaX > 0 ? 0 : -__deltaX
        y: control.__deltaY > 0 ? 0 : -__deltaY

        topPadding: control.__config.label_contentItem.topPadding || 0
        leftPadding: control.__config.label_contentItem.leftPadding || 0
        rightPadding: control.__config.label_contentItem.rightPadding || 0
        bottomPadding: control.__config.label_contentItem.bottomPadding || 0

        height: Math.max(implicitHeight, control.__config.label.height)

        text: control.title
        font: control.font
        color: control.palette.windowText
        elide: Text.ElideRight
        horizontalAlignment: control.__config.label_text.textHAlignment
        verticalAlignment: control.__config.label_text.textVAlignment

        background: StyleImage {
            imageConfig: control.__config.label_background
        }
    }

    background: StyleImage {
        imageConfig: control.__config.background
        height: parent.height - control.topPadding + control.bottomPadding
    }
}