Marble

KmlColorTagHandler.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "KmlColorTagHandler.h"
8
9#include "GeoDataColorStyle.h"
10#include "GeoDataOverlay.h"
11#include "GeoParser.h"
12#include "KmlElementDictionary.h"
13
14namespace Marble
15{
16namespace kml
17{
18KML_DEFINE_TAG_HANDLER(color)
19
20GeoNode *KmlcolorTagHandler::parse(GeoParser &parser) const
21{
22 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1StringView(kmlTag_color)));
23
24 GeoStackItem parentItem = parser.parentElement();
25
26 if (parentItem.is<GeoDataColorStyle>() || parentItem.is<GeoDataOverlay>()) {
27 QColor const color = parseColor(parser.readElementText().trimmed());
28 if (parentItem.is<GeoDataColorStyle>()) {
29 parentItem.nodeAs<GeoDataColorStyle>()->setColor(color);
30 } else if (parentItem.is<GeoDataOverlay>()) {
31 parentItem.nodeAs<GeoDataOverlay>()->setColor(color);
32 }
33 }
34 return nullptr;
35}
36
37QColor KmlcolorTagHandler::parseColor(const QString &colorString)
38{
39 // color tag uses AABBGGRR whereas QColor uses AARRGGBB - use some shifts for that
40 // be aware that QRgb needs to be a typedef for 32 bit UInt for this to work properly
41 bool ok;
42 QRgb abgr = colorString.toUInt(&ok, 16);
43 unsigned a = abgr >> 24;
44 abgr = abgr << 8; //"rgb0"
45 unsigned b = abgr >> 24;
46 abgr = abgr << 8; //"gb00"
47 unsigned g = abgr >> 24;
48 abgr = abgr << 8; //"b000"
49 unsigned r = abgr >> 24;
50 QRgb rgba = (a << 24) | (r << 16) | (g << 8) | (b);
51 return ok ? QColor::fromRgba(rgba) : QColor();
52}
53
54}
55}
Binds a QML item to a specific geodetic location in screen coordinates.
QColor fromRgba(QRgb rgba)
uint toUInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 21 2025 11:58:54 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.