From 9f438a3f8419f1b593f2b74279361d5fa1f5a77f Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Tue, 19 Aug 2014 15:49:08 +0200 Subject: [PATCH] Prototype of experimental UI using Qt Quick --- src/interface/quick/OpenGLView.cpp | 44 ++++++++++++++++++++++++++ src/interface/quick/OpenGLView.h | 28 +++++++++++++++++ src/interface/quick/deployment.pri | 27 ++++++++++++++++ src/interface/quick/main.cpp | 19 ++++++++++++ src/interface/quick/main.qml | 11 +++++++ src/interface/quick/qml.qrc | 5 +++ src/interface/quick/quick.pro | 50 ++++++++++++++++++++++++++++++ src/interface/quick/quick_global.h | 16 ++++++++++ src/paysages.pro | 1 + 9 files changed, 201 insertions(+) create mode 100644 src/interface/quick/OpenGLView.cpp create mode 100644 src/interface/quick/OpenGLView.h create mode 100644 src/interface/quick/deployment.pri create mode 100644 src/interface/quick/main.cpp create mode 100644 src/interface/quick/main.qml create mode 100644 src/interface/quick/qml.qrc create mode 100644 src/interface/quick/quick.pro create mode 100644 src/interface/quick/quick_global.h diff --git a/src/interface/quick/OpenGLView.cpp b/src/interface/quick/OpenGLView.cpp new file mode 100644 index 0000000..6f35ec2 --- /dev/null +++ b/src/interface/quick/OpenGLView.cpp @@ -0,0 +1,44 @@ +#include "OpenGLView.h" + +#include + +// TEMP +#include "OpenGLRenderer.h" +#include "Scenery.h" +static OpenGLRenderer renderer; +static Scenery scenery; + +OpenGLView::OpenGLView(QQuickItem *parent) : + QQuickItem(parent) +{ + initialized = false; + + connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); + + scenery.autoPreset(); + renderer.setScenery(&scenery); +} + +void OpenGLView::handleWindowChanged(QQuickWindow *win) +{ + if (win) + { + connect(window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection); + + win->setClearBeforeRendering(false); + + initialized = false; + } +} + +void OpenGLView::paint() +{ + if (not initialized) + { + renderer.initialize(); + initialized = true; + } + + renderer.resize(window()->width(), window()->height()); + renderer.paint(); +} diff --git a/src/interface/quick/OpenGLView.h b/src/interface/quick/OpenGLView.h new file mode 100644 index 0000000..f741a44 --- /dev/null +++ b/src/interface/quick/OpenGLView.h @@ -0,0 +1,28 @@ +#ifndef OPENGLVIEW_H +#define OPENGLVIEW_H + +#include "quick_global.h" + +#include + +namespace paysages { +namespace quick { + +class OpenGLView : public QQuickItem +{ + Q_OBJECT +public: + explicit OpenGLView(QQuickItem *parent = 0); + +public slots: + void handleWindowChanged(QQuickWindow *win); + void paint(); + +private: + bool initialized; +}; + +} +} + +#endif // OPENGLVIEW_H diff --git a/src/interface/quick/deployment.pri b/src/interface/quick/deployment.pri new file mode 100644 index 0000000..5441b63 --- /dev/null +++ b/src/interface/quick/deployment.pri @@ -0,0 +1,27 @@ +android-no-sdk { + target.path = /data/user/qt + export(target.path) + INSTALLS += target +} else:android { + x86 { + target.path = /libs/x86 + } else: armeabi-v7a { + target.path = /libs/armeabi-v7a + } else { + target.path = /libs/armeabi + } + export(target.path) + INSTALLS += target +} else:unix { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/src/interface/quick/main.cpp b/src/interface/quick/main.cpp new file mode 100644 index 0000000..6a8db3f --- /dev/null +++ b/src/interface/quick/main.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + +#include "OpenGLView.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + qmlRegisterType("Paysages", 1, 0, "OpenGLView"); + + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl("qrc:///main.qml")); + view.show(); + + return app.exec(); +} diff --git a/src/interface/quick/main.qml b/src/interface/quick/main.qml new file mode 100644 index 0000000..55b587b --- /dev/null +++ b/src/interface/quick/main.qml @@ -0,0 +1,11 @@ +import QtQuick 2.2 +import Paysages 1.0 + +Item { + + width: 640 + height: 480 + + OpenGLView { + } +} diff --git a/src/interface/quick/qml.qrc b/src/interface/quick/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/src/interface/quick/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + + diff --git a/src/interface/quick/quick.pro b/src/interface/quick/quick.pro new file mode 100644 index 0000000..6b90cf3 --- /dev/null +++ b/src/interface/quick/quick.pro @@ -0,0 +1,50 @@ +TEMPLATE = app + +QT += qml quick widgets + +include(../../common.pri) + +SOURCES += main.cpp \ + OpenGLView.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) + +HEADERS += \ + quick_global.h \ + OpenGLView.h + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../../system +DEPENDPATH += $$PWD/../../system + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../basics/release/ -lpaysages_basics +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../basics/debug/ -lpaysages_basics +else:unix: LIBS += -L$$OUT_PWD/../../basics/ -lpaysages_basics +INCLUDEPATH += $$PWD/../../basics +DEPENDPATH += $$PWD/../../basics + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../definition/release/ -lpaysages_definition +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../definition/debug/ -lpaysages_definition +else:unix: LIBS += -L$$OUT_PWD/../../definition/ -lpaysages_definition +INCLUDEPATH += $$PWD/../../definition +DEPENDPATH += $$PWD/../../definition + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../render/software/release/ -lpaysages_render_software +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../render/software/debug/ -lpaysages_render_software +else:unix: LIBS += -L$$OUT_PWD/../../render/software/ -lpaysages_render_software +INCLUDEPATH += $$PWD/../../render/software +DEPENDPATH += $$PWD/../../render/software + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../render/opengl/release/ -lpaysages_render_opengl +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../render/opengl/debug/ -lpaysages_render_opengl +else:unix: LIBS += -L$$OUT_PWD/../../render/opengl/ -lpaysages_render_opengl +INCLUDEPATH += $$PWD/../../render/opengl +DEPENDPATH += $$PWD/../../render/opengl diff --git a/src/interface/quick/quick_global.h b/src/interface/quick/quick_global.h new file mode 100644 index 0000000..b92e58b --- /dev/null +++ b/src/interface/quick/quick_global.h @@ -0,0 +1,16 @@ +#ifndef QUICK_GLOBAL_H +#define QUICK_GLOBAL_H + +#include "definition_global.h" +#include "software_global.h" +#include "opengl_global.h" + +namespace paysages { +namespace quick { + class ItemOpenGLView; +} +} + +using namespace paysages::quick; + +#endif // QUICK_GLOBAL_H diff --git a/src/paysages.pro b/src/paysages.pro index bd05472..347045e 100644 --- a/src/paysages.pro +++ b/src/paysages.pro @@ -10,5 +10,6 @@ SUBDIRS = \ render/opengl \ interface/commandline \ interface/desktop \ + interface/quick \ tests/googletest \ tests