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
10#include "MarbleDebug.h"
11#include "KmlElementDictionary.h"
12#include "GeoDataColorStyle.h"
13#include "GeoDataOverlay.h"
14#include "GeoParser.h"
15
16namespace Marble
17{
18namespace kml
19{
20KML_DEFINE_TAG_HANDLER( color )
21
22GeoNode* KmlcolorTagHandler::parse( GeoParser& parser ) const
23{
24 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(kmlTag_color)));
25
26 GeoStackItem parentItem = parser.parentElement();
27
28 if ( parentItem.is<GeoDataColorStyle>() || parentItem.is<GeoDataOverlay>() ) {
29 QColor const color = parseColor( parser.readElementText().trimmed() );
30 if ( parentItem.is<GeoDataColorStyle>() ) {
31 parentItem.nodeAs<GeoDataColorStyle>()->setColor( color );
32 } else if ( parentItem.is<GeoDataOverlay>() ) {
33 parentItem.nodeAs<GeoDataOverlay>()->setColor( color );
34 }
35 }
36 return nullptr;
37}
38
39QColor KmlcolorTagHandler::parseColor( const QString &colorString )
40{
41 // color tag uses AABBGGRR whereas QColor uses AARRGGBB - use some shifts for that
42 // be aware that QRgb needs to be a typedef for 32 bit UInt for this to work properly
43 bool ok;
44 QRgb abgr = colorString.toUInt( &ok, 16 );
45 unsigned a = abgr >> 24; abgr = abgr << 8; //"rgb0"
46 unsigned b = abgr >> 24; abgr = abgr << 8; //"gb00"
47 unsigned g = abgr >> 24; abgr = abgr << 8; //"b000"
48 unsigned r = abgr >> 24;
49 QRgb rgba = (a << 24)|(r << 16)|(g << 8)|(b);
50 return ok ? QColor::fromRgba( rgba ) : QColor();
51}
52
53}
54}
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-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:57 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.