Marble

KmlColorTagHandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Patrick Spendrin <[email protected]>
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 
16 namespace Marble
17 {
18 namespace kml
19 {
20 KML_DEFINE_TAG_HANDLER( color )
21 
22 GeoNode* 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 
39 QColor 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 }
QColor fromRgba(QRgb rgba)
Binds a QML item to a specific geodetic location in screen coordinates.
uint toUInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.