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

marble

  • sources
  • kde-4.12
  • 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 QString PostalCodeItem::itemType() const
38 {
39  return "postalCodeItem";
40 }
41 
42 bool PostalCodeItem::initialized() const
43 {
44  return !m_text.isEmpty();
45 }
46 
47 bool PostalCodeItem::operator<( const AbstractDataPluginItem *other ) const
48 {
49  return this->id() < other->id();
50 }
51 
52 QString PostalCodeItem::text() const
53 {
54  return m_text;
55 }
56 
57 void PostalCodeItem::setText( const QString& text )
58 {
59  QFontMetrics metrics( s_font );
60  setSize( metrics.size( 0, text ) + QSize( 10, 10 ) );
61  m_text = text;
62 }
63 
64 void PostalCodeItem::paint( QPainter *painter )
65 {
66  painter->save();
67 
68  const int fontAscent = QFontMetrics( s_font ).ascent();
69 
70  QPen outlinepen( Qt::white );
71  outlinepen.setWidthF( s_labelOutlineWidth );
72  QBrush outlinebrush( Qt::black );
73 
74  const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent );
75 
76  QPainterPath outlinepath;
77  outlinepath.addText( baseline, s_font, m_text );
78 
79  painter->setRenderHint( QPainter::Antialiasing, true );
80  painter->setPen( outlinepen );
81  painter->setBrush( outlinebrush );
82  painter->drawPath( outlinepath );
83  painter->setPen( Qt::NoPen );
84  painter->drawPath( outlinepath );
85  painter->setRenderHint( QPainter::Antialiasing, false );
86 
87  painter->restore();
88 }
89 
90 #include "PostalCodeItem.moc"
PostalCodeItem.h
QPainter
Marble::PostalCodeItem::PostalCodeItem
PostalCodeItem(QObject *parent)
Definition: PostalCodeItem.cpp:26
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
Marble::PostalCodeItem::itemType
QString itemType() const
Returns the type of this specific item.
Definition: PostalCodeItem.cpp:37
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
Marble::PostalCodeItem::text
QString text() const
Definition: PostalCodeItem.cpp:52
QObject
Marble::AbstractDataPluginItem::id
QString id() const
Definition: AbstractDataPluginItem.cpp:81
Marble::PostalCodeItem::paint
void paint(QPainter *painter)
Paints the item in item coordinates.
Definition: PostalCodeItem.cpp:64
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
Marble::PostalCodeItem::initialized
bool initialized() const
Definition: PostalCodeItem.cpp:42
Marble::PostalCodeItem::~PostalCodeItem
~PostalCodeItem()
Definition: PostalCodeItem.cpp:33
ViewportParams.h
This file contains the headers for ViewportParams.
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:47
Marble::PostalCodeItem::setText
void setText(const QString &text)
Definition: PostalCodeItem.cpp:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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