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
7#include "GeoDataLabelStyle.h"
8
9#include <QFont>
10#include <QColor>
11#include <QDataStream>
12
13#include "GeoDataTypes.h"
14
15namespace Marble
16{
17#ifdef Q_OS_MACX
18static const int defaultSize = 10;
19#else
20static const int defaultSize = 8;
21#endif
22
23
24class GeoDataLabelStylePrivate
25{
26 public:
27 GeoDataLabelStylePrivate()
28 : m_scale( 1.0 ),
29 m_alignment( GeoDataLabelStyle::Corner ),
30 m_font( QFont(QStringLiteral("Sans Serif")).family(), defaultSize, 50, false ),
31 m_glow( true )
32 {
33 }
34
35 explicit GeoDataLabelStylePrivate( const QFont &font )
36 : m_scale( 1.0 ),
37 m_alignment( GeoDataLabelStyle::Corner ),
38 m_font( font ),
39 m_glow( true )
40 {
41 }
42
43 /// The current scale of the label
44 float m_scale;
45 /// The current alignment of the label
46 GeoDataLabelStyle::Alignment m_alignment;
47 /// The current font of the label
48 QFont m_font; // Not a KML property
49 /// Whether or not the text should glow
50 bool m_glow; // Not a KML property
51};
52
54 : d (new GeoDataLabelStylePrivate )
55{
57}
58
60 : GeoDataColorStyle( other ), d (new GeoDataLabelStylePrivate( *other.d ) )
61{
62}
63
65 : d (new GeoDataLabelStylePrivate( font ) )
66{
67 setColor( color );
68}
69
70GeoDataLabelStyle::~GeoDataLabelStyle()
71{
72 delete d;
73}
74
76{
78 *d = *other.d;
79 return *this;
80}
81
82bool GeoDataLabelStyle::operator==( const GeoDataLabelStyle &other ) const
83{
84 if ( GeoDataColorStyle::operator!=( other ) ) {
85 return false;
86 }
87
88 return d->m_scale == other.d->m_scale &&
89 d->m_alignment == other.d->m_alignment &&
90 d->m_font == other.d->m_font &&
91 d->m_glow == other.d->m_glow;
92}
93
94bool GeoDataLabelStyle::operator!=( const GeoDataLabelStyle &other ) const
95{
96 return !this->operator==( other );
97}
98
99const char* GeoDataLabelStyle::nodeType() const
100{
101 return GeoDataTypes::GeoDataLabelStyleType;
102}
103
104void GeoDataLabelStyle::setAlignment( GeoDataLabelStyle::Alignment alignment )
105{
106 d->m_alignment = alignment;
107}
108
109GeoDataLabelStyle::Alignment GeoDataLabelStyle::alignment() const
110{
111 return d->m_alignment;
112}
113
115{
116 d->m_scale = scale;
117}
118
120{
121 return d->m_scale;
122}
123
125{
126 d->m_font = font;
127}
128
130{
131 return d->m_font;
132}
133
135{
136 // Font shouldn't be smaller (or equal to) than 0, but if it is, regular font is returned
137 // setPointSize() takes an integer as parameter, so rounded value should be checked
138 if( qRound( font().pointSize() * scale() ) <= 0 ) {
139 return font();
140 }
141
144 return scaledFont;
145}
146
148{
149 return d->m_glow;
150}
151
153{
154 d->m_glow = on;
155}
156
158{
159 GeoDataColorStyle::pack( stream );
160
161 stream << d->m_scale;
162 stream << d->m_alignment;
163 stream << d->m_font;
164}
165
167{
168 int a;
170
171 stream >> d->m_scale;
172 stream >> a;
173 stream >> d->m_font;
174
175 d->m_alignment = static_cast<GeoDataLabelStyle::Alignment>( a );
176}
177
178}
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.