[qt] Implement QQuickMapboxGL color property

This commit is contained in:
Bruno de Oliveira Abinader
2016-07-27 16:04:59 +03:00
parent 5870fceb25
commit 6edaf2dc81
4 changed files with 63 additions and 29 deletions

View File

@@ -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;

View File

@@ -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()
}
}
}
}

View File

@@ -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)

View File

@@ -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());
}
}