File: main.qml

package info (click to toggle)
qzxing 3.3.0%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,128 kB
  • sloc: cpp: 28,650; makefile: 29
file content (172 lines) | stat: -rw-r--r-- 4,830 bytes parent folder | download | duplicates (3)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
//import QtQuick.Dialogs 1.3
import Qt.labs.platform 1.1

ApplicationWindow {
    id: mainWindow
    visible: true
    width: 640
    height: 480

    minimumWidth: formatGroupBox.width +
                  errorCorrectionlevelGroupBox.width +
                  borderStatus.width +
                  transparentStatus.width +
                  5 * advancedOptions.spacing

    property bool isAdvancedOptionsEnabled: advancedSwitch.position;

    property string advancedUrl: "image://QZXing/encode/" + inputField.text +
                                 "?correctionLevel=" + errorCorrectionlevelCombo.currentText +
                                 "&format=" + formatCombo.currentText +
                                 "&border=" + (borderStatus.checkState !== Qt.Unchecked) +
                                 "&transparent=" + (transparentStatus.checkState !== Qt.Unchecked) +
                                 "&explicitSize=" + explicitSizeCombo.currentText

    property string normalUrl: "image://QZXing/encode/" + inputField.text

    ColumnLayout {
        id: mainLayout
        anchors {
            fill: parent
            margins: 10
        }

        TextArea {
            id: inputField
            Layout.fillWidth: true
            selectByMouse: true
            text: "Hello world!"

            Rectangle{
                anchors.fill: parent
                border.color: "#656565"
                border.width: 1
                color: "transparent"
            }
        }

        Row {
            Layout.fillWidth: true

            Label {
                id: resultLabel
                text: "Result barcode image"
                anchors.verticalCenter: parent.verticalCenter
            }

            Rectangle {
                height: 1
                width: parent.width - resultLabel.width - advancedSwitch.width
            }

            Switch {
                id: advancedSwitch
                text: "Advanced"
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Row {
            id: advancedOptions
            Layout.fillWidth: true
            visible: mainWindow.isAdvancedOptionsEnabled
            clip: true

            spacing: 5

            GroupBox {
                id: formatGroupBox
                title: "Format"
                anchors.verticalCenter: parent.verticalCenter
                ComboBox {
                    id: formatCombo
                    model: ["qrcode"]
                }
            }

            GroupBox {
                id: errorCorrectionlevelGroupBox
                title: "Error Correction Level"
                anchors.verticalCenter: parent.verticalCenter
                ComboBox {
                    id: errorCorrectionlevelCombo
                    model: ["L", "M", "Q", "H"]
                }
            }

            GroupBox {
                id: explicitSizeGroupBox
                title: "Explicit Size"
                anchors.verticalCenter: parent.verticalCenter
                ComboBox {
                    id: explicitSizeCombo
                    model: ["auto", "60", "120", "240"]
                }
            }
        }

        Row {
            visible: mainWindow.isAdvancedOptionsEnabled
            CheckBox {
                id: borderStatus
                text: "Border"
            }

            CheckBox {
                id: colorPickerButton
                text: "Color"

                background: Rectangle {
                    color: barcodeRectangle.color
                }

                onCheckStateChanged: colorDialog.visible = true
            }

            CheckBox {
                id: transparentStatus
                text: "Transparent"
            }
        }

        Rectangle {
            id: barcodeRectangle
            Layout.fillWidth: true
            Layout.fillHeight: true
            border.width: 1
            border.color: "#bdbebf"
            clip: true
            color: "white"

            property int imageWidth: Math.min(height, width) * 0.7;

            Image{
                id:resultImage
                anchors.centerIn: parent
                sourceSize.width: 200
                sourceSize.height: 200

                source: mainLayout.getImageRequestString()
                cache: false;
            }
        }

        ColorDialog{
            id: colorDialog
            title: "Please choose a color"
            onAccepted: {
                barcodeRectangle.color = colorDialog.color
            }
        }

        function getImageRequestString() {
            if(mainWindow.isAdvancedOptionsEnabled)
                return advancedUrl;
            else
                return normalUrl;
        }
    }
}