[prev in list] [next in list] [prev in thread] [next in thread] 

List:       amarok-devel
Subject:    [PATCH] (needs review) fix lyrics applet
From:       Martin <darklight.xdarklight () googlemail ! com>
Date:       2009-09-14 19:02:20
Message-ID: 888a464d0909141202w4b7125aep70f702b0ace1997b () mail ! gmail ! com
[Download RAW message or body]

Hi,

ok, fixing 'some' lyrics issues was not enough for me :)
I was really annoyed by the fact that the lyrics applet
did NOT use system colors. as I'm using the Obisidan Coast
theme I have a dark color scheme - but somehow (not a bug
but a feature ;)) the background of the lyrics applet was
white (SIGH)

there's a bug report about this problem..
https://bugs.kde.org/show_bug.cgi?id=206495

so - I started refactoring the lyrics applet a bit
here's a list of changes that I've made:

* use system colors (FINALLY)
* show that cool spinner (from videoapplet) when a script
  is searching for lyrics
* optimize m_titleText away
* set the title of the applet to "Lyrics : Fetching ..."
  when a script is searching for lyrics (note: this does
  NOT break the string freeze as "Fetching ..." has
  been translated for the videoapplet already)
* removed some unused code
* tiny code cleanup

if you disagree with my coding style please feel free to
inform me what I should change :)

this patch needs testing before it can be pushed into
any stable branch! so you better don't put it in 2.2 ;)

PS: I'll try to seperate the color fix from all other changes
so maybe that part of the patch can go into 2.2
(if it's stable enough)

Regards,
Martin

["amarok-fix_lyrics_applet.patch" (text/x-diff)]

diff --git a/src/context/applets/lyrics/LyricsApplet.cpp \
b/src/context/applets/lyrics/LyricsApplet.cpp index 9efe994..28a8c9a 100644
--- a/src/context/applets/lyrics/LyricsApplet.cpp
+++ b/src/context/applets/lyrics/LyricsApplet.cpp
@@ -42,7 +42,6 @@
 
 LyricsApplet::LyricsApplet( QObject* parent, const QVariantList& args )
     : Context::Applet( parent, args )
-    , m_titleText( i18n( "Lyrics" ) )
     , m_titleLabel( 0 )
     , m_saveIcon( 0 )
     , m_editIcon( 0 )
@@ -53,7 +52,6 @@ LyricsApplet::LyricsApplet( QObject* parent, const QVariantList& \
args )  {
     setHasConfigurationInterface( false );
     setBackgroundHints( Plasma::Applet::NoBackground );
-
 }
 
 LyricsApplet::~ LyricsApplet()
@@ -104,29 +102,23 @@ void LyricsApplet::init()
     connect( m_reloadIcon, SIGNAL( activated() ), this, SLOT( refreshLyrics() ) );
 
     m_lyricsProxy = new QGraphicsProxyWidget( this );
+    
     m_lyrics = new QTextBrowser;
+    // required - if removed the background color change
+    // functionality in edit mode will break!
     m_lyrics->setAttribute( Qt::WA_NoSystemBackground );
     m_lyrics->setOpenExternalLinks( true );
     m_lyrics->setWordWrapMode( QTextOption::WordWrap );
     m_lyrics->setTextInteractionFlags( Qt::TextBrowserInteraction | \
Qt::TextSelectableByKeyboard ); +
     setEditing( false );
 
     m_lyrics->setStyleSheet( QString( "QTextBrowser { background-color: %1; \
                border-width: 0px; border-radius: 0px; color: %2; }" )
-        .arg( PaletteHandler::highlightColor().lighter( 150 ).name() )
-        .arg( PaletteHandler::highlightColor().darker( 400 ).name() ) );
-
+        .arg( App::instance()->palette().background().color().name() )
+        .arg( App::instance()->palette().text().color().name() ) );
+    
     m_lyricsProxy->setWidget( m_lyrics );
 
