aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/ios/impl/DialogButtonBoxDelegate.qml
blob: 2be1f9535e9c417da9a5bb7624cc5f5912ece38c (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
// Copyright (C) 2023 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

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.impl
import QtQuick.Controls.iOS.impl

Button {
    id: delegate

    implicitHeight: 44

    readonly property var dialogButtonBox: DialogButtonBox.buttonBox
    readonly property bool hasVerticalLayout: dialogButtonBox && (dialogButtonBox.count !== 2)
    readonly property bool isLastItem: dialogButtonBox
                                       && (dialogButtonBox.contentChildren)
                                       && (dialogButtonBox.itemAt(count - 1) == delegate)
    readonly property int count: dialogButtonBox ? dialogButtonBox.count : 0

    flat: true

    contentItem: IconLabel {
        readonly property var redColor: Qt.styleHints.colorScheme === Qt.Light ? "#ff3b30" : "#ff453a"
        text: delegate.text
        font: delegate.font
        spacing: delegate.spacing
        color: delegate.DialogButtonBox.buttonRole === DialogButtonBox.DestructiveRole
                ? redColor
                : (delegate.down ? delegate.palette.highlight : delegate.palette.button)
    }

    background: Item {
        // The assets below only support the typical iOS Dialog look with buttons
        // positioned at the bottom and that fill the entire width of the parent.
        // Don't draw a background if these conditions are not met
        visible: delegate.dialogButtonBox
                  && delegate.dialogButtonBox.position === DialogButtonBox.Footer
                  && delegate.dialogButtonBox.alignment === 0
        implicitHeight: 44
        readonly property bool leftItem: !delegate.hasVerticalLayout && !delegate.isLastItem
        readonly property bool rightItem: !delegate.hasVerticalLayout && !leftItem
        readonly property bool flip: delegate.mirrored ? leftItem : rightItem

        NinePatchImage {
            transform: [
                // flip
                Translate { x: (!delegate.background.flip ? 0 : -width) },
                Scale { xScale: (!delegate.background.flip ? 1 : -1) }
            ]
            width: parent.width
            height: parent.height
            source: IOS.url + "dialogbuttonbox-delegate"
            NinePatchImageSelector on source {
                states: [
                    {"horizontal": !delegate.hasVerticalLayout},
                    {"vertical": delegate.hasVerticalLayout},
                    {"last": delegate.hasVerticalLayout && delegate.isLastItem},
                    {"pressed": delegate.down},
                    {"light": Qt.styleHints.colorScheme === Qt.Light},
                    {"dark": Qt.styleHints.colorScheme === Qt.Dark},
                ]
            }
        }


    }
}