Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[qt] Implement QQuickMapboxGL color property
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Jul 27, 2016
1 parent 5870fce commit 6edaf2d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
2 changes: 2 additions & 0 deletions platform/qt/include/qquickmapboxgl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
PanNeedsSync = 1 << 3,
BearingNeedsSync = 1 << 4,
PitchNeedsSync = 1 << 5,
ColorNeedsSync = 1 << 6,
};

int swapSyncState();
Expand Down Expand Up @@ -122,6 +123,7 @@ public slots:

QGeoCoordinate m_center;
QGeoShape m_visibleRegion;
QColor m_color = Qt::black;

QString m_style;
qreal m_bearing = 0;
Expand Down
69 changes: 45 additions & 24 deletions platform/qt/qmlapp/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -51,7 +59,7 @@ ApplicationWindow {
bearing: bearingSlider.value
pitch: pitchSlider.value

color: "red"
color: colorDialog.currentColor
copyrightsVisible: true

Image {
Expand Down Expand Up @@ -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()
}
}
}
}
17 changes: 12 additions & 5 deletions platform/qt/src/qquickmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions platform/qt/src/qquickmapboxglrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 6edaf2d

Please sign in to comment.