Marble

GeoDataLabelStyle.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
4//
5
6#include "GeoDataLabelStyle.h"
7
8#include <QColor>
9#include <QDataStream>
10#include <QFont>
11
12#include "GeoDataTypes.h"
13
14namespace Marble
15{
16#ifdef Q_OS_MACX
17static const int defaultSize = 10;
18#else
19static const int defaultSize = 8;
20#endif
21
22class GeoDataLabelStylePrivate
23{
24public:
25 GeoDataLabelStylePrivate()
26 : m_scale(1.0)
27 , m_alignment(GeoDataLabelStyle::Corner)
28 , m_font(QFont(QStringLiteral("Sans Serif")).family(), defaultSize, 50, false)
29 , m_glow(true)
30 {
31 }
32
33 explicit GeoDataLabelStylePrivate(const QFont &font)
34 : m_scale(1.0)
35 , m_alignment(GeoDataLabelStyle::Corner)
36 , m_font(font)
37 , m_glow(true)
38 {
39 }
40
41 /// The current scale of the label
42 float m_scale;
43 /// The current alignment of the label
44 GeoDataLabelStyle::Alignment m_alignment;
45 /// The current font of the label
46 QFont m_font; // Not a KML property
47 /// Whether or not the text should glow
48 bool m_glow; // Not a KML property
49};
50
52 : d(new GeoDataLabelStylePrivate)
53{
55}
56
58 : GeoDataColorStyle(other)
59 , d(new GeoDataLabelStylePrivate(*other.d))
60{
61}
62
64 : d(new GeoDataLabelStylePrivate(font))
65{
67}
68
69GeoDataLabelStyle::~GeoDataLabelStyle()
70{
71 delete d;
72}
73
75{
77 *d = *other.d;
78 return *this;
79}
80
81bool GeoDataLabelStyle::operator==(const GeoDataLabelStyle &other) const
82{
83 if (GeoDataColorStyle::operator!=(other)) {
84 return false;
85 }
86
87 return d->m_scale == other.d->m_scale && d->m_alignment == other.d->m_alignment && d->m_font == other.d->m_font && d->m_glow == other.d->m_glow;
88}
89
90bool GeoDataLabelStyle::operator!=(const GeoDataLabelStyle &other) const
91{
92 return !this->operator==(other);
93}
94
95const char *GeoDataLabelStyle::nodeType() const
96{
97 return GeoDataTypes::GeoDataLabelStyleType;
98}
99
100void GeoDataLabelStyle::setAlignment(GeoDataLabelStyle::Alignment alignment)
101{
102 d->m_alignment = alignment;
103}
104
105GeoDataLabelStyle::Alignment GeoDataLabelStyle::alignment() const
106{
107 return d->m_alignment;
108}
109
111{
112 d->m_scale = scale;
113}
114
116{
117 return d->m_scale;
118}
119
121{
122 d->m_font = font;
123}
124
126{
127 return d->m_font;
128}
129
131{
132 // Font shouldn't be smaller (or equal to) than 0, but if it is, regular font is returned
133 // setPointSize() takes an integer as parameter, so rounded value should be checked
134 if (qRound(font().pointSize() * scale()) <= 0) {
135 return font();
136 }
137
140 return scaledFont;
141}
142
144{
145 return d->m_glow;
146}
147
149{
150 d->m_glow = on;
151}
152
154{
156
157 stream << d->m_scale;
158 stream << d->m_alignment;
159 stream << d->m_font;
160}
161
163{
164 int a;
166
167 stream >> d->m_scale;
168 stream >> a;
169 stream >> d->m_font;
170
171 d->m_alignment = static_cast<GeoDataLabelStyle::Alignment>(a);
172}
173
174}
an abstract base class for various style classes
QColor color() const
Return the color component.
void setColor(const QColor &value)
Set a new color.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
void pack(QDataStream &stream) const override
Serialize the style to a stream.
GeoDataColorStyle & operator=(const GeoDataColorStyle &other)
assignment operator
specifies how the name of a GeoDataFeature is drawn
GeoDataLabelStyle & operator=(const GeoDataLabelStyle &other)
assignment operator
QFont font() const
Return the current font of the label.
float scale() const
Return the current scale of the label.
const char * nodeType() const override
Provides type information for downcasting a GeoData.
GeoDataLabelStyle()
Construct a new GeoDataLabelStyle.
void setAlignment(GeoDataLabelStyle::Alignment alignment)
Set the alignment of the label.
void setScale(float scale)
Set the scale of the label.
QFont scaledFont() const
Return the scaled font of the label.
GeoDataLabelStyle::Alignment alignment() const
Return the alignment of the label.
bool glow() const
Return true if the text of the label should glow, false otherwise.
void pack(QDataStream &stream) const override
Serialize the style to a stream.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
void setGlow(bool on)
Enable or disable a glow effect around the text of the label.
void setFont(const QFont &font)
Set the font of the label.
Binds a QML item to a specific geodetic location in screen coordinates.
int pointSize() const const
void setPointSize(int pointSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.