WIP on QtQuick toolbars

This commit is contained in:
Michaël Lemaire 2014-08-28 10:29:12 +02:00
parent d909ff380f
commit 2251db361c
18 changed files with 282 additions and 39 deletions

BIN
graphics/icons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

99
graphics/icons.svg Normal file
View file

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="icons.svg"
inkscape:export-filename="/home/michael/workspace/paysages3d/graphics/icons.png"
inkscape:export-xdpi="154.89854"
inkscape:export-ydpi="154.89854">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.959798"
inkscape:cx="170.49504"
inkscape:cy="957.94588"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1920"
inkscape:window-height="1030"
inkscape:window-x="1440"
inkscape:window-y="25"
inkscape:window-maximized="1"
showguides="true">
<inkscape:grid
type="xygrid"
id="grid3004" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#000000;stroke:#000000;stroke-width:3.7;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 55,32.362183 c -10,35 -25,40 -25,50 0,10 5.355339,25.254827 23.790623,25.254827 C 72.225907,107.61701 80,92.362183 80,82.362183 c 0,-10 -15,-15 -25,-50 z"
id="path3006"
inkscape:connector-curvature="0"
sodipodi:nodetypes="czzzc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 46.711902,68.575386 c -4.70494,1.249464 -15,15 -10,15 5,0 10,5 10,5 -1.6011,-6.345755 4.41534,-10.613999 10,-15 0,0 -5.29506,-6.249464 -10,-5 z"
id="path3776"
inkscape:connector-curvature="0"
sodipodi:nodetypes="zzccz" />
<path
style="fill:none;stroke:#000000;stroke-width:4.319;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 140.61815,83.142861 c 0,0 10.6138,-9.86109 20.06933,-9.708785 17.76848,0.286206 17.35284,19.13136 35.12131,19.417571 18.91107,0.304603 21.21711,-19.417571 40.13865,-19.417571 18.92154,0 21.2171,19.417571 40.13864,19.417571 9.46077,0 20.06933,-9.708786 20.06933,-9.708786"
id="path3780"
inkscape:connector-curvature="0"
sodipodi:nodetypes="caaaac" />
<path
style="fill:none;stroke:#000000;stroke-width:4.319;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 153.97268,88.56225 c 0,0 10.6138,-9.861089 20.06933,-9.708784 17.76847,0.286206 17.35284,19.13136 35.12131,19.417571 18.91106,0.304603 21.21711,-19.417571 40.13865,-19.417571 18.92153,0 21.2171,19.417571 40.13864,19.417571 9.46077,0 20.06933,-9.708787 20.06933,-9.708787"
id="path3780-5"
inkscape:connector-curvature="0"
sodipodi:nodetypes="caaaac" />
<path
style="fill:none;stroke:#000000;stroke-width:4.319;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 167.88393,94.110016 c 0,0 10.6138,-9.86109 20.06933,-9.708785 17.76847,0.286206 17.35284,19.131359 35.12131,19.417569 18.91106,0.30461 21.21711,-19.417569 40.13865,-19.417569 18.92153,0 21.2171,19.417569 40.13864,19.417569 9.46077,0 20.06933,-9.708784 20.06933,-9.708784"
id="path3780-3"
inkscape:connector-curvature="0"
sodipodi:nodetypes="caaaac" />
<path
style="fill:none;stroke:#000000;stroke-width:3.58400011;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 185.73773,125.20138 0,-77.092101 -25.69737,0 38.54605,-32.121711 38.54605,32.121711 -25.69736,0 0,77.092101 25.69736,0 -38.54605,32.12171 -38.54605,-32.12171 z"
id="path3807"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

@ -0,0 +1,24 @@
#include "MainModelerWindow.h"
#include "OpenGLView.h"
#include "Scenery.h"
#include "OpenGLRenderer.h"
MainModelerWindow::MainModelerWindow()
{
scenery = new Scenery();
scenery->autoPreset();
renderer = new OpenGLRenderer(scenery);
qmlRegisterType<OpenGLView>("Paysages", 1, 0, "OpenGLView");
setTitle(QObject::tr("Paysages 3D"));
setResizeMode(QQuickView::SizeRootObjectToView);
setSource(QUrl("qrc:///main.qml"));
}
MainModelerWindow::~MainModelerWindow()
{
delete renderer;
delete scenery;
}

View file

