File: CustomDialog.qml

package info (click to toggle)
qflipper 1.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,320 kB
  • sloc: cpp: 18,500; sh: 247; ansic: 191; xml: 38; python: 14; makefile: 5
file content (149 lines) | stat: -rw-r--r-- 4,103 bytes parent folder | download | duplicates (2)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import QtQuick 2.15
import QtQuick.Controls 2.15

import Theme 1.0
import Primitives 1.0

Popup {
    id: control

    signal accepted
    signal rejected

    padding: 0

    width: parent.width
    height: parent.height

    property alias radius: shadow.radius
    property alias title: titleLabel.text

    property bool closable: false
    property bool invertTitle: true
    property bool result: false
    property Item contentWidget: Item {}

    enter: Transition {
        PropertyAnimation {
            property: "opacity"; duration: 150; easing.type: Easing.InOutQuad; from: 0; to: 1
        }
    }

    exit: Transition {
        PropertyAnimation {
            property: "opacity"; duration: 150; easing.type: Easing.InOutQuad; from: 1; to: 0
        }
    }

    background: Rectangle {
        id: shadow
        color: "black"
        opacity: 0.8
    }

    contentItem: Item {
        Rectangle {
            id: blackBorder
            anchors.fill: contentBg
            anchors.margins: -3

            opacity: 0.5
            color: "black"

            radius: contentBg.radius - anchors.margins
        }

        Rectangle {
            id: contentBg

            width: Math.max(contentWidget.implicitWidth, titleLabel.implicitWidth + closable ? closeButton.width : 0) + border.width * 2
            height: header.height + contentWidget.implicitHeight + border.width * 2

            radius: 7
            border.width: 2

            anchors.centerIn: parent

            color: "black"
            border.color: Theme.color.lightorange2

            Rectangle {
                id: header
                height: 42
                x: contentBg.border.width
                y: contentBg.border.width
                width: contentBg.width - contentBg.border.width * 2
                radius: invertTitle ? 0 : contentBg.radius - contentBg.border.width
                color: invertTitle ? Theme.color.lightorange2 : Theme.color.darkorange1

                Rectangle {
                    color: parent.color
                    width: parent.width
                    height: parent.radius
                    y: parent.height - height
                    visible: parent.radius > 0
                }

                TextLabel {
                    id: titleLabel

                    anchors.fill: parent
                    anchors.leftMargin: 8
                    anchors.rightMargin: 8

                    color: invertTitle ? Theme.color.darkorange1 : Theme.color.lightorange2

                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                    elide: Text.ElideMiddle

                    Item {
                        id: closeButton
                        visible: closable
                        height: parent.height
                        width: height
                        anchors.right: parent.right

                        Button {
                            flat: true
                            padding: 0

                            width: 24
                            height: 24

                            backgroundColor: ColorSet {
                                normal: Theme.color.darkorange1
                                hover: Theme.color.mediumorange2
                                down: Theme.color.lightred2
                            }

                            anchors.centerIn: parent
                            icon.source: "qrc:/assets/gfx/controls/windows/close.svg"
                            icon.width: 20
                            icon.height: 20
                            onClicked: control.close()
                        }
                    }
                }
            }
        }
    }

    Component.onCompleted: {
        accepted.connect(close);
        rejected.connect(close);

        contentWidget.parent = contentBg;
        contentWidget.x = header.x;
        contentWidget.y = header.y + header.height;
    }

    onAccepted: {
        result = true;
    }

    onRejected: {
        result = false;
    }
}