xref: /OK3568_Linux_fs/app/forlinx/flapp/src/plugins/imxwayland/qmlvideofx/qml/qmlvideofx/Content.qml (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Mobility Components.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34import QtQuick 2.1
35
36Rectangle {
37    id: root
38    property alias effect: effectLoader.item
39    property alias gripSize: divider.gripSize
40    property string effectSource
41    property real volume: 0.5
42
43    signal videoFramePainted
44
45    Divider {
46        id: divider
47        visible: false
48        z: 1.0
49        onValueChanged: updateDivider()
50    }
51
52    ShaderEffectSource {
53        id: theSource
54        smooth: true
55        hideSource: true
56    }
57
58    Loader {
59        id: contentLoader
60    }
61
62    Loader {
63        id: effectLoader
64        source: effectSource
65    }
66
67    Connections {
68        id: videoFramePaintedConnection
69        onFramePainted: {
70            if (performanceLoader.item)
71               root.videoFramePainted()
72        }
73        ignoreUnknownSignals: true
74    }
75
76    onWidthChanged: {
77        if (effectLoader.item)
78            effectLoader.item.targetWidth = root.width
79    }
80
81    onHeightChanged: {
82        if (effectLoader.item)
83            effectLoader.item.targetHeight = root.height
84    }
85
86    onEffectSourceChanged: {
87        effectLoader.source = effectSource
88        effectLoader.item.parent = root
89        effectLoader.item.targetWidth = root.width
90        effectLoader.item.targetHeight = root.height
91        updateSource()
92        effectLoader.item.source = theSource
93        divider.visible = effectLoader.item.divider
94        updateDivider()
95    }
96
97    function init() {
98        openImage("qrc:/images/qt-logo.png")
99        root.effectSource = "EffectPassThrough.qml"
100    }
101
102    function updateDivider() {
103        if (effectLoader.item && effectLoader.item.divider)
104            effectLoader.item.dividerValue = divider.value
105    }
106
107    function updateSource() {
108        if (contentLoader.item) {
109            contentLoader.item.parent = root
110            contentLoader.item.anchors.fill = root
111            theSource.sourceItem = contentLoader.item
112            if (effectLoader.item)
113                effectLoader.item.anchors.fill = contentLoader.item
114        }
115    }
116
117    function openImage(path) {
118        stop()
119        contentLoader.source = "ContentImage.qml"
120        videoFramePaintedConnection.target = null
121        contentLoader.item.source = path
122        updateSource()
123    }
124
125    function openVideo(path) {
126        stop()
127        contentLoader.source = "ContentVideo.qml"
128        videoFramePaintedConnection.target = contentLoader.item
129        contentLoader.item.mediaSource = path
130        contentLoader.item.volume = volume
131        contentLoader.item.play()
132        updateSource()
133    }
134
135    function openCamera() {
136        stop()
137        contentLoader.source = "ContentCamera.qml"
138        videoFramePaintedConnection.target = contentLoader.item
139        updateSource()
140    }
141
142    function stop() {
143        if (contentLoader.source == "ContentVideo.qml")
144            contentLoader.item.stop()
145        theSource.sourceItem = null
146    }
147}
148