@ -0,0 +1,28 @@
#ifndef MAINMODELERWINDOW_H
#define MAINMODELERWINDOW_H
#include "modeler_global.h"
#include <QQuickView>
namespace paysages {
namespace modeler {
class MainModelerWindow: public QQuickView
{
Q_OBJECT
public:
MainModelerWindow();
virtual ~MainModelerWindow();
inline OpenGLRenderer *getRenderer() const {return renderer;}
private:
OpenGLRenderer *renderer;
Scenery *scenery;
};
}
}
#endif // MAINMODELERWINDOW_H

View file

@ -2,27 +2,22 @@
#include <QQuickWindow> #include <QQuickWindow>
#include <QHoverEvent> #include <QHoverEvent>
#include "MainModelerWindow.h"
// TEMP #include "CameraDefinition.h"
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "Scenery.h" #include "Scenery.h"
#include "CameraDefinition.h"
static OpenGLRenderer renderer;
static Scenery scenery;
OpenGLView::OpenGLView(QQuickItem *parent) : OpenGLView::OpenGLView(QQuickItem *parent) :
QQuickItem(parent) QQuickItem(parent)
{ {
initialized = false; initialized = false;
window = NULL; window = NULL;
renderer = NULL;
setAcceptedMouseButtons(Qt::AllButtons); setAcceptedMouseButtons(Qt::AllButtons);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setKeepMouseGrab(true); setKeepMouseGrab(true);
scenery.autoPreset();
renderer.setScenery(&scenery);
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
startTimer(250); startTimer(250);
} }
@ -31,27 +26,31 @@ void OpenGLView::handleWindowChanged(QQuickWindow *win)
{ {
if (win) if (win)
{ {
window = win; window = qobject_cast<MainModelerWindow *>(win);
if (window)
{
renderer = window->getRenderer();
connect(window, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection); connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
win->setClearBeforeRendering(false); win->setClearBeforeRendering(false);
initialized = false; initialized = false;
} }
} }
}
void OpenGLView::paint() void OpenGLView::paint()
{ {
if (not initialized) if (not initialized)
{ {
renderer.initialize(); renderer->initialize();
initialized = true; initialized = true;
} }
renderer.resize(width(), height()); renderer->resize(width(), height());
renderer.prepareOpenGLState(); renderer->prepareOpenGLState();
renderer.paint(); renderer->paint();
if (window) if (window)
{ {
@ -61,18 +60,23 @@ void OpenGLView::paint()
void OpenGLView::hoverMoveEvent(QHoverEvent *event) void OpenGLView::hoverMoveEvent(QHoverEvent *event)
{ {
if (!renderer)
{
return;
}
CameraDefinition camera; CameraDefinition camera;
renderer.getScenery()->getCamera(&camera); renderer->getScenery()->getCamera(&camera);
QPointF diff = event->posF() - event->oldPosF(); QPointF diff = event->posF() - event->oldPosF();
camera.strafeRight(diff.x() * 0.1); camera.strafeRight(diff.x() * 0.1);
camera.strafeUp(diff.y() * 0.1); camera.strafeUp(diff.y() * 0.1);
camera.validate(); camera.validate();
camera.copy(renderer.render_camera); camera.copy(renderer->render_camera);
renderer.getScenery()->setCamera(&camera); renderer->getScenery()->setCamera(&camera);
renderer.getScenery()->getCamera(&camera); renderer->getScenery()->getCamera(&camera);
renderer.cameraChangeEvent(&camera); renderer->cameraChangeEvent(&camera);
if (window) if (window)
{ {
window->update(); window->update();

View file

@ -24,7 +24,8 @@ protected:
private: private:
bool initialized; bool initialized;
QQuickWindow *window; MainModelerWindow *window;
OpenGLRenderer *renderer;
}; };
} }

View file

@ -1,19 +1,12 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QQuickView>
#include <QtQml>
#include "OpenGLView.h" #include "MainModelerWindow.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
qmlRegisterType<OpenGLView>("Paysages", 1, 0, "OpenGLView"); MainModelerWindow view;
QQuickView view;
view.setTitle(QObject::tr("Paysages 3D"));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///main.qml"));
view.show(); view.show();
return app.exec(); return app.exec();

View file

@ -7,7 +7,8 @@
namespace paysages { namespace paysages {
namespace modeler { namespace modeler {
class ItemOpenGLView; class MainModelerWindow;
class OpenGLView;
} }
} }

View file

@ -0,0 +1,27 @@
import QtQuick 2.0
Rectangle {
property ToolbarButton tool
id: panel
width: 200
height: parent.height - 100
color: "red"
enabled: visible
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
states: [
State {
name: "Active"
when: tool.selected
PropertyChanges {
target: panel
visible: true
}
}
]
}

View file

@ -0,0 +1,11 @@
import QtQuick 2.2
import QtQuick.Controls 1.2
BasePanel {
width: 20
Slider {
orientation: Qt.Vertical
anchors.fill: parent
}
}

View file

@ -5,7 +5,8 @@ Rectangle {
default property alias children : inner_space.children default property alias children : inner_space.children
width: 70 width: 70
height: parent.height height: parent.height
color: "#50000000" color: "#50888888"
enabled: opacity > 0
Column { Column {
id: inner_space id: inner_space

View file

@ -1,4 +1,5 @@
import QtQuick 2.0 import QtQuick 2.0
import QtGraphicalEffects 1.0
Item { Item {
property string picture property string picture
@ -13,7 +14,7 @@ Item {
Rectangle { Rectangle {
id: glow id: glow
anchors.fill: parent anchors.fill: parent
color: "white" color: "#cccccc"
radius: 8 radius: 8
opacity: parent.selected ? 1.0 : (parent.hovered ? 0.5 : 0.0) opacity: parent.selected ? 1.0 : (parent.hovered ? 0.5 : 0.0)
@ -22,6 +23,13 @@ Item {
duration: 200 duration: 200
} }
} }
RectangularGlow {
anchors.fill: glow
glowRadius: 8
spread: 0.2
color: "white"
cornerRadius: glow.radius + glowRadius
}
} }
Image { Image {
@ -30,6 +38,16 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
width: 32 width: 32
height: 32 height: 32
antialiasing: true
}
DropShadow {
anchors.fill: image
horizontalOffset: 2
verticalOffset: 2
radius: 4.0
samples: 16
color: "#80000000"
source: image
} }
MouseArea { MouseArea {

View file

@ -13,5 +13,9 @@
<file>images/display_topdown.png</file> <file>images/display_topdown.png</file>
<file>images/help.png</file> <file>images/help.png</file>
<file>Tooltip.qml</file> <file>Tooltip.qml</file>
<file>images/icon_water.png</file>
<file>images/icon_water_level.png</file>
<file>BasePanel.qml</file>
<file>PanelWaterLevel.qml</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -17,7 +17,7 @@ OpenGLView {
Toolbar { Toolbar {
id: primary_toolbar id: primary_toolbar
color: "#90000000" color: "#90888888"
anchors.left: parent.left anchors.left: parent.left
@ -36,7 +36,8 @@ OpenGLView {
} }
ToolbarButton { ToolbarButton {
id: tool_water id: tool_water
picture: "images/tab_water.png" picture: "images/icon_water.png"
hovertext: "Water tools"
} }
ToolbarButton { ToolbarButton {
id: tool_atmosphere id: tool_atmosphere
@ -65,6 +66,24 @@ OpenGLView {
} }
} }
Toolbar {
id: water_toolbar
opacity: 0
anchors.left: primary_toolbar.right
ToolbarButton {
id: tool_water_level
picture: "images/icon_water_level.png"
hovertext: qsTr("Change the water altitude")
}
}
PanelWaterLevel {
id: panel_water_level
visible: false
tool: tool_water_level
}
states: [ states: [
State { State {
name: "Display Mode" name: "Display Mode"
@ -74,6 +93,15 @@ OpenGLView {
target: display_toolbar target: display_toolbar
opacity: 1 opacity: 1
} }
},
State {
name: "Water Mode"
when: tool_water.selected
PropertyChanges {
target: water_toolbar
opacity: 1
}
} }
] ]

View file

@ -5,7 +5,8 @@ QT += qml quick widgets
include(../../../common.pri) include(../../../common.pri)
SOURCES += main.cpp \ SOURCES += main.cpp \
OpenGLView.cpp OpenGLView.cpp \
MainModelerWindow.cpp
RESOURCES += \ RESOURCES += \
qml/app.qrc qml/app.qrc
@ -20,7 +21,8 @@ include(deployment.pri)
HEADERS += \ HEADERS += \
OpenGLView.h \ OpenGLView.h \
modeler_global.h modeler_global.h \
MainModelerWindow.h
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../system/release/ -lpaysages_system 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:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../system/debug/ -lpaysages_system
@ -57,4 +59,6 @@ OTHER_FILES += \
qml/ToolbarButton.qml \ qml/ToolbarButton.qml \
qml/OpenGLView.qml \ qml/OpenGLView.qml \
qml/Toolbar.qml \ qml/Toolbar.qml \
qml/Tooltip.qml qml/Tooltip.qml \
qml/BasePanel.qml \
qml/PanelWaterLevel.qml