mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 17:29:42 +01:00
* Added TrackItemDelegate, to replace the various FoobarDelegates.
This commit is contained in:
parent
caddca1d31
commit
e8652e5c31
132
src/libtomahawk/playlist/TrackItemDelegate.cpp
Normal file
132
src/libtomahawk/playlist/TrackItemDelegate.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TrackItemDelegate.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QDateTime>
|
||||
|
||||
#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();
|
||||
}
|
58
src/libtomahawk/playlist/TrackItemDelegate.h
Normal file
58
src/libtomahawk/playlist/TrackItemDelegate.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRACKITEMDELEGATE_H
|
||||
#define TRACKITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextDocument>
|
||||
#include <QTextOption>
|
||||
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user