aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols/translation/data/stackView.qml
blob: 44d85c2ea12f10b0530ed53af36c42c2b40f9baa (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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Controls
import QtQuick.Window

Window {
    id: window
    width: 640
    height: 480

    property var engine

    signal calledTranslate

    property int pagesCreated: 0

    Component {
        id: translatePageComponent
        Item {
            id: root

            Component.onCompleted: objectName = "translatePageRootItem" + pagesCreated++

            StackView.onActivating: {
                retranslateTimer.start()
            }

            Timer {
                id: retranslateTimer
                objectName: "retranslateTimer"
                interval: 100
                repeat: true

                property int count: 0

                onTriggered: {

                    // This triggers the crash without retranslate().
                    // retranslate() got cleverer in 6.2, sidestepping the issue.
                    replaceExit.animations[0].target = null;
                    replaceExit.animations[0].target = replaceExit.ViewTransition.item

                    console.log("timer within", root, "is about to call retranslate")
                    window.engine.retranslate()
                    window.calledTranslate()
                    count++
                    if(count >= 10) {
                        stop()
                        count = 0
                    }
                }
            }

            Button {
                objectName: "button"
                text: qsTr("Push")
                onClicked: root.StackView.view.replace(translatePageComponent)
            }
        }
    }

    StackView {
        id: stack
        objectName: "stackView"
        anchors.fill: parent
        initialItem: translatePageComponent

        replaceEnter: Transition {
            id: replaceEnter
            objectName: "enterTransition"

            PropertyAnimation {
                objectName: replaceEnter.objectName + "PropertyAnimation"
                target: replaceEnter.ViewTransition.item
                property: "opacity"
                from: 0
                to: 1
                duration: 10
            }

        }

        replaceExit: Transition {
            id: replaceExit
            objectName: "exitTransition"

            PropertyAnimation {
                objectName: replaceExit.objectName + "PropertyAnimation"
                target: replaceExit.ViewTransition.item
                property: "opacity"
                from: 1
                to: 0
                duration: 10
            }
        }
    }
}