diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-03-14 11:55:38 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-03-15 08:28:41 +0000 |
commit | f98e2139692092890176059afa56eb0245cd892e (patch) | |
tree | ba55cc38b32ed5a8cd61c4b4abd902614fd4da5c /tests | |
parent | 760fa928d786442e9bb67e34d09c6f62f309f53c (diff) |
Implement SetProperty, FireEvent, Next/PreviousSlide actions
Change-Id: I9e5a25694d36da8f412c66e5aa140a34c0d3c5f6
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/uippresentation/tst_q3dsuippresentation.cpp | 28 | ||||
-rw-r--r-- | tests/scenes/behaviors/actionevent.qml | 70 | ||||
-rw-r--r-- | tests/scenes/behaviors/actionevent.uip | 98 |
3 files changed, 196 insertions, 0 deletions
diff --git a/tests/auto/uippresentation/tst_q3dsuippresentation.cpp b/tests/auto/uippresentation/tst_q3dsuippresentation.cpp index d42ad5b..89b1528 100644 --- a/tests/auto/uippresentation/tst_q3dsuippresentation.cpp +++ b/tests/auto/uippresentation/tst_q3dsuippresentation.cpp @@ -43,6 +43,7 @@ private slots: void slideGraphChangeNotification(); void slideConstruct(); void events(); + void eventsCatchAll(); private: void makePresentation(Q3DSUipPresentation &presentation); @@ -536,5 +537,32 @@ void tst_Q3DSUipPresentation::events() QCOMPARE(triggerCount[4], 2); } +void tst_Q3DSUipPresentation::eventsCatchAll() +{ + Q3DSUipPresentation presentation; + makePresentation(presentation); + + Q3DSModelNode *model1 = presentation.object<Q3DSModelNode>("model1"); + QVERIFY(model1); + const QString event1Key = QLatin1String("some event"); + const QString event2Key = QLatin1String("another event"); + int triggerCount[] = { 0, 0 }; + model1->addEventHandler(QString(), [model1, &triggerCount, event1Key, event2Key](Q3DSGraphObject *obj, const QString &event) { + if (obj == model1) { + if (event == event1Key) + ++triggerCount[0]; + if (event == event2Key) + ++triggerCount[1]; + } + }); + + model1->processEvent(event1Key); + QCOMPARE(triggerCount[0], 1); + QCOMPARE(triggerCount[1], 0); + model1->processEvent(event2Key); + QCOMPARE(triggerCount[0], 1); + QCOMPARE(triggerCount[1], 1); +} + #include <tst_q3dsuippresentation.moc> QTEST_MAIN(tst_Q3DSUipPresentation) diff --git a/tests/scenes/behaviors/actionevent.qml b/tests/scenes/behaviors/actionevent.qml new file mode 100644 index 0000000..7526a84 --- /dev/null +++ b/tests/scenes/behaviors/actionevent.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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.0 +import QtStudio3D.Behavior 2.0 + +Behavior { + property var origColor + onInitialize: { + origColor = getAttribute("SphereMaterial", "diffuse"); + registerForEvent("onPressureDown", function() { + console.log("behavior's owner got pressureDown event"); + setAttribute("SphereMaterial", "diffuse", "1 0 0"); + }); + registerForEvent("onPressureUp", function() { + console.log("behavior's owner got pressureUp event"); + setAttribute("SphereMaterial", "diffuse", origColor); + }); + } +} diff --git a/tests/scenes/behaviors/actionevent.uip b/tests/scenes/behaviors/actionevent.uip new file mode 100644 index 0000000..2e489bd --- /dev/null +++ b/tests/scenes/behaviors/actionevent.uip @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<UIP version="3" > + <Project > + <ProjectSettings author="" company="" presentationWidth="1366" presentationHeight="768" maintainAspect="False" > + <CustomColors count="16" >#ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff</CustomColors> + </ProjectSettings> + <Classes > + <Behavior id="Behav1" name="Behavior 1" sourcepath="actionevent.qml" /> + </Classes> + <Graph > + <Scene id="Scene" backgroundcolor="0.929412 0.956863 0.34902" > + <Layer id="Layer" > + <Camera id="Camera" /> + <Light id="Light" /> + <Model id="Rectangle" > + <Material id="Material" /> + </Model> + <Model id="Sphere" > + <Material id="Material_001" /> + <Behavior id="Behavior_001" class="#Behav1" /> + </Model> + <Model id="Cylinder" > + <Material id="Material_002" /> + </Model> + <Model id="Cone" > + <Material id="Material_003" /> + </Model> + <Text id="Text" /> + <Text id="Text_001" /> + <Text id="Text2" /> + <Text id="Text3" /> + <Model id="Sphere2" > + <Material id="Default" name="Default" /> + </Model> + </Layer> + <Layer id="Layer2" > + <Camera id="Camera_001" /> + <Light id="Light_001" /> + <Group id="Group" > + <Model id="Rectangle_001" > + <Material id="Material_004" /> + </Model> + <Model id="Cube" > + <Material id="Material_005" /> + </Model> + </Group> + <Model id="Cone_001" > + <Material id="Material_006" /> + </Model> + </Layer> + </Scene> + </Graph> + <Logic > + <State name="Master Slide" component="#Scene" > + <Add ref="#Layer" /> + <Add ref="#Camera" position="0 -40 -600" rotation="-10 0 -10" /> + <Add ref="#Light" /> + <State id="Scene-Slide1" name="Slide1" > + <Add ref="#Rectangle" name="Rectangle" position="-407.032 -97.8609 0" sourcepath="#Rectangle" /> + <Add ref="#Material" /> + <Add ref="#Sphere" name="Sphere" position="-479.719 208.826 220.558" rotation="-20.8358 34.3489 -62.5045" sourcepath="#Sphere" /> + <Add ref="#Material_001" name="SphereMaterial" blendmode="Normal" diffuse="0.341176 0.258824 0.8" /> + <Add ref="#Behavior_001" name="Behavior instance 1" /> + <Add ref="#Cylinder" name="Cylinder" position="211.66 54.7973 -123.049" rotation="-29.16 22.9975 -41.0578" scale="0.89855 0.969231 1" sourcepath="#Cylinder" > + <Action id="Cylinder-Action" eyeball="True" triggerObject="#Cylinder" event="onPressureDown" targetObject="#Sphere" handler="Fire Event" > + <HandlerArgument name="Event" type="String" argtype="Event" value="onPressureDown" /> + </Action> + </Add> + <Add ref="#Material_002" diffuse="0.215686 0.815686 0.756863" /> + <Add ref="#Cone" name="Cone" rotation="-47.4815 2.69907 11.9215" sourcepath="#Cone" > + <Action id="Cone-Action" eyeball="True" triggerObject="#Cone" event="onPressureDown" targetObject="#Scene" handler="Next Slide" /> + </Add> + <Add ref="#Material_003" diffuse="0.890196 0.341176 0.615686" /> + <Add ref="#Text" name="Text" font="TitilliumWeb-Regular" position="-373.457 220.512 0" textstring="Press to trigger QML" /> + <Add ref="#Text_001" name="Text" font="TitilliumWeb-Regular" position="271.371 192.426 0" textstring="Press to fake a press on sphere" /> + <Add ref="#Text2" name="Text2" font="TitilliumWeb-Regular" position="-22.6025 107.143 0" textstring="Press for next slide" /> + <Add ref="#Layer2" name="Layer2" background="Transparent" blendtype="Normal" disabledepthtest="False" /> + <Add ref="#Camera_001" /> + <Add ref="#Light_001" /> + <Add ref="#Group" name="Group" opacity="50" /> + <Add ref="#Rectangle_001" name="Rectangle" scale="10 6 1" sourcepath="#Rectangle" /> + <Add ref="#Material_004" diffuse="0.65098 0.619608 0.533333" /> + <Add ref="#Cube" name="Cube" position="482.629 -108.253 10" rotation="-12.3559 8.88262 8.26342" sourcepath="#Cube" /> + <Add ref="#Material_005" /> + <Add ref="#Cone_001" name="Cone" position="501.573 148.848 10" sourcepath="#Cone" /> + <Add ref="#Material_006" /> + </State> + <State id="Scene-Slide2" name="Slide2" initialplaystate="Play" playmode="Stop at end" playthroughto="Previous" > + <Add ref="#Text3" name="Text3" font="TitilliumWeb-Regular" position="-0.443962 367.803 0" textstring="Previous slide" /> + <Add ref="#Sphere2" name="Sphere2" position="-16.1459 261.794 0" sourcepath="#Sphere" > + <Action id="Sphere2-Action" eyeball="True" triggerObject="#Sphere2" event="onPressureDown" targetObject="#Scene" handler="Previous Slide" /> + </Add> + <Add ref="#Default" /> + </State> + </State> + </Logic> + </Project> +</UIP> |