• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • postalcode
PostalCodeItem.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Valery Kharitonov <kharvd@gmail.com>
9 //
10 
11 // Self
12 #include "PostalCodeItem.h"
13 
14 // Marble
15 #include "ViewportParams.h"
16 
17 // Qt
18 #include <QFontMetrics>
19 #include <QPainter>
20 
21 using namespace Marble;
22 
23 const QFont PostalCodeItem::s_font = QFont( "Sans Serif", 10, QFont::Bold );
24 const int PostalCodeItem::s_labelOutlineWidth = 5;
25 
26 PostalCodeItem::PostalCodeItem( QObject *parent )
27  : AbstractDataPluginItem( parent )
28 {
29  setSize( QSize( 0, 0 ) );
30  setCacheMode( ItemCoordinateCache );
31 }
32 
33 PostalCodeItem::~PostalCodeItem()
34 {
35 }
36 
37 bool PostalCodeItem::initialized() const
38 {
39  return !m_text.isEmpty();
40 }
41 
42 bool PostalCodeItem::operator<( const AbstractDataPluginItem *other ) const
43 {
44  return this->id() < other->id();
45 }
46 
47 QString PostalCodeItem::text() const
48 {
49  return m_text;
50 }
51 
52 void PostalCodeItem::setText( const QString& text )
53 {
54  QFontMetrics metrics( s_font );
55  setSize( metrics.size( 0, text ) + QSize( 10, 10 ) );
56  m_text = text;
57 }
58 
59 void PostalCodeItem::paint( QPainter *painter )
60 {
61  painter->save();
62 
63  const int fontAscent = QFontMetrics( s_font ).ascent();
64 
65  QPen outlinepen( Qt::white );
66  outlinepen.setWidthF( s_labelOutlineWidth );
67  QBrush outlinebrush( Qt::black );
68 
69  const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent );
70 
71  QPainterPath outlinepath;
72  outlinepath.addText( baseline, s_font, m_text );
73 
74  painter->setRenderHint( QPainter::Antialiasing, true );
75  painter->setPen( outlinepen );
76  painter->setBrush( outlinebrush );
77  painter->drawPath( outlinepath );
78  painter->setPen( Qt::NoPen );
79  painter->drawPath( outlinepath );
80  painter->setRenderHint( QPainter::Antialiasing, false );
81 
82  painter->restore();
83 }
84 
85 #include "PostalCodeItem.moc"
PostalCodeItem.h
Marble::PostalCodeItem::PostalCodeItem
PostalCodeItem(QObject *parent)
Definition: PostalCodeItem.cpp:26
QFontMetrics::ascent
int ascent() const
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
QFont
QPainter::save
void save()
QBrush
Marble::PostalCodeItem::text
QString text() const
Definition: PostalCodeItem.cpp:47
QFontMetrics
QPainterPath::addText
void addText(const QPointF &point, const QFont &font, const QString &text)
Marble::AbstractDataPluginItem::id
QString id() const
Definition: AbstractDataPluginItem.cpp:81
QPointF
QObject
QPainter::setPen
void setPen(const QColor &color)
Marble::PostalCodeItem::paint
void paint(QPainter *painter)
Paints the item in item coordinates.
Definition: PostalCodeItem.cpp:59
QPainter
QString::isEmpty
bool isEmpty() const
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
QPen::setWidthF
void setWidthF(qreal width)
QPainter::setBrush
void setBrush(const QBrush &brush)
QString
Marble::PostalCodeItem::initialized
bool initialized() const
Definition: PostalCodeItem.cpp:37
QSize
Marble::PostalCodeItem::~PostalCodeItem
~PostalCodeItem()
Definition: PostalCodeItem.cpp:33
ViewportParams.h
This file contains the headers for ViewportParams.
QPainter::restore
void restore()
QPainterPath
QPainter::drawPath
void drawPath(const QPainterPath &path)
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
Marble::PostalCodeItem::operator<
bool operator<(const AbstractDataPluginItem *other) const
Definition: PostalCodeItem.cpp:42
QPen
QFontMetrics::size
QSize size(int flags, const QString &text, int tabStops, int *tabArray) const
Marble::PostalCodeItem::setText
void setText(const QString &text)
Definition: PostalCodeItem.cpp:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal