mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
fix painting bg by making the row height 1 larger
cleanup the anim code a bit
This commit is contained in:
@@ -203,30 +203,8 @@ DynamicView::collapseEntries( int startRow, int num, int numToKeep )
|
|||||||
m_fadingPointAnchor = QPoint( 0, fadingRectViewport.topLeft().y() );
|
m_fadingPointAnchor = QPoint( 0, fadingRectViewport.topLeft().y() );
|
||||||
|
|
||||||
// get the background
|
// get the background
|
||||||
m_bg = QPixmap( m_fadingIndexes.size() );
|
m_bg = backgroundBetween( m_fadingIndexes.rect(), startRow );
|
||||||
m_bg.fill( Qt::white );
|
|
||||||
QPainter p( &m_bg );
|
|
||||||
QStyleOptionViewItemV4 opt = viewOptions();
|
|
||||||
// code taken from QTreeViewPrivate::paintAlternatingRowColors
|
|
||||||
if( alternatingRowColors() ) {
|
|
||||||
m_fadebg = !style()->styleHint( QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea, &opt );
|
|
||||||
qDebug() << "PAINTING ALTERNATING ROW BG!: " << fadingRectViewport;
|
|
||||||
int rowHeight = itemDelegate()->sizeHint( opt, QModelIndex() ).height();
|
|
||||||
int y = m_fadingIndexes.rect().topLeft().y();
|
|
||||||
int current = startRow;
|
|
||||||
while( y <= m_fadingIndexes.rect().bottomLeft().y() ) {
|
|
||||||
opt.rect.setRect(0, y, viewport()->width(), rowHeight);
|
|
||||||
qDebug() << "Painting a row from " << y << "to" << y + rowHeight << ":" << opt.rect;
|
|
||||||
if( current & 1 ) {
|
|
||||||
opt.features |= QStyleOptionViewItemV2::Alternate;
|
|
||||||
} else {
|
|
||||||
opt.features &= ~QStyleOptionViewItemV2::Alternate;
|
|
||||||
}
|
|
||||||
++current;
|
|
||||||
style()->drawPrimitive( QStyle::PE_PanelItemViewRow, &opt, &p );
|
|
||||||
y += rowHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_fadeOutAnim.start();
|
m_fadeOutAnim.start();
|
||||||
|
|
||||||
qDebug() << "Grabbed fading indexes from rect:" << fadingRect << m_fadingIndexes.size();
|
qDebug() << "Grabbed fading indexes from rect:" << fadingRect << m_fadingIndexes.size();
|
||||||
@@ -243,7 +221,6 @@ DynamicView::collapseEntries( int startRow, int num, int numToKeep )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
topLeft = proxyModel()->index( startRow + realNum, 0, QModelIndex() );
|
topLeft = proxyModel()->index( startRow + realNum, 0, QModelIndex() );
|
||||||
bottomRight = proxyModel()->index( startRow + realNum + numToKeep - 1, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() );
|
bottomRight = proxyModel()->index( startRow + realNum + numToKeep - 1, proxyModel()->columnCount( QModelIndex() ) - 1, QModelIndex() );
|
||||||
QRect slidingRect = visualRegionForSelection( QItemSelection( topLeft, bottomRight ) ).boundingRect();
|
QRect slidingRect = visualRegionForSelection( QItemSelection( topLeft, bottomRight ) ).boundingRect();
|
||||||
@@ -274,6 +251,35 @@ DynamicView::collapseEntries( int startRow, int num, int numToKeep )
|
|||||||
proxyModel()->removeIndexes( todel );
|
proxyModel()->removeIndexes( todel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
DynamicView::backgroundBetween( QRect rect, int rowStart )
|
||||||
|
{
|
||||||
|
QPixmap bg = QPixmap( rect.size() );
|
||||||
|
bg.fill( Qt::white );
|
||||||
|
QPainter p( &bg );
|
||||||
|
QStyleOptionViewItemV4 opt = viewOptions();
|
||||||
|
// code taken from QTreeViewPrivate::paintAlternatingRowColors
|
||||||
|
m_fadebg = !style()->styleHint( QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea, &opt );
|
||||||
|
// qDebug() << "PAINTING ALTERNATING ROW BG!: " << fadingRectViewport;
|
||||||
|
int rowHeight = itemDelegate()->sizeHint( opt, QModelIndex() ).height() + 1;
|
||||||
|
int y = 0;
|
||||||
|
int current = rowStart;
|
||||||
|
while( y <= rect.bottomLeft().y() ) {
|
||||||
|
opt.rect.setRect(0, y, viewport()->width(), rowHeight);
|
||||||
|
// qDebug() << "PAINTING BG ROW IN RECT" << y << "to" << y + rowHeight << ":" << opt.rect;
|
||||||
|
if( current & 1 ) {
|
||||||
|
opt.features |= QStyleOptionViewItemV2::Alternate;
|
||||||
|
} else {
|
||||||
|
opt.features &= ~QStyleOptionViewItemV2::Alternate;
|
||||||
|
}
|
||||||
|
++current;
|
||||||
|
style()->drawPrimitive( QStyle::PE_PanelItemViewRow, &opt, &p );
|
||||||
|
y += rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bg;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicView::animFinished()
|
DynamicView::animFinished()
|
||||||
{
|
{
|
||||||
@@ -294,7 +300,6 @@ DynamicView::paintEvent( QPaintEvent* event )
|
|||||||
bg.moveTo( m_fadingPointAnchor ); // cover up the background
|
bg.moveTo( m_fadingPointAnchor ); // cover up the background
|
||||||
if( m_fadebg ) {
|
if( m_fadebg ) {
|
||||||
p.save();
|
p.save();
|
||||||
p.fillRect( bg, Qt::white );
|
|
||||||
|
|
||||||
p.setOpacity( 1 - m_fadeOutAnim.currentValue() );
|
p.setOpacity( 1 - m_fadeOutAnim.currentValue() );
|
||||||
}
|
}
|
||||||
@@ -302,19 +307,13 @@ DynamicView::paintEvent( QPaintEvent* event )
|
|||||||
if( m_fadebg ) {
|
if( m_fadebg ) {
|
||||||
p.restore();
|
p.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << "FAST SETOPACITY:" << p.paintEngine()->hasFeature(QPaintEngine::ConstantOpacity);
|
// qDebug() << "FAST SETOPACITY:" << p.paintEngine()->hasFeature(QPaintEngine::ConstantOpacity);
|
||||||
p.setOpacity( 1 - m_fadeOutAnim.currentValue() );
|
p.setOpacity( 1 - m_fadeOutAnim.currentValue() );
|
||||||
p.drawPixmap( m_fadingPointAnchor, m_fadingIndexes );
|
p.drawPixmap( m_fadingPointAnchor, m_fadingIndexes );
|
||||||
|
|
||||||
p.restore();
|
p.restore();
|
||||||
|
|
||||||
if( m_slideAnim.state() == QTimeLine::Running ) {
|
if( m_slideAnim.state() == QTimeLine::Running ) {
|
||||||
// draw the collapsing entry
|
// draw the collapsing entry
|
||||||
QRect bg = m_slidingIndex.rect();
|
|
||||||
bg.moveTo( m_bottomAnchor );
|
|
||||||
bg.setBottom( m_bottomOfAnim.y() );
|
|
||||||
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( 0, m_bottomAnchor.y(), m_slidingIndex );
|
p.drawPixmap( 0, m_bottomAnchor.y(), m_slidingIndex );
|
||||||
|
@@ -63,6 +63,8 @@ private slots:
|
|||||||
void animFinished();
|
void animFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QPixmap backgroundBetween( QRect rect, int rowStart );
|
||||||
|
|
||||||
DynamicModel* m_model;
|
DynamicModel* m_model;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_body;
|
QString m_body;
|
||||||
|
Reference in New Issue
Block a user