1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 16:14:40 +02:00

Handle a scrolled qtreeview.

Though don't really handle it, since we can't animate the way we are for when the view is scrolled. But now we
support it at least.
This commit is contained in:
Leo Franchi
2011-02-06 22:04:27 -05:00
parent 738d462545
commit 9ae4f3858c
2 changed files with 47 additions and 32 deletions

View File

@@ -110,7 +110,7 @@ DynamicModel::trackResolveFinished( bool success )
Query* q = qobject_cast<Query*>(sender()); Query* q = qobject_cast<Query*>(sender());
qDebug() << "Got not resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts; qDebug() << "Got not resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
m_currentAttempts++; m_currentAttempts++;
if( m_currentAttempts < 30 ) { if( m_currentAttempts < 20 ) {
m_playlist->generator()->fetchNext(); m_playlist->generator()->fetchNext();
} else { } else {
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) ); emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) );

View File

@@ -19,10 +19,13 @@
#include "widgets/overlaywidget.h" #include "widgets/overlaywidget.h"
#include "playlistmodel.h" #include "playlistmodel.h"
#include "trackproxymodel.h" #include "trackproxymodel.h"
#include "trackheader.h"
#include <QPainter> #include <QPainter>
#include <QPaintEvent> #include <QPaintEvent>
#include <QtGui/qpaintengine.h> #include <QtGui/qpaintengine.h>
#include <QScrollBar>
using namespace Tomahawk; using namespace Tomahawk;
#define FADE_LENGTH 800 #define FADE_LENGTH 800
@@ -100,6 +103,9 @@ DynamicView::onTrackCountChanged( unsigned int tracks )
} }
else else
overlay()->hide(); overlay()->hide();
// make sure we can see all our tracks
scrollTo( proxyModel()->index( proxyModel()->rowCount() - 1, 0, QModelIndex() ), EnsureVisible );
} }
void void
@@ -107,36 +113,45 @@ DynamicView::collapseEntries( int startRow, int num )
{ {
if( m_fadeOutAnim.state() == QTimeLine::Running ) if( m_fadeOutAnim.state() == QTimeLine::Running )
qDebug() << "COLLAPSING TWICE!"; qDebug() << "COLLAPSING TWICE!";
// we capture the image of the rows we're going to collapse // TODO if we are scrolled, we can't animate this way.
// then we capture the image of the target row we're going to animate downwards // we have to animate the top coming down, which i haven't implemented yet..
// then we fade the first image out while sliding the second image up. if( verticalScrollBar()->sliderPosition() == 0 ) {
QModelIndex topLeft = proxyModel()->index( startRow, 0, QModelIndex() ); // we capture the image of the rows we're going to collapse
QModelIndex bottomRight = proxyModel()->index( startRow + num - 1, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() ); // then we capture the image of the target row we're going to animate downwards
QItemSelection sel( topLeft, bottomRight ); // then we fade the first image out while sliding the second image up.
QRect fadingRect = visualRegionForSelection( sel ).boundingRect(); QModelIndex topLeft = proxyModel()->index( startRow, 0, QModelIndex() );
QModelIndex bottomRight = proxyModel()->index( startRow + num - 1, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() );
m_fadingIndexes = QPixmap::grabWidget( viewport(), fadingRect ); QItemSelection sel( topLeft, bottomRight );
m_fadingPointAnchor = fadingRect.topLeft(); QRect fadingRect = visualRegionForSelection( sel ).boundingRect();
QRect fadingRectViewport = fadingRect; // all values that we use in paintEvent() have to be in viewport coords
qDebug() << "Grabbed fading indexes from rect:" << fadingRect << m_fadingIndexes.size(); fadingRect.moveTo( viewport()->mapTo( this, fadingRect.topLeft() ) );
topLeft = proxyModel()->index( startRow + num, 0, QModelIndex() ); m_fadingIndexes = QPixmap::grabWidget( this, fadingRect ); // but all values we use to grab the widgetr have to be in scrollarea coords :(
bottomRight = proxyModel()->index( startRow + num, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() ); m_fadingPointAnchor = QPoint( 0, fadingRectViewport.topLeft().y() );
QRect slidingRect = visualRegionForSelection( QItemSelection( topLeft, bottomRight ) ).boundingRect();
qDebug() << "Grabbed fading indexes from rect:" << fadingRect << m_fadingIndexes.size();
m_slidingIndex = QPixmap::grabWidget( viewport(), slidingRect );
m_bottomAnchor = slidingRect.topLeft(); topLeft = proxyModel()->index( startRow + num, 0, QModelIndex() );
m_bottomOfAnim = slidingRect.bottomLeft(); bottomRight = proxyModel()->index( startRow + num, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() );
qDebug() << "Grabbed sliding index from rect:" << slidingRect << m_slidingIndex.size(); QRect slidingRect = visualRegionForSelection( QItemSelection( topLeft, bottomRight ) ).boundingRect();
QRect slidingRectViewport = slidingRect;
// slide from the current position to the new one // map internal view cord to external qscrollarea
int frameRange = fadingRect.topLeft().y() - slidingRect.topLeft().y(); slidingRect.moveTo( viewport()->mapTo( this, slidingRect.topLeft() ) );
m_slideAnim.setDuration( SLIDE_LENGTH + frameRange * LONG_MULT );
m_slideAnim.setFrameRange( slidingRect.topLeft().y(), fadingRect.topLeft().y() ); m_slidingIndex = QPixmap::grabWidget( this, slidingRect );
m_bottomAnchor = QPoint( 0, slidingRectViewport.topLeft().y() );
m_fadeOutAnim.start(); m_bottomOfAnim = QPoint( 0, slidingRectViewport.bottomLeft().y() );
QTimer::singleShot( SLIDE_OFFSET, &m_slideAnim, SLOT( start() ) ); qDebug() << "Grabbed sliding index from rect:" << slidingRect << m_slidingIndex.size();
// slide from the current position to the new one
int frameRange = fadingRect.topLeft().y() - slidingRect.topLeft().y();
m_slideAnim.setDuration( SLIDE_LENGTH + frameRange * LONG_MULT );
m_slideAnim.setFrameRange( slidingRectViewport.topLeft().y(), fadingRectViewport.topLeft().y() );
m_fadeOutAnim.start();
QTimer::singleShot( SLIDE_OFFSET, &m_slideAnim, SLOT( start() ) );
}
// delete the actual indices
QModelIndexList todel; QModelIndexList todel;
for( int i = 0; i < num; i++ ) { for( int i = 0; i < num; i++ ) {
for( int k = 0; k < proxyModel()->columnCount( QModelIndex() ); k++ ) { for( int k = 0; k < proxyModel()->columnCount( QModelIndex() ); k++ ) {
@@ -172,7 +187,7 @@ DynamicView::paintEvent( QPaintEvent* event )
p.fillRect( bg, Qt::white ); p.fillRect( bg, Qt::white );
p.drawPixmap( 0, m_slideAnim.currentFrame(), m_slidingIndex ); p.drawPixmap( 0, m_slideAnim.currentFrame(), m_slidingIndex );
} else if( m_fadeOutAnim.state() == QTimeLine::Running ) { } else if( m_fadeOutAnim.state() == QTimeLine::Running ) {
p.drawPixmap( m_bottomAnchor, m_slidingIndex ); p.drawPixmap( 0, m_bottomAnchor.y(), m_slidingIndex );
} }
} }
} }