Commit 145947a7 authored by Richard Lin's avatar Richard Lin
Browse files

ADD: two new cluster scene plugins, from qtws2017 demo, which designed by Qt3DStudio.

Modify: Finish cluster code. Test in x64 linux. Modify READNE.md
parent dfc8d086
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Scene Changing Framework Demo.
**
** $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.8
import QtQuick.Window 2.2
Window {
id: base_root
visible: true
width: 1920
height: 720
color: "grey"
Loader {
id: base_content
anchors.fill: parent
source: sceneManager.currentScene.entryPath
Connections {
target: sceneManager
onCurrentSceneChanged: {
base_content.setSource( sceneManager.currentScene.entryPath );
}
}
}
SceneSelector {
id: sceneSelector
x: 100
y: 100
width: parent.width / 3
height: parent.height / 1.5
}
}
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Scene Changing Framework Demo.
**
** $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.8
ListView {
id: root
model: sceneManager.sceneList
opacity: 0
clip: true
focus: true
highlightRangeMode: ListView.StrictlyEnforceRange
preferredHighlightBegin: height / 3
preferredHighlightEnd: height / 3
highlight: Rectangle {
width: parent.width
color: "steelblue";
opacity: 0.7
}
delegate: Rectangle {
id: selectorItem
color: sceneManager.currentSceneNumber === index ? "green" : "transparent"
opacity: root.currentIndex === index ? 1 : 0.5
width: root.width
height: root.currentIndex === index ? root.height / 3 : root.height / 6
clip: true
Image {
anchors.right: parent.right
width: parent.width / 1.5
height: parent.height * 0.8
anchors.verticalCenter: parent.verticalCenter
fillMode: Image.PreserveAspectFit
source: "image://sceneManager/" + index
}
Text {
color: "white"
font.pixelSize: parent.height / 5
anchors.left: parent.left
text: sceneManager.sceneList[index].name
}
Behavior on height {
NumberAnimation {
easing.type: Easing.OutCirc; duration: 1000 }
}
}
Timer {
id: selectorFadeTimer
running: false
interval: 5000
onTriggered: {
selectorFadeAnimator.start();
}
}
PropertyAnimation {
id: selectorFadeAnimator
target: root
property: "opacity"
from: 1;
to: 0;
duration: 2000
}
Keys.onPressed: {
if (event.key == Qt.Key_Up) {
root.opacity = 1
selectorFadeTimer.restart()
if (currentIndex > 0)
currentIndex = currentIndex -1;
event.accepted = true;
} else if (event.key == Qt.Key_Down) {
root.opacity = 1
selectorFadeTimer.restart()
if (currentIndex < (count -1))
currentIndex ++;
event.accepted = true;
} else if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter) {
root.opacity = 1
selectorFadeTimer.restart()
sceneManager.setScene(currentIndex);
event.accepted = true;
}
}
}
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Scene Changing Framework Demo.
**
** $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$
**
****************************************************************************/
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QFontDatabase>
#include "scenemanager.h"
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
//scene manager
SceneManager* cm = new SceneManager(&engine);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
//for qt 3d studio scene plugins
engine.addImportPath(QStringLiteral("/home/linbin/QtPlayground/QtGit/qt3dstudio/qml"));
//qt demo default fonts
QFontDatabase::addApplicationFont("qrc:/fonts/TitilliumWeb-SemiBold.ttf");
QFont defaultFont;
defaultFont.setFamily("Titillium Web");
QGuiApplication::setFont(defaultFont);
engine.load(QUrl(QStringLiteral("qrc:/Main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
......
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.VirtualKeyboard 2.1
Window {
id: root
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "grey"
Loader {
id: content
anchors.fill: parent
}
Item {
id: s
property int sceneNumber: 0
property int sceneCounts: 0
Connections {
target: sceneManager
onSceneListChanged: {
s.sceneCounts = sceneManager.sceneList.size();
s.sceneNumber = 0
}
}
function selectScene(number) {
if (number < 0 || number > s.sceneCounts) return;
s.sceneNumber = number;
content.setSource( sceneManager.sceneList.at(number).entryPath );
}
}
ListView {
id: sceneSelector
x: 0
y: 0
width: parent.width / 3
height: parent.height / 1.5
model: sceneManager.sceneList
delegate: Rectangle {
width: sceneSelector.width
height: sceneSelector.height / 3
Text {
text: sceneManager.sceneList[index].name
}
Image {
source: "image://sceneManager/" + index
}
}
}
}
<!DOCTYPE RCC>
<RCC version="1.0">
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>Main.qml</file>
<file>SceneSelector.qml</file>
<file>fonts/TitilliumWeb-SemiBold.ttf</file>
<file>main.cpp</file>
<file>sceneinfo.cpp</file>
<file>sceneinfo.h</file>
<file>scenemanager.cpp</file>
<file>scenemanager.h</file>
</qresource>
</RCC>
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Scene Changing Framework Demo.
**
** $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$
**
****************************************************************************/
#include "sceneinfo.h"
#include <QDebug>
SceneInfo::SceneInfo(QObject *parent) : QObject(parent), _pSnapShot(nullptr) {
SceneInfo::SceneInfo(QObject *parent) :
QObject(parent), _pSnapShot(nullptr), _pLoader(nullptr)
{
init();
}
SceneInfo::~SceneInfo(void) {
init();
}
bool SceneInfo::init(void) {
unload();
if (_pLoader) {
_pLoader->deleteLater();
_pLoader = nullptr;
}
_version = 0;
_name = QString();
_entryPath = QString();
delete _pSnapShot;
emit propertyChanged();
return true;
}
bool SceneInfo::loadFile(const QString& filePath) {
bool SceneInfo::init(const QString& filePath) {
if (QLibrary::isLibrary(filePath)) {
QPluginLoader* newLoader = new QPluginLoader(filePath);
const QJsonObject meta = newLoader->metaData();
if (meta["MetaData"]["type"].toString(QString()) == QString("scenePlugin") &&
meta["MetaData"]["version"].toInt(0) > 0 &&
meta["MetaData"]["name"].toString(QString()) != _name) {
iPlugin *plugin = qobject_cast<iPlugin*>(newLoader->instance());
QPluginLoader* pNewLoader = new QPluginLoader(filePath);
const QJsonValue& meta = pNewLoader->metaData()["MetaData"];
if (meta["type"].toString(QString()) == QString("scenePlugin") &&
meta["version"].toString(QString()).toInt() > 0 &&
meta["name"].toString(QString()) != _name) {
iPlugin *plugin = qobject_cast<iPlugin*>(pNewLoader->instance());
if (plugin) {
//success
unload();
_version = meta["MetaData"]["version"].toInt(0);
_name = meta["MetaData"]["name"].toString(QString());
_entryPath = meta["MetaData"]["entryPath"].toString(QString());
_pLoader = newLoader;
_pSnapShot = plugin->snapShot();
init();
_version = meta["version"].toInt(0);
_name = meta["name"].toString(QString());
_entryPath = meta["entryPath"].toString(QString());
QString snapShotPath = meta["snapShot"].toString(QString());
snapShotPath = snapShotPath.right(snapShotPath.length()-3);
_pSnapShot = new QImage(snapShotPath, "PNG");
_pLoader = pNewLoader;
emit propertyChanged();
plugin->deleteLater();
pNewLoader->unload();
return true;
}
}
newLoader->deleteLater();
if(pNewLoader->isLoaded())
pNewLoader->unload();
pNewLoader->deleteLater();
}
//failed
return false;
}
void SceneInfo::unload(void) {
if (!_pLoader) {
_pLoader->deleteLater();
_pLoader = nullptr;
bool SceneInfo::load(void) {
bool ret =false;
if (_pLoader) {
if (!_pLoader->isLoaded())
ret = _pLoader->instance();
}
_version = 0;
_name = QString();
_entryPath = QString();
_pSnapShot.clear();
emit propertyChanged();
return ret;
}
QPluginLoader* SceneInfo::loader(void) {
return _pLoader;
bool SceneInfo::unload(void) {
bool ret =false;
if (_pLoader) {
if (_pLoader->isLoaded())
ret = _pLoader->unload();
}
return ret;
}
QSharedPointer<QImage> SceneInfo::snapShot(void) {
QImage* SceneInfo::snapShot(void) {
return _pSnapShot;
}
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Scene Changing Framework Demo.
**
** $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$
**
****************************************************************************/
#ifndef SCENEINFO_H
#define SCENEINFO_H
......@@ -16,17 +66,18 @@ public:
explicit SceneInfo(QObject *parent = nullptr);
virtual ~SceneInfo(void);
bool loadFile(const QString& filePath);
void unload(void);
QPluginLoader* loader(void);
QSharedPointer<QImage> snapShot(void);
bool init(void);
bool init(const QString& filePath);
bool load(void);
bool unload(void);
QImage *snapShot(void);
private:
QString _name;
int _version;
QString _entryPath;
QSharedPointer<QImage> _pSnapShot;
QImage* _pSnapShot;
QPluginLoader* _pLoader;