Git commit 0da397249f895a5b036166d966ce03f2cf601243 by Kevin Funk. Committed on 25/08/2011 at 16:03. Pushed by kfunk into branch 'master'.
Add covergrid applet to playground/ Fixed some minor issues while applying the patch * Whitespace fixes * Added missing copyright headers to AlbumItem.(cpp|h) * Adapt API changes: Fix invalid signal/slot connection Courtesy of Emmanuel Wagner <manu.wagner at sfr.fr> REVIEW: 100841 GUI: A +45 -0 playground/src/context/applets/covergrid/CoverGridSettings.ui A +44 -0 playground/src/context/applets/covergrid/AlbumItem.h [License: GPL (v2+)] A +65 -0 playground/src/context/applets/covergrid/CoverGridApplet.h [License: GPL (v2+)] A +20 -0 playground/src/context/applets/covergrid/amarok-context-applet-covergrid.desktop A +25 -0 playground/src/context/applets/covergrid/CMakeLists.txt A +181 -0 playground/src/context/applets/covergrid/CoverGridApplet.cpp [License: GPL (v2+)] A +83 -0 playground/src/context/applets/covergrid/AlbumItem.cpp [License: GPL (v2+)] M +1 -0 playground/src/context/applets/CMakeLists.txt http://commits.kde.org/amarok/0da397249f895a5b036166d966ce03f2cf601243 diff --git a/playground/src/context/applets/CMakeLists.txt b/playground/src/context/applets/CMakeLists.txt index 44760ea..5b47765 100644 --- a/playground/src/context/applets/CMakeLists.txt +++ b/playground/src/context/applets/CMakeLists.txt @@ -1,2 +1,3 @@ #add_subdirectory( cloud ) add_subdirectory( coverbling ) +add_subdirectory( covergrid ) diff --git a/playground/src/context/applets/covergrid/AlbumItem.cpp b/playground/src/context/applets/covergrid/AlbumItem.cpp new file mode 100644 index 0000000..9d9ac69 --- /dev/null +++ b/playground/src/context/applets/covergrid/AlbumItem.cpp @@ -0,0 +1,83 @@ +/**************************************************************************************** + * Copyright (c) 2011 Emmanuel Wagner <manu.wagner at sfr.fr> * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see <http://www.gnu.org/licenses/>. * + ****************************************************************************************/ + +#include "AlbumItem.h" +// Amarok +#include "playlist/PlaylistModelStack.h" +#include "core/meta/Meta.h" +#include "playlist/PlaylistController.h" +// Qt +#include <QGraphicsPixmapItem> +#include <QStyleOptionGraphicsItem> +#include <QPaintEvent> +#include <QPainter> +#include <QPalette> +#include <QImage> +// Other +#include <math.h> + + +AlbumItem::AlbumItem( const QPixmap & pixmap, Meta::AlbumPtr album , QWidget * parent, Qt::WindowFlags f ) + + : QLabel( parent, f ) +{ + m_album = album; + m_pixmap = pixmap; + setPixmap( pixmap ); + m_size = pixmap.height(); + setMouseTracking( true ); + setDisabled( false ); + if( album ) + { + Meta::ArtistPtr artist = album->albumArtist(); + QString label = album->prettyName(); + if( artist ) label += " - " + artist->prettyName(); + setToolTip( label ); + } +} + +Meta::AlbumPtr AlbumItem::getAlbum() +{ + return m_album; +} +void AlbumItem::mousePressEvent( QMouseEvent * event ) +{ + Q_UNUSED( event ) +} +void AlbumItem::mouseDoubleClickEvent( QMouseEvent * event ) +{ + Q_UNUSED( event ) + The::playlistController()->insertOptioned( m_album->tracks(), Playlist::AppendAndPlay ); +} +void AlbumItem::leaveEvent( QEvent * event ) +{ + setPixmap( m_pixmap ); +} +void AlbumItem::enterEvent( QEvent * event ) +{ + Q_UNUSED( event ) + QImage image = m_pixmap.toImage(); + QPixmap transparent( image.size() ); + transparent.fill( Qt::transparent ); + QPainter p; + p.begin( &transparent ); + p.setCompositionMode( QPainter::CompositionMode_Source ); + p.drawPixmap( 0, 0, QPixmap::fromImage( image ) ); + p.setCompositionMode( QPainter::CompositionMode_DestinationIn ); + p.fillRect( transparent.rect(), QColor( 0, 0, 0, 150 ) ); + p.end(); + setPixmap( transparent ); +} diff --git a/playground/src/context/applets/covergrid/AlbumItem.h b/playground/src/context/applets/covergrid/AlbumItem.h new file mode 100644 index 0000000..1f4df0f --- /dev/null +++ b/playground/src/context/applets/covergrid/AlbumItem.h @@ -0,0 +1,44 @@ +/**************************************************************************************** + * Copyright (c) 2011 Emmanuel Wagner <manu.wagner at sfr.fr> * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see <http://www.gnu.org/licenses/>. * + ****************************************************************************************/ + +#include "core/meta/Meta.h" + +#include <QLabel> + +class QMouseEvent; +class QStyleOptionGraphicsItem; +class QPaintEvent; +class QEvent; + +class AlbumItem : public QLabel +{ + Q_OBJECT + +public: + AlbumItem( const QPixmap & pixmap, Meta::AlbumPtr album, QWidget * parent = 0, Qt::WindowFlags f = 0 ); + Meta::AlbumPtr getAlbum(); + +protected : + void mousePressEvent( QMouseEvent * event ); + void leaveEvent( QEvent * event); + void enterEvent( QEvent * event); + void mouseDoubleClickEvent( QMouseEvent * event ); + +private: + Meta::AlbumPtr m_album; + int m_size; + QPixmap m_pixmap; +}; diff --git a/playground/src/context/applets/covergrid/CMakeLists.txt b/playground/src/context/applets/covergrid/CMakeLists.txt new file mode 100644 index 0000000..0f08454 --- /dev/null +++ b/playground/src/context/applets/covergrid/CMakeLists.txt @@ -0,0 +1,25 @@ +project(context-covergrid) + +set(covergrid_SRCS + CoverGridApplet.cpp + AlbumItem.cpp +) + +include_directories( ../../.. + ../.. + ${KDE4_INCLUDE_DIR}/amarok # this way we don't need to prefix it with amarok/ (and it compiles this way too :) +) + +kde4_add_ui_files( covergrid_SRCS CoverGridSettings.ui ) +kde4_add_plugin(amarok_context_applet_covergrid ${covergrid_SRCS}) + + +target_link_libraries(amarok_context_applet_covergrid + amarokcore + amaroklib + ${KDE4_PLASMA_LIBS} + ${KDE4_KIO_LIBS} +) + +install(TARGETS amarok_context_applet_covergrid DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES amarok-context-applet-covergrid.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/playground/src/context/applets/covergrid/CoverGridApplet.cpp b/playground/src/context/applets/covergrid/CoverGridApplet.cpp new file mode 100644 index 0000000..2432df6 --- /dev/null +++ b/playground/src/context/applets/covergrid/CoverGridApplet.cpp @@ -0,0 +1,181 @@ +/**************************************************************************************** + * Copyright (c) 2011 Emmanuel Wagner <manu.wagner at sfr.fr> * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see <http://www.gnu.org/licenses/>. * + ****************************************************************************************/ + +#define DEBUG_PREFIX "CoverGridApplet" + +#include "CoverGridApplet.h" +#include "AlbumItem.h" +// Amarok +#include "core/support/Amarok.h" +#include "EngineController.h" +#include "core/support/Debug.h" +#include "context/ContextView.h" +#include "core/collections/Collection.h" +#include "core-impl/collections/support/CollectionManager.h" +#include "playlist/PlaylistModelStack.h" +#include "playlist/PlaylistController.h" +// KDE +#include <KAction> +#include <KColorScheme> +#include <KConfigDialog> +#include <KGlobalSettings> +#include <Plasma/ScrollWidget> +#include "covermanager/CoverCache.h" +#include <KStandardDirs> +// Qt +#include <QGraphicsLinearLayout> +#include <QGraphicsProxyWidget> +#include <QGraphicsSimpleTextItem> +#include <QGraphicsWidget> +#include <QLabel> +#include <QPixmap> +#include <QGraphicsPixmapItem> +#include <QGraphicsGridLayout> + + +CoverGridApplet::CoverGridApplet( QObject* parent, const QVariantList& args ) + : Context::Applet( parent, args ) +{ + DEBUG_BLOCK + + setHasConfigurationInterface( true ); +} + +void +CoverGridApplet::init() +{ + // Call the base implementation. + Context::Applet::init(); + setBackgroundHints( Plasma::Applet::NoBackground ); + + KConfigGroup config = Amarok::config( "CoverGrid Applet" ); + m_coversize = config.readEntry( "CoverSize", 70 ); + + QGraphicsLinearLayout* lay = new QGraphicsLinearLayout( Qt::Vertical ); + setLayout( lay ); + m_scroll = new Plasma::ScrollWidget( this ); + m_scroll->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + m_scroll->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + m_scroll->show(); + + m_proxywidget = new QGraphicsProxyWidget( this ) ; + m_layout = new QGraphicsGridLayout( m_proxywidget ); + m_layout->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + + setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + // create a scroll Area + m_scroll->setWidget( m_proxywidget ); + lay->addItem( m_scroll ); + + Collections::Collection *coll = CollectionManager::instance()->primaryCollection(); + Collections::QueryMaker *qm = coll->queryMaker(); + qm->setAutoDelete( true ); + qm->setQueryType( Collections::QueryMaker::Album ); + qm->orderBy( Meta::valArtist ); + + connect( qm, SIGNAL( newResultReady( Meta::AlbumList ) ), + this, SLOT( slotAlbumQueryResult( Meta::AlbumList ) ) ); + qm->run(); +} + +CoverGridApplet::~CoverGridApplet() +{ + delete m_proxywidget; +} + +void CoverGridApplet::slotAlbumQueryResult( Meta::AlbumList albums ) //SLOT +{ + DEBUG_BLOCK + + m_album_list = albums; + prepareLayout(); +} + +void CoverGridApplet::appendAlbum( int islideindex ) +{ + Meta::AlbumPtr album = m_album_list[islideindex]; + if( album ) + { + The::playlistController()->insertOptioned( album->tracks(), Playlist::AppendAndPlay ); + } + +} +void CoverGridApplet::createConfigurationInterface( KConfigDialog *parent ) +{ + KConfigGroup configuration = config(); + QWidget * const settings = new QWidget; + ui_Settings.setupUi( settings ); + if( m_coversize ) + ui_Settings.coversizeSpin->setValue( m_coversize ); + parent->addPage( settings, i18n( "Covergrid Settings" ), "preferences-system" ); + connect( parent, SIGNAL( accepted() ), this, SLOT( saveSettings( ) ) ); +} +bool +CoverGridApplet::hasHeightForWidth() const +{ + return false; +} +void CoverGridApplet::saveSettings() +{ + m_coversize = ui_Settings.coversizeSpin->value(); + KConfigGroup config = Amarok::config( "CoverGrid Applet" ); + config.writeEntry( "CoverSize", m_coversize ); + prepareLayout(); +} +void CoverGridApplet::prepareLayout() +{ + int nb_prev = m_layout->count(); + for( int i = nb_prev - 1; i >= 0; i-- ) m_layout->removeAt( i ); + m_layout->invalidate(); + + const int vertical_size = boundingRect().height(); + const int horizontal_size = boundingRect().width(); + int x_pos = 0; + int y_pos = 0; + int nb_albums = m_album_list.size(); + int nbcolumns = horizontal_size / m_coversize; + for( int index = 0; index < nb_albums; index++ ) + { + Meta::AlbumPtr album = m_album_list[index]; + QPixmap pixmap; + if( album->hasImage() ) + { + pixmap = The::coverCache()->getCover( album, m_coversize ); + } + else + { + pixmap = QPixmap( KStandardDirs::locate( "data", "amarok/images/nocover.png" ) ); + QImage image = pixmap.toImage(); + image = image.scaled( QSize( m_coversize, m_coversize ), Qt::KeepAspectRatio, Qt::SmoothTransformation ); + pixmap = QPixmap::fromImage( image ); + } + + QGraphicsProxyWidget* proxywidget = new QGraphicsProxyWidget( this ) ; + + AlbumItem *pixmap_widget = new AlbumItem( pixmap, album ); + proxywidget->setWidget( pixmap_widget ); + m_layout->addItem( proxywidget, y_pos, x_pos, 0 ); + x_pos ++; + + if( x_pos > nbcolumns ) + { + x_pos = 0; y_pos++; + } + } + m_layout->activate(); +} + +#include "CoverGridApplet.moc" diff --git a/playground/src/context/applets/covergrid/CoverGridApplet.h b/playground/src/context/applets/covergrid/CoverGridApplet.h new file mode 100644 index 0000000..3e41ca7 --- /dev/null +++ b/playground/src/context/applets/covergrid/CoverGridApplet.h @@ -0,0 +1,65 @@ +/**************************************************************************************** + * Copyright (c) 2011 Emmanuel Wagner <manu.wagner at sfr.fr> * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see <http://www.gnu.org/licenses/>. * + ****************************************************************************************/ + +#ifndef COVERGRID_APPLET_H +#define COVERGRID_APPLET_H + +#include "context/Applet.h" +#include "ui_CoverGridSettings.h" +#include "core/meta/Meta.h" + +class KConfigDialog; +class QGraphicsProxyWidget; +class QGraphicsGridLayout; + +namespace Plasma +{ + class ScrollWidget; +} + +class CoverGridApplet : public Context::Applet +{ + Q_OBJECT + + public: + CoverGridApplet( QObject* parent, const QVariantList& args ); + ~CoverGridApplet(); + + void init(); + bool hasHeightForWidth() const; + + public slots: + void slotAlbumQueryResult( Meta::AlbumList albums); + void appendAlbum( int islideindex ); + void saveSettings(); + + protected : + void createConfigurationInterface(KConfigDialog *parent); + + private: + void prepareLayout(); + + QGraphicsProxyWidget * m_proxywidget; + Plasma::ScrollWidget *m_scroll; + QGraphicsGridLayout * m_layout; + Meta::AlbumList m_album_list; + Ui::CoverGridSettings ui_Settings; + int m_coversize; +}; + +AMAROK_EXPORT_APPLET( covergrid, CoverGridApplet ) + +#endif /* COVERGRID_APPLET_H */ diff --git a/playground/src/context/applets/covergrid/CoverGridSettings.ui b/playground/src/context/applets/covergrid/CoverGridSettings.ui new file mode 100644 index 0000000..3d79172 --- /dev/null +++ b/playground/src/context/applets/covergrid/CoverGridSettings.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CoverGridSettings</class> + <widget class="QWidget" name="coverGridSettings"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>265</width> + <height>66</height> + </rect> + </property> + <widget class="QLabel" name="label_3"> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>101</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>Cover size (pixels)</string> + </property> + </widget> + <widget class="QSpinBox" name="coversizeSpin"> + <property name="geometry"> + <rect> + <x>120</x> + <y>20</y> + <width>51</width> + <height>21</height> + </rect> + </property> + <property name="minimum"> + <number>10</number> + </property> + <property name="maximum"> + <number>500</number> + </property> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/playground/src/context/applets/covergrid/amarok-context-applet-covergrid.desktop b/playground/src/context/applets/covergrid/amarok-context-applet-covergrid.desktop new file mode 100644 index 0000000..f878c01 --- /dev/null +++ b/playground/src/context/applets/covergrid/amarok-context-applet-covergrid.desktop @@ -0,0 +1,20 @@ + +[Desktop Entry] +Encoding=UTF-8 +Name=CoverGrid +Type=Service +ServiceTypes=Plasma/Applet + +X-KDE-Library=amarok_context_applet_covergrid +X-KDE-PluginInfo-Author=manuw2009 +X-KDE-PluginInfo-Email=manu.wagner at sfr.fr +X-KDE-PluginInfo-Name=covergrid +X-KDE-PluginInfo-Version=0.10 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category= +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-ParentApp=amarok +X-KDE-PluginInfo-Category=Current +Name[fr_FR]=amarok-context-applet-covergrid.desktop
