Commit f127afdf authored by Titta Heikkala's avatar Titta Heikkala

Add Home Automation demo

Added Home Automation demo for Qt 3D Studio 1.0.0

Task-number: QT3DS-291
parent 72b0b208
TEMPLATE = app
QT += qml quick
target.path = $$[QT_INSTALL_EXAMPLES]/studio3d/$$TARGET
INSTALLS += target
SOURCES += main.cpp \
housemodel.cpp
HEADERS += \
housemodel.h
RESOURCES += HomeAutom.qrc
OTHER_FILES += qml/HomeAutom/*
RC_ICONS += HomeAutom.ico
QML_IMPORT_PATH = $$PWD/qml/imports
DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
<RCC>
<qresource prefix="/">
<file>qml/images/QtSymbol.png</file>
<file alias="main.qml">qml/HomeAutom/main.qml</file>
<file alias="HomeView.qml">qml/HomeAutom/HomeView.qml</file>
<file alias="SplashScreen.qml">qml/HomeAutom/SplashScreen.qml</file>
<file alias="MainMenu.qml">qml/HomeAutom/MainMenu.qml</file>
<file alias="TempSlider.qml">qml/HomeAutom/TempSlider.qml</file>
<file alias="SliderControl.qml">qml/HomeAutom/SliderControl.qml</file>
<file alias="LightSlider.qml">qml/HomeAutom/LightSlider.qml</file>
<file alias="RoomLabel.qml">qml/HomeAutom/RoomLabel.qml</file>
<file>uip/houseStudio.uip</file>
<file>uip/maps/Ground.png</file>
<file>uip/maps/HouseGroundOpacitymap.png</file>
<file>uip/maps/HouseTexture.png</file>
<file>uip/maps/OpenfootageNET_Pinzgau-512.hdr</file>
<file>uip/maps/Roof.png</file>
<file>uip/models/HeatAreas/meshes/Heat_Entrance HeatAreas.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_BathRoom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_BedRoom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_DressRoom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_LivingRoom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_MasterBedroom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_Sauna.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_StoreRoom.mesh</file>
<file>uip/models/HeatAreas/meshes/HeatAreas Heat_Toilet.mesh</file>
<file>uip/models/HeatAreas/HeatAreas.import</file>
<file>uip/models/House/meshes/Ground.mesh</file>
<file>uip/models/House/meshes/House.mesh</file>
<file>uip/models/House/meshes/Roof.mesh</file>
<file>uip/models/House/meshes/Windows.mesh</file>
<file>uip/models/House/House.import</file>
<file>uip/models/Light/Light.import</file>
<file>uip/House/meshes/house1.mesh</file>
<file>uip/House/meshes/roof1.mesh</file>
<file>uip/maps/BathroomLightmap.png</file>
<file>uip/maps/BedRoomLightmap.png</file>
<file>uip/maps/EntranceLightmap.png</file>
<file>uip/maps/LivingRoomLightMap.png</file>
<file>uip/maps/MasterBedroomLightmap.png</file>
<file>uip/models/RoomLights/RoomLights.import</file>
<file>uip/models/RoomLights/meshes/BathroomLightmap.mesh</file>
<file>uip/models/RoomLights/meshes/BedroomLightmap.mesh</file>
<file>uip/models/RoomLights/meshes/EntranceLightmap.mesh</file>
<file>uip/models/RoomLights/meshes/LivingroomLightMap.mesh</file>
<file>uip/models/RoomLights/meshes/MasterbedroomLightmap.mesh</file>
<file>qml/images/icon_light.png</file>
<file>qml/images/icon_temp.png</file>
<file>uip/maps/HouseTexture.jpg</file>
<file>qml/imports/Style/qmldir</file>
<file>qml/imports/Style/Style.qml</file>
</qresource>
</RCC>
<?xml version="1.0"?>
<manifest package="org.qtproject.homeautomationdemo" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Home Automation Demo" android:icon="@drawable/icon" android:debuggable="false">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="Home Automation Demo" android:screenOrientation="sensorLandscape" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Application arguments -->
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Used to specify custom system library path to run with local system libs -->
<!-- <meta-data android:name="android.app.system_libs_prefix" android:value="/system/lib/"/> -->
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
<!-- Splash screen -->
<!-- Background running -->
<!-- Warning: changing this value to true may cause unexpected crashes if the
application still try to draw after
"applicationStateChanged(Qt::ApplicationSuspended)"
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="false"/>
<!-- Background running -->
<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
<!-- auto screen scale factor -->
<!-- extract android style -->
<!-- available android:values :
* full - useful QWidget & Quick Controls 1 apps
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
* none - useful for apps that don't use any of the above Qt modules
-->
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
<!-- extract android style -->
</activity>
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
</manifest>
<?xml version='1.0' encoding='utf-8'?>
<resources>
<array name="qt_sources">
<item>https://download.qt.io/ministro/android/qt5/qt-5.9</item>
</array>
<!-- The following is handled automatically by the deployment tool. It should
not be edited manually. -->
<array name="bundled_libs">
<!-- %%INSERT_EXTRA_LIBS%% -->
</array>
<array name="qt_libs">
<!-- %%INSERT_QT_LIBS%% -->
</array>
<array name="bundled_in_lib">
<!-- %%INSERT_BUNDLED_IN_LIB%% -->
</array>
<array name="bundled_in_assets">
<!-- %%INSERT_BUNDLED_IN_ASSETS%% -->
</array>
</resources>
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $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 "housemodel.h"
HouseModel::HouseModel(QObject *parent) : QAbstractListModel(parent)
{
generateRooms();
}
QHash<int, QByteArray> HouseModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ItemRole] = "item";
roles[TemperatureRole] = "temperature";
roles[LightRole] = "light";
roles[XPosRole] = "xPos";
roles[YPosRole] = "yPos";
return roles;
}
QVariant HouseModel::data(const QModelIndex &index, int role) const
{
if (role == NameRole)
return m_rooms.at(index.row()).getName();
else if (role == ItemRole)
return m_rooms.at(index.row()).getItem();
else if (role == TemperatureRole)
return m_rooms.at(index.row()).getTemperature();
else if (role == LightRole)
return m_rooms.at(index.row()).getLight();
else if (role == XPosRole)
return m_rooms.at(index.row()).getXPos();
else if (role == YPosRole)
return m_rooms.at(index.row()).getYPos();
else return QVariant();
}
bool HouseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid()) {
if (role == TemperatureRole) {
m_rooms[index.row()].setTemperature(value.toInt());
emit dataChanged(index, index);
return true;
} else if (role == LightRole) {
m_rooms[index.row()].setLight(value.toDouble());
emit dataChanged(index, index);
return true;
}
}
return false;
}
int HouseModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_rooms.length();
}
bool HouseModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(row)
Q_UNUSED(count)
Q_UNUSED(parent)
beginResetModel();
m_rooms.clear();
endResetModel();
return true;
}
void HouseModel::addRoom(const QString &name, const QString &item,
int temperature, double light, int xPos, int yPos)
{
int row = m_rooms.size();
beginInsertRows(QModelIndex(), row, row);
m_rooms.insert(row, Room(name, item, temperature, light, xPos, yPos));
endInsertRows();
}
void HouseModel::generateRooms()
{
removeRows(0, m_rooms.length());
// Position of labels is defined from the center point of window
addRoom(QStringLiteral("Living Room"), QStringLiteral("Livingroom"), 21, 0.8, 120, 200);
addRoom(QStringLiteral("Master Bedroom"), QStringLiteral("Masterbedroom"), 18, 0.8, -380, -290);
addRoom(QStringLiteral("Bedroom"), QStringLiteral("Bedroom"), 15, 0.0, -405, 170);
addRoom(QStringLiteral("Bath Room"), QStringLiteral("Bathroom"), 30, 1.0, -20, -320);
addRoom(QStringLiteral("Entrance"), QStringLiteral("Entrance"), 20, 0.6, -450, -70);
}
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $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 HOUSEMODEL_H
#define HOUSEMODEL_H
#include <QAbstractListModel>
#include <QUrl>
#include <QRect>
class Room
{
public:
Room(const QString &name, const QString &item,
int temperature, double light, int x, int y)
: m_name(name)
, m_item(item)
, m_temperature(temperature)
, m_light(light)
, m_xPos(x)
, m_yPos(y) {}
QString getName() const { return m_name; }
QString getItem() const { return m_item; }
int getTemperature() const { return m_temperature; }
int getXPos() const { return m_xPos; }
int getYPos() const { return m_yPos; }
void setTemperature(int temperature) { m_temperature = temperature; }
double getLight() const { return m_light; }
void setLight(double light) { m_light = light; }
void setXPos(int x) { m_xPos = x; }
void setYPos(int y) { m_xPos = y; }
private:
QString m_name;
QString m_item;
int m_temperature;
double m_light;
int m_xPos;
int m_yPos;
};
class HouseModel : public QAbstractListModel
{
Q_OBJECT
public:
enum RoomRoles {
NameRole = 0,
ItemRole,
TemperatureRole,
LightRole,
XPosRole,
YPosRole
};
HouseModel(QObject *parent = 0);
virtual QHash<int, QByteArray> roleNames() const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
void addRoom(const QString &name, const QString &item,
int temperature, double light, int xPos, int yPos);
private:
void generateRooms();
QList<Room> m_rooms;
};
#endif // HOUSEMODEL_H
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $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 <QtGui/QGuiApplication>
#include <QtCore/QDir>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtGui/QScreen>
#include <QtQml/QQmlPropertyMap>
#include "housemodel.h"
// Uncomment for 1280x900 window
//#define FIXEDWINDOW
int applyFontRatio(const int value, const int ratioFont)
{
return int(value * ratioFont);
}
int applyRatio(const int value, const int ratio)
{
return qMax(2, int(value * ratio));
}
int main(int argc, char *argv[])
{
#if defined(Q_OS_MACOS)
QSurfaceFormat openGLFormat;
openGLFormat.setRenderableType(QSurfaceFormat::OpenGL);
openGLFormat.setProfile(QSurfaceFormat::CoreProfile);
openGLFormat.setMajorVersion(4);
openGLFormat.setMinorVersion(1);
openGLFormat.setStencilBufferSize(8);
QSurfaceFormat::setDefaultFormat(openGLFormat);
#endif
QGuiApplication app(argc, argv);
// Define size variants for scaling
qreal refDpi = 96.;
qreal refWidth = 1280.;
qreal refHeight = 900.;
QRect rect = QGuiApplication::primaryScreen()->geometry();
qreal width = rect.width();
qreal height = rect.height();
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
qreal widthRatio = width / refWidth;
qreal heightRatio = height / refHeight;
qreal ratioFont = qMin(height * dpi / (refDpi * refHeight), width * dpi / (refDpi * refWidth));
if (widthRatio < 1.)
widthRatio = 1;
if (heightRatio < 1.)
heightRatio = 1;
if (ratioFont < 1.)
ratioFont = 1;
#ifdef FIXEDWINDOW
width = refWidth;
height = refHeight;
widthRatio = 1;
heightRatio = 1;
ratioFont = 1;
#endif
QQmlPropertyMap sizesMap;
sizesMap.insert(QStringLiteral("screenHeight"), QVariant(height));
sizesMap.insert(QStringLiteral("screenWidth"), QVariant(width));
sizesMap.insert(QStringLiteral("fontSize"), QVariant(applyFontRatio(26, ratioFont)));
sizesMap.insert(QStringLiteral("controlHeight"), QVariant(applyFontRatio(64, ratioFont)));
sizesMap.insert(QStringLiteral("labelMouseMargin"), QVariant(applyRatio(20, widthRatio)));
sizesMap.insert(QStringLiteral("controlMargin"), QVariant(applyRatio(20, widthRatio)));
sizesMap.insert(QStringLiteral("controlBorderWidth"), QVariant(applyRatio(3, widthRatio)));
sizesMap.insert(QStringLiteral("sliderMaxWidth"), QVariant(applyRatio(300, widthRatio)));
QQuickView viewer;
viewer.engine()->addImportPath(QStringLiteral(":/qml/imports"));
#ifndef Q_OS_ANDROID
// Hack to get self build working.
// Also needs the Qt3DStudio\bin directory in run environment path.
viewer.engine()->addImportPath(QStringLiteral("C:/Qt/Tools/Qt3DStudio/qml"));
#endif
HouseModel *m_houseModel = new HouseModel;
viewer.engine()->rootContext()->setContextProperty(QStringLiteral("houseModel"), m_houseModel);
viewer.engine()->rootContext()->setContextProperty(QStringLiteral("sizesMap"), &sizesMap);
viewer.engine()->rootContext()->setContextProperty(QStringLiteral("heightRatio"), heightRatio);
viewer.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
viewer.setTitle(QStringLiteral("Qt 3D Studio Home Automation Demo"));
viewer.setResizeMode(QQuickView::SizeViewToRootObject);
#ifdef FIXEDWINDOW
viewer.setMinimumSize(QSize(width, height));
viewer.setMaximumSize(QSize(width, height));
viewer.show();
#else
viewer.showFullScreen();
#endif
return app.exec();
}
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $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
SliderControl {
id: lightSlider
property real lightValue: lightSlider.position
sliderColor: "black"
currentValue: lightValue.toFixed(1)
text: currentValue * 100 + "%"
iconSource: "qml/images/icon_light.png"
onPositionChanged: {
setNewLightColor()
}
function setNewLightColor() {
// From black to white
var newColorValue = lightSlider.position * 255
sliderColor = rgbToHex(newColorValue, newColorValue, newColorValue)
}
}
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in