diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-27 16:04:59 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-27 16:24:11 +0300 |
commit | 6edaf2dc81ab771d1da27c939b19502753aa895f (patch) | |
tree | 81b5887b02173981743bb32ead6ed6870d8e470c | |
parent | 5870fceb25fe7f9c67b9275236d2bab2339384f3 (diff) | |
download | qtlocation-mapboxgl-6edaf2dc81ab771d1da27c939b19502753aa895f.tar.gz |
[qt] Implement QQuickMapboxGL color property
-rw-r--r-- | platform/qt/include/qquickmapboxgl.hpp | 2 | ||||
-rw-r--r-- | platform/qt/qmlapp/main.qml | 69 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxgl.cpp | 17 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxglrenderer.cpp | 4 |
4 files changed, 63 insertions, 29 deletions
diff --git a/platform/qt/include/qquickmapboxgl.hpp b/platform/qt/include/qquickmapboxgl.hpp index 6c2847fe59..de783a1f62 100644 --- a/platform/qt/include/qquickmapboxgl.hpp +++ b/platform/qt/include/qquickmapboxgl.hpp @@ -89,6 +89,7 @@ public: PanNeedsSync = 1 << 3, BearingNeedsSync = 1 << 4, PitchNeedsSync = 1 << 5, + ColorNeedsSync = 1 << 6, }; int swapSyncState(); @@ -122,6 +123,7 @@ private: QGeoCoordinate m_center; QGeoShape m_visibleRegion; + QColor m_color = Qt::black; QString m_style; qreal m_bearing = 0; diff --git a/platform/qt/qmlapp/main.qml b/platform/qt/qmlapp/main.qml index a8629e94f6..a5e51e9801 100644 --- a/platform/qt/qmlapp/main.qml +++ b/platform/qt/qmlapp/main.qml @@ -3,6 +3,7 @@ import QtPositioning 5.0 import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 +import QtQuick.Dialogs 1.0 import QQuickMapboxGL 1.0 @@ -12,6 +13,13 @@ ApplicationWindow { height: 768 visible: true + ColorDialog { + id: colorDialog + title: "Background color" + visible: false + color: "black" + } + RowLayout { anchors.fill: parent anchors.margins: 50 @@ -51,7 +59,7 @@ ApplicationWindow { bearing: bearingSlider.value pitch: pitchSlider.value - color: "red" + color: colorDialog.currentColor copyrightsVisible: true Image { @@ -184,37 +192,50 @@ ApplicationWindow { } } - Slider { - id: bearingSlider + ColumnLayout { + RowLayout { + anchors.margins: 50 + spacing: anchors.margins - Layout.fillHeight: true - orientation: Qt.Vertical + Slider { + id: bearingSlider - value: 0 - minimumValue: 0 - maximumValue: 180 - } + Layout.fillHeight: true + orientation: Qt.Vertical - Slider { - id: pitchSlider + value: 0 + minimumValue: 0 + maximumValue: 180 + } - Layout.fillHeight: true - orientation: Qt.Vertical + Slider { + id: pitchSlider - value: 0 - minimumValue: 0 - maximumValue: 60 - } + Layout.fillHeight: true + orientation: Qt.Vertical - Slider { - id: flipSlider + value: 0 + minimumValue: 0 + maximumValue: 60 + } - Layout.fillHeight: true - orientation: Qt.Vertical + Slider { + id: flipSlider - value: 0 - minimumValue: 0 - maximumValue: 180 + Layout.fillHeight: true + orientation: Qt.Vertical + + value: 0 + minimumValue: 0 + maximumValue: 180 + } + } + + Button { + id: colorChangeButton + text: "Change background color" + onClicked: colorDialog.open() + } } } } diff --git a/platform/qt/src/qquickmapboxgl.cpp b/platform/qt/src/qquickmapboxgl.cpp index 2961925c8b..69878e0776 100644 --- a/platform/qt/src/qquickmapboxgl.cpp +++ b/platform/qt/src/qquickmapboxgl.cpp @@ -148,16 +148,23 @@ bool QQuickMapboxGL::copyrightsVisible() const return false; } -void QQuickMapboxGL::setColor(const QColor &) +void QQuickMapboxGL::setColor(const QColor &color) { - // TODO: can be made functional after landing #837 - qWarning() << __PRETTY_FUNCTION__ - << "Use Mapbox Studio to change the map background color."; + if (color == m_color) { + return; + } + + m_color = color; + + m_syncState |= ColorNeedsSync; + update(); + + emit colorChanged(m_color); } QColor QQuickMapboxGL::color() const { - return QColor(); + return m_color; } void QQuickMapboxGL::pan(int dx, int dy) diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp index 6212c4f128..330b5dc7e5 100644 --- a/platform/qt/src/qquickmapboxglrenderer.cpp +++ b/platform/qt/src/qquickmapboxglrenderer.cpp @@ -75,4 +75,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item) if (syncStatus & QQuickMapboxGL::PitchNeedsSync) { m_map->setPitch(quickMap->pitch()); } + + if (syncStatus & QQuickMapboxGL::ColorNeedsSync && m_map->isFullyLoaded()) { + m_map->setPaintProperty("background", "background-color", quickMap->color()); + } } |