From e8652e5c31cd663582034f4cd6a93c2baa18ad01 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 12 Aug 2014 20:01:54 +0200 Subject: [PATCH] * Added TrackItemDelegate, to replace the various FoobarDelegates. --- .../playlist/TrackItemDelegate.cpp | 132 ++++++++++++++++++ src/libtomahawk/playlist/TrackItemDelegate.h | 58 ++++++++ 2 files changed, 190 insertions(+) create mode 100644 src/libtomahawk/playlist/TrackItemDelegate.cpp create mode 100644 src/libtomahawk/playlist/TrackItemDelegate.h diff --git a/src/libtomahawk/playlist/TrackItemDelegate.cpp b/src/libtomahawk/playlist/TrackItemDelegate.cpp new file mode 100644 index 000000000..c0bc09945 --- /dev/null +++ b/src/libtomahawk/playlist/TrackItemDelegate.cpp @@ -0,0 +1,132 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + +#include "TrackItemDelegate.h" + +#include +#include +#include + +#include "Query.h" +#include "Result.h" +#include "Artist.h" +#include "Source.h" +#include "SourceList.h" + +#include "PlaylistView.h" +#include "PlayableModel.h" +#include "PlayableItem.h" +#include "PlayableProxyModel.h" +#include "TrackView.h" +#include "ViewHeader.h" + +#include "audio/AudioEngine.h" +#include "utils/ImageRegistry.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" + +// Forward Declarations breaking QSharedPointer +#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) + #include "utils/PixmapDelegateFader.h" +#endif + + +using namespace Tomahawk; + + +TrackItemDelegate::TrackItemDelegate( DisplayMode mode, TrackView* parent, PlayableProxyModel* proxy ) + : PlaylistItemDelegate( parent, proxy ) + , m_view( parent ) + , m_model( proxy ) + , m_mode( mode ) +{ +} + + +QSize +TrackItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + QSize size = QStyledItemDelegate::sizeHint( option, index ); + + PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) ); + Q_ASSERT( item ); + + const int rowHeight = option.fontMetrics.height() + 5; + if ( item->source() ) + { + if ( index.row() == 0 ) + { + size.setHeight( rowHeight * 3 ); + } + else + { + size.setHeight( rowHeight * 4.5 ); + } + } + else + { + size.setHeight( rowHeight * 2.5 ); + } + + return size; +} + + +void +TrackItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) ); + Q_ASSERT( item ); + + QStyleOptionViewItemV4 opt = option; + prepareStyleOption( &opt, index, item ); + + if ( m_view->header()->visualIndex( index.column() ) > 0 ) + return; + + if ( item->source() ) + { + drawSource( painter, opt, index, opt.rect, item ); + } + + if ( item->query() ) + { + bool isUnlistened = true; + if ( m_mode == Inbox ) + { + QList< Tomahawk::SocialAction > socialActions = item->query()->queryTrack()->allSocialActions(); + foreach ( const Tomahawk::SocialAction& sa, socialActions ) + { + if ( sa.action.toString() == "Inbox" && sa.value.toBool() == false ) + { + isUnlistened = false; + break; + } + } + } + + drawTrack( painter, opt, index, opt.rect, item ); + } +} + + +void +TrackItemDelegate::modelChanged() +{ + PlaylistItemDelegate::modelChanged(); +} diff --git a/src/libtomahawk/playlist/TrackItemDelegate.h b/src/libtomahawk/playlist/TrackItemDelegate.h new file mode 100644 index 000000000..75cbd3263 --- /dev/null +++ b/src/libtomahawk/playlist/TrackItemDelegate.h @@ -0,0 +1,58 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + +#ifndef TRACKITEMDELEGATE_H +#define TRACKITEMDELEGATE_H + +#include +#include +#include + +#include "PlaylistItemDelegate.h" +#include "DllMacro.h" +#include "Typedefs.h" + +class PlayableItem; +class PlayableProxyModel; +class TrackView; + +class DLLEXPORT TrackItemDelegate : public PlaylistItemDelegate +{ +Q_OBJECT + +public: + enum DisplayMode + { LovedTracks, RecentlyPlayed, LatestAdditions, Inbox }; + + TrackItemDelegate( DisplayMode mode, TrackView* parent, PlayableProxyModel* proxy ); + + virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; + +protected: + void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; + +protected slots: + virtual void modelChanged(); + +private: + TrackView* m_view; + PlayableProxyModel* m_model; + DisplayMode m_mode; +}; + +#endif // TRACKITEMDELEGATE_H