From 637c6004b46cd5ae68b5ec9b62df0e9480289e80 Mon Sep 17 00:00:00 2001 From: Sergey Dubitskiy Date: Mon, 30 Jan 2012 12:01:10 +1000 Subject: ModelTweaker was renamed to "3D Asset Viewer" Change-Id: Ib34723c2bbb0171b15edec0db798bc7e01bbdbc8 Reviewed-by: Danny Pope --- util/qt3d/assetviewer/assetviewer.desktop | 7 + util/qt3d/assetviewer/assetviewer.pro | 25 + util/qt3d/assetviewer/assetviewer.rc | 1 + util/qt3d/assetviewer/main.cpp | 100 ++++ util/qt3d/assetviewer/qml/AssetViewer.qml | 292 +++++++++++ util/qt3d/assetviewer/qml/BlenderValueSlider.qml | 175 +++++++ util/qt3d/assetviewer/qml/ButtonBarPane.qml | 51 ++ util/qt3d/assetviewer/qml/CheckBox.qml | 45 ++ util/qt3d/assetviewer/qml/ColorPicker.qml | 286 +++++++++++ util/qt3d/assetviewer/qml/ColorUtils.js | 61 +++ util/qt3d/assetviewer/qml/HelpOverlay.qml | 56 +++ util/qt3d/assetviewer/qml/ModelPropertiesPane.qml | 543 +++++++++++++++++++++ util/qt3d/assetviewer/qml/ModelViewport.qml | 452 +++++++++++++++++ util/qt3d/assetviewer/qml/SaveButton.qml | 12 + .../qt3d/assetviewer/qml/Widgets/BlenderToggle.qml | 48 ++ util/qt3d/assetviewer/qml/Widgets/Checkered.qml | 27 + .../qt3d/assetviewer/qml/Widgets/ColorSelector.qml | 72 +++ util/qt3d/assetviewer/qml/Widgets/ColorWidget.qml | 37 ++ util/qt3d/assetviewer/qml/Widgets/HSVColor.qml | 15 + util/qt3d/assetviewer/qml/Widgets/InputBox.qml | 39 ++ .../qml/Widgets/ModelViewportResize.qml | 30 ++ util/qt3d/assetviewer/qml/Widgets/SliderHandle.qml | 76 +++ util/qt3d/assetviewer/qml/Widgets/ZoomControls.qml | 41 ++ util/qt3d/assetviewer/qml/Widgets/images/grow.png | Bin 0 -> 252 bytes .../qt3d/assetviewer/qml/Widgets/images/shrink.png | Bin 0 -> 249 bytes .../qt3d/assetviewer/qml/Widgets/images/zoomin.png | Bin 0 -> 187 bytes .../assetviewer/qml/Widgets/images/zoomout.png | Bin 0 -> 155 bytes util/qt3d/assetviewer/qml/fileHandling.js | 106 ++++ util/qt3d/assetviewer/qml/images/help.png | Bin 0 -> 737 bytes util/qt3d/assetviewer/qml/images/lock.png | Bin 0 -> 273 bytes util/qt3d/assetviewer/qml/images/minus.png | Bin 0 -> 224 bytes util/qt3d/assetviewer/qml/images/model.png | Bin 0 -> 754 bytes util/qt3d/assetviewer/qml/images/open.png | Bin 0 -> 596 bytes util/qt3d/assetviewer/qml/images/plus.png | Bin 0 -> 224 bytes util/qt3d/assetviewer/qml/images/save.png | Bin 0 -> 706 bytes util/qt3d/assetviewer/qml/images/unlock.png | Bin 0 -> 292 bytes util/qt3d/assetviewer/qml/meshes/monkey.3ds | Bin 0 -> 13886 bytes util/qt3d/assetviewer/qml/meshes/penguin.3ds | Bin 0 -> 36301 bytes util/qt3d/assetviewer/qtquick3d.ico | Bin 0 -> 67646 bytes util/qt3d/assetviewer/qtquick3d.png | Bin 0 -> 4050 bytes util/qt3d/assetviewer/quickfile.cpp | 163 +++++++ util/qt3d/assetviewer/quickfile.h | 46 ++ util/qt3d/modeltweak/main.cpp | 99 ---- util/qt3d/modeltweak/modeltweak.desktop | 7 - util/qt3d/modeltweak/modeltweak.pro | 25 - util/qt3d/modeltweak/modeltweak.rc | 1 - util/qt3d/modeltweak/qml/BlenderValueSlider.qml | 175 ------- util/qt3d/modeltweak/qml/ButtonBarPane.qml | 51 -- util/qt3d/modeltweak/qml/CheckBox.qml | 45 -- util/qt3d/modeltweak/qml/ColorPicker.qml | 286 ----------- util/qt3d/modeltweak/qml/ColorUtils.js | 61 --- util/qt3d/modeltweak/qml/HelpOverlay.qml | 56 --- util/qt3d/modeltweak/qml/ModelPropertiesPane.qml | 543 --------------------- util/qt3d/modeltweak/qml/ModelTweak.qml | 292 ----------- util/qt3d/modeltweak/qml/ModelViewport.qml | 452 ----------------- util/qt3d/modeltweak/qml/SaveButton.qml | 12 - util/qt3d/modeltweak/qml/Widgets/BlenderToggle.qml | 48 -- util/qt3d/modeltweak/qml/Widgets/Checkered.qml | 27 - util/qt3d/modeltweak/qml/Widgets/ColorSelector.qml | 72 --- util/qt3d/modeltweak/qml/Widgets/ColorWidget.qml | 37 -- util/qt3d/modeltweak/qml/Widgets/HSVColor.qml | 15 - util/qt3d/modeltweak/qml/Widgets/InputBox.qml | 39 -- .../modeltweak/qml/Widgets/ModelViewportResize.qml | 30 -- util/qt3d/modeltweak/qml/Widgets/SliderHandle.qml | 76 --- util/qt3d/modeltweak/qml/Widgets/ZoomControls.qml | 41 -- util/qt3d/modeltweak/qml/Widgets/images/grow.png | Bin 252 -> 0 bytes util/qt3d/modeltweak/qml/Widgets/images/shrink.png | Bin 249 -> 0 bytes util/qt3d/modeltweak/qml/Widgets/images/zoomin.png | Bin 187 -> 0 bytes .../qt3d/modeltweak/qml/Widgets/images/zoomout.png | Bin 155 -> 0 bytes util/qt3d/modeltweak/qml/fileHandling.js | 106 ---- util/qt3d/modeltweak/qml/images/help.png | Bin 737 -> 0 bytes util/qt3d/modeltweak/qml/images/lock.png | Bin 273 -> 0 bytes util/qt3d/modeltweak/qml/images/minus.png | Bin 224 -> 0 bytes util/qt3d/modeltweak/qml/images/model.png | Bin 754 -> 0 bytes util/qt3d/modeltweak/qml/images/open.png | Bin 596 -> 0 bytes util/qt3d/modeltweak/qml/images/plus.png | Bin 224 -> 0 bytes util/qt3d/modeltweak/qml/images/save.png | Bin 706 -> 0 bytes util/qt3d/modeltweak/qml/images/unlock.png | Bin 292 -> 0 bytes util/qt3d/modeltweak/qml/meshes/monkey.3ds | Bin 13886 -> 0 bytes util/qt3d/modeltweak/qml/meshes/penguin.3ds | Bin 36301 -> 0 bytes util/qt3d/modeltweak/qtquick3d.ico | Bin 67646 -> 0 bytes util/qt3d/modeltweak/qtquick3d.png | Bin 4050 -> 0 bytes util/qt3d/modeltweak/quickfile.cpp | 163 ------- util/qt3d/modeltweak/quickfile.h | 46 -- util/qt3d/qt3d.pro | 2 +- 85 files changed, 2807 insertions(+), 2806 deletions(-) create mode 100644 util/qt3d/assetviewer/assetviewer.desktop create mode 100644 util/qt3d/assetviewer/assetviewer.pro create mode 100644 util/qt3d/assetviewer/assetviewer.rc create mode 100644 util/qt3d/assetviewer/main.cpp create mode 100644 util/qt3d/assetviewer/qml/AssetViewer.qml create mode 100644 util/qt3d/assetviewer/qml/BlenderValueSlider.qml create mode 100644 util/qt3d/assetviewer/qml/ButtonBarPane.qml create mode 100644 util/qt3d/assetviewer/qml/CheckBox.qml create mode 100644 util/qt3d/assetviewer/qml/ColorPicker.qml create mode 100644 util/qt3d/assetviewer/qml/ColorUtils.js create mode 100644 util/qt3d/assetviewer/qml/HelpOverlay.qml create mode 100644 util/qt3d/assetviewer/qml/ModelPropertiesPane.qml create mode 100644 util/qt3d/assetviewer/qml/ModelViewport.qml create mode 100644 util/qt3d/assetviewer/qml/SaveButton.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/BlenderToggle.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/Checkered.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/ColorSelector.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/ColorWidget.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/HSVColor.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/InputBox.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/ModelViewportResize.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/SliderHandle.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/ZoomControls.qml create mode 100644 util/qt3d/assetviewer/qml/Widgets/images/grow.png create mode 100644 util/qt3d/assetviewer/qml/Widgets/images/shrink.png create mode 100644 util/qt3d/assetviewer/qml/Widgets/images/zoomin.png create mode 100644 util/qt3d/assetviewer/qml/Widgets/images/zoomout.png create mode 100644 util/qt3d/assetviewer/qml/fileHandling.js create mode 100644 util/qt3d/assetviewer/qml/images/help.png create mode 100644 util/qt3d/assetviewer/qml/images/lock.png create mode 100644 util/qt3d/assetviewer/qml/images/minus.png create mode 100644 util/qt3d/assetviewer/qml/images/model.png create mode 100644 util/qt3d/assetviewer/qml/images/open.png create mode 100644 util/qt3d/assetviewer/qml/images/plus.png create mode 100644 util/qt3d/assetviewer/qml/images/save.png create mode 100644 util/qt3d/assetviewer/qml/images/unlock.png create mode 100644 util/qt3d/assetviewer/qml/meshes/monkey.3ds create mode 100644 util/qt3d/assetviewer/qml/meshes/penguin.3ds create mode 100644 util/qt3d/assetviewer/qtquick3d.ico create mode 100644 util/qt3d/assetviewer/qtquick3d.png create mode 100644 util/qt3d/assetviewer/quickfile.cpp create mode 100644 util/qt3d/assetviewer/quickfile.h delete mode 100644 util/qt3d/modeltweak/main.cpp delete mode 100644 util/qt3d/modeltweak/modeltweak.desktop delete mode 100644 util/qt3d/modeltweak/modeltweak.pro delete mode 100644 util/qt3d/modeltweak/modeltweak.rc delete mode 100644 util/qt3d/modeltweak/qml/BlenderValueSlider.qml delete mode 100644 util/qt3d/modeltweak/qml/ButtonBarPane.qml delete mode 100644 util/qt3d/modeltweak/qml/CheckBox.qml delete mode 100644 util/qt3d/modeltweak/qml/ColorPicker.qml delete mode 100644 util/qt3d/modeltweak/qml/ColorUtils.js delete mode 100644 util/qt3d/modeltweak/qml/HelpOverlay.qml delete mode 100644 util/qt3d/modeltweak/qml/ModelPropertiesPane.qml delete mode 100644 util/qt3d/modeltweak/qml/ModelTweak.qml delete mode 100644 util/qt3d/modeltweak/qml/ModelViewport.qml delete mode 100644 util/qt3d/modeltweak/qml/SaveButton.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/BlenderToggle.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/Checkered.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/ColorSelector.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/ColorWidget.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/HSVColor.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/InputBox.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/ModelViewportResize.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/SliderHandle.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/ZoomControls.qml delete mode 100644 util/qt3d/modeltweak/qml/Widgets/images/grow.png delete mode 100644 util/qt3d/modeltweak/qml/Widgets/images/shrink.png delete mode 100644 util/qt3d/modeltweak/qml/Widgets/images/zoomin.png delete mode 100644 util/qt3d/modeltweak/qml/Widgets/images/zoomout.png delete mode 100644 util/qt3d/modeltweak/qml/fileHandling.js delete mode 100644 util/qt3d/modeltweak/qml/images/help.png delete mode 100644 util/qt3d/modeltweak/qml/images/lock.png delete mode 100644 util/qt3d/modeltweak/qml/images/minus.png delete mode 100644 util/qt3d/modeltweak/qml/images/model.png delete mode 100644 util/qt3d/modeltweak/qml/images/open.png delete mode 100644 util/qt3d/modeltweak/qml/images/plus.png delete mode 100644 util/qt3d/modeltweak/qml/images/save.png delete mode 100644 util/qt3d/modeltweak/qml/images/unlock.png delete mode 100644 util/qt3d/modeltweak/qml/meshes/monkey.3ds delete mode 100644 util/qt3d/modeltweak/qml/meshes/penguin.3ds delete mode 100644 util/qt3d/modeltweak/qtquick3d.ico delete mode 100644 util/qt3d/modeltweak/qtquick3d.png delete mode 100644 util/qt3d/modeltweak/quickfile.cpp delete mode 100644 util/qt3d/modeltweak/quickfile.h diff --git a/util/qt3d/assetviewer/assetviewer.desktop b/util/qt3d/assetviewer/assetviewer.desktop new file mode 100644 index 000000000..1d682515c --- /dev/null +++ b/util/qt3d/assetviewer/assetviewer.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=3D Asset Viewer +Icon=/usr/share/icons/hicolor/80x80/apps/qtquick3d.png +Exec=/usr/bin/invoker --type=e -s /usr/bin/modeltweak -fullscreen +OnlyShowIn=X-MeeGo; +X-MeeGo-Logical-Id=qtn_comm_appname_assetviewer diff --git a/util/qt3d/assetviewer/assetviewer.pro b/util/qt3d/assetviewer/assetviewer.pro new file mode 100644 index 000000000..ee4737d3b --- /dev/null +++ b/util/qt3d/assetviewer/assetviewer.pro @@ -0,0 +1,25 @@ +TEMPLATE = app +TARGET = assetviewer +CONFIG += qt warn_on + +INSTALL_DIRS = qml +CONFIG += qt3d_deploy_qml qt3dquick_deploy_pkg +include(../../../pkg.pri) +qtcAddDeployment() + +SOURCES += main.cpp \ + quickfile.cpp + +symbian { + qmlDeployment2.sources = qml\meshes\* + qmlDeployment2.path = qml\meshes + DEPLOYMENT += qmlDeployment2 +} + +OTHER_FILES += \ + assetviewer.rc + +RC_FILE = assetviewer.rc + +HEADERS += \ + quickfile.h diff --git a/util/qt3d/assetviewer/assetviewer.rc b/util/qt3d/assetviewer/assetviewer.rc new file mode 100644 index 000000000..1b6228c97 --- /dev/null +++ b/util/qt3d/assetviewer/assetviewer.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "qtquick3d.ico" diff --git a/util/qt3d/assetviewer/main.cpp b/util/qt3d/assetviewer/main.cpp new file mode 100644 index 000000000..954ed4c68 --- /dev/null +++ b/util/qt3d/assetviewer/main.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qdeclarativeview3d.h" +#include +#include +#include + +#include "../../../demos/quick3d/qmlres.h" +#include "quickfile.h" + +QString filename; + +int main(int argc, char *argv[]) +{ + qmlRegisterType("AssetViewer", 1, 0, "QuickFile"); + + QApplication app(argc, argv); + QDeclarativeView3D view; + + QString qml = q_get_qmldir(QLatin1String("qml/AssetViewer.qml")); + view.setSource(QUrl::fromLocalFile(qml)); + view.setWindowTitle(QString("3D Asset Viewer")); + + //disable close button + // view.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); + + QString fn; + QStringList args = QApplication::arguments(); + for (int i = 0; i < args.size(); ++i) + { + //FIXME: QML likes files relative to QML directory above, or full paths. + // We need to sort out how this is implemented once we've worked how how it's going to + // be called via Qt Creator. + if (args.at(i).startsWith(QLatin1String("-model")) && (i+1 < args.size())) + { + fn = args.at(i+1); + qDebug() << fn; + QGraphicsObject *object = view.rootObject(); + object->setProperty("targetMesh", args.at(i+1)); + break; + } + } + + view.setResizeMode(QDeclarativeView::SizeRootObjectToView); + +#ifdef Q_OS_SYMBIAN + view.setAttribute(Qt::WA_LockLandscapeOrientation, true); + view.setResizeMode(QDeclarativeView::SizeRootObjectToView); + view.showFullScreen(); +#else + if (QApplication::arguments().contains(QLatin1String("-maximize"))) + view.showMaximized(); + else if (QApplication::arguments().contains(QLatin1String("-fullscreen"))) + view.showFullScreen(); + else + view.show(); +#endif + + return app.exec(); +} diff --git a/util/qt3d/assetviewer/qml/AssetViewer.qml b/util/qt3d/assetviewer/qml/AssetViewer.qml new file mode 100644 index 000000000..af5b4b961 --- /dev/null +++ b/util/qt3d/assetviewer/qml/AssetViewer.qml @@ -0,0 +1,292 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 Nokia Corporation and its Subsidiary(-ies) 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 1.0 +import Qt3D 1.0 +import AssetViewer 1.0 +import "fileHandling.js" as FileHandler +import "Widgets" +import "ColorUtils.js" as ColorUtils + +Rectangle { + id: outerWindow; + width: 1024 + height: 768 + property alias modelEffect: customEffect + property alias modelMaterial: customMaterial + property bool useCustomEffect: false + property bool useCustomMaterial: false + + property bool changed: false + Component.onCompleted: { + outerWindow.changed = false; + } + + Component.onDestruction: { + if (outerWindow.changed) + { + FileHandler.save_qml(true); + } + } + + Rectangle { + id: menu + x: parent.x + y: parent.y + height: 24 + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + + color: "#B4B4B4" + border.color: "black" + + ButtonBarPane { + id: buttonBarPane + anchors.fill: parent + } + } + + Rectangle { + id: mainwindow + anchors.left: parent.left + anchors.right: parent.right + anchors.top: menu.bottom + anchors.bottom: outerWindow.bottom + + color: "#444444" + border.color: "black" + + property alias targetMesh: quickFile.filename + + QuickFile { + id: quickFile + filename: "meshes/penguin.3ds" + title: "Open 3D Asset File" + filter: "Asset files (*.*)" + } + + QuickFile { + id: textureFile + filename: "" + title: "Open Texture File" + filter: "Images (*.gif *.png *.jpg *.tif *.bmp)" + } + + Mesh { + id: source_mesh + source: quickFile.filename + } + + Translation3D { id: transformTranslate; translate: Qt.vector3d(0, 0, 0); } + Rotation3D { id: transformRotateX; axis: Qt.vector3d(1, 0, 0); angle: 0; } + Rotation3D { id: transformRotateY; axis: Qt.vector3d(0, 1, 0); angle: 0; } + Rotation3D { id: transformRotateZ; axis: Qt.vector3d(0, 0, 1); angle: 0; } + Scale3D { id: transformScale; scale: Qt.vector3d(1, 1, 1); } + + Effect { + id: customEffect; + property alias hsv: hsvColor + material: useCustomMaterial ? customMaterial : null; + color: hsv.color + blending: (hsv.alpha < 1.0) + || (useCustomMaterial && (hsvAmbColor.alpha*hsvDifColor.alpha*hsvSpecColor.alpha < 1.0)) + texture: textureFile.filename + } + Material { + id: customMaterial + property alias amb_hsv: hsvAmbColor + property alias dif_hsv: hsvDifColor + property alias spec_hsv: hsvSpecColor + ambientColor: hsvAmbColor.color + diffuseColor: hsvDifColor.color + specularColor: hsvSpecColor.color + textureUrl: textureFile.filename + } + HSVColor { id: hsvColor } + HSVColor { id: hsvAmbColor } + HSVColor { id: hsvDifColor } + HSVColor { id: hsvSpecColor } + + ModelViewport { + id: mvpZY + x: 0; + y: 0; + camera.eye: Qt.vector3d(20, 0, 0); + stateName: "ZYMaximised" + viewportName: "Z,Y axis (right)" + + rightVector: Qt.vector3d(0, 0, -1) + upVector: Qt.vector3d(0, 1, 0) + + property alias position: transformTranslate.translate; + + onMouseTranslateX: if (!modelPropertiesPane.translateLocked) position = Qt.vector3d(position.x, position.y, translate.z + (down.x - mouse.x)/translateSensitivity) + onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, translate.y + (down.y - mouse.y)/translateSensitivity, position.z) + onMouseRotateX: if (!modelPropertiesPane.rotateLocked)transformRotateY.angle = rotate.y - (down.x - mouse.x)/rotateSensitivity + onMouseRotateY: if (!modelPropertiesPane.rotateLocked)transformRotateZ.angle = rotate.z - (down.y - mouse.y)/rotateSensitivity + onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.z - (down.x - mouse.x)/scaleSensitivity; + transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, s<0 ? 0 : s) + } + onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.y + (down.y - mouse.y)/scaleSensitivity; + transformScale.scale = Qt.vector3d(transformScale.scale.x, s<0 ? 0 : s, transformScale.scale.z) + } + } + + ModelViewport { + id: mvpXY + x: parent.width/2 + y: 0; + camera.eye: Qt.vector3d(0, 0, 20); + stateName: "XYMaximised" + viewportName: "X,Y axis (front)" + + rightVector: Qt.vector3d(1, 0, 0) + upVector: Qt.vector3d(0, 1, 0) + + property alias position: transformTranslate.translate; + + onMouseTranslateX: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(translate.x - (down.x - mouse.x)/translateSensitivity, position.y, position.z) + onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, translate.y + (down.y - mouse.y)/translateSensitivity, position.z) + onMouseRotateX: if (!modelPropertiesPane.rotateLocked) transformRotateY.angle = rotate.y - (down.x - mouse.x)/rotateSensitivity + onMouseRotateY: if (!modelPropertiesPane.rotateLocked) transformRotateX.angle = rotate.x - (down.y - mouse.y)/rotateSensitivity + onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.x - (down.x - mouse.x)/scaleSensitivity + transformScale.scale = Qt.vector3d(s<0 ? 0 : s, transformScale.scale.y, transformScale.scale.z) + } + onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.y + (down.y - mouse.y)/scaleSensitivity + transformScale.scale = Qt.vector3d(transformScale.scale.x, s<0 ? 0 : s, transformScale.scale.z) + } + } + + ModelViewport { + id: mvpXZ + x: parent.width/2; + y: parent.height/2; + camera.eye: Qt.vector3d(0, 20, 0); + camera.upVector: Qt.vector3d(0, 0, -1); + stateName: "XZMaximised" + viewportName: "X,Z axis (top)" + + rightVector: Qt.vector3d(1, 0, 0) + upVector: Qt.vector3d(0, 0, -1) + + property alias position: transformTranslate.translate; + + onMouseTranslateX: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(translate.x - (down.x - mouse.x)/translateSensitivity, position.y, position.z) + onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, position.y, translate.z - (down.y - mouse.y)/translateSensitivity) + onMouseRotateX: if (!modelPropertiesPane.rotateLocked)transformRotateZ.angle = rotate.z + (down.x - mouse.x)/rotateSensitivity + onMouseRotateY: if (!modelPropertiesPane.rotateLocked)transformRotateX.angle = rotate.x - (down.y - mouse.y)/rotateSensitivity + onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.x - (down.x - mouse.x)/scaleSensitivity; + transformScale.scale = Qt.vector3d(s<0 ? 0 : s, transformScale.scale.y, transformScale.scale.z) + } + onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { + var s = scale3d.z + (down.y - mouse.y)/scaleSensitivity; + transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, s<0 ? 0 : s) + } + } + + Rectangle { + id: meshName + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottomMargin: 10 + anchors.bottom: parent.bottom + radius: 10 + border.width: 1 + border.color: "black" + color: "white" + width: parent.width - 20 + height: 20 + + Text { + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + text: "Hold left mouse button to move, middle button to scale, and right button to rotate the asset." + } + } + + ModelPropertiesPane { + id: modelPropertiesPane + x: 16; + y: parent.height / 2 + 16 + onChanged: {outerWindow.changed=true} + } + + ColorPicker { + id: colorPicker + visible: false + } + + HelpOverlay { + id: helpOverlay + visible: false + } + + states: [ + State { + name: "3Views" + }, + State { + name: "ZYMaximised" + PropertyChanges { target: mvpZY; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } + PropertyChanges { target: mvpXY; x: mainwindow.width; y: 0; width: 0; height: mainwindow.height/2; } + PropertyChanges { target: mvpXZ; x: mainwindow.width; y: mainwindow.height; width: 0; height: 0; } + }, + State { + name: "XYMaximised" + PropertyChanges { target: mvpZY; x: 0; y: 0; width: 0; height: mainwindow.height/2; } + PropertyChanges { target: mvpXY; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } + PropertyChanges { target: mvpXZ; x: mainwindow.width/2; y: mainwindow.height; width: mainwindow.width/2; height: 0; } + }, + State { + name: "XZMaximised" + PropertyChanges { target: mvpZY; x: 0; y: 0; width: 0; height: 0; } + PropertyChanges { target: mvpXY; x: mainwindow.width/2; y: 0; width: mainwindow.width/2; height: 0; } + PropertyChanges { target: mvpXZ; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } + } + ] + + state: "3Views" + } +} diff --git a/util/qt3d/assetviewer/qml/BlenderValueSlider.qml b/util/qt3d/assetviewer/qml/BlenderValueSlider.qml new file mode 100644 index 000000000..2f223380a --- /dev/null +++ b/util/qt3d/assetviewer/qml/BlenderValueSlider.qml @@ -0,0 +1,175 @@ +import QtQuick 1.0 +import Qt3D 1.0 +import AssetViewer 1.0 + +Item { + id: valueSlider + + property string label: ""; + property alias value: textInput.text; + property double delta: 0.1; + property double max: 1; + property double min: -1; + property bool limitMax: false; + property bool limitMin: false; + property bool locked: false + + width: rect.width + height: 20 + + property int textWidth: 80 + + signal next + signal prev + signal gotFocus + signal fail + signal changed + + Rectangle { + id: rect + radius: 8 + border.width: 1 + border.color: "#191919" + color: "#B4B4B4" + width: radius/2 + valueSlider.textWidth + plus.width + minus.width + height: parent.height + + + Text { + id: textLabel + color: "black" + width: textInput.width + height: textInput.height + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: valueSlider.label + " " + textInput.text + visible: true + onTextChanged: changed(); + } + + + TextInput { + id: textInput + readOnly: valueSlider.locked + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: TextInput.AlignHCenter + width: valueSlider.textWidth + validator: DoubleValidator{} + onAccepted: { + parent.parent.update(text) + focus = false + } + visible: false + onFocusChanged: { + if (focus == false) { + parent.parent.update(text) + visible = false + textLabel.visible = true + } + else { + visible = true + textLabel.visible = false + } + } + + Keys.onTabPressed: valueSlider.next() + Keys.onBacktabPressed: valueSlider.prev() + } + Image { + id: plus + source: "images/plus.png" + anchors.left: textInput.right + anchors.verticalCenter: parent.verticalCenter + } + Image { + id: minus + source: "images/minus.png" + anchors.right: textInput.left + anchors.verticalCenter: parent.verticalCenter + } + MouseArea { + id: mouseArea + anchors.fill: parent + onEntered: parent.color = "#999999" + onExited: parent.color = "#B4B4B4" + hoverEnabled: true + onClicked: { + if (!valueSlider.locked) + { + if (mouse.xwidth/3*2) + incDelta(); + else { + valueSlider.gotFocus() + } + } else { + valueSlider.fail(); + } + + } + onPressed: parent.color = "#808080" + onReleased: parent.color = "#999999" + } + } + + Timer { + interval: 100; + running: mouseArea.pressedButtons & Qt.LeftButton && (mouseArea.mouseX > valueSlider.width/3*2) + repeat: true + onTriggered: if (!valueSlider.locked) incDelta() + } + + Timer { + interval: 100; + running: mouseArea.pressedButtons & Qt.LeftButton && (mouseArea.mouseX < valueSlider.width/3) + repeat: true + onTriggered: if (!valueSlider.locked) decDelta() + } + + function updateMe() { + update(textInput.text) + } + + function incDelta() { + var t = value*1 + delta; + if (limitMax) + update(t>max ? max : t); + else + update(t); + + } + + function decDelta() { + var t = value*1 - delta; + if (limitMin) + update(t
  • Clicking on one of the panes with the Left Mouse Button and dragging will translate the position.
  • " + + "
  • Clicking on one of the panes with the Right Mouse Button and dragging will rotate the position.
  • " + + "
  • Clicking on one of the panes with the Middle Mouse Button and dragging will resize the model." + } + + Text { + anchors.bottom: parent.bottom + anchors.bottomMargin: 16 + anchors.horizontalCenter: parent.horizontalCenter + text: "[ Click to Close ]" + } + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton + onClicked: parent.visible = false + } +} + diff --git a/util/qt3d/assetviewer/qml/ModelPropertiesPane.qml b/util/qt3d/assetviewer/qml/ModelPropertiesPane.qml new file mode 100644 index 000000000..384a8b6ed --- /dev/null +++ b/util/qt3d/assetviewer/qml/ModelPropertiesPane.qml @@ -0,0 +1,543 @@ +import QtQuick 1.0 +import Qt3D 1.0 +import AssetViewer 1.0 +import "Widgets" +import "ColorUtils.js" as ColorUtils + +Row { + id: properties + spacing: 30 + property alias rotateLocked: imageR.isLocked + property alias scaleLocked: imageS.isLocked + property alias translateLocked: imageP.isLocked; + + signal changed; + Column { + width: posX.width + height: parent.height + spacing: 4 + + // POSITION + Item { + id: positionPanel + width: parent.width + height: imageP.height + + Text { + anchors.left: parent.left + anchors.leftMargin: 8 + text: "Position"; + color: "#FFFFFF"; + font.bold: true; + } + Image { + id: imageP + anchors.right: parent.right + anchors.rightMargin: 8 + + //Animation to pulse the lock icon if attempting to modify while locked. + property bool bounce: false + + SequentialAnimation on scale{ + running: imageP.bounce + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + onCompleted: imageP.bounce = false + } + + //Manage locked/unlocked state + state: "UNLOCKED" + property bool isLocked: false + + states: [ + State { + name: "UNLOCKED" + PropertyChanges { target: imageP; source: "images/unlock.png"} + PropertyChanges { target: imageP; isLocked: false;} + }, + State { + name: "LOCKED" + PropertyChanges { target: imageP; source: "images/lock.png"} + PropertyChanges { target: imageP; isLocked: true;} + } + ] + + MouseArea { + anchors.fill: parent + onDoubleClicked: { + if (parent.state=="LOCKED") + parent.state="UNLOCKED" + else + parent.state="LOCKED" + } + } + } + } + BlenderValueSlider { + focus: true + id: posX + label: "X:" + locked: imageP.isLocked + value: transformTranslate.translate.x.toFixed(3) + function update (f) { + transformTranslate.translate = Qt.vector3d(f, transformTranslate.translate.y, transformTranslate.translate.z); + } + onNext: { updateMe(); focus = false; posY.focus = true; } + onPrev: { updateMe(); focus = false; scaleZ.focus = true; } + onFail: { imageP.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: posY + label: "Y:" + locked: imageP.isLocked + value: transformTranslate.translate.y.toFixed(3) + function update (f) { + transformTranslate.translate = Qt.vector3d(transformTranslate.translate.x, f, transformTranslate.translate.z); + } + onNext: { updateMe(); focus = false; posZ.focus = true; } + onPrev: { updateMe(); focus = false; posX.focus = true; } + onFail: { imageP.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: posZ + label: "Z:" + locked: imageP.isLocked + value: transformTranslate.translate.z.toFixed(3) + function update (f) { + transformTranslate.translate = Qt.vector3d(transformTranslate.translate.x, transformTranslate.translate.y, f); + } + onNext: { updateMe(); focus = false; rotX.focus = true; } + onPrev: { updateMe(); focus = false; posY.focus = true; } + onFail: { imageP.bounce=true; } + onChanged: { properties.changed(); } + } + + // ROTATE + Item { + id: rotationPanel + width: parent.width + height: imageR.height + property bool dirty: false + Text { + anchors.left: parent.left + anchors.leftMargin: 8 + text: "Rotation"; + color: "#FFFFFF" + font.bold: true + } + + Image { + id: imageR + anchors.right: parent.right + anchors.rightMargin: 8 + + //Animation to pulse the lock icon if attempting to modify while locked. + property bool bounce: false + + SequentialAnimation on scale{ + running: imageR.bounce + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + onCompleted: imageR.bounce = false + } + + //Manage locked/unlocked state + state: "UNLOCKED" + property bool isLocked: false + + states: [ + State { + name: "UNLOCKED" + PropertyChanges { target: imageR; source: "images/unlock.png"} + PropertyChanges { target: imageR; isLocked: false;} + }, + State { + name: "LOCKED" + PropertyChanges { target: imageR; source: "images/lock.png"} + PropertyChanges { target: imageR; isLocked: true;} + } + ] + + MouseArea { + anchors.fill: parent + onDoubleClicked: { + if (parent.state=="LOCKED") + parent.state="UNLOCKED" + else + parent.state="LOCKED" + } + } + } + } + BlenderValueSlider { + id: rotX + label: "X:" + delta: 1 + locked: imageR.isLocked + min: 0; limitMin: true + max: 360; limitMax: true + value: transformRotateX.angle.toFixed(3) + function update (f) { transformRotateX.angle = f } + onNext: { updateMe(); focus = false; rotY.focus = true; } + onPrev: { updateMe(); focus = false; posZ.focus = true; } + onFail: { imageR.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: rotY + label: "Y:" + delta: 1 + locked: imageR.isLocked + min: 0; limitMin: true + max: 360; limitMax: true + value: transformRotateY.angle.toFixed(3) + function update (f) { transformRotateY.angle = f } + onNext: { updateMe(); focus = false; rotZ.focus = true; } + onPrev: { updateMe(); focus = false; rotX.focus = true; } + onFail: { imageR.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: rotZ + label: "Z:" + delta: 1 + locked: imageR.isLocked + min: 0; limitMin: true + max: 360; limitMax: true + value: transformRotateZ.angle.toFixed(3) + function update (f) { transformRotateZ.angle = f } + onNext: { updateMe(); focus = false; scaleX.focus = true; } + onPrev: { updateMe(); focus = false; rotY.focus = true; } + onFail: { imageR.bounce=true; } + onChanged: { properties.changed(); } + } + + // SCALE + Item { + id: scalePanel + width: parent.width + height: imageS.height + property bool dirty: false + + Item { + width: parent.width + height: scaleText.height + Text { + id: scaleText + anchors.left: parent.left + anchors.leftMargin: 8 + text: "Scale"; + color: "#FFFFFF" + font.bold: true + } + } + + Image { + id: imageS + anchors.right: parent.right + anchors.rightMargin: 8 + + //Animation to pulse the lock icon if attempting to modify while locked. + property bool bounce: false + + SequentialAnimation on scale{ + running: imageS.bounce + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } + NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } + onCompleted: imageS.bounce = false + } + + //Manage locked/unlocked state + state: "UNLOCKED" + property bool isLocked: false + + states: [ + State { + name: "UNLOCKED" + PropertyChanges { target: imageS; source: "images/unlock.png"} + PropertyChanges { target: imageS; isLocked: false;} + }, + State { + name: "LOCKED" + PropertyChanges { target: imageS; source: "images/lock.png"} + PropertyChanges { target: imageS; isLocked: true;} + } + ] + + MouseArea { + anchors.fill: parent + onDoubleClicked: { + if (parent.state=="LOCKED") + parent.state="UNLOCKED" + else + parent.state="LOCKED" + } + } + } + } + BlenderValueSlider { + id: scaleX + label: "X:" + locked: imageS.isLocked + min: 0; limitMin: true + value: transformScale.scale.x.toFixed(3) + function update (f) { transformScale.scale = Qt.vector3d(f, transformScale.scale.y, transformScale.scale.z); } + onNext: { updateMe(); focus = false; scaleY.focus = true; } + onPrev: { updateMe(); focus = false; rotZ.focus = true; } + onFail: { imageS.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: scaleY + label: "Y:" + locked: imageS.isLocked + min: 0; limitMin: true + value: transformScale.scale.y.toFixed(3) + function update (f) { transformScale.scale = Qt.vector3d(transformScale.scale.x, f, transformScale.scale.z); } + onNext: { updateMe(); focus = false; scaleZ.focus = true; } + onPrev: { updateMe(); focus = false; scaleX.focus = true; } + onFail: { imageS.bounce=true; } + onChanged: { properties.changed(); } + } + BlenderValueSlider { + id: scaleZ + label: "Z:" + locked: imageS.isLocked + min: 0; limitMin: true + value: transformScale.scale.z.toFixed(3) + function update (f) { transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, f); } + onNext: { updateMe(); focus = false; posX.focus = true; } + onPrev: { updateMe(); focus = false; scaleY.focus = true; } + onFail: { imageS.bounce=true; } + onChanged: { properties.changed(); } + } + } + + // Material, Effect + Column { + width: 150 + spacing: 5 + Item { + id: effectPanel + width: parent.width + height: imageS.height + property bool dirty: false + + Item { + width: parent.width + height: effectText.height + Text { + id: effectText + anchors.left: parent.left + anchors.leftMargin: 8 + text: "Effect"; + color: "#FFFFFF" + font.bold: true + } + } + } + + + CheckBox { + id: fromMesh + width: parent.width + text: "From Mesh" + checked: true + onClicked: { + useCustomEffect = !checked; + if (checked) { + // A horrible hack to reload the default mesh material + // TODO: Find a better way of doing this (i.e. no runtime errors) + source_mesh.source = ""; + source_mesh.source = targetMesh; + } + } + } + + Column { + enabled: !fromMesh.checked + opacity: enabled ? 1.0: 0.5 + width: parent.width; spacing: 5 + + move: Transition { + NumberAnimation { + properties: "y" + easing.type: Easing.InOutQuad; + duration: 150 + } + } + + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + + CheckBox { + width: parent.width + text: "Decal" + checked: false + onClicked: { + modelEffect.decal = checked + } + } + + Item { + width: parent.width + height: colorText.height + Text { + id: colorText + anchors.left: parent.left + anchors.leftMargin: 8 + text: "- Color"; + color: "#FFFFFF" + font.bold: true + } + } + + CheckBox { + id: simpleColor + width: parent.width + text: "Simple" + checked: true + onClicked: { + useCustomMaterial = !checked; + } + } + + ColorWidget { + id: flat + visible: opacity != 0 + opacity: simpleColor.checked + width: parent.width; height: 16 + targetColor: modelEffect.hsv + text: "Flat Color" + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + } + + ColorWidget { + id: ambient + visible: opacity != 0 + opacity: !flat.visible + width: parent.width; height: 16 + targetColor: modelMaterial.amb_hsv + text: "Ambient Color" + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + } + + ColorWidget { + id: diffuse + visible: opacity != 0 + opacity: !flat.visible + width: parent.width; height: 16 + targetColor: modelMaterial.dif_hsv + text: "Diffuse Color" + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + } + + ColorWidget { + id: specular + visible: opacity != 0 + opacity: !flat.visible + width: parent.width; height: 16 + targetColor: modelMaterial.spec_hsv + text: "Specular Color" + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + } + + Item { width: parent.width; height: 5 } + + Item { + visible: opacity != 0 + opacity: !flat.visible + height: shineText.height + shinyValue.height + 5 + width: parent.width + + Behavior on opacity { + NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } + } + + Text { + id: shineText + text: "Shininess:" + color: "white" + } + InputBox { + anchors.right: parent.right + width: parent.width - shineText.width - 5 + height: shineText.height + input.text: modelMaterial.shininess + } + Rectangle { + width: parent.width - 8; height: 1 + anchors.centerIn: shinyValue + color: "gray" + } + + SliderHandle { + id: shinyValue + width: parent.width; height: 10 + anchors { top: shineText.bottom; topMargin: 5 } + horizontal: true + onValueChanged: { + modelMaterial.shininess = Math.round(value * 128) + } + } + } + + Item { width: parent.width; height: 5 } + + Item { + width: parent.width + height: textureText.height + Text { + id: textureText + anchors.left: parent.left + anchors.leftMargin: 8 + text: "- Texture"; + color: "#FFFFFF" + font.bold: true + } + } + + Item { + width: parent.width + height: texturePreview.height + Image { + id: texturePreview + width: 60; height: width + source: textureFile.filename + } + Rectangle { + anchors.fill: texturePreview + border.color: "white" + border.width: 1 + color: "transparent" + } + + BlenderToggle { + width: 60; height: 20 + anchors.right: parent.right + buttonText: "Open..." + onClicked: { + textureFile.load(); + } + } + } + } + } +} diff --git a/util/qt3d/assetviewer/qml/ModelViewport.qml b/util/qt3d/assetviewer/qml/ModelViewport.qml new file mode 100644 index 000000000..541c147ad --- /dev/null +++ b/util/qt3d/assetviewer/qml/ModelViewport.qml @@ -0,0 +1,452 @@ +import QtQuick 1.0 +import Qt3D 1.0 +import Qt3D.Shapes 1.0 +import AssetViewer 1.0 +import "Widgets" + +Rectangle { + id: view + width: parent.width/2; + height: parent.height/2 + + color: parent.color + border.color: parent.border.color + + property alias itemPosition: mainItem.position; + property alias itemScale: mainItem.scale; + property alias camera: viewport.camera + property alias viewportName: viewportText.text; + + // the current x/y positions of the mouse when the onPressed event was triggered; + // values are invalid if onRelease has occured + property variant down; + + // current xyz values of the Translation3D/Rotation3Ds/Scale3D when onPressed was triggered; + // values are invalid if onRelease has occured + property variant translate; + property variant rotate; + property variant scale3d; + + // the pixel sensitivity values of the mousemovements + // TODO: expose via api + // TODO: maybe save in settings api? + property double translateSensitivity: 32; + property double rotateSensitivity: 8; + property double scaleSensitivity: 32; + + // the name of this viewport's state + property string stateName; + + property variant upVector: Qt.vector3d(0, 1, 0) + property variant rightVector: Qt.vector3d(0, 1, 0) + + // the smoothness values for the state change transformations + // TODO: this should be alterable via the gui and saved in a settings file + Behavior on x { NumberAnimation { duration: 300 } } + Behavior on y { NumberAnimation { duration: 300 } } + Behavior on width { NumberAnimation { duration: 300 } } + Behavior on height { NumberAnimation { duration: 300 } } + + signal mouseTranslateX(variant mouse) + signal mouseTranslateY(variant mouse) + signal mouseRotateX(variant mouse) + signal mouseRotateY(variant mouse) + signal mouseScaleX(variant mouse) + signal mouseScaleY(variant mouse) + + property real cameraZoom: 1.0 + + Viewport { + id: viewport + anchors.fill: parent + picking: false + blending: true + + // TODO: camera's position/rotation-around-origin/farplane should be alterable via gui + camera: Camera { + farPlane: 2000 // debugging + projectionType: Camera.Orthographic + viewSize: Qt.size(2*cameraZoom, 2*cameraZoom) + } + navigation: false + + Item3D { + id: mainItem + mesh: source_mesh + transform: [ + transformScale, + transformRotateX, + transformRotateY, + transformRotateZ, + transformTranslate, + ] + effect: useCustomEffect ? modelEffect : null; + } + + Effect { + id: coordLinesThickEffect + color: "white" + } + Effect { + id: coordLinesThinEffect + color: "black" + } + + // horizontal lines + Line { + id: lineAxisRight + width: 3.0 + vertices: [ + cameraZoom*(-10*rightVector.x), cameraZoom*(-10*rightVector.y), cameraZoom*(-10*rightVector.z), + cameraZoom*(10*rightVector.x), cameraZoom*(10*rightVector.y), cameraZoom*(10*rightVector.z), + cameraZoom*(10*rightVector.x + 0.001*upVector.x), cameraZoom*(10*rightVector.y + 0.001*upVector.y), cameraZoom*(10*rightVector.z + 0.001*upVector.z) + ] + effect: coordLinesThickEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x + 0.25*upVector.x), cameraZoom*(-10*rightVector.y + 0.25*upVector.y), cameraZoom*(-10*rightVector.z + 0.25*upVector.z), + cameraZoom*(10*rightVector.x + 0.25*upVector.x), cameraZoom*(10*rightVector.y + 0.25*upVector.y), cameraZoom*(10*rightVector.z + 0.25*upVector.z), + cameraZoom*(10*rightVector.x + 0.251*upVector.x), cameraZoom*(10*rightVector.y + 0.251*upVector.y), cameraZoom*(10*rightVector.z + 0.251*upVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x + 0.5*upVector.x), cameraZoom*(-10*rightVector.y + 0.5*upVector.y), cameraZoom*(-10*rightVector.z + 0.5*upVector.z), + cameraZoom*(10*rightVector.x + 0.5*upVector.x), cameraZoom*(10*rightVector.y + 0.5*upVector.y), cameraZoom*(10*rightVector.z + 0.5*upVector.z), + cameraZoom*(10*rightVector.x + 0.501*upVector.x), cameraZoom*(10*rightVector.y + 0.501*upVector.y), cameraZoom*(10*rightVector.z + 0.501*upVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x + 0.75*upVector.x), cameraZoom*(-10*rightVector.y + 0.75*upVector.y), cameraZoom*(-10*rightVector.z + 0.75*upVector.z), + cameraZoom*(10*rightVector.x + 0.75*upVector.x), cameraZoom*(10*rightVector.y + 0.75*upVector.y), cameraZoom*(10*rightVector.z + 0.75*upVector.z), + cameraZoom*(10*rightVector.x + 0.751*upVector.x), cameraZoom*(10*rightVector.y + 0.751*upVector.y), cameraZoom*(10*rightVector.z + 0.751*upVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x - 0.25*upVector.x), cameraZoom*(-10*rightVector.y - 0.25*upVector.y), cameraZoom*(-10*rightVector.z - 0.25*upVector.z), + cameraZoom*(10*rightVector.x - 0.25*upVector.x), cameraZoom*(10*rightVector.y - 0.25*upVector.y), cameraZoom*(10*rightVector.z - 0.25*upVector.z), + cameraZoom*(10*rightVector.x - 0.251*upVector.x), cameraZoom*(10*rightVector.y - 0.251*upVector.y), cameraZoom*(10*rightVector.z - 0.251*upVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x - 0.5*upVector.x), cameraZoom*(-10*rightVector.y - 0.5*upVector.y), cameraZoom*(-10*rightVector.z - 0.5*upVector.z), + cameraZoom*(10*rightVector.x - 0.5*upVector.x), cameraZoom*(10*rightVector.y - 0.5*upVector.y), cameraZoom*(10*rightVector.z - 0.5*upVector.z), + cameraZoom*(10*rightVector.x - 0.501*upVector.x), cameraZoom*(10*rightVector.y - 0.501*upVector.y), cameraZoom*(10*rightVector.z - 0.501*upVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*rightVector.x - 0.75*upVector.x), cameraZoom*(-10*rightVector.y - 0.75*upVector.y), cameraZoom*(-10*rightVector.z - 0.75*upVector.z), + cameraZoom*(10*rightVector.x - 0.75*upVector.x), cameraZoom*(10*rightVector.y - 0.75*upVector.y), cameraZoom*(10*rightVector.z - 0.75*upVector.z), + cameraZoom*(10*rightVector.x - 0.751*upVector.x), cameraZoom*(10*rightVector.y - 0.751*upVector.y), cameraZoom*(10*rightVector.z - 0.751*upVector.z) + ] + effect: coordLinesThinEffect + } + + // vertical lines + Line { + id: lineAxisUp + width: 3.0 + vertices: [ + cameraZoom*(-10*upVector.x), cameraZoom*(-10*upVector.y), cameraZoom*(-10*upVector.z), + cameraZoom*(10*upVector.x), cameraZoom*(10*upVector.y), cameraZoom*(10*upVector.z), + cameraZoom*(10*upVector.x + 0.01*rightVector.x), cameraZoom*(10*upVector.y + 0.01*rightVector.y), cameraZoom*(10*upVector.z + 0.01*rightVector.z) + ] + effect: coordLinesThickEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x + 0.25*rightVector.x), cameraZoom*(-10*upVector.y + 0.25*rightVector.y), cameraZoom*(-10*upVector.z + 0.25*rightVector.z), + cameraZoom*(10*upVector.x + 0.25*rightVector.x), cameraZoom*(10*upVector.y + 0.25*rightVector.y), cameraZoom*(10*upVector.z + 0.25*rightVector.z), + cameraZoom*(10*upVector.x + 0.251*rightVector.x), cameraZoom*(10*upVector.y + 0.251*rightVector.y), cameraZoom*(10*upVector.z + 0.251*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x + 0.5*rightVector.x), cameraZoom*(-10*upVector.y + 0.5*rightVector.y), cameraZoom*(-10*upVector.z + 0.5*rightVector.z), + cameraZoom*(10*upVector.x + 0.5*rightVector.x), cameraZoom*(10*upVector.y + 0.5*rightVector.y), cameraZoom*(10*upVector.z + 0.5*rightVector.z), + cameraZoom*(10*upVector.x + 0.501*rightVector.x), cameraZoom*(10*upVector.y + 0.501*rightVector.y), cameraZoom*(10*upVector.z + 0.501*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x + 0.75*rightVector.x), cameraZoom*(-10*upVector.y + 0.75*rightVector.y), cameraZoom*(-10*upVector.z + 0.75*rightVector.z), + cameraZoom*(10*upVector.x + 0.75*rightVector.x), cameraZoom*(10*upVector.y + 0.75*rightVector.y), cameraZoom*(10*upVector.z + 0.75*rightVector.z), + cameraZoom*(10*upVector.x + 0.751*rightVector.x), cameraZoom*(10*upVector.y + 0.751*rightVector.y), cameraZoom*(10*upVector.z + 0.751*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x + 1.00*rightVector.x), cameraZoom*(-10*upVector.y + 1.00*rightVector.y), cameraZoom*(-10*upVector.z + 1.00*rightVector.z), + cameraZoom*(10*upVector.x + 1.00*rightVector.x), cameraZoom*(10*upVector.y + 1.00*rightVector.y), cameraZoom*(10*upVector.z + 1.00*rightVector.z), + cameraZoom*(10*upVector.x + 1.001*rightVector.x), cameraZoom*(10*upVector.y + 1.001*rightVector.y), cameraZoom*(10*upVector.z + 1.001*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x - 0.25*rightVector.x), cameraZoom*(-10*upVector.y - 0.25*rightVector.y), cameraZoom*(-10*upVector.z - 0.25*rightVector.z), + cameraZoom*(10*upVector.x - 0.25*rightVector.x), cameraZoom*(10*upVector.y - 0.25*rightVector.y), cameraZoom*(10*upVector.z - 0.25*rightVector.z), + cameraZoom*(10*upVector.x - 0.251*rightVector.x), cameraZoom*(10*upVector.y - 0.251*rightVector.y), cameraZoom*(10*upVector.z - 0.251*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x - 0.5*rightVector.x), cameraZoom*(-10*upVector.y - 0.5*rightVector.y), cameraZoom*(-10*upVector.z - 0.5*rightVector.z), + cameraZoom*(10*upVector.x - 0.5*rightVector.x), cameraZoom*(10*upVector.y - 0.5*rightVector.y), cameraZoom*(10*upVector.z - 0.5*rightVector.z), + cameraZoom*(10*upVector.x - 0.501*rightVector.x), cameraZoom*(10*upVector.y - 0.501*rightVector.y), cameraZoom*(10*upVector.z - 0.501*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x - 0.75*rightVector.x), cameraZoom*(-10*upVector.y - 0.75*rightVector.y), cameraZoom*(-10*upVector.z - 0.75*rightVector.z), + cameraZoom*(10*upVector.x - 0.75*rightVector.x), cameraZoom*(10*upVector.y - 0.75*rightVector.y), cameraZoom*(10*upVector.z - 0.75*rightVector.z), + cameraZoom*(10*upVector.x - 0.751*rightVector.x), cameraZoom*(10*upVector.y - 0.751*rightVector.y), cameraZoom*(10*upVector.z - 0.751*rightVector.z) + ] + effect: coordLinesThinEffect + } + Line { + width: 1.0 + vertices: [ + cameraZoom*(-10*upVector.x - 1.00*rightVector.x), cameraZoom*(-10*upVector.y - 1.00*rightVector.y), cameraZoom*(-10*upVector.z - 1.00*rightVector.z), + cameraZoom*(10*upVector.x - 1.00*rightVector.x), cameraZoom*(10*upVector.y - 1.00*rightVector.y), cameraZoom*(10*upVector.z - 1.00*rightVector.z), + cameraZoom*(10*upVector.x - 1.001*rightVector.x), cameraZoom*(10*upVector.y - 1.001*rightVector.y), cameraZoom*(10*upVector.z - 1.001*rightVector.z) + ] + effect: coordLinesThinEffect + } + + } + + MouseArea { + property int mouseDown: Qt.NoButton + + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton + + onMouseXChanged: { + if (mouseDown & Qt.LeftButton) + mouseTranslateX(mouse) + else if (mouseDown === Qt.RightButton) + mouseRotateX(mouse); + else if (mouseDown === Qt.MiddleButton) + mouseScaleX(mouse) + } + + onMouseYChanged: { + if (mouseDown & Qt.LeftButton) + mouseTranslateY(mouse) + else if (mouseDown === Qt.RightButton) + mouseRotateY(mouse); + else if (mouseDown === Qt.MiddleButton) + mouseScaleY(mouse) + } + + onPressed: { + // if we already have a mouse button down we don't want to do anything else until it's up again + if (mouseDown !== Qt.NoButton) + return; + + mouseDown = mouse.button; + down = Qt.point(mouse.x, mouse.y) + translate = transformTranslate.translate + rotate = Qt.vector3d(transformRotateX.angle, transformRotateY.angle, transformRotateZ.angle) + scale3d = transformScale.scale + } + + // clear the current mouse button upon release + onReleased: { mouseDown = Qt.NoButton } + } + + ModelViewportResize { + anchors { + top: view.top; topMargin: 2; + right: view.right; rightMargin: 2; + } + } + + ZoomControls { + anchors { + top: view.top; topMargin: 24; + right: view.right; rightMargin: 2; + } + onZoomIn: { + cameraZoom = 0.5 * cameraZoom; + } + onZoomOut: { + cameraZoom = 2.0 * cameraZoom; + } + } + + Text { + id: viewportText + anchors { + top: view.top; topMargin: 4; + left: view.left; leftMargin: 4; + } + color: "white" + font.pixelSize: 16 + } + + // --------- grid text begin --------- + + property bool bTall: view.width +#include + #include + +/*! + \qmlclass QuickFile QuickFile + \brief QuickFile is a quick-and-dirty file handling object that supports file-io that QML/Javascript doesn't. + \inherits QObject + + The QuickFile element is part of the \c{ModelTweak} namespace, + so the following must appear at the top of any QML file that + references it: + + \code + import ModelTweak 1.0 + \endcode + + \sa QObject +*/ + +/*! + \internal +*/ +QuickFile::QuickFile(QObject *parent) : + QObject(parent) +{ +} + +/*! + Prompts for a location and filename to save the qml \c{QuickFile::data} generated by ModelTweaker. + Returns an error message if the file was unsuccessfully saved, + or an empty string if the save was successful/cancelled. +*/ +QString QuickFile::save() const +{ + QString filename = QFileDialog::getSaveFileName(0, tr("Save QML File"), "",tr("Files (*.qml)")); + + //If cancel button pressed (ie. filename empty), we can just drop out immediately + if (filename.isEmpty()) { + return QString(); + } + + // FIXME: ensure fileName is appropriate as a qml Component + if (!filename.endsWith(".qml")) + filename.append(".qml"); + + QDir outputDir = QFileInfo(filename).absoluteDir(); + + QString modelFilename = QUrl(_filename).toLocalFile(); + QString modelFN = QFileInfo(modelFilename).fileName(); + + QString dstModelLocation = outputDir.path() + QDir::separator() + modelFN; + if (dstModelLocation.compare(modelFilename,Qt::CaseInsensitive) != 0) { + // src and dst model paths are different. + // Copy model file over. + qDebug("Attempting to copy:"); + qDebug(" from: %s",modelFilename.toAscii().constData()); + qDebug(" to : %s",dstModelLocation.toAscii().constData()); + QFile dstModelFile(dstModelLocation); + if (dstModelFile.exists()) { + if (!dstModelFile.remove()) { + qDebug(" failed to remove dst file!"); + } + } + QFile srcModelFile(modelFilename); + if (srcModelFile.copy(dstModelLocation)) { + qDebug(" Model was copied successfully."); + } else { + qDebug(" failed to copy model file !"); + } + } + + QFile file(filename); + + qDebug("Attempting to write: %s", file.fileName().toAscii().constData()); + + if (!file.open(QFile::WriteOnly)) + return file.errorString(); + + QString dataToWrite = _data.arg(modelFN); + + file.write(dataToWrite.toUtf8()); + + file.close(); + + return QString(); +} + +/*! + Save/Close dialog for unsaved changes to QML files. This is shown if the user + closes the app without saving the modifications they have made. + + Returns an error message if the file was unsuccessfully saved, + or an empty string if the save was successful/cancelled. +*/ +QString QuickFile::promptSave() const +{ + QMessageBox msgBox; + msgBox.setText("The document has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + + if (ret==QMessageBox::Save) { + return save(); + } else { + return QString(); + } +} + +/*! + Prompts for a location to load a model file from and stores it into the the \c{QuickFile::filename} + variable. +*/ +void QuickFile::load() +{ + QString qmlFilename = QFileDialog::getOpenFileName(0, _title, "", _filter); + setFilename(qmlFilename); +} + + +QString QuickFile::filename() const { + return _filename; +} + +void QuickFile::setFilename(const QString filename) { + if (_filename != filename) + _filename = filename; + emit filenameChanged(filename); +} + +QString QuickFile::title() const { + return _title; +} + +void QuickFile::setTitle(const QString title) { + if (_title != title) + _title = title; + emit titleChanged(title); +} + +QString QuickFile::filter() const { + return _filter; +} + +void QuickFile::setFilter(const QString filter) { + if (_filter != filter) + _filter = filter; + emit filterChanged(filter); +} + +QString QuickFile::data() const { + return _data; +} + +void QuickFile::setData(const QString data) { + if (_data != data) + _data = data; + emit dataChanged(data); +} + diff --git a/util/qt3d/assetviewer/quickfile.h b/util/qt3d/assetviewer/quickfile.h new file mode 100644 index 000000000..1c66c60bb --- /dev/null +++ b/util/qt3d/assetviewer/quickfile.h @@ -0,0 +1,46 @@ +#ifndef QUICKFILE_H +#define QUICKFILE_H + +#include + +class QuickFile : public QObject +{ + Q_OBJECT + + QString _filename; + QString _title; + QString _filter; + QString _data; + + Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) + Q_PROPERTY(QString data READ data WRITE setData NOTIFY dataChanged) + +public: + explicit QuickFile(QObject *parent = 0); + + QString filename() const; + void setFilename(const QString filename); + + QString title() const; + void setTitle(const QString title); + + QString filter() const; + void setFilter(const QString filter); + + QString data() const; + void setData(const QString data); + + Q_INVOKABLE QString save() const; + Q_INVOKABLE void load(); + Q_INVOKABLE QString promptSave() const; + +signals: + void filenameChanged(const QString newFilename); + void titleChanged(const QString newTitle); + void filterChanged(const QString newFilter); + void dataChanged(const QString newData); +}; + +#endif // QUICKFILE_H diff --git a/util/qt3d/modeltweak/main.cpp b/util/qt3d/modeltweak/main.cpp deleted file mode 100644 index 619bc6c3e..000000000 --- a/util/qt3d/modeltweak/main.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qdeclarativeview3d.h" -#include -#include -#include - -#include "../../../demos/quick3d/qmlres.h" -#include "quickfile.h" - -QString filename; - -int main(int argc, char *argv[]) -{ - qmlRegisterType("ModelTweak", 1, 0, "QuickFile"); - - QApplication app(argc, argv); - QDeclarativeView3D view; - - QString qml = q_get_qmldir(QLatin1String("qml/ModelTweak.qml")); - view.setSource(QUrl::fromLocalFile(qml)); - - //disable close button - // view.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); - - QString fn; - QStringList args = QApplication::arguments(); - for (int i = 0; i < args.size(); ++i) - { - //FIXME: QML likes files relative to QML directory above, or full paths. - // We need to sort out how this is implemented once we've worked how how it's going to - // be called via Qt Creator. - if (args.at(i).startsWith(QLatin1String("-model")) && (i+1 < args.size())) - { - fn = args.at(i+1); - qDebug() << fn; - QGraphicsObject *object = view.rootObject(); - object->setProperty("targetMesh", args.at(i+1)); - break; - } - } - - view.setResizeMode(QDeclarativeView::SizeRootObjectToView); - -#ifdef Q_OS_SYMBIAN - view.setAttribute(Qt::WA_LockLandscapeOrientation, true); - view.setResizeMode(QDeclarativeView::SizeRootObjectToView); - view.showFullScreen(); -#else - if (QApplication::arguments().contains(QLatin1String("-maximize"))) - view.showMaximized(); - else if (QApplication::arguments().contains(QLatin1String("-fullscreen"))) - view.showFullScreen(); - else - view.show(); -#endif - - return app.exec(); -} diff --git a/util/qt3d/modeltweak/modeltweak.desktop b/util/qt3d/modeltweak/modeltweak.desktop deleted file mode 100644 index a66676766..000000000 --- a/util/qt3d/modeltweak/modeltweak.desktop +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Type=Application -Name=Model Tweaker -Icon=/usr/share/icons/hicolor/80x80/apps/qtquick3d.png -Exec=/usr/bin/invoker --type=e -s /usr/bin/modeltweak -fullscreen -OnlyShowIn=X-MeeGo; -X-MeeGo-Logical-Id=qtn_comm_appname_modeltweak diff --git a/util/qt3d/modeltweak/modeltweak.pro b/util/qt3d/modeltweak/modeltweak.pro deleted file mode 100644 index 285927aa5..000000000 --- a/util/qt3d/modeltweak/modeltweak.pro +++ /dev/null @@ -1,25 +0,0 @@ -TEMPLATE = app -TARGET = modeltweak -CONFIG += qt warn_on - -INSTALL_DIRS = qml -CONFIG += qt3d_deploy_qml qt3dquick_deploy_pkg -include(../../../pkg.pri) -qtcAddDeployment() - -SOURCES += main.cpp \ - quickfile.cpp - -symbian { - qmlDeployment2.sources = qml\meshes\* - qmlDeployment2.path = qml\meshes - DEPLOYMENT += qmlDeployment2 -} - -OTHER_FILES += \ - modeltweak.rc - -RC_FILE = modeltweak.rc - -HEADERS += \ - quickfile.h diff --git a/util/qt3d/modeltweak/modeltweak.rc b/util/qt3d/modeltweak/modeltweak.rc deleted file mode 100644 index 1b6228c97..000000000 --- a/util/qt3d/modeltweak/modeltweak.rc +++ /dev/null @@ -1 +0,0 @@ -IDI_ICON1 ICON DISCARDABLE "qtquick3d.ico" diff --git a/util/qt3d/modeltweak/qml/BlenderValueSlider.qml b/util/qt3d/modeltweak/qml/BlenderValueSlider.qml deleted file mode 100644 index e5709c5fc..000000000 --- a/util/qt3d/modeltweak/qml/BlenderValueSlider.qml +++ /dev/null @@ -1,175 +0,0 @@ -import QtQuick 1.0 -import Qt3D 1.0 -import ModelTweak 1.0 - -Item { - id: valueSlider - - property string label: ""; - property alias value: textInput.text; - property double delta: 0.1; - property double max: 1; - property double min: -1; - property bool limitMax: false; - property bool limitMin: false; - property bool locked: false - - width: rect.width - height: 20 - - property int textWidth: 80 - - signal next - signal prev - signal gotFocus - signal fail - signal changed - - Rectangle { - id: rect - radius: 8 - border.width: 1 - border.color: "#191919" - color: "#B4B4B4" - width: radius/2 + valueSlider.textWidth + plus.width + minus.width - height: parent.height - - - Text { - id: textLabel - color: "black" - width: textInput.width - height: textInput.height - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - text: valueSlider.label + " " + textInput.text - visible: true - onTextChanged: changed(); - } - - - TextInput { - id: textInput - readOnly: valueSlider.locked - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - horizontalAlignment: TextInput.AlignHCenter - width: valueSlider.textWidth - validator: DoubleValidator{} - onAccepted: { - parent.parent.update(text) - focus = false - } - visible: false - onFocusChanged: { - if (focus == false) { - parent.parent.update(text) - visible = false - textLabel.visible = true - } - else { - visible = true - textLabel.visible = false - } - } - - Keys.onTabPressed: valueSlider.next() - Keys.onBacktabPressed: valueSlider.prev() - } - Image { - id: plus - source: "images/plus.png" - anchors.left: textInput.right - anchors.verticalCenter: parent.verticalCenter - } - Image { - id: minus - source: "images/minus.png" - anchors.right: textInput.left - anchors.verticalCenter: parent.verticalCenter - } - MouseArea { - id: mouseArea - anchors.fill: parent - onEntered: parent.color = "#999999" - onExited: parent.color = "#B4B4B4" - hoverEnabled: true - onClicked: { - if (!valueSlider.locked) - { - if (mouse.xwidth/3*2) - incDelta(); - else { - valueSlider.gotFocus() - } - } else { - valueSlider.fail(); - } - - } - onPressed: parent.color = "#808080" - onReleased: parent.color = "#999999" - } - } - - Timer { - interval: 100; - running: mouseArea.pressedButtons & Qt.LeftButton && (mouseArea.mouseX > valueSlider.width/3*2) - repeat: true - onTriggered: if (!valueSlider.locked) incDelta() - } - - Timer { - interval: 100; - running: mouseArea.pressedButtons & Qt.LeftButton && (mouseArea.mouseX < valueSlider.width/3) - repeat: true - onTriggered: if (!valueSlider.locked) decDelta() - } - - function updateMe() { - update(textInput.text) - } - - function incDelta() { - var t = value*1 + delta; - if (limitMax) - update(t>max ? max : t); - else - update(t); - - } - - function decDelta() { - var t = value*1 - delta; - if (limitMin) - update(t
  • Clicking on one of the panes with the Left Mouse Button and dragging will translate the position.
  • " + - "
  • Clicking on one of the panes with the Right Mouse Button and dragging will rotate the position.
  • " + - "
  • Clicking on one of the panes with the Middle Mouse Button and dragging will resize the model." - } - - Text { - anchors.bottom: parent.bottom - anchors.bottomMargin: 16 - anchors.horizontalCenter: parent.horizontalCenter - text: "[ Click to Close ]" - } - } - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton - onClicked: parent.visible = false - } -} - diff --git a/util/qt3d/modeltweak/qml/ModelPropertiesPane.qml b/util/qt3d/modeltweak/qml/ModelPropertiesPane.qml deleted file mode 100644 index 2b0e4dee9..000000000 --- a/util/qt3d/modeltweak/qml/ModelPropertiesPane.qml +++ /dev/null @@ -1,543 +0,0 @@ -import QtQuick 1.0 -import Qt3D 1.0 -import ModelTweak 1.0 -import "Widgets" -import "ColorUtils.js" as ColorUtils - -Row { - id: properties - spacing: 30 - property alias rotateLocked: imageR.isLocked - property alias scaleLocked: imageS.isLocked - property alias translateLocked: imageP.isLocked; - - signal changed; - Column { - width: posX.width - height: parent.height - spacing: 4 - - // POSITION - Item { - id: positionPanel - width: parent.width - height: imageP.height - - Text { - anchors.left: parent.left - anchors.leftMargin: 8 - text: "Position"; - color: "#FFFFFF"; - font.bold: true; - } - Image { - id: imageP - anchors.right: parent.right - anchors.rightMargin: 8 - - //Animation to pulse the lock icon if attempting to modify while locked. - property bool bounce: false - - SequentialAnimation on scale{ - running: imageP.bounce - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - onCompleted: imageP.bounce = false - } - - //Manage locked/unlocked state - state: "UNLOCKED" - property bool isLocked: false - - states: [ - State { - name: "UNLOCKED" - PropertyChanges { target: imageP; source: "images/unlock.png"} - PropertyChanges { target: imageP; isLocked: false;} - }, - State { - name: "LOCKED" - PropertyChanges { target: imageP; source: "images/lock.png"} - PropertyChanges { target: imageP; isLocked: true;} - } - ] - - MouseArea { - anchors.fill: parent - onDoubleClicked: { - if (parent.state=="LOCKED") - parent.state="UNLOCKED" - else - parent.state="LOCKED" - } - } - } - } - BlenderValueSlider { - focus: true - id: posX - label: "X:" - locked: imageP.isLocked - value: transformTranslate.translate.x.toFixed(3) - function update (f) { - transformTranslate.translate = Qt.vector3d(f, transformTranslate.translate.y, transformTranslate.translate.z); - } - onNext: { updateMe(); focus = false; posY.focus = true; } - onPrev: { updateMe(); focus = false; scaleZ.focus = true; } - onFail: { imageP.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: posY - label: "Y:" - locked: imageP.isLocked - value: transformTranslate.translate.y.toFixed(3) - function update (f) { - transformTranslate.translate = Qt.vector3d(transformTranslate.translate.x, f, transformTranslate.translate.z); - } - onNext: { updateMe(); focus = false; posZ.focus = true; } - onPrev: { updateMe(); focus = false; posX.focus = true; } - onFail: { imageP.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: posZ - label: "Z:" - locked: imageP.isLocked - value: transformTranslate.translate.z.toFixed(3) - function update (f) { - transformTranslate.translate = Qt.vector3d(transformTranslate.translate.x, transformTranslate.translate.y, f); - } - onNext: { updateMe(); focus = false; rotX.focus = true; } - onPrev: { updateMe(); focus = false; posY.focus = true; } - onFail: { imageP.bounce=true; } - onChanged: { properties.changed(); } - } - - // ROTATE - Item { - id: rotationPanel - width: parent.width - height: imageR.height - property bool dirty: false - Text { - anchors.left: parent.left - anchors.leftMargin: 8 - text: "Rotation"; - color: "#FFFFFF" - font.bold: true - } - - Image { - id: imageR - anchors.right: parent.right - anchors.rightMargin: 8 - - //Animation to pulse the lock icon if attempting to modify while locked. - property bool bounce: false - - SequentialAnimation on scale{ - running: imageR.bounce - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - onCompleted: imageR.bounce = false - } - - //Manage locked/unlocked state - state: "UNLOCKED" - property bool isLocked: false - - states: [ - State { - name: "UNLOCKED" - PropertyChanges { target: imageR; source: "images/unlock.png"} - PropertyChanges { target: imageR; isLocked: false;} - }, - State { - name: "LOCKED" - PropertyChanges { target: imageR; source: "images/lock.png"} - PropertyChanges { target: imageR; isLocked: true;} - } - ] - - MouseArea { - anchors.fill: parent - onDoubleClicked: { - if (parent.state=="LOCKED") - parent.state="UNLOCKED" - else - parent.state="LOCKED" - } - } - } - } - BlenderValueSlider { - id: rotX - label: "X:" - delta: 1 - locked: imageR.isLocked - min: 0; limitMin: true - max: 360; limitMax: true - value: transformRotateX.angle.toFixed(3) - function update (f) { transformRotateX.angle = f } - onNext: { updateMe(); focus = false; rotY.focus = true; } - onPrev: { updateMe(); focus = false; posZ.focus = true; } - onFail: { imageR.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: rotY - label: "Y:" - delta: 1 - locked: imageR.isLocked - min: 0; limitMin: true - max: 360; limitMax: true - value: transformRotateY.angle.toFixed(3) - function update (f) { transformRotateY.angle = f } - onNext: { updateMe(); focus = false; rotZ.focus = true; } - onPrev: { updateMe(); focus = false; rotX.focus = true; } - onFail: { imageR.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: rotZ - label: "Z:" - delta: 1 - locked: imageR.isLocked - min: 0; limitMin: true - max: 360; limitMax: true - value: transformRotateZ.angle.toFixed(3) - function update (f) { transformRotateZ.angle = f } - onNext: { updateMe(); focus = false; scaleX.focus = true; } - onPrev: { updateMe(); focus = false; rotY.focus = true; } - onFail: { imageR.bounce=true; } - onChanged: { properties.changed(); } - } - - // SCALE - Item { - id: scalePanel - width: parent.width - height: imageS.height - property bool dirty: false - - Item { - width: parent.width - height: scaleText.height - Text { - id: scaleText - anchors.left: parent.left - anchors.leftMargin: 8 - text: "Scale"; - color: "#FFFFFF" - font.bold: true - } - } - - Image { - id: imageS - anchors.right: parent.right - anchors.rightMargin: 8 - - //Animation to pulse the lock icon if attempting to modify while locked. - property bool bounce: false - - SequentialAnimation on scale{ - running: imageS.bounce - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 2.0; duration: 150; easing.type: "OutQuad" } - NumberAnimation { to : 1.0; duration: 150; easing.type: "OutQuad" } - onCompleted: imageS.bounce = false - } - - //Manage locked/unlocked state - state: "UNLOCKED" - property bool isLocked: false - - states: [ - State { - name: "UNLOCKED" - PropertyChanges { target: imageS; source: "images/unlock.png"} - PropertyChanges { target: imageS; isLocked: false;} - }, - State { - name: "LOCKED" - PropertyChanges { target: imageS; source: "images/lock.png"} - PropertyChanges { target: imageS; isLocked: true;} - } - ] - - MouseArea { - anchors.fill: parent - onDoubleClicked: { - if (parent.state=="LOCKED") - parent.state="UNLOCKED" - else - parent.state="LOCKED" - } - } - } - } - BlenderValueSlider { - id: scaleX - label: "X:" - locked: imageS.isLocked - min: 0; limitMin: true - value: transformScale.scale.x.toFixed(3) - function update (f) { transformScale.scale = Qt.vector3d(f, transformScale.scale.y, transformScale.scale.z); } - onNext: { updateMe(); focus = false; scaleY.focus = true; } - onPrev: { updateMe(); focus = false; rotZ.focus = true; } - onFail: { imageS.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: scaleY - label: "Y:" - locked: imageS.isLocked - min: 0; limitMin: true - value: transformScale.scale.y.toFixed(3) - function update (f) { transformScale.scale = Qt.vector3d(transformScale.scale.x, f, transformScale.scale.z); } - onNext: { updateMe(); focus = false; scaleZ.focus = true; } - onPrev: { updateMe(); focus = false; scaleX.focus = true; } - onFail: { imageS.bounce=true; } - onChanged: { properties.changed(); } - } - BlenderValueSlider { - id: scaleZ - label: "Z:" - locked: imageS.isLocked - min: 0; limitMin: true - value: transformScale.scale.z.toFixed(3) - function update (f) { transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, f); } - onNext: { updateMe(); focus = false; posX.focus = true; } - onPrev: { updateMe(); focus = false; scaleY.focus = true; } - onFail: { imageS.bounce=true; } - onChanged: { properties.changed(); } - } - } - - // Material, Effect - Column { - width: 150 - spacing: 5 - Item { - id: effectPanel - width: parent.width - height: imageS.height - property bool dirty: false - - Item { - width: parent.width - height: effectText.height - Text { - id: effectText - anchors.left: parent.left - anchors.leftMargin: 8 - text: "Effect"; - color: "#FFFFFF" - font.bold: true - } - } - } - - - CheckBox { - id: fromMesh - width: parent.width - text: "From Mesh" - checked: true - onClicked: { - useCustomEffect = !checked; - if (checked) { - // A horrible hack to reload the default mesh material - // TODO: Find a better way of doing this (i.e. no runtime errors) - source_mesh.source = ""; - source_mesh.source = targetMesh; - } - } - } - - Column { - enabled: !fromMesh.checked - opacity: enabled ? 1.0: 0.5 - width: parent.width; spacing: 5 - - move: Transition { - NumberAnimation { - properties: "y" - easing.type: Easing.InOutQuad; - duration: 150 - } - } - - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - - CheckBox { - width: parent.width - text: "Decal" - checked: false - onClicked: { - modelEffect.decal = checked - } - } - - Item { - width: parent.width - height: colorText.height - Text { - id: colorText - anchors.left: parent.left - anchors.leftMargin: 8 - text: "- Color"; - color: "#FFFFFF" - font.bold: true - } - } - - CheckBox { - id: simpleColor - width: parent.width - text: "Simple" - checked: true - onClicked: { - useCustomMaterial = !checked; - } - } - - ColorWidget { - id: flat - visible: opacity != 0 - opacity: simpleColor.checked - width: parent.width; height: 16 - targetColor: modelEffect.hsv - text: "Flat Color" - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - } - - ColorWidget { - id: ambient - visible: opacity != 0 - opacity: !flat.visible - width: parent.width; height: 16 - targetColor: modelMaterial.amb_hsv - text: "Ambient Color" - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - } - - ColorWidget { - id: diffuse - visible: opacity != 0 - opacity: !flat.visible - width: parent.width; height: 16 - targetColor: modelMaterial.dif_hsv - text: "Diffuse Color" - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - } - - ColorWidget { - id: specular - visible: opacity != 0 - opacity: !flat.visible - width: parent.width; height: 16 - targetColor: modelMaterial.spec_hsv - text: "Specular Color" - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - } - - Item { width: parent.width; height: 5 } - - Item { - visible: opacity != 0 - opacity: !flat.visible - height: shineText.height + shinyValue.height + 5 - width: parent.width - - Behavior on opacity { - NumberAnimation { easing.type: Easing.InOutQuad; duration: 100 } - } - - Text { - id: shineText - text: "Shininess:" - color: "white" - } - InputBox { - anchors.right: parent.right - width: parent.width - shineText.width - 5 - height: shineText.height - input.text: modelMaterial.shininess - } - Rectangle { - width: parent.width - 8; height: 1 - anchors.centerIn: shinyValue - color: "gray" - } - - SliderHandle { - id: shinyValue - width: parent.width; height: 10 - anchors { top: shineText.bottom; topMargin: 5 } - horizontal: true - onValueChanged: { - modelMaterial.shininess = Math.round(value * 128) - } - } - } - - Item { width: parent.width; height: 5 } - - Item { - width: parent.width - height: textureText.height - Text { - id: textureText - anchors.left: parent.left - anchors.leftMargin: 8 - text: "- Texture"; - color: "#FFFFFF" - font.bold: true - } - } - - Item { - width: parent.width - height: texturePreview.height - Image { - id: texturePreview - width: 60; height: width - source: textureFile.filename - } - Rectangle { - anchors.fill: texturePreview - border.color: "white" - border.width: 1 - color: "transparent" - } - - BlenderToggle { - width: 60; height: 20 - anchors.right: parent.right - buttonText: "Open..." - onClicked: { - textureFile.load(); - } - } - } - } - } -} diff --git a/util/qt3d/modeltweak/qml/ModelTweak.qml b/util/qt3d/modeltweak/qml/ModelTweak.qml deleted file mode 100644 index 3efc3b631..000000000 --- a/util/qt3d/modeltweak/qml/ModelTweak.qml +++ /dev/null @@ -1,292 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtQuick3D examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 Nokia Corporation and its Subsidiary(-ies) 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 1.0 -import Qt3D 1.0 -import ModelTweak 1.0 -import "fileHandling.js" as FileHandler -import "Widgets" -import "ColorUtils.js" as ColorUtils - -Rectangle { - id: outerWindow; - width: 1024 - height: 768 - property alias modelEffect: customEffect - property alias modelMaterial: customMaterial - property bool useCustomEffect: false - property bool useCustomMaterial: false - - property bool changed: false - Component.onCompleted: { - outerWindow.changed = false; - } - - Component.onDestruction: { - if (outerWindow.changed) - { - FileHandler.save_qml(true); - } - } - - Rectangle { - id: menu - x: parent.x - y: parent.y - height: 24 - anchors.left: parent.left - anchors.right: parent.right - anchors.top: parent.top - - color: "#B4B4B4" - border.color: "black" - - ButtonBarPane { - id: buttonBarPane - anchors.fill: parent - } - } - - Rectangle { - id: mainwindow - anchors.left: parent.left - anchors.right: parent.right - anchors.top: menu.bottom - anchors.bottom: outerWindow.bottom - - color: "#444444" - border.color: "black" - - property alias targetMesh: quickFile.filename - - QuickFile { - id: quickFile - filename: "meshes/penguin.3ds" - title: "Open 3D Asset File" - filter: "Asset files (*.*)" - } - - QuickFile { - id: textureFile - filename: "" - title: "Open Texture File" - filter: "Images (*.gif *.png *.jpg *.tif *.bmp)" - } - - Mesh { - id: source_mesh - source: quickFile.filename - } - - Translation3D { id: transformTranslate; translate: Qt.vector3d(0, 0, 0); } - Rotation3D { id: transformRotateX; axis: Qt.vector3d(1, 0, 0); angle: 0; } - Rotation3D { id: transformRotateY; axis: Qt.vector3d(0, 1, 0); angle: 0; } - Rotation3D { id: transformRotateZ; axis: Qt.vector3d(0, 0, 1); angle: 0; } - Scale3D { id: transformScale; scale: Qt.vector3d(1, 1, 1); } - - Effect { - id: customEffect; - property alias hsv: hsvColor - material: useCustomMaterial ? customMaterial : null; - color: hsv.color - blending: (hsv.alpha < 1.0) - || (useCustomMaterial && (hsvAmbColor.alpha*hsvDifColor.alpha*hsvSpecColor.alpha < 1.0)) - texture: textureFile.filename - } - Material { - id: customMaterial - property alias amb_hsv: hsvAmbColor - property alias dif_hsv: hsvDifColor - property alias spec_hsv: hsvSpecColor - ambientColor: hsvAmbColor.color - diffuseColor: hsvDifColor.color - specularColor: hsvSpecColor.color - textureUrl: textureFile.filename - } - HSVColor { id: hsvColor } - HSVColor { id: hsvAmbColor } - HSVColor { id: hsvDifColor } - HSVColor { id: hsvSpecColor } - - ModelViewport { - id: mvpZY - x: 0; - y: 0; - camera.eye: Qt.vector3d(20, 0, 0); - stateName: "ZYMaximised" - viewportName: "Z,Y axis (right)" - - rightVector: Qt.vector3d(0, 0, -1) - upVector: Qt.vector3d(0, 1, 0) - - property alias position: transformTranslate.translate; - - onMouseTranslateX: if (!modelPropertiesPane.translateLocked) position = Qt.vector3d(position.x, position.y, translate.z + (down.x - mouse.x)/translateSensitivity) - onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, translate.y + (down.y - mouse.y)/translateSensitivity, position.z) - onMouseRotateX: if (!modelPropertiesPane.rotateLocked)transformRotateY.angle = rotate.y - (down.x - mouse.x)/rotateSensitivity - onMouseRotateY: if (!modelPropertiesPane.rotateLocked)transformRotateZ.angle = rotate.z - (down.y - mouse.y)/rotateSensitivity - onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.z - (down.x - mouse.x)/scaleSensitivity; - transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, s<0 ? 0 : s) - } - onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.y + (down.y - mouse.y)/scaleSensitivity; - transformScale.scale = Qt.vector3d(transformScale.scale.x, s<0 ? 0 : s, transformScale.scale.z) - } - } - - ModelViewport { - id: mvpXY - x: parent.width/2 - y: 0; - camera.eye: Qt.vector3d(0, 0, 20); - stateName: "XYMaximised" - viewportName: "X,Y axis (front)" - - rightVector: Qt.vector3d(1, 0, 0) - upVector: Qt.vector3d(0, 1, 0) - - property alias position: transformTranslate.translate; - - onMouseTranslateX: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(translate.x - (down.x - mouse.x)/translateSensitivity, position.y, position.z) - onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, translate.y + (down.y - mouse.y)/translateSensitivity, position.z) - onMouseRotateX: if (!modelPropertiesPane.rotateLocked) transformRotateY.angle = rotate.y - (down.x - mouse.x)/rotateSensitivity - onMouseRotateY: if (!modelPropertiesPane.rotateLocked) transformRotateX.angle = rotate.x - (down.y - mouse.y)/rotateSensitivity - onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.x - (down.x - mouse.x)/scaleSensitivity - transformScale.scale = Qt.vector3d(s<0 ? 0 : s, transformScale.scale.y, transformScale.scale.z) - } - onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.y + (down.y - mouse.y)/scaleSensitivity - transformScale.scale = Qt.vector3d(transformScale.scale.x, s<0 ? 0 : s, transformScale.scale.z) - } - } - - ModelViewport { - id: mvpXZ - x: parent.width/2; - y: parent.height/2; - camera.eye: Qt.vector3d(0, 20, 0); - camera.upVector: Qt.vector3d(0, 0, -1); - stateName: "XZMaximised" - viewportName: "X,Z axis (top)" - - rightVector: Qt.vector3d(1, 0, 0) - upVector: Qt.vector3d(0, 0, -1) - - property alias position: transformTranslate.translate; - - onMouseTranslateX: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(translate.x - (down.x - mouse.x)/translateSensitivity, position.y, position.z) - onMouseTranslateY: if (!modelPropertiesPane.translateLocked)position = Qt.vector3d(position.x, position.y, translate.z - (down.y - mouse.y)/translateSensitivity) - onMouseRotateX: if (!modelPropertiesPane.rotateLocked)transformRotateZ.angle = rotate.z + (down.x - mouse.x)/rotateSensitivity - onMouseRotateY: if (!modelPropertiesPane.rotateLocked)transformRotateX.angle = rotate.x - (down.y - mouse.y)/rotateSensitivity - onMouseScaleX: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.x - (down.x - mouse.x)/scaleSensitivity; - transformScale.scale = Qt.vector3d(s<0 ? 0 : s, transformScale.scale.y, transformScale.scale.z) - } - onMouseScaleY: if (!modelPropertiesPane.scaleLocked) { - var s = scale3d.z + (down.y - mouse.y)/scaleSensitivity; - transformScale.scale = Qt.vector3d(transformScale.scale.x, transformScale.scale.y, s<0 ? 0 : s) - } - } - - Rectangle { - id: meshName - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottomMargin: 10 - anchors.bottom: parent.bottom - radius: 10 - border.width: 1 - border.color: "black" - color: "white" - width: parent.width - 20 - height: 20 - - Text { - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - text: "Hold left mouse button to move, middle button to scale, and right button to rotate the asset." - } - } - - ModelPropertiesPane { - id: modelPropertiesPane - x: 16; - y: parent.height / 2 + 16 - onChanged: {outerWindow.changed=true} - } - - ColorPicker { - id: colorPicker - visible: false - } - - HelpOverlay { - id: helpOverlay - visible: false - } - - states: [ - State { - name: "3Views" - }, - State { - name: "ZYMaximised" - PropertyChanges { target: mvpZY; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } - PropertyChanges { target: mvpXY; x: mainwindow.width; y: 0; width: 0; height: mainwindow.height/2; } - PropertyChanges { target: mvpXZ; x: mainwindow.width; y: mainwindow.height; width: 0; height: 0; } - }, - State { - name: "XYMaximised" - PropertyChanges { target: mvpZY; x: 0; y: 0; width: 0; height: mainwindow.height/2; } - PropertyChanges { target: mvpXY; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } - PropertyChanges { target: mvpXZ; x: mainwindow.width/2; y: mainwindow.height; width: mainwindow.width/2; height: 0; } - }, - State { - name: "XZMaximised" - PropertyChanges { target: mvpZY; x: 0; y: 0; width: 0; height: 0; } - PropertyChanges { target: mvpXY; x: mainwindow.width/2; y: 0; width: mainwindow.width/2; height: 0; } - PropertyChanges { target: mvpXZ; x: 0; y: 0; width: mainwindow.width; height: mainwindow.height; } - } - ] - - state: "3Views" - } -} diff --git a/util/qt3d/modeltweak/qml/ModelViewport.qml b/util/qt3d/modeltweak/qml/ModelViewport.qml deleted file mode 100644 index ed3118375..000000000 --- a/util/qt3d/modeltweak/qml/ModelViewport.qml +++ /dev/null @@ -1,452 +0,0 @@ -import QtQuick 1.0 -import Qt3D 1.0 -import Qt3D.Shapes 1.0 -import ModelTweak 1.0 -import "Widgets" - -Rectangle { - id: view - width: parent.width/2; - height: parent.height/2 - - color: parent.color - border.color: parent.border.color - - property alias itemPosition: mainItem.position; - property alias itemScale: mainItem.scale; - property alias camera: viewport.camera - property alias viewportName: viewportText.text; - - // the current x/y positions of the mouse when the onPressed event was triggered; - // values are invalid if onRelease has occured - property variant down; - - // current xyz values of the Translation3D/Rotation3Ds/Scale3D when onPressed was triggered; - // values are invalid if onRelease has occured - property variant translate; - property variant rotate; - property variant scale3d; - - // the pixel sensitivity values of the mousemovements - // TODO: expose via api - // TODO: maybe save in settings api? - property double translateSensitivity: 32; - property double rotateSensitivity: 8; - property double scaleSensitivity: 32; - - // the name of this viewport's state - property string stateName; - - property variant upVector: Qt.vector3d(0, 1, 0) - property variant rightVector: Qt.vector3d(0, 1, 0) - - // the smoothness values for the state change transformations - // TODO: this should be alterable via the gui and saved in a settings file - Behavior on x { NumberAnimation { duration: 300 } } - Behavior on y { NumberAnimation { duration: 300 } } - Behavior on width { NumberAnimation { duration: 300 } } - Behavior on height { NumberAnimation { duration: 300 } } - - signal mouseTranslateX(variant mouse) - signal mouseTranslateY(variant mouse) - signal mouseRotateX(variant mouse) - signal mouseRotateY(variant mouse) - signal mouseScaleX(variant mouse) - signal mouseScaleY(variant mouse) - - property real cameraZoom: 1.0 - - Viewport { - id: viewport - anchors.fill: parent - picking: false - blending: true - - // TODO: camera's position/rotation-around-origin/farplane should be alterable via gui - camera: Camera { - farPlane: 2000 // debugging - projectionType: Camera.Orthographic - viewSize: Qt.size(2*cameraZoom, 2*cameraZoom) - } - navigation: false - - Item3D { - id: mainItem - mesh: source_mesh - transform: [ - transformScale, - transformRotateX, - transformRotateY, - transformRotateZ, - transformTranslate, - ] - effect: useCustomEffect ? modelEffect : null; - } - - Effect { - id: coordLinesThickEffect - color: "white" - } - Effect { - id: coordLinesThinEffect - color: "black" - } - - // horizontal lines - Line { - id: lineAxisRight - width: 3.0 - vertices: [ - cameraZoom*(-10*rightVector.x), cameraZoom*(-10*rightVector.y), cameraZoom*(-10*rightVector.z), - cameraZoom*(10*rightVector.x), cameraZoom*(10*rightVector.y), cameraZoom*(10*rightVector.z), - cameraZoom*(10*rightVector.x + 0.001*upVector.x), cameraZoom*(10*rightVector.y + 0.001*upVector.y), cameraZoom*(10*rightVector.z + 0.001*upVector.z) - ] - effect: coordLinesThickEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x + 0.25*upVector.x), cameraZoom*(-10*rightVector.y + 0.25*upVector.y), cameraZoom*(-10*rightVector.z + 0.25*upVector.z), - cameraZoom*(10*rightVector.x + 0.25*upVector.x), cameraZoom*(10*rightVector.y + 0.25*upVector.y), cameraZoom*(10*rightVector.z + 0.25*upVector.z), - cameraZoom*(10*rightVector.x + 0.251*upVector.x), cameraZoom*(10*rightVector.y + 0.251*upVector.y), cameraZoom*(10*rightVector.z + 0.251*upVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x + 0.5*upVector.x), cameraZoom*(-10*rightVector.y + 0.5*upVector.y), cameraZoom*(-10*rightVector.z + 0.5*upVector.z), - cameraZoom*(10*rightVector.x + 0.5*upVector.x), cameraZoom*(10*rightVector.y + 0.5*upVector.y), cameraZoom*(10*rightVector.z + 0.5*upVector.z), - cameraZoom*(10*rightVector.x + 0.501*upVector.x), cameraZoom*(10*rightVector.y + 0.501*upVector.y), cameraZoom*(10*rightVector.z + 0.501*upVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x + 0.75*upVector.x), cameraZoom*(-10*rightVector.y + 0.75*upVector.y), cameraZoom*(-10*rightVector.z + 0.75*upVector.z), - cameraZoom*(10*rightVector.x + 0.75*upVector.x), cameraZoom*(10*rightVector.y + 0.75*upVector.y), cameraZoom*(10*rightVector.z + 0.75*upVector.z), - cameraZoom*(10*rightVector.x + 0.751*upVector.x), cameraZoom*(10*rightVector.y + 0.751*upVector.y), cameraZoom*(10*rightVector.z + 0.751*upVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x - 0.25*upVector.x), cameraZoom*(-10*rightVector.y - 0.25*upVector.y), cameraZoom*(-10*rightVector.z - 0.25*upVector.z), - cameraZoom*(10*rightVector.x - 0.25*upVector.x), cameraZoom*(10*rightVector.y - 0.25*upVector.y), cameraZoom*(10*rightVector.z - 0.25*upVector.z), - cameraZoom*(10*rightVector.x - 0.251*upVector.x), cameraZoom*(10*rightVector.y - 0.251*upVector.y), cameraZoom*(10*rightVector.z - 0.251*upVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x - 0.5*upVector.x), cameraZoom*(-10*rightVector.y - 0.5*upVector.y), cameraZoom*(-10*rightVector.z - 0.5*upVector.z), - cameraZoom*(10*rightVector.x - 0.5*upVector.x), cameraZoom*(10*rightVector.y - 0.5*upVector.y), cameraZoom*(10*rightVector.z - 0.5*upVector.z), - cameraZoom*(10*rightVector.x - 0.501*upVector.x), cameraZoom*(10*rightVector.y - 0.501*upVector.y), cameraZoom*(10*rightVector.z - 0.501*upVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*rightVector.x - 0.75*upVector.x), cameraZoom*(-10*rightVector.y - 0.75*upVector.y), cameraZoom*(-10*rightVector.z - 0.75*upVector.z), - cameraZoom*(10*rightVector.x - 0.75*upVector.x), cameraZoom*(10*rightVector.y - 0.75*upVector.y), cameraZoom*(10*rightVector.z - 0.75*upVector.z), - cameraZoom*(10*rightVector.x - 0.751*upVector.x), cameraZoom*(10*rightVector.y - 0.751*upVector.y), cameraZoom*(10*rightVector.z - 0.751*upVector.z) - ] - effect: coordLinesThinEffect - } - - // vertical lines - Line { - id: lineAxisUp - width: 3.0 - vertices: [ - cameraZoom*(-10*upVector.x), cameraZoom*(-10*upVector.y), cameraZoom*(-10*upVector.z), - cameraZoom*(10*upVector.x), cameraZoom*(10*upVector.y), cameraZoom*(10*upVector.z), - cameraZoom*(10*upVector.x + 0.01*rightVector.x), cameraZoom*(10*upVector.y + 0.01*rightVector.y), cameraZoom*(10*upVector.z + 0.01*rightVector.z) - ] - effect: coordLinesThickEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x + 0.25*rightVector.x), cameraZoom*(-10*upVector.y + 0.25*rightVector.y), cameraZoom*(-10*upVector.z + 0.25*rightVector.z), - cameraZoom*(10*upVector.x + 0.25*rightVector.x), cameraZoom*(10*upVector.y + 0.25*rightVector.y), cameraZoom*(10*upVector.z + 0.25*rightVector.z), - cameraZoom*(10*upVector.x + 0.251*rightVector.x), cameraZoom*(10*upVector.y + 0.251*rightVector.y), cameraZoom*(10*upVector.z + 0.251*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x + 0.5*rightVector.x), cameraZoom*(-10*upVector.y + 0.5*rightVector.y), cameraZoom*(-10*upVector.z + 0.5*rightVector.z), - cameraZoom*(10*upVector.x + 0.5*rightVector.x), cameraZoom*(10*upVector.y + 0.5*rightVector.y), cameraZoom*(10*upVector.z + 0.5*rightVector.z), - cameraZoom*(10*upVector.x + 0.501*rightVector.x), cameraZoom*(10*upVector.y + 0.501*rightVector.y), cameraZoom*(10*upVector.z + 0.501*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x + 0.75*rightVector.x), cameraZoom*(-10*upVector.y + 0.75*rightVector.y), cameraZoom*(-10*upVector.z + 0.75*rightVector.z), - cameraZoom*(10*upVector.x + 0.75*rightVector.x), cameraZoom*(10*upVector.y + 0.75*rightVector.y), cameraZoom*(10*upVector.z + 0.75*rightVector.z), - cameraZoom*(10*upVector.x + 0.751*rightVector.x), cameraZoom*(10*upVector.y + 0.751*rightVector.y), cameraZoom*(10*upVector.z + 0.751*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x + 1.00*rightVector.x), cameraZoom*(-10*upVector.y + 1.00*rightVector.y), cameraZoom*(-10*upVector.z + 1.00*rightVector.z), - cameraZoom*(10*upVector.x + 1.00*rightVector.x), cameraZoom*(10*upVector.y + 1.00*rightVector.y), cameraZoom*(10*upVector.z + 1.00*rightVector.z), - cameraZoom*(10*upVector.x + 1.001*rightVector.x), cameraZoom*(10*upVector.y + 1.001*rightVector.y), cameraZoom*(10*upVector.z + 1.001*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x - 0.25*rightVector.x), cameraZoom*(-10*upVector.y - 0.25*rightVector.y), cameraZoom*(-10*upVector.z - 0.25*rightVector.z), - cameraZoom*(10*upVector.x - 0.25*rightVector.x), cameraZoom*(10*upVector.y - 0.25*rightVector.y), cameraZoom*(10*upVector.z - 0.25*rightVector.z), - cameraZoom*(10*upVector.x - 0.251*rightVector.x), cameraZoom*(10*upVector.y - 0.251*rightVector.y), cameraZoom*(10*upVector.z - 0.251*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x - 0.5*rightVector.x), cameraZoom*(-10*upVector.y - 0.5*rightVector.y), cameraZoom*(-10*upVector.z - 0.5*rightVector.z), - cameraZoom*(10*upVector.x - 0.5*rightVector.x), cameraZoom*(10*upVector.y - 0.5*rightVector.y), cameraZoom*(10*upVector.z - 0.5*rightVector.z), - cameraZoom*(10*upVector.x - 0.501*rightVector.x), cameraZoom*(10*upVector.y - 0.501*rightVector.y), cameraZoom*(10*upVector.z - 0.501*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x - 0.75*rightVector.x), cameraZoom*(-10*upVector.y - 0.75*rightVector.y), cameraZoom*(-10*upVector.z - 0.75*rightVector.z), - cameraZoom*(10*upVector.x - 0.75*rightVector.x), cameraZoom*(10*upVector.y - 0.75*rightVector.y), cameraZoom*(10*upVector.z - 0.75*rightVector.z), - cameraZoom*(10*upVector.x - 0.751*rightVector.x), cameraZoom*(10*upVector.y - 0.751*rightVector.y), cameraZoom*(10*upVector.z - 0.751*rightVector.z) - ] - effect: coordLinesThinEffect - } - Line { - width: 1.0 - vertices: [ - cameraZoom*(-10*upVector.x - 1.00*rightVector.x), cameraZoom*(-10*upVector.y - 1.00*rightVector.y), cameraZoom*(-10*upVector.z - 1.00*rightVector.z), - cameraZoom*(10*upVector.x - 1.00*rightVector.x), cameraZoom*(10*upVector.y - 1.00*rightVector.y), cameraZoom*(10*upVector.z - 1.00*rightVector.z), - cameraZoom*(10*upVector.x - 1.001*rightVector.x), cameraZoom*(10*upVector.y - 1.001*rightVector.y), cameraZoom*(10*upVector.z - 1.001*rightVector.z) - ] - effect: coordLinesThinEffect - } - - } - - MouseArea { - property int mouseDown: Qt.NoButton - - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton - - onMouseXChanged: { - if (mouseDown & Qt.LeftButton) - mouseTranslateX(mouse) - else if (mouseDown === Qt.RightButton) - mouseRotateX(mouse); - else if (mouseDown === Qt.MiddleButton) - mouseScaleX(mouse) - } - - onMouseYChanged: { - if (mouseDown & Qt.LeftButton) - mouseTranslateY(mouse) - else if (mouseDown === Qt.RightButton) - mouseRotateY(mouse); - else if (mouseDown === Qt.MiddleButton) - mouseScaleY(mouse) - } - - onPressed: { - // if we already have a mouse button down we don't want to do anything else until it's up again - if (mouseDown !== Qt.NoButton) - return; - - mouseDown = mouse.button; - down = Qt.point(mouse.x, mouse.y) - translate = transformTranslate.translate - rotate = Qt.vector3d(transformRotateX.angle, transformRotateY.angle, transformRotateZ.angle) - scale3d = transformScale.scale - } - - // clear the current mouse button upon release - onReleased: { mouseDown = Qt.NoButton } - } - - ModelViewportResize { - anchors { - top: view.top; topMargin: 2; - right: view.right; rightMargin: 2; - } - } - - ZoomControls { - anchors { - top: view.top; topMargin: 24; - right: view.right; rightMargin: 2; - } - onZoomIn: { - cameraZoom = 0.5 * cameraZoom; - } - onZoomOut: { - cameraZoom = 2.0 * cameraZoom; - } - } - - Text { - id: viewportText - anchors { - top: view.top; topMargin: 4; - left: view.left; leftMargin: 4; - } - color: "white" - font.pixelSize: 16 - } - - // --------- grid text begin --------- - - property bool bTall: view.width -#include - #include - -/*! - \qmlclass QuickFile QuickFile - \brief QuickFile is a quick-and-dirty file handling object that supports file-io that QML/Javascript doesn't. - \inherits QObject - - The QuickFile element is part of the \c{ModelTweak} namespace, - so the following must appear at the top of any QML file that - references it: - - \code - import ModelTweak 1.0 - \endcode - - \sa QObject -*/ - -/*! - \internal -*/ -QuickFile::QuickFile(QObject *parent) : - QObject(parent) -{ -} - -/*! - Prompts for a location and filename to save the qml \c{QuickFile::data} generated by ModelTweaker. - Returns an error message if the file was unsuccessfully saved, - or an empty string if the save was successful/cancelled. -*/ -QString QuickFile::save() const -{ - QString filename = QFileDialog::getSaveFileName(0, tr("Save QML File"), "",tr("Files (*.qml)")); - - //If cancel button pressed (ie. filename empty), we can just drop out immediately - if (filename.isEmpty()) { - return QString(); - } - - // FIXME: ensure fileName is appropriate as a qml Component - if (!filename.endsWith(".qml")) - filename.append(".qml"); - - QDir outputDir = QFileInfo(filename).absoluteDir(); - - QString modelFilename = QUrl(_filename).toLocalFile(); - QString modelFN = QFileInfo(modelFilename).fileName(); - - QString dstModelLocation = outputDir.path() + QDir::separator() + modelFN; - if (dstModelLocation.compare(modelFilename,Qt::CaseInsensitive) != 0) { - // src and dst model paths are different. - // Copy model file over. - qDebug("Attempting to copy:"); - qDebug(" from: %s",modelFilename.toAscii().constData()); - qDebug(" to : %s",dstModelLocation.toAscii().constData()); - QFile dstModelFile(dstModelLocation); - if (dstModelFile.exists()) { - if (!dstModelFile.remove()) { - qDebug(" failed to remove dst file!"); - } - } - QFile srcModelFile(modelFilename); - if (srcModelFile.copy(dstModelLocation)) { - qDebug(" Model was copied successfully."); - } else { - qDebug(" failed to copy model file !"); - } - } - - QFile file(filename); - - qDebug("Attempting to write: %s", file.fileName().toAscii().constData()); - - if (!file.open(QFile::WriteOnly)) - return file.errorString(); - - QString dataToWrite = _data.arg(modelFN); - - file.write(dataToWrite.toUtf8()); - - file.close(); - - return QString(); -} - -/*! - Save/Close dialog for unsaved changes to QML files. This is shown if the user - closes the app without saving the modifications they have made. - - Returns an error message if the file was unsuccessfully saved, - or an empty string if the save was successful/cancelled. -*/ -QString QuickFile::promptSave() const -{ - QMessageBox msgBox; - msgBox.setText("The document has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); - msgBox.setDefaultButton(QMessageBox::Save); - int ret = msgBox.exec(); - - if (ret==QMessageBox::Save) { - return save(); - } else { - return QString(); - } -} - -/*! - Prompts for a location to load a model file from and stores it into the the \c{QuickFile::filename} - variable. -*/ -void QuickFile::load() -{ - QString qmlFilename = QFileDialog::getOpenFileName(0, _title, "", _filter); - setFilename(qmlFilename); -} - - -QString QuickFile::filename() const { - return _filename; -} - -void QuickFile::setFilename(const QString filename) { - if (_filename != filename) - _filename = filename; - emit filenameChanged(filename); -} - -QString QuickFile::title() const { - return _title; -} - -void QuickFile::setTitle(const QString title) { - if (_title != title) - _title = title; - emit titleChanged(title); -} - -QString QuickFile::filter() const { - return _filter; -} - -void QuickFile::setFilter(const QString filter) { - if (_filter != filter) - _filter = filter; - emit filterChanged(filter); -} - -QString QuickFile::data() const { - return _data; -} - -void QuickFile::setData(const QString data) { - if (_data != data) - _data = data; - emit dataChanged(data); -} - diff --git a/util/qt3d/modeltweak/quickfile.h b/util/qt3d/modeltweak/quickfile.h deleted file mode 100644 index 1c66c60bb..000000000 --- a/util/qt3d/modeltweak/quickfile.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef QUICKFILE_H -#define QUICKFILE_H - -#include - -class QuickFile : public QObject -{ - Q_OBJECT - - QString _filename; - QString _title; - QString _filter; - QString _data; - - Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) - Q_PROPERTY(QString data READ data WRITE setData NOTIFY dataChanged) - -public: - explicit QuickFile(QObject *parent = 0); - - QString filename() const; - void setFilename(const QString filename); - - QString title() const; - void setTitle(const QString title); - - QString filter() const; - void setFilter(const QString filter); - - QString data() const; - void setData(const QString data); - - Q_INVOKABLE QString save() const; - Q_INVOKABLE void load(); - Q_INVOKABLE QString promptSave() const; - -signals: - void filenameChanged(const QString newFilename); - void titleChanged(const QString newTitle); - void filterChanged(const QString newFilter); - void dataChanged(const QString newData); -}; - -#endif // QUICKFILE_H diff --git a/util/qt3d/qt3d.pro b/util/qt3d/qt3d.pro index b0afb1398..4539ef6f7 100644 --- a/util/qt3d/qt3d.pro +++ b/util/qt3d/qt3d.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qglinfo modeltweak +SUBDIRS = qglinfo assetviewer -- cgit v1.2.3