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 <QColor>
12#include <QDataStream>
13#include <QRandomGenerator>
14#include <cstdlib>
15
16namespace Marble
17{
18
19class GeoDataColorStylePrivate
20{
21public:
22 GeoDataColorStylePrivate()
23 : m_color(Qt::white)
24 , m_colorMode(GeoDataColorStyle::Normal)
25 {
26 }
27
28 /// stores the current color
29 QColor m_color;
30
31 /// stores random color
32 QColor m_randomColor;
33
34 /// stores the current color mode
36};
37
38GeoDataColorStyle::GeoDataColorStyle()
39 : d(new GeoDataColorStylePrivate)
40{
41}
42
43GeoDataColorStyle::GeoDataColorStyle(const GeoDataColorStyle &other)
44 : GeoDataObject(other)
45 , d(new GeoDataColorStylePrivate(*other.d))
46{
47}
48
49GeoDataColorStyle::~GeoDataColorStyle()
50{
51 delete d;
52}
53
54GeoDataColorStyle &GeoDataColorStyle::operator=(const GeoDataColorStyle &other)
55{
56 GeoDataObject::operator=(other);
57 *d = *other.d;
58 return *this;
59}
60
61bool GeoDataColorStyle::operator==(const GeoDataColorStyle &other) const
62{
63 return equals(other) && d->m_color == other.d->m_color && 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 * (QRandomGenerator::global()->generate() / randMax));
86 d->m_randomColor.setGreenF(green * (QRandomGenerator::global()->generate() / randMax));
87 d->m_randomColor.setBlueF(blue * (QRandomGenerator::global()->generate() / 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.
float valueF() const const
QRandomGenerator * global()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.