mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
* Moved info button handling into PlaylistItemDelegate.
This commit is contained in:
parent
5c60f5d3cc
commit
14c5b9d983
@ -21,10 +21,12 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "Query.h"
|
||||
#include "Result.h"
|
||||
#include "Artist.h"
|
||||
#include "Album.h"
|
||||
#include "Source.h"
|
||||
#include "SourceList.h"
|
||||
|
||||
@ -33,6 +35,7 @@
|
||||
#include "PlayableProxyModel.h"
|
||||
#include "TrackView.h"
|
||||
#include "ViewHeader.h"
|
||||
#include "ViewManager.h"
|
||||
|
||||
#include "utils/TomahawkUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
@ -82,16 +85,6 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel
|
||||
}
|
||||
|
||||
|
||||
QWidget*
|
||||
PlaylistItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
Q_UNUSED( parent );
|
||||
Q_UNUSED( option );
|
||||
Q_UNUSED( index );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const
|
||||
{
|
||||
@ -228,7 +221,7 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
||||
opt.text.clear();
|
||||
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
|
||||
|
||||
if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() && !index.data().toString().isEmpty() &&
|
||||
if ( m_hoveringOver == index && !index.data().toString().isEmpty() &&
|
||||
( index.column() == PlayableModel::Artist || index.column() == PlayableModel::Album || index.column() == PlayableModel::Track ) )
|
||||
{
|
||||
opt.rect.setWidth( opt.rect.width() - opt.rect.height() - 2 );
|
||||
@ -236,6 +229,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
||||
|
||||
QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
|
||||
painter->drawPixmap( arrowRect, infoIcon );
|
||||
|
||||
m_infoButtonRects[ index ] = arrowRect;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
@ -289,3 +284,100 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||
{
|
||||
Q_UNUSED( model );
|
||||
Q_UNUSED( option );
|
||||
|
||||
if ( event->type() != QEvent::MouseButtonRelease &&
|
||||
event->type() != QEvent::MouseMove &&
|
||||
event->type() != QEvent::MouseButtonPress &&
|
||||
event->type() != QEvent::Leave )
|
||||
return false;
|
||||
|
||||
bool hoveringInfo = false;
|
||||
if ( m_infoButtonRects.contains( index ) )
|
||||
{
|
||||
const QRect infoRect = m_infoButtonRects[ index ];
|
||||
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||
hoveringInfo = infoRect.contains( ev->pos() );
|
||||
}
|
||||
|
||||
if ( event->type() == QEvent::MouseMove )
|
||||
{
|
||||
if ( hoveringInfo )
|
||||
m_view->setCursor( Qt::PointingHandCursor );
|
||||
else
|
||||
m_view->setCursor( Qt::ArrowCursor );
|
||||
|
||||
if ( m_hoveringOver != index || ( !hoveringInfo && m_hoveringOver.isValid() ) )
|
||||
{
|
||||
emit updateIndex( m_hoveringOver );
|
||||
m_hoveringOver = index;
|
||||
emit updateIndex( index );
|
||||
}
|
||||
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
// reset mouse cursor. we switch to a pointing hand cursor when hovering an info button
|
||||
m_view->setCursor( Qt::ArrowCursor );
|
||||
|
||||
if ( hoveringInfo )
|
||||
{
|
||||
if ( event->type() == QEvent::MouseButtonRelease )
|
||||
{
|
||||
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||
if ( !item )
|
||||
return false;
|
||||
|
||||
if ( m_model->style() != PlayableProxyModel::Detailed )
|
||||
{
|
||||
if ( item->query() )
|
||||
ViewManager::instance()->show( item->query()->displayQuery() );
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( index.column() )
|
||||
{
|
||||
case PlayableModel::Artist:
|
||||
{
|
||||
ViewManager::instance()->show( Artist::get( item->query()->displayQuery()->artist() ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayableModel::Album:
|
||||
{
|
||||
artist_ptr artist = Artist::get( item->query()->displayQuery()->artist() );
|
||||
ViewManager::instance()->show( Album::get( artist, item->query()->displayQuery()->album() ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayableModel::Track:
|
||||
{
|
||||
ViewManager::instance()->show( item->query()->displayQuery() );
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
else if ( event->type() == QEvent::MouseButtonPress )
|
||||
{
|
||||
// Stop the whole item from having a down click action as we just want the info button to be clicked
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -47,7 +47,10 @@ protected:
|
||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
|
||||
|
||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||
|
||||
QPersistentModelIndex hoveringOver() const { return m_hoveringOver; }
|
||||
void setInfoButtonRect( const QPersistentModelIndex& index, const QRect& rect ) const { m_infoButtonRects[ index ] = rect; }
|
||||
|
||||
private:
|
||||
void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
@ -56,6 +59,9 @@ private:
|
||||
QTextOption m_topOption;
|
||||
QTextOption m_bottomOption;
|
||||
|
||||
mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
|
||||
QPersistentModelIndex m_hoveringOver;
|
||||
|
||||
TrackView* m_view;
|
||||
PlayableProxyModel* m_model;
|
||||
};
|
||||
|
@ -192,8 +192,31 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
smallFont.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
|
||||
|
||||
r.adjust( pixmapRect.width() + 12, 1, - 16, 0 );
|
||||
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
|
||||
QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
|
||||
QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 );
|
||||
|
||||
const int sourceIconSize = avatarRect.width() - 6;
|
||||
|
||||
if ( hoveringOver() == index && !index.data().toString().isEmpty() && index.column() == 0 )
|
||||
{
|
||||
const QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, QSize( sourceIconSize, sourceIconSize ) );
|
||||
QRect arrowRect = QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, infoIcon.width(), infoIcon.height() );
|
||||
painter->drawPixmap( arrowRect, infoIcon );
|
||||
|
||||
setInfoButtonRect( index, arrowRect );
|
||||
rightRect.moveLeft( rightRect.left() - infoIcon.width() - 8 );
|
||||
leftRect.adjust( 0, 0, -( infoIcon.width() + 8 ), 0 );
|
||||
}
|
||||
else if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
|
||||
{
|
||||
const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) );
|
||||
painter->setOpacity( 0.8 );
|
||||
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
|
||||
painter->setOpacity( 1.0 );
|
||||
|
||||
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
|
||||
leftRect.adjust( 0, 0, -( sourceIcon.width() + 8 ), 0 );
|
||||
}
|
||||
|
||||
painter->setFont( boldFont );
|
||||
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
|
||||
@ -209,7 +232,8 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
textDoc.setDefaultFont( painter->font() );
|
||||
textDoc.setDefaultTextOption( m_topOption );
|
||||
|
||||
drawRichText( painter, opt, leftRect.adjusted( 0, boldFontMetrics.height() + 1, 0, 0 ), Qt::AlignTop, textDoc );
|
||||
if ( textDoc.idealWidth() <= leftRect.width() )
|
||||
drawRichText( painter, opt, leftRect.adjusted( 0, boldFontMetrics.height() + 1, 0, 0 ), Qt::AlignTop, textDoc );
|
||||
|
||||
if ( !( option.state & QStyle::State_Selected || item->isPlaying() ) )
|
||||
painter->setPen( Qt::gray );
|
||||
@ -224,16 +248,6 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
|
||||
drawRichText( painter, opt, leftRect, Qt::AlignBottom, textDoc );
|
||||
|
||||
const int sourceIconSize = avatarRect.width() - 6;
|
||||
if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
|
||||
{
|
||||
const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) );
|
||||
painter->setOpacity( 0.8 );
|
||||
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
|
||||
painter->setOpacity( 1.0 );
|
||||
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
|
||||
}
|
||||
|
||||
if ( duration > 0 )
|
||||
{
|
||||
painter->setPen( opt.palette.text().color() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user