Marble

GeoDataColorStyle.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
4// SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
5//
6
7#include "GeoDataColorStyle.h"
8
9#include "GeoDataTypes.h"
10
11#include <cstdlib>
12#include <QDataStream>
13#include <QColor>
14
15namespace Marble
16{
17
18class 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
35};
36
37GeoDataColorStyle::GeoDataColorStyle()
38 : d( new GeoDataColorStylePrivate )
39{
40}
41
42GeoDataColorStyle::GeoDataColorStyle( const GeoDataColorStyle& other )
43 : GeoDataObject( other ),
44 d( new GeoDataColorStylePrivate( *other.d ) )
45{
46}
47
48GeoDataColorStyle::~GeoDataColorStyle()
49{
50 delete d;
51}
52
53GeoDataColorStyle& GeoDataColorStyle::operator=( const GeoDataColorStyle& other )
54{
55 GeoDataObject::operator=( other );
56 *d = *other.d;
57 return *this;
58}
59
60bool 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
66bool GeoDataColorStyle::operator!=( const GeoDataColorStyle &other ) const
67{
68 return !this->operator==(other);
69}
70
71const char* GeoDataColorStyle::nodeType() const
72{
73 return GeoDataTypes::GeoDataColorStyleType;
74}
75
76void 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
90QColor GeoDataColorStyle::color() const
91{
92 return d->m_color;
93}
94
95QColor GeoDataColorStyle::paintedColor() const
96{
97 return d->m_colorMode == Normal ? d->m_color : d->m_randomColor;
98}
99
100void GeoDataColorStyle::setColorMode(ColorMode colorMode)
101{
102 d->m_colorMode = colorMode;
103}
104
105GeoDataColorStyle::ColorMode GeoDataColorStyle::colorMode() const
106{
107 return d->m_colorMode;
108}
109
110void GeoDataColorStyle::pack( QDataStream& stream ) const
111{
112 GeoDataObject::pack( stream );
113
114 stream << d->m_color;
115 // FIXME: Why is not colorMode saved?
116// stream << m_colorMode;
117}
118
119void GeoDataColorStyle::unpack( QDataStream& stream )
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}
an abstract base class for various style classes
QColor color() const
Return the color component.
static QString contrastColor(const QColor &color)
Binds a QML item to a specific geodetic location in screen coordinates.
qreal valueF() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:44:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.