bool GridItemDelegate::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 hoveringArtist = false; if ( m_artistNameRects.contains( index ) ) { const QRect artistNameRect = m_artistNameRects[ index ]; const QMouseEvent* ev = static_cast< QMouseEvent* >( event ); hoveringArtist = artistNameRect.contains( ev->pos() ); } if ( event->type() == QEvent::MouseMove ) { if ( hoveringArtist ) m_view->setCursor( Qt::PointingHandCursor ); else m_view->setCursor( Qt::ArrowCursor ); foreach ( const QModelIndex& idx, m_playButton.keys() ) { if ( index != idx ) m_playButton.take( idx )->deleteLater(); } if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) ) { foreach ( ImageButton* button, m_playButton ) button->deleteLater(); m_playButton.clear(); // only add the play button to a album picture if the party mode is not active const bool isPartyMode = TomahawkSettings::instance()->partyModeEnabled(); if ( !isPartyMode ) { ImageButton* button = new ImageButton( m_view ); button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); button->setFixedSize( 48, 48 ); button->move( option.rect.center() - QPoint( 23, 23 ) ); button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); button->show(); NewClosure( button, SIGNAL( clicked( bool ) ), const_cast<GridItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); m_playButton[ index ] = button; } }
bool AlbumItemDelegate::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 hoveringArtist = false; if ( m_artistNameRects.contains( index ) ) { const QRect artistNameRect = m_artistNameRects[ index ]; const QMouseEvent* ev = static_cast< QMouseEvent* >( event ); hoveringArtist = artistNameRect.contains( ev->pos() ); } if ( event->type() == QEvent::MouseMove ) { foreach ( const QModelIndex& idx, m_playButton.keys() ) { if ( index != idx ) m_playButton.take( idx )->deleteLater(); } if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) ) { foreach ( ImageButton* button, m_playButton ) button->deleteLater(); m_playButton.clear(); ImageButton* button = new ImageButton( m_view ); button->setPixmap( RESPATH "images/play-rest.png" ); button->setPixmap( RESPATH "images/play-pressed.png", QIcon::Off, QIcon::Active ); button->setFixedSize( 48, 48 ); button->move( option.rect.center() - QPoint( 23, 23 ) ); button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); button->show(); NewClosure( button, SIGNAL( clicked( bool ) ), const_cast<AlbumItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); m_playButton[ index ] = button; }
bool GridItemDelegate::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 hoveringArtist = false; if ( m_artistNameRects.contains( index ) ) { const QRect artistNameRect = m_artistNameRects[ index ]; const QMouseEvent* ev = static_cast< QMouseEvent* >( event ); hoveringArtist = artistNameRect.contains( ev->pos() ); } if ( event->type() == QEvent::MouseMove ) { if ( hoveringArtist ) m_view->setCursor( Qt::PointingHandCursor ); else m_view->setCursor( Qt::ArrowCursor ); foreach ( const QModelIndex& idx, m_playButton.keys() ) { if ( index != idx ) m_playButton.take( idx )->deleteLater(); } if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) ) { foreach ( ImageButton* button, m_playButton ) button->deleteLater(); m_playButton.clear(); ImageButton* button = new ImageButton( m_view ); button->setPixmap( RESPATH "images/play-rest.png" ); button->setPixmap( RESPATH "images/play-pressed.png", QIcon::Off, QIcon::Active ); button->setFixedSize( 48, 48 ); button->move( option.rect.center() - QPoint( 23, 23 ) ); button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); button->show(); NewClosure( button, SIGNAL( clicked( bool ) ), const_cast<GridItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); m_playButton[ index ] = button; } if ( m_hoveringOver != index || ( !hoveringArtist && m_hoveringOver.isValid() ) ) { emit updateIndex( m_hoveringOver ); if ( hoveringArtist ) m_hoveringOver = index; else m_hoveringOver = QPersistentModelIndex(); emit updateIndex( index ); } if ( m_hoverIndex != index ) { if ( m_hoverIndex.isValid() ) { QTimeLine* fadeOut = createTimeline( QTimeLine::Forward ); _detail::Closure* c = NewClosure( fadeOut, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) ); c->setAutoDelete( false ); c = NewClosure( fadeOut, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) ); c->setAutoDelete( false ); m_hoverFaders[ m_hoverIndex ] = fadeOut; fadeOut->start(); } emit updateIndex( m_hoverIndex ); m_hoverIndex = index; QTimeLine* fadeIn = createTimeline( QTimeLine::Backward ); _detail::Closure* c = NewClosure( fadeIn, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); c->setAutoDelete( false ); c = NewClosure( fadeIn, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); c->setAutoDelete( false ); m_hoverFaders[ index ] = fadeIn; fadeIn->start(); emit updateIndex( index ); }