aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data/tst_popup.qml
blob: 4f97a1af1d4702649e4394cc3438ebb29d743dc9 (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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.4
import QtTest 1.0
import Qt.labs.controls 1.0

TestCase {
    id: testCase
    width: 480
    height: 360
    visible: true
    when: windowShown
    name: "Control"

    function getChild(control, objname, idx) {
        var index = idx
        for (var i = index+1; i < control.children.length; i++)
        {
            if (control.children[i].objectName === objname) {
                index = i
                break
            }
        }
        return index
    }

    Component {
        id: component
        Pane {
            id: panel
            property alias button: _button;
            property alias popup: _popup;
            property alias listview: _listview
            font.pixelSize: 30
            Column {
                Button {
                    id: _button
                    text: "Button"
                    font.pixelSize: 20

                    Popup {
                        id: _popup
                        y: button.height
                        implicitHeight: Math.min(396, _listview.contentHeight)
                        contentItem: ListView {
                            id: _listview
                            height: _button.height * 20
                            model: 2
                            delegate: Button {
                                objectName: "delegate"
                                width: _button.width
                                height: _button.height
                                text: "N: " + index
                                checkable: true
                                autoExclusive: true
                            }
                        }
                    }
                }
            }
        }
    }

    function test_font() { // QTBUG_50984
        var control = component.createObject(testCase)
        verify(control)
        verify(control.button)
        verify(control.popup)
        verify(control.listview)

        waitForRendering(control)

        control.forceActiveFocus()
        verify(control.activeFocus)

        compare(control.font.pixelSize, 30)
        compare(control.button.font.pixelSize, 20)

        var popup = control.popup
        popup.open()

        verify(popup.contentItem)

        var listview = popup.contentItem
        verify(listview.contentItem)
        waitForRendering(listview)

        var idx1 = getChild(listview.contentItem, "delegate", -1)
        compare(listview.contentItem.children[idx1].font.pixelSize, 20)
        var idx2 = getChild(listview.contentItem, "delegate", idx1)
        compare(listview.contentItem.children[idx2].font.pixelSize, 20)

        control.button.font.pixelSize = control.button.font.pixelSize + 10
        compare(control.button.font.pixelSize, 30)
        waitForRendering(listview)
        compare(listview.contentItem.children[idx1].font.pixelSize, 30)
        compare(listview.contentItem.children[idx2].font.pixelSize, 30)

        control.destroy()
    }

    Component {
        id: localeComponent
        Pane {
            id: panel
            property alias button: _button;
            property alias popup: _popup;
            property alias button1: _button1;
            property alias button2: _button2;
            locale: Qt.locale("en_US")
            Column {
                Button {
                    id: _button
                    text: "Button"
                    locale: Qt.locale("nb_NO")
                    Popup {
                        id: _popup
                        y: _button.height
                        implicitHeight: Math.min(396, _column.contentHeight)
                        contentItem: Column {
                            id: _column
                            Button {
                                id: _button1
                                text: "Button 1"
                            }
                            Button {
                                id: _button2
                                text: "Button 2"
                            }
                        }
                    }
                }
            }
        }
    }

    function test_locale() { // QTBUG_50984
        // test looking up natural locale from ancestors
        var control = localeComponent.createObject(testCase)
        verify(control)
        verify(control.button)
        verify(control.popup)
        verify(control.button1)
        verify(control.button2)

        waitForRendering(control)

        control.forceActiveFocus()
        verify(control.activeFocus)

        var popup = control.popup
        popup.open()

        compare(control.locale.name, "en_US")
        compare(control.button.locale.name, "nb_NO")
        compare(control.button1.locale.name, "nb_NO")
        compare(control.button2.locale.name, "nb_NO")

        control.destroy()
    }

    Component {
        id: localeComponent2
        Pane {
            id: panel
            property alias button: _button;
            property alias popup: _popup;
            property alias button1: _button1;
            property alias button2: _button2;
            property alias localespy: _lspy;
            property alias mirroredspy: _mspy;
            property alias localespy_1: _lspy_1;
            property alias mirroredspy_1: _mspy_1;
            property alias localespy_2: _lspy_2;
            property alias mirroredspy_2: _mspy_2;
            Column {
                Button {
                    id: _button
                    text: "Button"
                    Popup {
                        id: _popup
                        y: _button.height
                        implicitHeight: Math.min(396, _column.contentHeight)
                        contentItem: Column {
                            id: _column
                            Button {
                                id: _button1
                                text: "Button 1"
                                SignalSpy {
                                    id: _lspy_1
                                    target: _button1
                                    signalName: "localeChanged"
                                }
                                SignalSpy {
                                    id: _mspy_1
                                    target: _button1
                                    signalName: "mirroredChanged"
                                }
                            }
                            Button {
                                id: _button2
                                text: "Button 2"
                                SignalSpy {
                                    id: _lspy_2
                                    target: _button2
                                    signalName: "localeChanged"
                                }
                                SignalSpy {
                                    id: _mspy_2
                                    target: _button2
                                    signalName: "mirroredChanged"
                                }
                            }
                        }
                    }
                    SignalSpy {
                        id: _lspy
                        target: _button
                        signalName: "localeChanged"
                    }
                    SignalSpy {
                        id: _mspy
                        target: _button
                        signalName: "mirroredChanged"
                    }
                }
            }
        }
    }

    function test_locale_2() { // QTBUG_50984
        // test default locale and locale inheritance
        var control = localeComponent2.createObject(testCase)
        verify(control)
        verify(control.button)
        verify(control.popup)
        verify(control.button1)
        verify(control.button2)

        waitForRendering(control)

        control.forceActiveFocus()
        verify(control.activeFocus)

        var popup = control.popup
        popup.open()

        var defaultLocale = Qt.locale()

        compare(control.locale.name, defaultLocale.name)
        compare(control.button.locale.name, defaultLocale.name)
        compare(control.button1.locale.name, defaultLocale.name)
        compare(control.button2.locale.name, defaultLocale.name)

        control.locale = Qt.locale("nb_NO")
        control.localespy.wait()
        compare(control.localespy.count, 1)
        compare(control.mirroredspy.count, 0)
        compare(control.locale.name, "nb_NO")
        compare(control.button.locale.name, "nb_NO")
        compare(control.button1.locale.name, "nb_NO")
        compare(control.button2.locale.name, "nb_NO")
        compare(control.localespy_1.count, 1)
        compare(control.mirroredspy_1.count, 0)
        compare(control.localespy_2.count, 1)
        compare(control.mirroredspy_2.count, 0)

        control.locale = Qt.locale("ar_EG")
        control.localespy.wait()
        compare(control.localespy.count, 2)
        compare(control.mirroredspy.count, 1)
        compare(control.locale.name, "ar_EG")
        compare(control.button.locale.name, "ar_EG")
        compare(control.button1.locale.name, "ar_EG")
        compare(control.button2.locale.name, "ar_EG")
        compare(control.localespy_1.count, 2)
        compare(control.mirroredspy_1.count, 1)
        compare(control.localespy_2.count, 2)
        compare(control.mirroredspy_2.count, 1)

        control.destroy()
    }
}