1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 00:42:04 +02:00

Add lock/unlock icons to toggle realtime listening along

This commit is contained in:
Jeff Mitchell 2012-01-12 19:05:14 -05:00
parent 9242a7c942
commit 25a67447d3
12 changed files with 67 additions and 15 deletions

Binary file not shown.

After

(image error) Size: 1.2 KiB

Binary file not shown.

After

(image error) Size: 1.1 KiB

@ -128,6 +128,8 @@
<file>data/images/headphones.png</file>
<file>data/images/headphones-off.png</file>
<file>data/images/headphones-sidebar.png</file>
<file>data/images/closed-padlock.png</file>
<file>data/images/open-padlock.png</file>
<file>data/images/headphones-bigger.png</file>
<file>data/images/no-album-no-case.png</file>
<file>data/images/rdio.png</file>

@ -193,6 +193,16 @@ SourceItem::localLatchedOn() const
}
Tomahawk::PlaylistInterface::LatchMode
SourceItem::localLatchMode() const
{
if ( !m_source.isNull() && !m_source->isLocal() )
return m_source->getPlaylistInterface()->latchMode();
return Tomahawk::PlaylistInterface::StayOnSong;
}
void
SourceItem::latchedOff( const source_ptr& from, const source_ptr& to )
{
@ -217,6 +227,7 @@ SourceItem::latchedOn( const source_ptr& from, const source_ptr& to )
}
void
SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists )
{

@ -42,6 +42,7 @@ public:
virtual int IDValue() const;
virtual bool localLatchedOn() const;
virtual Tomahawk::PlaylistInterface::LatchMode localLatchMode() const;
Tomahawk::source_ptr source() const;

@ -66,6 +66,8 @@ SourceDelegate::SourceDelegate( QAbstractItemView* parent )
m_headphonesOff.load( RESPATH "images/headphones-off.png" );
m_headphonesOn.load( RESPATH "images/headphones-sidebar.png" );
m_realtimeLocked.load( RESPATH "images/closed-padlock.png" );
m_realtimeUnlocked.load( RESPATH "images/open-padlock.png" );
m_nowPlayingSpeaker.load( RESPATH "images/now-playing-speaker.png" );
m_nowPlayingSpeakerDark.load( RESPATH "images/now-playing-speaker-dark.png" );
}
@ -201,23 +203,39 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
if ( isPlaying || ( !colItem->source().isNull() && colItem->source()->isLocal() ) )
{
// Show a listen icon
QPixmap pm;
QPixmap listenAlongPixmap;
QPixmap realtimeListeningAlongPixmap;
if ( index.data( SourcesModel::LatchedOnRole ).toBool() )
{
// Currently listening along
pm = m_headphonesOn;
listenAlongPixmap = m_headphonesOn;
if ( !colItem->source()->isLocal() )
{
realtimeListeningAlongPixmap =
colItem->source()->getPlaylistInterface()->latchMode() == Tomahawk::PlaylistInterface::RealTime ?
m_realtimeLocked : m_realtimeUnlocked;
}
}
else if ( !colItem->source()->isLocal() )
{
pm = m_headphonesOff;
listenAlongPixmap = m_headphonesOff;
}
if ( !pm.isNull() )
if ( !listenAlongPixmap.isNull() )
{
QRect pmRect = textRect;
pmRect.setTop( pmRect.bottom() - painter->fontMetrics().height() + 3 );
pmRect.setRight( pmRect.left() + pmRect.height() );
painter->drawPixmap( pmRect, pm.scaledToHeight( pmRect.height(), Qt::SmoothTransformation ) );
painter->drawPixmap( pmRect, listenAlongPixmap.scaledToHeight( pmRect.height(), Qt::SmoothTransformation ) );
textRect.adjust( pmRect.width() + 3, 0, 0, 0 );
}
if ( !realtimeListeningAlongPixmap.isNull() )
{
QRect pmRect = textRect;
pmRect.setTop( pmRect.bottom() - painter->fontMetrics().height() + 3 );
pmRect.setRight( pmRect.left() + pmRect.height() );
painter->drawPixmap( pmRect, realtimeListeningAlongPixmap.scaledToHeight( pmRect.height(), Qt::SmoothTransformation ) );
textRect.adjust( pmRect.width() + 3, 0, 0, 0 );
}
}
@ -578,15 +596,23 @@ SourceDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
const int height = fm.height() + 3;
QRect headphonesRect( option.rect.height() + 10, o.rect.bottom() - height, height, height );
if ( headphonesRect.contains( ev->pos() ) )
bool headphonesRectContainsClick = headphonesRect.contains( ev->pos() );
QRect lockRect( option.rect.height() + 20, o.rect.bottom() - height, height, height );
bool lockRectContainsClick = lockRect.contains( ev->pos() );
if ( headphonesRectContainsClick || lockRectContainsClick )
{
if ( event->type() == QEvent::MouseButtonRelease )
{
if ( index.data( SourcesModel::LatchedOnRole ).toBool() )
// unlatch
emit latchOff( colItem->source() );
else
emit latchOn( colItem->source() );
if ( headphonesRectContainsClick )
{
if ( index.data( SourcesModel::LatchedOnRole ).toBool() )
// unlatch
emit latchOff( colItem->source() );
else
emit latchOn( colItem->source() );
}
else // it's in the lock rect
emit toggleRealtimeLatch( colItem->source(), !index.data( SourcesModel::LatchedRealtimeRole ).toBool() );
}
return true;
}