-    QPalette pal;
-    QBrush brush( PaletteHandler::highlightColor().lighter( 170 ) );
-    brush.setStyle( Qt::SolidPattern );
-    pal.setBrush( QPalette::Active, QPalette::Base, brush );
-    pal.setBrush( QPalette::Inactive, QPalette::Base, brush );
-    pal.setBrush( QPalette::Disabled, QPalette::Base, brush );
-    pal.setBrush( QPalette::Window, brush );
-    m_lyrics->setPalette( pal );
-    m_lyricsProxy->setPalette( pal );
-
     // only show when we need to let the user
     // choose between suggestions
     m_suggested = new QGraphicsTextItem( this );
@@ -170,7 +162,7 @@ void LyricsApplet::constraintsEvent( Plasma::Constraints \
                constraints )
     qreal widmax = boundingRect().width() - 2 * iconWidth * 3 - 6 * \
                standardPadding();
     QRectF rect( ( boundingRect().width() - widmax ) / 2, 0 , widmax, 15 );
     
-    m_titleLabel->setScrollingText( m_titleText, rect );
+    m_titleLabel->setScrollingText( m_titleLabel->text(), rect );
     m_titleLabel->setPos( ( size().width() - m_titleLabel->boundingRect().width() ) \
/ 2 , standardPadding() + 3 );  
     m_reloadIcon->setPos( size().width() - iconWidth - standardPadding(), \
standardPadding() ); @@ -196,47 +188,64 @@ void LyricsApplet::dataUpdated( const \
QString& name, const Plasma::DataEngine::D  
     m_hasLyrics = false;
 
-    if( data.size() == 0 ) return;
+    if( data.size() == 0 )
+        return;
 
     //debug() << "got lyrics data: " << data;
 
+    m_titleLabel->setText( i18n( "Lyrics" ) );
+
     m_titleLabel->show();
+
+    setBusy( false );
+    
     if( data.contains( "noscriptrunning" ) )
     {
         m_suggested->hide();
-        m_lyrics->show();m_lyrics->setPlainText( i18n( "No lyrics script is \
running." ) ); +
+        m_lyrics->show();
+        m_lyrics->setPlainText( i18n( "No lyrics script is running." ) );
     }
     else if( data.contains( "stopped" ) )
     {
-        m_lyrics->clear();
-        m_titleText = QString( "%1" ).arg( i18n( "Lyrics" ) );
+        m_lyrics->hide();
+
         setCollapseHeight( 40 );
         setCollapseOn();
     }
     else if( data.contains( "fetching" ) )
     {
+        m_titleLabel->setText( i18n( "Lyrics" ) + QString( " : " ) + i18n( "Fetching \
..." ) ); +        
         m_suggested->hide();
+
         m_lyrics->show();
         m_lyrics->setPlainText( i18n( "Lyrics are being fetched." ) );
-        setCollapseHeight( 80 );
-        debug() << "lyrics small sizehint height:" << m_lyrics->sizeHint().height();
+
+        setCollapseHeight( 130 );
         setCollapseOn();
+
+        setBusy( true );
     }
     else if( data.contains( "error" ) )
     {
         m_suggested->hide();
+
         m_lyrics->show();
         m_lyrics->setPlainText( i18n( "Could not download lyrics.\nPlease check your \
internet connection.\nError message:\n%1", data["error"].toString() ) ); +
         setCollapseHeight( 80 );
         setCollapseOn();
     }
     else if( data.contains( "suggested" ) )
     {
         m_lyrics->hide();
+
         QVariantList suggested = data[ "suggested" ].toList();
         // build simple HTML to show
         // a list
         QString html = QString( "<br><br>" );
+        
         foreach( const QVariant &suggestion, suggested )
         {
             const QString sug = suggestion.toString();
@@ -244,38 +253,47 @@ void LyricsApplet::dataUpdated( const QString& name, const \
Plasma::DataEngine::D  const QString link = QString( "<a href=\"%1|%2|%3\">%4 - \
%5</a><br>" ).arg( pieces[ 0 ] ).arg( pieces[ 1 ] ).arg( pieces[ 2 ] ).arg( pieces[ 1 \
] ).arg( pieces[ 0 ] );  html += link;
         }
+        
         m_suggested->setHtml( html );
         m_suggested->show();
     }
     else if( data.contains( "html" ) )
     {
         m_hasLyrics = true;
+        
         // show pure html in the text area
         m_suggested->hide();
+
         m_lyrics->setHtml( data[ "html" ].toString() );
         m_lyrics->show();
+        
         setCollapseOff();
     }
     else if( data.contains( "lyrics" ) )
     {
         m_hasLyrics = true;
+
+        QVariantList lyrics  = data[ "lyrics" ].toList();
+        
+        m_titleLabel->setText(QString( " %1 : %2 - %3" ).arg( i18n( "Lyrics" ) \
).arg( lyrics[ 0 ].toString() ).arg( lyrics[ 1 ].toString() ) ); +        
         m_suggested->hide();
+
         m_lyrics->show();
-        QVariantList lyrics  = data[ "lyrics" ].toList();
 
-        m_titleText = QString( " %1 : %2 - %3" ).arg( i18n( "Lyrics" ) ).arg( \
lyrics[ 0 ].toString() ).arg( lyrics[ 1 ].toString() );  //  need padding for title
         m_lyrics->setPlainText( lyrics[ 3 ].toString().trimmed() );
+        
         setCollapseOff();
     }
     else if( data.contains( "notfound" ) )
     {
         m_suggested->hide();
+
         m_lyrics->show();
         m_lyrics->setPlainText( i18n( "There were no lyrics found for this track" ) \
);  
-        setCollapseHeight( m_lyrics->sizeHint().height() );
-        debug() << "lyrics small sizehint height:" << m_lyrics->sizeHint().height();
+        setCollapseHeight( 40 );
         setCollapseOn();
     }
 
@@ -295,6 +313,7 @@ LyricsApplet::paintInterface( QPainter *p, const \
QStyleOptionGraphicsItem *optio  {
     Q_UNUSED( option );
     Q_UNUSED( contentsRect );
+
     p->setRenderHint( QPainter::Antialiasing );
 
     // tint the whole applet
@@ -307,13 +326,12 @@ LyricsApplet::paintInterface( QPainter *p, const \
QStyleOptionGraphicsItem *optio  //draw background of lyrics text
     p->save();
 
-    QColor background = Qt::white; // TODO: Looks crap on dark colour schemes?
-    if( m_lyrics->isReadOnly() )
+    QColor background( App::instance()->palette().background().color() );
+    
+    if( !m_lyrics->isReadOnly() )
     {
-        QColor highlight( App::instance()->palette().highlight().color() );
-        highlight.setHsvF( highlight.hueF(), 0.07, 1, highlight.alphaF() );
-
-        background = highlight;
+        // different background color when we're in edit mode
+        background = App::instance()->palette().alternateBase().color();
     }
 
     // HACK
@@ -336,8 +354,9 @@ LyricsApplet::paletteChanged( const QPalette & palette )
     Q_UNUSED( palette )
 
     if( m_lyrics )
-       m_lyrics->setStyleSheet( QString( "QTextBrowser { background-color: %1; \
                border-width: 0px; border-radius: 0px; color: %2; }" )
-            .arg( PaletteHandler::highlightColor().lighter( 150 ).name() ).arg( \
PaletteHandler::highlightColor().darker( 400 ).name() ) ); +        \
m_lyrics->setStyleSheet( QString( "QTextBrowser { background-color: %1; border-width: \
0px; border-radius: 0px; color: %2; }" ) +            .arg( \
App::instance()->palette().background().color().name() ) +            .arg( \
App::instance()->palette().text().color().name() ) );  }
 
 void
diff --git a/src/context/applets/lyrics/LyricsApplet.h \
b/src/context/applets/lyrics/LyricsApplet.h index d5d9154..b160a8c 100644
--- a/src/context/applets/lyrics/LyricsApplet.h
+++ b/src/context/applets/lyrics/LyricsApplet.h
@@ -66,7 +66,6 @@ private:
 
     void collapseToMin();
 
-    QString m_titleText;
     TextScrollingWidget* m_titleLabel;
 
     Plasma::IconWidget*  m_saveIcon;



_______________________________________________
Amarok-devel mailing list
Amarok-devel@kde.org
https://mail.kde.org/mailman/listinfo/amarok-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic