Marble

GeoDataLabelStyle.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2007 Murad Tagirov <[email protected]>
4 //
5 
6 
7 #include "GeoDataLabelStyle.h"
8 
9 #include <QFont>
10 #include <QColor>
11 #include <QDataStream>
12 
13 #include "GeoDataTypes.h"
14 
15 namespace Marble
16 {
17 #ifdef Q_OS_MACX
18 static const int defaultSize = 10;
19 #else
20 static const int defaultSize = 8;
21 #endif
22 
23 
24 class 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 
70 GeoDataLabelStyle::~GeoDataLabelStyle()
71 {
72  delete d;
73 }
74 
76 {
78  *d = *other.d;
79  return *this;
80 }
81 
82 bool 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 
94 bool GeoDataLabelStyle::operator!=( const GeoDataLabelStyle &other ) const
95 {
96  return !this->operator==( other );
97 }
98 
99 const char* GeoDataLabelStyle::nodeType() const
100 {
101  return GeoDataTypes::GeoDataLabelStyleType;
102 }
103 
104 void GeoDataLabelStyle::setAlignment( GeoDataLabelStyle::Alignment alignment )
105 {
106  d->m_alignment = alignment;
107 }
108 
109 GeoDataLabelStyle::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 
142  QFont scaledFont = font();
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;
169  GeoDataColorStyle::unpack( stream );
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 }
void pack(QDataStream &stream) const override
Serialize the style to a stream.
GeoDataLabelStyle::Alignment alignment() const
Return the alignment of the label.
void setPointSize(int pointSize)
int pointSize() const const
QFont scaledFont() const
Return the scaled font of the label.
specifies how the name of a GeoDataFeature is drawn
const char * nodeType() const override
Provides type information for downcasting a GeoData.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
QColor color() const
Return the color component.
void setScale(float scale)
Set the scale of the label.
void setGlow(bool on)
Enable or disable a glow effect around the text of the label.
bool glow() const
Return true if the text of the label should glow, false otherwise.
Binds a QML item to a specific geodetic location in screen coordinates.
GeoDataColorStyle & operator=(const GeoDataColorStyle &other)
assignment operator
GeoDataLabelStyle()
Construct a new GeoDataLabelStyle.
an abstract base class for various style classes
void setAlignment(GeoDataLabelStyle::Alignment alignment)
Set the alignment of the label.
QFont font() const
Return the current font of the label.
GeoDataLabelStyle & operator=(const GeoDataLabelStyle &other)
assignment operator
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
void setColor(const QColor &value)
Set a new color.
float scale() const
Return the current scale of the label.
void pack(QDataStream &stream) const override
Serialize the style to a stream.
void setFont(const QFont &font)
Set the font of the label.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Oct 4 2023 04:09:41 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.