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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 // Self
0007 #include "PanoramioItem.h"
0008 
0009 // Marble
0010 #include "MarbleDebug.h"
0011 #include "MarbleWidget.h"
0012 #include "layers/PopupLayer.h"
0013 
0014 #include <QAction>
0015 #include <QPainter>
0016 
0017 using namespace Marble;
0018 
0019 PanoramioItem::PanoramioItem( MarbleWidget *marbleWidget, QObject *parent ) :
0020     AbstractDataPluginItem( parent ),
0021     m_marbleWidget( marbleWidget )
0022 {
0023     m_action = new QAction( this );
0024     connect( m_action, SIGNAL(triggered()), this, SLOT(openBrowser()) );
0025 }
0026 
0027 bool PanoramioItem::initialized() const
0028 {
0029     return !smallImage.isNull();
0030 }
0031 
0032 void PanoramioItem::addDownloadedFile( const QString &url, const QString &type )
0033 {
0034     if( standardImageSize == type ) {
0035         // Loading original image
0036         QImage largeImage;
0037         largeImage.load( url );
0038 
0039         // Scaling the image to the half of the original size
0040         smallImage = largeImage.scaled( largeImage.size() / 3,
0041                                         Qt::IgnoreAspectRatio,
0042                                         Qt::SmoothTransformation );
0043         setSize( smallImage.size() );
0044         update();
0045     }
0046     else {
0047         mDebug() << "can't handle type" << type;
0048     }
0049 }
0050 
0051 void PanoramioItem::setPhotoUrl( const QUrl &url )
0052 {
0053     m_url = url;
0054 }
0055 
0056 QDate PanoramioItem::uploadDate() const
0057 {
0058     return m_uploadDate;
0059 }
0060 
0061 void PanoramioItem::setUploadDate( const QDate &uploadDate )
0062 {
0063     m_uploadDate = uploadDate;
0064 }
0065 
0066 bool PanoramioItem::operator<( const AbstractDataPluginItem *other ) const
0067 {
0068     Q_ASSERT( dynamic_cast<const PanoramioItem *>( other ) != 0 );
0069 
0070     return uploadDate() > static_cast<const PanoramioItem *>( other )->uploadDate();
0071 }
0072 
0073 void PanoramioItem::paint( QPainter *painter )
0074 {
0075     painter->drawImage( 0, 0, smallImage );
0076 }
0077 
0078 QAction *Marble::PanoramioItem::action()
0079 {
0080     if( m_action->icon().isNull() ) {
0081         m_action->setIcon( QIcon( QPixmap::fromImage( smallImage ) ) );
0082     }
0083 
0084     return m_action;
0085 }
0086 
0087 void PanoramioItem::openBrowser()
0088 {
0089     if ( m_marbleWidget ) {
0090         PopupLayer* popup = m_marbleWidget->popupLayer();
0091         popup->setCoordinates( coordinate(), Qt::AlignRight | Qt::AlignVCenter );
0092         popup->setSize(QSizeF(720, 470));
0093         popup->setUrl( m_url );
0094         popup->popup();
0095     }
0096 }
0097 
0098 #include "moc_PanoramioItem.cpp"