Marble

GeoDataColorStyle.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2007 Murad Tagirov <[email protected]>
4 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <[email protected]>
5 //
6 
7 #include "GeoDataColorStyle.h"
8 
9 #include "GeoDataTypes.h"
10 
11 #include <cstdlib>
12 #include <QDataStream>
13 #include <QColor>
14 
15 namespace Marble
16 {
17 
18 class GeoDataColorStylePrivate
19 {
20  public:
21  GeoDataColorStylePrivate()
22  : m_color( Qt::white ),
23  m_colorMode( GeoDataColorStyle::Normal )
24  {
25  }
26 
27  /// stores the current color
28  QColor m_color;
29 
30  /// stores random color
31  QColor m_randomColor;
32 
33  /// stores the current color mode
34  GeoDataColorStyle::ColorMode m_colorMode;
35 };
36 
37 GeoDataColorStyle::GeoDataColorStyle()
38  : d( new GeoDataColorStylePrivate )
39 {
40 }
41 
42 GeoDataColorStyle::GeoDataColorStyle( const GeoDataColorStyle& other )
43  : GeoDataObject( other ),
44  d( new GeoDataColorStylePrivate( *other.d ) )
45 {
46 }
47 
48 GeoDataColorStyle::~GeoDataColorStyle()
49 {
50  delete d;
51 }
52 
54 {
55  GeoDataObject::operator=( other );
56  *d = *other.d;
57  return *this;
58 }
59 
60 bool GeoDataColorStyle::operator==( const GeoDataColorStyle &other ) const
61 {
62  return equals(other) && d->m_color == other.d->m_color &&
63  d->m_colorMode == other.d->m_colorMode;
64 }
65 
66 bool GeoDataColorStyle::operator!=( const GeoDataColorStyle &other ) const
67 {
68  return !this->operator==(other);
69 }
70 
71 const char* GeoDataColorStyle::nodeType() const
72 {
73  return GeoDataTypes::GeoDataColorStyleType;
74 }
75 
76 void GeoDataColorStyle::setColor( const QColor &value )
77 {
78  d->m_color = value;
79 
80  qreal red = d->m_color.redF();
81  qreal green = d->m_color.greenF();
82  qreal blue = d->m_color.blueF();
83  d->m_randomColor = d->m_color;
84  qreal const randMax = RAND_MAX;
85  d->m_randomColor.setRedF(red*(qrand()/randMax));
86  d->m_randomColor.setGreenF(green*(qrand()/randMax));
87  d->m_randomColor.setBlueF(blue*(qrand()/randMax));
88 }
89 
91 {
92  return d->m_color;
93 }
94 
96 {
97  return d->m_colorMode == Normal ? d->m_color : d->m_randomColor;
98 }
99 
101 {
102  d->m_colorMode = colorMode;
103 }
104 
106 {
107  return d->m_colorMode;
108 }
109 
111 {
112  GeoDataObject::pack( stream );
113 
114  stream << d->m_color;
115  // FIXME: Why is not colorMode saved?
116 // stream << m_colorMode;
117 }
118 
120 {
121  GeoDataObject::unpack( stream );
122 
123  stream >> d->m_color;
124  // FIXME: Why is not colorMode saved?
125  // stream >> m_colorMode;
126 }
127 
129 {
130  return color.valueF() > 0.85 ? QStringLiteral("black") : QStringLiteral("white");
131 }
132 
133 }
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
Binds a QML item to a specific geodetic location in screen coordinates.
void setColor(const QColor &value)
Set a new color.
void pack(QDataStream &stream) const override
Serialize the style to a stream.
ColorMode colorMode() const
Return the color mode.
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
qreal valueF() const const
an abstract base class for various style classes
void setColorMode(ColorMode colorMode)
Set a new color mode.
static QString contrastColor(const QColor &color)
QColor color() const
Return the color component.
const char * nodeType() const override
Provides type information for downcasting a GeoData.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
GeoDataColorStyle & operator=(const GeoDataColorStyle &other)
assignment operator
QColor paintedColor() const
Returns the color that should be painted: Either color() or a randomized version of it...
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Jan 25 2022 23:11:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.