From 1d093b2ef2d3b2271527776bd46f01f01e817686 Mon Sep 17 00:00:00 2001 From: nhnielsen Date: Wed, 14 Nov 2007 11:49:21 +0000 Subject: [PATCH] Make the active (playing) track marker look a bit better. It is now rendered from an svg element in the src/images/playlist_items.svg file, so any artists out there are free to experiment with this :-) git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/extragear/multimedia/amarok@736590 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/images/playlist_items.svg | 52 +++++++++++++++++++++++++++--- src/playlist/PlaylistGraphicsItem.cpp | 59 ++++++++++++++++++++++++++--------- 2 files changed, 93 insertions(+), 18 deletions(-) diff --git a/src/images/playlist_items.svg b/src/images/playlist_items.svg index 30a198ddb..5a72903e7 100644 --- a/src/images/playlist_items.svg +++ b/src/images/playlist_items.svg @@ -20,6 +20,17 @@ + + + + + + inkscape:window-y="14" + showguides="false" /> @@ -1423,5 +1446,26 @@ style="fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.21765792;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + + + diff --git a/src/playlist/PlaylistGraphicsItem.cpp b/src/playlist/PlaylistGraphicsItem.cpp index b8da244aa..53aa2f7ba 100644 --- a/src/playlist/PlaylistGraphicsItem.cpp +++ b/src/playlist/PlaylistGraphicsItem.cpp @@ -58,7 +58,7 @@ struct Playlist::GraphicsItem::ActiveItems } - QGraphicsRectItem* foreground; + QGraphicsPixmapItem* foreground; Playlist::TextItem* bottomLeftText; Playlist::TextItem* bottomRightText; Playlist::TextItem* topLeftText; @@ -336,10 +336,30 @@ Playlist::GraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem { if( !m_items->foreground ) { - m_items->foreground = new QGraphicsRectItem( QRectF( 0.0, 0.0, trackRect.width(), trackRect.height() ) , this ); + + debug() << "Creating active track overlay"; + m_items->foreground = new QGraphicsPixmapItem( this ); m_items->foreground->setPos( 0.0, trackRect.top() ); m_items->foreground->setZValue( 10.0 ); - QRadialGradient gradient(trackRect.width() / 2.0, trackRect.height() / 2.0, trackRect.width() / 2.0, 20 + trackRect.width() / 2.0, trackRect.height() / 2.0 ); + + + QString key = QString("active_overlay:%1x%2").arg(trackRect.width()).arg(trackRect.height()); + QPixmap background( (int)( trackRect.width() ), (int)( trackRect.height() ) ); + background.fill( Qt::transparent ); + + debug() << "Key string: " << key; + + if (!QPixmapCache::find(key, background)) { + QPainter pt( &background ); + s_svgRenderer->render( &pt, "active_overlay", QRectF( 0, 0, trackRect.width(), trackRect.height() ) ); + QPixmapCache::insert(key, background); + } + m_items->foreground->setPixmap( background ); + m_items->foreground->show(); + debug() << "Done"; + + + /*QRadialGradient gradient(trackRect.width() / 2.0, trackRect.height() / 2.0, trackRect.width() / 2.0, 20 + trackRect.width() / 2.0, trackRect.height() / 2.0 ); m_items->overlayGradientStart = option->palette.highlightedText().color().light(); m_items->overlayGradientStart.setAlpha( 80 ); m_items->overlayGradientEnd = option->palette.highlightedText().color().dark(); @@ -348,12 +368,11 @@ Playlist::GraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem gradient.setColorAt( 1.0, m_items->overlayGradientEnd ); QBrush brush( gradient ); m_items->foreground->setBrush( brush ); - m_items->foreground->setPen( QPen( Qt::NoPen ) ); + m_items->foreground->setPen( QPen( Qt::NoPen ) );*/ } if( !m_items->foreground->isVisible() ) m_items->foreground->show(); - } - else if( m_items->foreground && m_items->foreground->isVisible() ) + } else if( m_items->foreground && m_items->foreground->isVisible() ) m_items->foreground->hide(); } @@ -496,14 +515,26 @@ Playlist::GraphicsItem::resize( Meta::TrackPtr track, int totalWidth ) if ( ( m_groupMode != Body) && !( ( m_groupMode == Head ) ) ) trackRect.setHeight( trackRect.height() - 2 ); // add a little space between items } - - QRadialGradient gradient(trackRect.width() / 2.0, trackRect.height() / 2.0, trackRect.width() / 2.0, 20 + trackRect.width() / 2.0, trackRect.height() / 2.0 ); - gradient.setColorAt( 0.0, m_items->overlayGradientStart ); - gradient.setColorAt( 1.0, m_items->overlayGradientEnd ); - QBrush brush( gradient ); - m_items->foreground->setRect( 0, 0, totalWidth, trackRect.height() ); - m_items->foreground->setBrush( brush ); - m_items->foreground->setPen( QPen( Qt::NoPen ) ); + + debug() << "Resizing active track overlay"; + + QString key = QString("active_overlay:%1x%2").arg(trackRect.width()).arg(trackRect.height()); + + debug() << "Key string: " << key; + QPixmap background( (int)( trackRect.width() ), (int)( trackRect.height() ) ); + background.fill( Qt::transparent ); + + + if (!QPixmapCache::find(key, background)) { + QPainter pt( &background ); + s_svgRenderer->render( &pt, "active_overlay", trackRect ); + QPixmapCache::insert(key, background); + } + m_items->foreground->setPixmap( background ); + m_items->foreground->setZValue( 10.0 ); + + debug() << "Done"; + } m_items->lastWidth = totalWidth; -- 2.11.4.GIT