aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/fluentwinui3/Dialog.qml
blob: 544da130a5a60cf347fbbe8382350edd40a807df (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
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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
import QtQuick.Effects

T.Dialog {
    id: control

    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                            implicitContentWidth + leftPadding + rightPadding,
                            implicitHeaderWidth,
                            implicitFooterWidth)
    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                             implicitContentHeight + topPadding + bottomPadding
                             + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
                             + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))

    readonly property bool __isHighContrast: Application.styleHints.accessibility.contrastPreference === Qt.HighContrast

    leftInset: __isHighContrast ? 0 : -32
    topInset: __isHighContrast ? 0 : -32
    rightInset: __isHighContrast ? 0 : -32
    bottomInset: __isHighContrast ? 0 : -32

    padding: 24
    topPadding: 12
    bottomPadding: 23

    enter: Transition {
        NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; easing.type: Easing.Linear; duration: 83 }
        NumberAnimation { property: "scale"; from: control.modal ? 1.05 : 1; to: 1; easing.type: Easing.OutCubic; duration: 167 }
    }

    exit: Transition {
        NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; easing.type: Easing.Linear; duration: 83 }
        NumberAnimation { property: "scale"; from: 1; to: control.modal ? 1.05 : 1; easing.type: Easing.OutCubic; duration: 167 }
    }

    background: Rectangle {
        color: control.__isHighContrast ? control.palette.window : "transparent"
        border.color: control.__isHighContrast ? control.palette.text : "transparent"
        border.width: 2
        radius: 8
        MultiEffect {
            visible: !control.__isHighContrast
            x: -control.leftInset
            y: -control.topInset
            width: source.width
            height: source.height
            source: Rectangle {
                width: control.background.width + control.leftInset + control.rightInset
                height: control.background.height + control.topInset + control.bottomInset
                color: Application.styleHints.colorScheme === Qt.Light ? "white" : Qt.tint(control.palette.window, Color.transparent("white", 0.05))
                border.color: "#66757575"
                radius: 8
            }
            shadowScale: 1
            shadowOpacity: 0.19
            shadowColor: control.palette.shadow
            shadowEnabled: true
            shadowHorizontalOffset: 0
            shadowVerticalOffset: 32
            blurMax: 64
        }
    }

    header: Label {
        text: control.title
        topPadding: control.padding
        leftPadding: control.padding
        rightPadding: control.padding
        visible: control.title && parent?.parent === Overlay.overlay
        elide: Label.ElideRight
        font.bold: true
        font.pixelSize: 20
        font.weight: Font.DemiBold
    }

    footer: DialogButtonBox {
        visible: count > 0
        leftInset: control.__isHighContrast ? 1 : 0
        topInset: control.__isHighContrast ? 1 : 0
        rightInset: control.__isHighContrast ? 1 : 0
        bottomInset: control.__isHighContrast ? 1 : 0
    }

    T.Overlay.modal: Rectangle {
        color: Color.transparent(control.palette.shadow, 0.3)
    }

    T.Overlay.modeless: Rectangle {
        color: "transparent"
    }
}