File indexing completed on 2024-05-05 03:50:49
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Valery Kharitonov <kharvd@gmail.com> 0004 // 0005 0006 // Self 0007 #include "PostalCodeItem.h" 0008 0009 // Marble 0010 #include "ViewportParams.h" 0011 0012 // Qt 0013 #include <QFontMetrics> 0014 #include <QPainter> 0015 #include <QPainterPath> 0016 0017 using namespace Marble; 0018 0019 const QFont PostalCodeItem::s_font = QFont( QStringLiteral( "Sans Serif" ), 10, QFont::Bold ); 0020 const int PostalCodeItem::s_labelOutlineWidth = 5; 0021 0022 PostalCodeItem::PostalCodeItem( QObject *parent ) 0023 : AbstractDataPluginItem( parent ) 0024 { 0025 setSize( QSize( 0, 0 ) ); 0026 setCacheMode( ItemCoordinateCache ); 0027 } 0028 0029 PostalCodeItem::~PostalCodeItem() 0030 { 0031 } 0032 0033 bool PostalCodeItem::initialized() const 0034 { 0035 return !m_text.isEmpty(); 0036 } 0037 0038 bool PostalCodeItem::operator<( const AbstractDataPluginItem *other ) const 0039 { 0040 return this->id() < other->id(); 0041 } 0042 0043 QString PostalCodeItem::text() const 0044 { 0045 return m_text; 0046 } 0047 0048 void PostalCodeItem::setText( const QString& text ) 0049 { 0050 QFontMetrics metrics( s_font ); 0051 setSize( metrics.size( 0, text ) + QSize( 10, 10 ) ); 0052 m_text = text; 0053 } 0054 0055 void PostalCodeItem::paint( QPainter *painter ) 0056 { 0057 painter->save(); 0058 0059 const int fontAscent = QFontMetrics( s_font ).ascent(); 0060 0061 QPen outlinepen( Qt::white ); 0062 outlinepen.setWidthF( s_labelOutlineWidth ); 0063 QBrush outlinebrush( Qt::black ); 0064 0065 const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent ); 0066 0067 QPainterPath outlinepath; 0068 outlinepath.addText( baseline, s_font, m_text ); 0069 0070 painter->setRenderHint( QPainter::Antialiasing, true ); 0071 painter->setPen( outlinepen ); 0072 painter->setBrush( outlinebrush ); 0073 painter->drawPath( outlinepath ); 0074 painter->setPen( Qt::NoPen ); 0075 painter->drawPath( outlinepath ); 0076 painter->setRenderHint( QPainter::Antialiasing, false ); 0077 0078 painter->restore(); 0079 } 0080 0081 #include "moc_PostalCodeItem.cpp"