summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorxylosper <darklin20@gmail.com>2019-02-15 17:38:40 +0900
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-20 16:16:34 +0200
commit0c66ce9a95905255d9b80e1f2c5a7640ca25a683 (patch)
treeda955ff67ce14b606d8d8f9493d48248900a74ff /platform/qt
parentc00d44740fcf4bb868b39fd4d907958f6fe534bb (diff)
downloadqtlocation-mapboxgl-0c66ce9a95905255d9b80e1f2c5a7640ca25a683.tar.gz
[qt] fix missing alpha channel for `QColor`
`QColor::name()` produces `#rrggbb` format where alpha is missing. Use `rgba(...)` string instead when convert `QColor` to mapbox style. Note: `QColor::name(QColor::HexArgb)` produces `#aarrggbb` format string, but mapbox does not support this format apparently.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/qmapboxgl.cpp6
-rw-r--r--platform/qt/src/qt_conversion.hpp11
2 files changed, 12 insertions, 5 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 721bba8ff0..c0ea5efd34 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -941,13 +941,13 @@ mbgl::optional<mbgl::Annotation> asMapboxGLAnnotation(const QMapbox::Annotation
return { mbgl::SymbolAnnotation(mbgl::Point<double> { pair.second, pair.first }, symbolAnnotation.icon.toStdString()) };
} else if (annotation.canConvert<QMapbox::LineAnnotation>()) {
QMapbox::LineAnnotation lineAnnotation = annotation.value<QMapbox::LineAnnotation>();
- auto color = mbgl::Color::parse(lineAnnotation.color.name().toStdString());
+ auto color = mbgl::Color::parse(mbgl::style::conversion::convertColor(lineAnnotation.color));
return { mbgl::LineAnnotation(asMapboxGLGeometry(lineAnnotation.geometry), lineAnnotation.opacity, lineAnnotation.width, { *color }) };
} else if (annotation.canConvert<QMapbox::FillAnnotation>()) {
QMapbox::FillAnnotation fillAnnotation = annotation.value<QMapbox::FillAnnotation>();
- auto color = mbgl::Color::parse(fillAnnotation.color.name().toStdString());
+ auto color = mbgl::Color::parse(mbgl::style::conversion::convertColor(fillAnnotation.color));
if (fillAnnotation.outlineColor.canConvert<QColor>()) {
- auto outlineColor = mbgl::Color::parse(fillAnnotation.outlineColor.value<QColor>().name().toStdString());
+ auto outlineColor = mbgl::Color::parse(mbgl::style::conversion::convertColor(fillAnnotation.outlineColor.value<QColor>()));
return { mbgl::FillAnnotation(asMapboxGLGeometry(fillAnnotation.geometry), fillAnnotation.opacity, { *color }, { *outlineColor }) };
} else {
return { mbgl::FillAnnotation(asMapboxGLGeometry(fillAnnotation.geometry), fillAnnotation.opacity, { *color }, {}) };
diff --git a/platform/qt/src/qt_conversion.hpp b/platform/qt/src/qt_conversion.hpp
index 6927f2510a..34d2dcce8e 100644
--- a/platform/qt/src/qt_conversion.hpp
+++ b/platform/qt/src/qt_conversion.hpp
@@ -13,6 +13,8 @@ namespace mbgl {
namespace style {
namespace conversion {
+std::string convertColor(const QColor &color);
+
template <>
class ConversionTraits<QVariant> {
public:
@@ -96,7 +98,7 @@ public:
if (value.type() == QVariant::String) {
return value.toString().toStdString();
} else if (value.type() == QVariant::Color) {
- return value.value<QColor>().name().toStdString();
+ return convertColor(value.value<QColor>());
} else {
return {};
}
@@ -108,7 +110,7 @@ public:
} else if (value.type() == QVariant::String) {
return { value.toString().toStdString() };
} else if (value.type() == QVariant::Color) {
- return { value.value<QColor>().name().toStdString() };
+ return { convertColor(value.value<QColor>()) };
} else if (value.type() == QVariant::Int) {
return { int64_t(value.toInt()) };
} else if (value.canConvert(QVariant::Double)) {
@@ -151,6 +153,11 @@ optional<T> convert(const QVariant& value, Error& error, Args&&...args) {
return convert<T>(Convertible(value), error, std::forward<Args>(args)...);
}
+inline std::string convertColor(const QColor &color) {
+ return QString::asprintf("rgba(%d,%d,%d,%lf)",
+ color.red(), color.green(), color.blue(), color.alphaF()).toStdString();
+}
+
} // namespace conversion
} // namespace style
} // namespace mbgl