File indexing completed on 2024-05-05 03:50:44

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Utku Aydın <utkuaydin34@gmail.com>
0004 //
0005 
0006 #include "FoursquareItem.h"
0007 #include "GeoPainter.h"
0008 #include "ViewportParams.h"
0009 
0010 #include <QFontMetrics>
0011 #include <QPainterPath>
0012  
0013 namespace Marble
0014 {
0015 
0016 QFont FoursquareItem::s_font = QFont( QStringLiteral( "Sans Serif" ), 8 );
0017 
0018 FoursquareItem::FoursquareItem(QObject* parent)
0019     : AbstractDataPluginItem( parent ),
0020     m_usersCount( 0 )
0021 {
0022     setSize( QSize( 0, 0 ) );
0023 }
0024 
0025 FoursquareItem::~FoursquareItem()
0026 {
0027 }
0028 
0029 bool FoursquareItem::initialized() const
0030 {
0031     // Find something logical for this
0032     return true;
0033 }
0034  
0035 bool FoursquareItem::operator<( const AbstractDataPluginItem *other ) const
0036 {
0037     const FoursquareItem* item = dynamic_cast<const FoursquareItem*>( other );
0038     return item && this->usersCount() > item->usersCount();
0039 }
0040 
0041 QString FoursquareItem::name() const
0042 {
0043     return m_name;
0044 }
0045 
0046 void FoursquareItem::setName(const QString& name)
0047 {
0048     if( name != m_name ) {
0049         m_name = name;
0050         QFontMetrics const fontMetrics( s_font );
0051         setSize( QSizeF( fontMetrics.horizontalAdvance( m_name ) + 10, fontMetrics.height() + 10 ) );
0052         emit nameChanged();
0053     }
0054 }
0055 
0056 QString FoursquareItem::category() const
0057 {
0058     return m_category;
0059 }
0060 
0061 void FoursquareItem::setCategory(const QString& category)
0062 {
0063     if( category != m_category ) {
0064         m_category = category;
0065         emit categoryChanged();
0066     }
0067 }
0068 
0069 QString FoursquareItem::address() const
0070 {
0071     return m_address;
0072 }
0073 
0074 void FoursquareItem::setAddress(const QString& address)
0075 {
0076     if( address != m_address ) {
0077         m_address = address;
0078         emit addressChanged();
0079     }
0080 }
0081 
0082 QString FoursquareItem::city() const
0083 {
0084     return m_city;
0085 }
0086 void FoursquareItem::setCity(const QString& city)
0087 {
0088     if( city != m_city ) {
0089         m_city = city;
0090         emit cityChanged();
0091     }
0092 }
0093 
0094 QString FoursquareItem::country() const
0095 {
0096     return m_country;
0097 }
0098 
0099 void FoursquareItem::setCountry(const QString& country)
0100 {
0101     if( country != m_country ) {
0102         m_country = country;
0103         emit countryChanged();
0104     }
0105 }
0106 
0107 int FoursquareItem::usersCount() const
0108 {
0109     return m_usersCount;
0110 }
0111 
0112 void FoursquareItem::setUsersCount(const int count)
0113 {
0114     if( count != m_usersCount ) {
0115         m_usersCount = count;
0116         emit usersCountChanged();
0117     }
0118 }
0119 
0120 QString FoursquareItem::categoryIconUrl() const
0121 {
0122     return m_categoryIconUrl;
0123 }
0124 
0125 void FoursquareItem::setCategoryIconUrl(const QString& url)
0126 {
0127     if( url != m_categoryIconUrl ) {
0128         m_categoryIconUrl = url;
0129         emit categoryIconUrlChanged();
0130     }
0131 }
0132 
0133 QString FoursquareItem::categoryLargeIconUrl() const
0134 {
0135     return m_categoryLargeIconUrl;
0136 }
0137 
0138 void FoursquareItem::setCategoryLargeIconUrl(const QString& url)
0139 {
0140     if( url != m_categoryLargeIconUrl ) {
0141         m_categoryLargeIconUrl = url;
0142         emit categoryLargeIconUrlChanged();
0143     }
0144 }
0145 
0146 void FoursquareItem::paint( QPainter* painter )
0147 {   
0148     // Save the old painter state.
0149     painter->save();
0150     painter->setPen( QPen( QColor( Qt::white ) ) );
0151     painter->setFont( s_font );
0152     
0153     // Draw the text into the given rect.
0154     QRect rect = QRect( QPoint( 0, 0 ), size().toSize() );
0155     QRect boundingRect = QRect( QPoint( rect.top(), rect.left() ), QSize( rect.width(), rect.height() ) );
0156     QPainterPath painterPath;
0157     painterPath.addRoundedRect( boundingRect, 5, 5 );
0158     painter->setClipPath( painterPath );
0159     painter->drawPath( painterPath );
0160     painter->fillPath( painterPath, QBrush( QColor( "#39AC39" ) ) );
0161     painter->drawText( rect.adjusted( 5, 5, -5, -5 ), 0, m_name );
0162     
0163     painter->restore();
0164 }
0165 
0166 }
0167 
0168 #include "moc_FoursquareItem.cpp"