mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Toggle subscription on/off via icon
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
@@ -148,6 +148,7 @@
|
||||
<file>data/images/jump-link.png</file>
|
||||
<file>data/images/scrollbar-vertical-handle.png</file>
|
||||
<file>data/images/scrollbar-horizontal-handle.png</file>
|
||||
<file>data/images/playlist-subscribed.png</file>
|
||||
<file>data/images/subscribe-on.png</file>
|
||||
<file>data/images/subscribe-off.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
|
||||
*
|
||||
*
|
||||
* 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
|
||||
@@ -74,7 +74,7 @@ public slots:
|
||||
void tomahawkPlaylistRenamed( const QString&, const QString& );
|
||||
|
||||
void aboutToDelete();
|
||||
|
||||
|
||||
private slots:
|
||||
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
||||
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData );
|
||||
|
@@ -78,7 +78,11 @@ public:
|
||||
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
||||
|
||||
virtual bool sync() const { return false; }
|
||||
virtual void setSync( bool ) {}
|
||||
|
||||
virtual bool canSubscribe() const { return false; }
|
||||
virtual bool subscribed() const { return false; }
|
||||
virtual void setSubscribed( bool ) {}
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
@@ -144,6 +144,8 @@ XspfUpdater::setAutoUpdate( bool autoUpdate )
|
||||
// Update immediately as well
|
||||
if ( m_autoUpdate )
|
||||
QTimer::singleShot( 0, this, SLOT( updateNow() ) );
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -158,3 +160,10 @@ XspfUpdater::setInterval( int intervalMsecs )
|
||||
|
||||
m_timer->setInterval( intervalMsecs );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XspfUpdater::setSubscribed( bool subscribed )
|
||||
{
|
||||
setAutoUpdate( subscribed );
|
||||
}
|
||||
|
@@ -48,7 +48,9 @@ public:
|
||||
void setInterval( int intervalMsecs ) ;
|
||||
int intervalMsecs() const { return m_timer->interval(); }
|
||||
|
||||
bool subscribed() const { return true; }
|
||||
bool canSubscribe() const { return true; }
|
||||
bool subscribed() const { return m_autoUpdate; }
|
||||
void setSubscribed( bool subscribed );
|
||||
|
||||
public slots:
|
||||
void updateNow();
|
||||
|
@@ -554,7 +554,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
QStyledItemDelegate::paint( painter, o, index );
|
||||
|
||||
PlaylistItem* plItem = qobject_cast< PlaylistItem* >( item );
|
||||
if ( plItem->subscribed() && !plItem->subscribedIcon().isNull() )
|
||||
if ( plItem->canSubscribe() && !plItem->subscribedIcon().isNull() )
|
||||
{
|
||||
const int padding = 2;
|
||||
const int imgWidth = o.rect.height() - 2*padding;
|
||||
@@ -655,10 +655,29 @@ SourceDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( event->type() == QEvent::MouseButtonRelease && type == SourcesModel::StaticPlaylist )
|
||||
{
|
||||
PlaylistItem* plItem = qobject_cast< PlaylistItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
||||
Q_ASSERT( plItem );
|
||||
|
||||
QMouseEvent* mev = static_cast< QMouseEvent* >( event );
|
||||
if ( plItem->canSubscribe() && !plItem->subscribedIcon().isNull() )
|
||||
{
|
||||
const int padding = 2;
|
||||
const int imgWidth = option.rect.height() - 2*padding;
|
||||
const QRect subRect( option.rect.right() - padding - imgWidth, option.rect.top() + padding, imgWidth, imgWidth );
|
||||
|
||||
if ( subRect.contains( mev->pos() ) )
|
||||
{
|
||||
// Toggle playlist subscription
|
||||
plItem->setSubscribed( !plItem->subscribed() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We emit our own clicked() signal instead of relying on QTreeView's, because that is fired whether or not a delegate accepts
|
||||
// a mouse press event. Since we want to swallow click events when they are on headphones other action items, here wemake sure we only
|
||||
// a mouse press event. Since we want to swallow click events when they are on headphones other action items, here we make sure we only
|
||||
// emit if we really want to
|
||||
if ( event->type() == QEvent::MouseButtonRelease )
|
||||
{
|
||||
|
@@ -40,6 +40,8 @@ using namespace Tomahawk;
|
||||
PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl, int index )
|
||||
: SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist, index )
|
||||
, m_loaded( false )
|
||||
, m_canSubscribe( false )
|
||||
, m_showSubscribed( false )
|
||||
, m_playlist( pl )
|
||||
{
|
||||
connect( pl.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||
@@ -293,18 +295,22 @@ PlaylistItem::createOverlay()
|
||||
if ( m_playlist->updaters().isEmpty() )
|
||||
return false;
|
||||
|
||||
m_showSubscribed = false;
|
||||
m_showSubscribed = false;
|
||||
m_canSubscribe = false;
|
||||
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
||||
{
|
||||
if ( updater->subscribed() )
|
||||
if ( updater->canSubscribe() )
|
||||
{
|
||||
m_showSubscribed = true;
|
||||
m_canSubscribe = true;
|
||||
m_showSubscribed = updater->subscribed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_showSubscribed && m_subscribedIcon.isNull() )
|
||||
m_subscribedIcon = QPixmap( RESPATH "images/playlist-subscribed.png" );
|
||||
if ( m_canSubscribe && m_showSubscribed && m_subscribedOnIcon.isNull() )
|
||||
m_subscribedOnIcon = QPixmap( RESPATH "images/subscribe-on.png" );
|
||||
else if ( m_canSubscribe && !m_showSubscribed && m_subscribedOffIcon.isNull() )
|
||||
m_subscribedOffIcon = QPixmap( RESPATH "images/subscribe-off.png" );
|
||||
|
||||
QList< QPixmap > icons;
|
||||
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
||||
@@ -313,6 +319,9 @@ PlaylistItem::createOverlay()
|
||||
icons << updater->typeIcon();
|
||||
}
|
||||
|
||||
m_overlaidIcon = QIcon();
|
||||
m_overlaidUpdaters = m_playlist->updaters();
|
||||
|
||||
if ( icons.isEmpty() )
|
||||
return false;
|
||||
|
||||
@@ -321,8 +330,6 @@ PlaylistItem::createOverlay()
|
||||
if ( icons.size() > 2 )
|
||||
icons = icons.mid( 0, 2 );
|
||||
|
||||
m_overlaidIcon = QIcon();
|
||||
m_overlaidUpdaters = m_playlist->updaters();
|
||||
|
||||
QPixmap base = m_icon.pixmap( 48, 48 );
|
||||
QPainter p( &base );
|
||||
@@ -384,6 +391,27 @@ PlaylistItem::activateCurrent()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItem::setSubscribed( bool subscribed )
|
||||
{
|
||||
Q_ASSERT( !m_overlaidUpdaters.isEmpty() );
|
||||
if ( m_overlaidUpdaters.isEmpty() )
|
||||
{
|
||||
qWarning() << "NO playlist updater but got a toggle subscribed action on the playlist item!?";
|
||||
return;
|
||||
}
|
||||
else if ( m_overlaidUpdaters.size() > 1 )
|
||||
{
|
||||
qWarning() << "Got TWO subscribed updaters at the same time? Toggling both... wtf";
|
||||
}
|
||||
|
||||
foreach( PlaylistUpdaterInterface* updater, m_overlaidUpdaters )
|
||||
{
|
||||
updater->setSubscribed( subscribed );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DynamicPlaylistItem::DynamicPlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const dynplaylist_ptr& pl, int index )
|
||||
: PlaylistItem( mdl, parent, pl.staticCast< Playlist >(), index )
|
||||
, m_dynplaylist( pl )
|
||||
|
@@ -42,9 +42,11 @@ public:
|
||||
|
||||
virtual SourceTreeItem* activateCurrent();
|
||||
|
||||
// subscription management
|
||||
bool canSubscribe() const { return m_canSubscribe; }
|
||||
bool subscribed() const { return m_showSubscribed; }
|
||||
QPixmap subscribedIcon() const { return m_subscribedIcon; }
|
||||
QList< QAction* > subscribedActions() const;
|
||||
QPixmap subscribedIcon() const { return m_showSubscribed ? m_subscribedOnIcon : m_subscribedOffIcon; }
|
||||
void setSubscribed( bool subscribed );
|
||||
|
||||
public slots:
|
||||
virtual void activate();
|
||||
@@ -62,10 +64,10 @@ private slots:
|
||||
private:
|
||||
bool createOverlay();
|
||||
|
||||
bool m_loaded, m_showSubscribed;
|
||||
bool m_loaded, m_canSubscribe, m_showSubscribed;
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
QIcon m_icon, m_overlaidIcon;
|
||||
QPixmap m_subscribedIcon;
|
||||
QPixmap m_subscribedOnIcon, m_subscribedOffIcon;
|
||||
QList<Tomahawk::PlaylistUpdaterInterface*> m_overlaidUpdaters;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
||||
|
Reference in New Issue
Block a user