mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Moved info button handling into TreeItemDelegate.
This commit is contained in:
parent
14c5b9d983
commit
ecadb3a1a7
src/libtomahawk/playlist
@ -23,6 +23,7 @@
|
||||
#include <QPainter>
|
||||
#include <QAbstractItemView>
|
||||
#include <QHeaderView>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "Query.h"
|
||||
#include "Result.h"
|
||||
@ -35,6 +36,7 @@
|
||||
#include "PlayableItem.h"
|
||||
#include "TreeProxyModel.h"
|
||||
#include "TreeView.h"
|
||||
#include "ViewManager.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
|
||||
@ -73,7 +75,7 @@ TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelInde
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// artist per default
|
||||
size.setHeight( option.fontMetrics.height() * 4 );
|
||||
return size;
|
||||
@ -135,13 +137,15 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
if ( oldX > 0 )
|
||||
o.rect.setX( oldX );
|
||||
|
||||
if ( m_view->hoveredIndex() == index && !index.data().toString().isEmpty() && index.column() == 0 )
|
||||
if ( m_hoveringOver == index && !index.data().toString().isEmpty() && index.column() == 0 )
|
||||
{
|
||||
o.rect.setWidth( o.rect.width() - o.rect.height() );
|
||||
QRect arrowRect( o.rect.x() + o.rect.width(), o.rect.y() + 1, o.rect.height() - 2, o.rect.height() - 2 );
|
||||
|
||||
QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
|
||||
painter->drawPixmap( arrowRect, infoIcon );
|
||||
|
||||
m_infoButtonRects[ index ] = arrowRect;
|
||||
}
|
||||
|
||||
{
|
||||
@ -226,3 +230,78 @@ TreeItemDelegate::doUpdateIndex( const QPersistentModelIndex& index )
|
||||
emit updateIndex( index );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TreeItemDelegate::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;
|
||||
|
||||
switch ( index.column() )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
|
||||
protected:
|
||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||
|
||||
signals:
|
||||
void updateIndex( const QModelIndex& idx );
|
||||
@ -54,6 +55,8 @@ private:
|
||||
TreeProxyModel* m_model;
|
||||
|
||||
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
||||
mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
|
||||
QPersistentModelIndex m_hoveringOver;
|
||||
};
|
||||
|
||||
#endif // TREEITEMDELEGATE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user