@ -44,6 +44,7 @@ public:
signals:
void latchOn( const Tomahawk::source_ptr& idx );
void latchOff( const Tomahawk::source_ptr& idx );
void toggleRealtimeLatch( const Tomahawk::source_ptr& idx, bool realtime );
protected:
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
@ -69,7 +70,7 @@ private:
QMimeData *m_dropMimeData;
mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
QMap< QModelIndex, AnimationHelper* > m_expandedMap;
QPixmap m_headphonesOn, m_headphonesOff, m_nowPlayingSpeaker, m_nowPlayingSpeakerDark;
QPixmap m_headphonesOn, m_headphonesOff, m_realtimeLocked, m_realtimeUnlocked, m_nowPlayingSpeaker, m_nowPlayingSpeakerDark;
QMap< int, SourceTreeItem::DropType > m_dropTypeMap;
QMap< int, QString > m_dropTypeTextMap;

@ -127,6 +127,15 @@ SourcesModel::data( const QModelIndex& index, int role ) const
}
return false;
}
case SourcesModel::LatchedRealtimeRole:
{
if ( itemFromIndex( index )->type() == Collection )
{
SourceItem* cItem = qobject_cast< SourceItem* >( itemFromIndex( index ) );
return cItem->localLatchMode() == Tomahawk::PlaylistInterface::RealTime;
}
return false;
}
}
return QVariant();
}

@ -70,7 +70,8 @@ public:
SourceTreeItemTypeRole = Qt::UserRole + 11,
SortRole = Qt::UserRole + 12,
IDRole = Qt::UserRole + 13,
LatchedOnRole = Qt::UserRole + 14
LatchedOnRole = Qt::UserRole + 14,
LatchedRealtimeRole = Qt::UserRole + 15
};
SourcesModel( QObject* parent = 0 );

@ -19,7 +19,7 @@
#include "sourcesproxymodel.h"
#include <QTreeView>
#include <QtGui/QTreeView>
#include "sourcelist.h"
#include "sourcesmodel.h"

@ -19,7 +19,7 @@
#ifndef SOURCESPROXYMODEL_H
#define SOURCESPROXYMODEL_H
#include <QSortFilterProxyModel>
#include <QtGui/QSortFilterProxyModel>
class SourcesModel;

@ -86,6 +86,7 @@ SourceTreeView::SourceTreeView( QWidget* parent )
m_delegate = new SourceDelegate( this );
connect( m_delegate, SIGNAL( latchOn( Tomahawk::source_ptr ) ), SLOT( latchOnOrCatchUp( Tomahawk::source_ptr ) ) );
connect( m_delegate, SIGNAL( latchOff( Tomahawk::source_ptr ) ), SLOT( latchOff( Tomahawk::source_ptr ) ) );
connect( m_delegate, SIGNAL( toggleRealtimeLatch( Tomahawk::source_ptr, bool ) ), m_latchManager, SLOT( latchModeChangeRequest( Tomahawk::source_ptr,bool ) ) );
setItemDelegate( m_delegate );