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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Utku Aydın <utkuaydin34@gmail.com>
0004 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0005 //
0006 
0007 #include "OpenDesktopItem.h"
0008 #include <QPainter>
0009 #include "ViewportParams.h"
0010 #include "layers/PopupLayer.h"
0011 
0012 #include <QAction>
0013 
0014 using namespace Marble;
0015 
0016 OpenDesktopItem::OpenDesktopItem(QObject *parent):
0017             AbstractDataPluginItem(parent)
0018 {
0019     m_action = new QAction( this );
0020     connect( m_action, SIGNAL(triggered()), this, SLOT(openBrowser()) );
0021     setCacheMode( ItemCoordinateCache );
0022 }
0023  
0024 OpenDesktopItem::~OpenDesktopItem()
0025 {
0026     delete m_action;
0027 }
0028  
0029 bool OpenDesktopItem::initialized() const
0030 {
0031     return size() != QSizeF(-1, -1);
0032 }
0033  
0034 bool OpenDesktopItem::operator<( const AbstractDataPluginItem *other ) const
0035 {
0036     // Custom avatars will have more priority than default ones
0037     QString noAvatar = "http://opendesktop.org/usermanager/nopic.png";
0038     const OpenDesktopItem* item = dynamic_cast<const OpenDesktopItem*>( other );
0039     
0040     if( item )
0041     {
0042         if( this->avatarUrl().toString() == noAvatar && item->avatarUrl().toString() != noAvatar )
0043             return false;
0044         
0045         else if( this->avatarUrl().toString() != noAvatar && item->avatarUrl().toString() == noAvatar )
0046             return true;   
0047     }
0048     
0049     return this > other;
0050 }
0051 
0052 void OpenDesktopItem::addDownloadedFile( const QString& url, const QString& type )
0053 {  
0054     if (type == QLatin1String("avatar")) {
0055         m_pixmap.load( url );
0056         setSize( m_pixmap.size() );
0057         emit updated();
0058     }
0059 }
0060 
0061 void OpenDesktopItem::paint( QPainter *painter )
0062 {
0063     painter->drawPixmap(0, 0, m_pixmap);  
0064 }
0065 
0066 void OpenDesktopItem::updateToolTip()
0067 {
0068     const QString toolTip = QLatin1String(
0069         "<html><head><meta name='qrichtext' content='1' />"
0070         "<style type='text/css'>"
0071         "body { font-family:'Sans Serif'; font-size:9pt; font-weight:400; }"
0072         "np, li { white-space: pre-wrap; }"
0073         "p { margin: 0; -qt-block-indent:0; text-indent:0px }"
0074         "</style></head><body><table>"
0075         "<tr><td align='right'>Fullname:</td><td>%1</td></tr>"
0076         "<tr><td align='right'>Location:</td><td>%2</td></tr>"
0077         "<tr><td align='right'>Role:</td><td>%3</td></tr>"
0078         "</table></body></html>");
0079     setToolTip( toolTip.arg( fullName() ).arg( location() ).arg( role() ) );
0080 }
0081 
0082 QAction *OpenDesktopItem::action()
0083 {
0084     m_action->setText( id() );
0085     return m_action;
0086 }
0087 
0088 void OpenDesktopItem::openBrowser()
0089 {
0090     PopupLayer *popup = m_marbleWidget->popupLayer();
0091     popup->setCoordinates( coordinate(), Qt::AlignRight | Qt::AlignVCenter );
0092     popup->setUrl( profileUrl() );
0093     popup->setSize( QSizeF( 900, 600 ) );
0094     popup->popup();
0095 }
0096 
0097 QUrl OpenDesktopItem::profileUrl() const
0098 {
0099    return QUrl( QString( "http://opendesktop.org/usermanager/search.php?username=%1" ).arg( id() ) );
0100 }
0101 
0102 QUrl OpenDesktopItem::avatarUrl() const
0103 {
0104     return m_avatarUrl;
0105 }
0106    
0107 void OpenDesktopItem::setAvatarUrl( const QUrl& url )
0108 {
0109     m_avatarUrl = url;
0110 }
0111 
0112 QString OpenDesktopItem::fullName() const
0113 {
0114     return m_fullName;
0115 }
0116    
0117 void OpenDesktopItem::setFullName( const QString& fullName )
0118 {
0119     m_fullName = fullName;
0120     updateToolTip();
0121 }
0122 
0123 QString OpenDesktopItem::location() const
0124 {
0125     return m_location;
0126 }
0127 
0128 void OpenDesktopItem::setLocation( const QString& location )
0129 {
0130     m_location = location;
0131     updateToolTip();
0132 }
0133 
0134 QString OpenDesktopItem::role() const
0135 {
0136     return m_role;
0137 }
0138 
0139 void OpenDesktopItem::setRole( const QString& role )
0140 {
0141     m_role = role;
0142     updateToolTip();
0143 }
0144 
0145 void OpenDesktopItem::setMarbleWidget(MarbleWidget *widget)
0146 {
0147     m_marbleWidget = widget;
0148 }
0149 
0150 // This is needed for all QObjects (see MOC)
0151 #include "moc_OpenDesktopItem.cpp"