Bug 220714

Summary: & in track title shows as & in lyrics title
Product: [Applications] amarok Reporter: Oliver
Component: Context ViewAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal CC: lfranchi, Oliver, simon.esneault, stuffcorpse
Priority: NOR    
Version: 2.3-GIT   
Target Milestone: 2.3.0   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Screenshot

Description Oliver 2009-12-30 18:46:39 UTC
Version:            (using KDE 4.3.3)
Compiler:          gcc (Gentoo 4.3.4 p1.0, pie-10.1.5) 4.3.4 
OS:                Linux
Installed from:    Gentoo Packages

A "&" in a track title (like 'Take a Bow (Tony Moran & Warren Rigg Remix)') is displayed as "&amp;" in the lyrics title in the context browser.

Tested with Amarok 2.2.1 and 2.2.1.90 (2.2.2 Beta 1).
Comment 1 Oliver 2009-12-30 18:49:33 UTC
Created attachment 39466 [details]
Screenshot
Comment 2 Mikko C. 2010-01-03 17:36:14 UTC
confirmed here with git master
Comment 3 Rick W. Chen 2010-01-04 04:13:06 UTC
commit 3d3a77f3481788cf365c26433ef9748bdb295a9a
Author: Rick W. Chen <stuffcorpse@archlinux.us>
Date:   Mon Jan 4 15:53:30 2010 +1300

    Support rich text in applet header text, for the love of ampersands
    
    BUG: 220714

diff --git a/ChangeLog b/ChangeLog
index a81d435..1da5bcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ VERSION 2.2.2
       fallback. Patch by Andreas Hartmetz <ahartmetz@gmail.com>.
 
   BUGFIXES:
+    * Fixed incorrect display of rich text in applet header text. (BR 220714)
     * Fixed GUI freezing after mounting and during parse of media devices
       (BR 180520)
     * Fixed occasional crash when custom biases go awry. (BR 219888)
diff --git a/src/context/Applet.cpp b/src/context/Applet.cpp
index df7fd32..745334a 100644
--- a/src/context/Applet.cpp
+++ b/src/context/Applet.cpp
@@ -101,7 +101,7 @@ Context::Applet::truncateTextToFit( QString text, const QFont& font, const QRect
 }
 
 void
-Context::Applet::drawRoundedRectAroundText( QPainter* p, QGraphicsSimpleTextItem* textItem )
+Context::Applet::drawRoundedRectAroundText( QPainter* p, QGraphicsTextItem* textItem )
 {
     p->save();
     p->setRenderHint( QPainter::Antialiasing );
diff --git a/src/context/Applet.h b/src/context/Applet.h
index 959dd82..a06db95 100644
--- a/src/context/Applet.h
+++ b/src/context/Applet.h
@@ -47,7 +47,7 @@ class AMAROK_EXPORT Applet : public Plasma::Applet
         QFont shrinkTextSizeToFit( const QString& text, const QRectF& bounds );
         QString truncateTextToFit( QString text, const QFont& font, const QRectF& bounds );
 
-        void drawRoundedRectAroundText( QPainter* p, QGraphicsSimpleTextItem* t );
+        void drawRoundedRectAroundText( QPainter* p, QGraphicsTextItem* t );
         void addGradientToAppletBackground( QPainter* p );
 
         /**
diff --git a/src/context/applets/videoclip/VideoclipApplet.cpp b/src/context/applets/videoclip/VideoclipApplet.cpp
index 0187901..d6b1894 100644
--- a/src/context/applets/videoclip/VideoclipApplet.cpp
+++ b/src/context/applets/videoclip/VideoclipApplet.cpp
@@ -34,6 +34,7 @@
 #include "SvgHandler.h"
 #include "widgets/kratingpainter.h"
 #include "widgets/kratingwidget.h"
+#include "widgets/TextScrollingWidget.h"
 
 // KDE
 #include <KColorScheme>
@@ -50,7 +51,6 @@
 // Qt
 #include <QGraphicsLinearLayout>
 #include <QGraphicsProxyWidget>
-#include <QGraphicsTextItem>
 #include <QGraphicsWidget>
 #include <QGridLayout>
 #include <QLabel>
@@ -112,7 +112,7 @@ VideoclipApplet::init()
     // Create label
     QFont labelFont;
     labelFont.setPointSize( labelFont.pointSize() + 2 );
-    m_headerText = new QGraphicsSimpleTextItem( this );
+    m_headerText = new TextScrollingWidget( this );
     m_headerText->setBrush( Plasma::Theme::defaultTheme()->color( Plasma::Theme::TextColor ) );
     m_headerText->setFont( labelFont );
     m_headerText->setText( i18n( "Video Clip" ) );
@@ -268,6 +268,11 @@ VideoclipApplet::constraintsEvent( Plasma::Constraints constraints )
     Q_UNUSED( constraints );
     prepareGeometryChange();
 
+    qreal widmax = boundingRect().width() - 4 * standardPadding();
+    QRectF rect( ( boundingRect().width() - widmax ) / 2, 0 , widmax, 15 );
+
+    m_headerText->setScrollingText( m_headerText->text(), rect );
+
     // tint the applet size
     m_headerText->setPos( size().width() / 2 - m_headerText->boundingRect().width() / 2, standardPadding() + 3 );
     m_widget->setPos( standardPadding(), m_headerText->pos().y() + m_headerText->boundingRect().height() + standardPadding() );
diff --git a/src/context/applets/videoclip/VideoclipApplet.h b/src/context/applets/videoclip/VideoclipApplet.h
index fb11459..56b185f 100644
--- a/src/context/applets/videoclip/VideoclipApplet.h
+++ b/src/context/applets/videoclip/VideoclipApplet.h
@@ -58,6 +58,7 @@ class QHBoxLayout;
 class QScrollArea;
 
 class CustomVideoWidget;
+class TextScrollingWidget;
 class VideoItemButton;
 
 
@@ -102,7 +103,7 @@ class VideoclipApplet : public Context::Applet, public EngineObserver
      //   Phonon::VideoWidget       *m_videoWidget;
 
         // The two big container, only one who need a resize
-        QGraphicsSimpleTextItem *m_headerText;
+        TextScrollingWidget     *m_headerText;
         QGraphicsProxyWidget    *m_widget;
         QScrollArea             *m_scroll;
         QHBoxLayout             *m_layout;
diff --git a/src/context/applets/wikipedia/WikipediaApplet.cpp b/src/context/applets/wikipedia/WikipediaApplet.cpp
index 6fb6365..ed8ec57 100644
--- a/src/context/applets/wikipedia/WikipediaApplet.cpp
+++ b/src/context/applets/wikipedia/WikipediaApplet.cpp
@@ -24,6 +24,7 @@
 #include "context/ContextView.h"
 #include "EngineController.h"
 #include "PaletteHandler.h"
+#include "widgets/TextScrollingWidget.h"
 
 #include <Plasma/Theme>
 #include <plasma/widgets/webview.h>
@@ -38,7 +39,6 @@
 
 #include <QAction>
 #include <QDesktopServices>
-#include <QGraphicsSimpleTextItem>
 #include <QPainter>
 #include <QMenu>
 #include <QWebHistory>
@@ -74,7 +74,7 @@ WikipediaApplet::~ WikipediaApplet()
 void
 WikipediaApplet::init()
 {   
-    m_wikipediaLabel = new QGraphicsSimpleTextItem( this );
+    m_wikipediaLabel = new TextScrollingWidget( this );
 
     m_webView = new Plasma::WebView( this );
     m_webView->setAttribute( Qt::WA_NoSystemBackground );
@@ -171,11 +171,15 @@ void
 WikipediaApplet::constraintsEvent( Plasma::Constraints constraints )
 {
     Q_UNUSED( constraints );
-    
+
     prepareGeometryChange();
     const float textWidth = m_wikipediaLabel->boundingRect().width();
     const float offsetX =  ( boundingRect().width() - textWidth ) / 2;
 
+    const qreal widmax = boundingRect().width() - 4 * standardPadding();
+    const QRectF rect( ( boundingRect().width() - widmax ) / 2, 0 , widmax, 15 );
+
+    m_wikipediaLabel->setScrollingText( m_wikipediaLabel->text(), rect );
     m_wikipediaLabel->setPos( offsetX, standardPadding() + 2 );
 
     m_webView->setPos( standardPadding(), m_wikipediaLabel->pos().y() + m_wikipediaLabel->boundingRect().height() + standardPadding() );
diff --git a/src/context/applets/wikipedia/WikipediaApplet.h b/src/context/applets/wikipedia/WikipediaApplet.h
index f8af410..fd52c70 100644
--- a/src/context/applets/wikipedia/WikipediaApplet.h
+++ b/src/context/applets/wikipedia/WikipediaApplet.h
@@ -31,10 +31,9 @@
 #include <ui_wikipediaSettings.h>
 
 class QAction;
-class QGraphicsSimpleTextItem;
-class QGraphicsTextItem;
 class KDialog;
 class KConfigDialog;
+class TextScrollingWidget;
 
 namespace Plasma
 {
@@ -69,7 +68,7 @@ private:
     qreal m_headerAspectRatio;
     QSizeF m_size;
 
-    QGraphicsSimpleTextItem* m_wikipediaLabel;
+    TextScrollingWidget* m_wikipediaLabel;
 
     Plasma::WebView * m_webView;
 
diff --git a/src/context/widgets/TextScrollingWidget.cpp b/src/context/widgets/TextScrollingWidget.cpp
index d376152..a4a9f13 100644
--- a/src/context/widgets/TextScrollingWidget.cpp
+++ b/src/context/widgets/TextScrollingWidget.cpp
@@ -20,10 +20,11 @@
 
 #include <QFont>
 #include <QFontMetrics>
-#include <QGraphicsSimpleTextItem>
+#include <QGraphicsTextItem>
 #include <QGraphicsSceneHoverEvent>
 #include <QGraphicsWidget>
 #include <QPainter>
+#include <QTextDocument>
 #include <QTimer>
 
 #include <Plasma/Animator>
@@ -32,7 +33,7 @@
 
 
 TextScrollingWidget::TextScrollingWidget( QGraphicsItem* parent )
-    : QGraphicsSimpleTextItem( parent )
+    : QGraphicsTextItem( parent )
     , m_fm( 0 )
     , m_text( 0 )
     , m_delta( 0 )
@@ -43,6 +44,13 @@ TextScrollingWidget::TextScrollingWidget( QGraphicsItem* parent )
 {
     setAcceptHoverEvents( true );
     connect ( Plasma::Animator::self(), SIGNAL(customAnimationFinished ( int ) ), this, SLOT( animationFinished( int ) ) );
+    document()->setDocumentMargin( 0 );
+}
+
+void
+TextScrollingWidget::setBrush( const QBrush &brush )
+{
+    setDefaultTextColor( brush.color() );
 }
 
 void
@@ -59,12 +67,26 @@ TextScrollingWidget::setScrollingText( const QString text, QRectF rect )
     Plasma::Animator::self()->stopCustomAnimation( m_animback );
     Plasma::Animator::self()->stopCustomAnimation( m_animfor );
     m_animating = false ;
-        
-    m_delta = m_fm->boundingRect( m_text ).width() + 5 > m_rect.width() ? m_fm->boundingRect( m_text ).width() + 8 - m_rect.width() : 0;
+
+    const QRect textRect = m_fm->boundingRect( m_text );
+    m_delta = textRect.width() + 5 > m_rect.width()
+            ? textRect.width() + 8 - m_rect.width() : 0;
     setText( m_fm->elidedText ( m_text, Qt::ElideRight, (int)m_rect.width() ) );
 }
 
 void
+TextScrollingWidget::setText( const QString &text )
+{
+    setHtml( text );
+}
+
+QString
+TextScrollingWidget::text() const
+{
+    return toPlainText();
+}
+
+void
 TextScrollingWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     // clip the widget.
@@ -72,7 +94,7 @@ TextScrollingWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
     rec.setWidth( m_rect.width() );
     
     painter->setClipRegion( QRegion( rec ) );
-    QGraphicsSimpleTextItem::paint( painter, option, widget );
+    QGraphicsTextItem::paint( painter, option, widget );
 }
 
 void
diff --git a/src/context/widgets/TextScrollingWidget.h b/src/context/widgets/TextScrollingWidget.h
index 66b3210..0b1d6e3 100644
--- a/src/context/widgets/TextScrollingWidget.h
+++ b/src/context/widgets/TextScrollingWidget.h
@@ -19,7 +19,7 @@
 
 #include "amarok_export.h"
 
-#include <QGraphicsSimpleTextItem>
+#include <QGraphicsTextItem>
 
 //forward
 class QFontMetrics;
@@ -30,28 +30,34 @@ namespace Plasma
 }
 
 /**
-* \brief An animated QGrahicsSimpleTextItem on hovering
+* \brief An animated QGrahicsTextItem on hovering
 *
 * The text will be automatically truncate to a QrectF and will be animated when hovering
 *
-* \sa QGraphicsSimpleTextItem
+* \sa QGraphicsTextItem
 *
 * \author Simon Esneault <simon.esneault@gmail.com>
 */
 
-class AMAROK_EXPORT TextScrollingWidget : public QObject, public QGraphicsSimpleTextItem
+class AMAROK_EXPORT TextScrollingWidget : public QGraphicsTextItem
 {
     Q_OBJECT
     public:
 
         TextScrollingWidget( QGraphicsItem* parent = 0 );
 
+        void setBrush( const QBrush &brush );
+
         /**
         * Set the Text and more important the QRectF which will define the scrolling area
         */
         void setScrollingText( const QString, QRectF );
 
-        bool isAnimating( );
+        void setText( const QString &text );
+
+        QString text() const;
+
+        bool isAnimating();
 
     public slots:
         void animateFor( qreal anim );
Comment 4 Rick W. Chen 2010-01-04 04:13:17 UTC
commit 3d3a77f3481788cf365c26433ef9748bdb295a9a
Author: Rick W. Chen <stuffcorpse@archlinux.us>
Date:   Mon Jan 4 15:53:30 2010 +1300

    Support rich text in applet header text, for the love of ampersands
    
    BUG: 220714

diff --git a/ChangeLog b/ChangeLog
index a81d435..1da5bcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ VERSION 2.2.2
       fallback. Patch by Andreas Hartmetz <ahartmetz@gmail.com>.
 
   BUGFIXES:
+    * Fixed incorrect display of rich text in applet header text. (BR 220714)
     * Fixed GUI freezing after mounting and during parse of media devices
       (BR 180520)
     * Fixed occasional crash when custom biases go awry. (BR 219888)
diff --git a/src/context/Applet.cpp b/src/context/Applet.cpp
index df7fd32..745334a 100644
--- a/src/context/Applet.cpp
+++ b/src/context/Applet.cpp
@@ -101,7 +101,7 @@ Context::Applet::truncateTextToFit( QString text, const QFont& font, const QRect
 }
 
 void
-Context::Applet::drawRoundedRectAroundText( QPainter* p, QGraphicsSimpleTextItem* textItem )
+Context::Applet::drawRoundedRectAroundText( QPainter* p, QGraphicsTextItem* textItem )
 {
     p->save();
     p->setRenderHint( QPainter::Antialiasing );
diff --git a/src/context/Applet.h b/src/context/Applet.h
index 959dd82..a06db95 100644
--- a/src/context/Applet.h
+++ b/src/context/Applet.h
@@ -47,7 +47,7 @@ class AMAROK_EXPORT Applet : public Plasma::Applet
         QFont shrinkTextSizeToFit( const QString& text, const QRectF& bounds );
         QString truncateTextToFit( QString text, const QFont& font, const QRectF& bounds );
 
-        void drawRoundedRectAroundText( QPainter* p, QGraphicsSimpleTextItem* t );
+        void drawRoundedRectAroundText( QPainter* p, QGraphicsTextItem* t );
         void addGradientToAppletBackground( QPainter* p );
 
         /**
diff --git a/src/context/applets/videoclip/VideoclipApplet.cpp b/src/context/applets/videoclip/VideoclipApplet.cpp
index 0187901..d6b1894 100644
--- a/src/context/applets/videoclip/VideoclipApplet.cpp
+++ b/src/context/applets/videoclip/VideoclipApplet.cpp
@@ -34,6 +34,7 @@
 #include "SvgHandler.h"
 #include "widgets/kratingpainter.h"
 #include "widgets/kratingwidget.h"
+#include "widgets/TextScrollingWidget.h"
 
 // KDE
 #include <KColorScheme>
@@ -50,7 +51,6 @@
 // Qt
 #include <QGraphicsLinearLayout>
 #include <QGraphicsProxyWidget>
-#include <QGraphicsTextItem>
 #include <QGraphicsWidget>
 #include <QGridLayout>
 #include <QLabel>
@@ -112,7 +112,7 @@ VideoclipApplet::init()
     // Create label
     QFont labelFont;
     labelFont.setPointSize( labelFont.pointSize() + 2 );
-    m_headerText = new QGraphicsSimpleTextItem( this );
+    m_headerText = new TextScrollingWidget( this );
     m_headerText->setBrush( Plasma::Theme::defaultTheme()->color( Plasma::Theme::TextColor ) );
     m_headerText->setFont( labelFont );
     m_headerText->setText( i18n( "Video Clip" ) );
@@ -268,6 +268,11 @@ VideoclipApplet::constraintsEvent( Plasma::Constraints constraints )
     Q_UNUSED( constraints );
     prepareGeometryChange();
 
+    qreal widmax = boundingRect().width() - 4 * standardPadding();
+    QRectF rect( ( boundingRect().width() - widmax ) / 2, 0 , widmax, 15 );
+
+    m_headerText->setScrollingText( m_headerText->text(), rect );
+
     // tint the applet size
     m_headerText->setPos( size().width() / 2 - m_headerText->boundingRect().width() / 2, standardPadding() + 3 );
     m_widget->setPos( standardPadding(), m_headerText->pos().y() + m_headerText->boundingRect().height() + standardPadding() );
diff --git a/src/context/applets/videoclip/VideoclipApplet.h b/src/context/applets/videoclip/VideoclipApplet.h
index fb11459..56b185f 100644
--- a/src/context/applets/videoclip/VideoclipApplet.h
+++ b/src/context/applets/videoclip/VideoclipApplet.h
@@ -58,6 +58,7 @@ class QHBoxLayout;
 class QScrollArea;
 
 class CustomVideoWidget;
+class TextScrollingWidget;
 class VideoItemButton;
 
 
@@ -102,7 +103,7 @@ class VideoclipApplet : public Context::Applet, public EngineObserver
      //   Phonon::VideoWidget       *m_videoWidget;
 
         // The two big container, only one who need a resize
-        QGraphicsSimpleTextItem *m_headerText;
+        TextScrollingWidget     *m_headerText;
         QGraphicsProxyWidget    *m_widget;
         QScrollArea             *m_scroll;
         QHBoxLayout             *m_layout;
diff --git a/src/context/applets/wikipedia/WikipediaApplet.cpp b/src/context/applets/wikipedia/WikipediaApplet.cpp
index 6fb6365..ed8ec57 100644
--- a/src/context/applets/wikipedia/WikipediaApplet.cpp
+++ b/src/context/applets/wikipedia/WikipediaApplet.cpp
@@ -24,6 +24,7 @@
 #include "context/ContextView.h"
 #include "EngineController.h"
 #include "PaletteHandler.h"
+#include "widgets/TextScrollingWidget.h"
 
 #include <Plasma/Theme>
 #include <plasma/widgets/webview.h>
@@ -38,7 +39,6 @@
 
 #include <QAction>
 #include <QDesktopServices>
-#include <QGraphicsSimpleTextItem>
 #include <QPainter>
 #include <QMenu>
 #include <QWebHistory>
@@ -74,7 +74,7 @@ WikipediaApplet::~ WikipediaApplet()
 void
 WikipediaApplet::init()
 {   
-    m_wikipediaLabel = new QGraphicsSimpleTextItem( this );
+    m_wikipediaLabel = new TextScrollingWidget( this );
 
     m_webView = new Plasma::WebView( this );
     m_webView->setAttribute( Qt::WA_NoSystemBackground );
@@ -171,11 +171,15 @@ void
 WikipediaApplet::constraintsEvent( Plasma::Constraints constraints )
 {
     Q_UNUSED( constraints );
-    
+
     prepareGeometryChange();
     const float textWidth = m_wikipediaLabel->boundingRect().width();
     const float offsetX =  ( boundingRect().width() - textWidth ) / 2;
 
+    const qreal widmax = boundingRect().width() - 4 * standardPadding();
+    const QRectF rect( ( boundingRect().width() - widmax ) / 2, 0 , widmax, 15 );
+
+    m_wikipediaLabel->setScrollingText( m_wikipediaLabel->text(), rect );
     m_wikipediaLabel->setPos( offsetX, standardPadding() + 2 );
 
     m_webView->setPos( standardPadding(), m_wikipediaLabel->pos().y() + m_wikipediaLabel->boundingRect().height() + standardPadding() );
diff --git a/src/context/applets/wikipedia/WikipediaApplet.h b/src/context/applets/wikipedia/WikipediaApplet.h
index f8af410..fd52c70 100644
--- a/src/context/applets/wikipedia/WikipediaApplet.h
+++ b/src/context/applets/wikipedia/WikipediaApplet.h
@@ -31,10 +31,9 @@
 #include <ui_wikipediaSettings.h>
 
 class QAction;
-class QGraphicsSimpleTextItem;
-class QGraphicsTextItem;
 class KDialog;
 class KConfigDialog;
+class TextScrollingWidget;
 
 namespace Plasma
 {
@@ -69,7 +68,7 @@ private:
     qreal m_headerAspectRatio;
     QSizeF m_size;
 
-    QGraphicsSimpleTextItem* m_wikipediaLabel;
+    TextScrollingWidget* m_wikipediaLabel;
 
     Plasma::WebView * m_webView;
 
diff --git a/src/context/widgets/TextScrollingWidget.cpp b/src/context/widgets/TextScrollingWidget.cpp
index d376152..a4a9f13 100644
--- a/src/context/widgets/TextScrollingWidget.cpp
+++ b/src/context/widgets/TextScrollingWidget.cpp
@@ -20,10 +20,11 @@
 
 #include <QFont>
 #include <QFontMetrics>
-#include <QGraphicsSimpleTextItem>
+#include <QGraphicsTextItem>
 #include <QGraphicsSceneHoverEvent>
 #include <QGraphicsWidget>
 #include <QPainter>
+#include <QTextDocument>
 #include <QTimer>
 
 #include <Plasma/Animator>
@@ -32,7 +33,7 @@
 
 
 TextScrollingWidget::TextScrollingWidget( QGraphicsItem* parent )
-    : QGraphicsSimpleTextItem( parent )
+    : QGraphicsTextItem( parent )
     , m_fm( 0 )
     , m_text( 0 )
     , m_delta( 0 )
@@ -43,6 +44,13 @@ TextScrollingWidget::TextScrollingWidget( QGraphicsItem* parent )
 {
     setAcceptHoverEvents( true );
     connect ( Plasma::Animator::self(), SIGNAL(customAnimationFinished ( int ) ), this, SLOT( animationFinished( int ) ) );
+    document()->setDocumentMargin( 0 );
+}
+
+void
+TextScrollingWidget::setBrush( const QBrush &brush )
+{
+    setDefaultTextColor( brush.color() );
 }
 
 void
@@ -59,12 +67,26 @@ TextScrollingWidget::setScrollingText( const QString text, QRectF rect )
     Plasma::Animator::self()->stopCustomAnimation( m_animback );
     Plasma::Animator::self()->stopCustomAnimation( m_animfor );
     m_animating = false ;
-        
-    m_delta = m_fm->boundingRect( m_text ).width() + 5 > m_rect.width() ? m_fm->boundingRect( m_text ).width() + 8 - m_rect.width() : 0;
+
+    const QRect textRect = m_fm->boundingRect( m_text );
+    m_delta = textRect.width() + 5 > m_rect.width()
+            ? textRect.width() + 8 - m_rect.width() : 0;
     setText( m_fm->elidedText ( m_text, Qt::ElideRight, (int)m_rect.width() ) );
 }
 
 void
+TextScrollingWidget::setText( const QString &text )
+{
+    setHtml( text );
+}
+
+QString
+TextScrollingWidget::text() const
+{
+    return toPlainText();
+}
+
+void
 TextScrollingWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     // clip the widget.
@@ -72,7 +94,7 @@ TextScrollingWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
     rec.setWidth( m_rect.width() );
     
     painter->setClipRegion( QRegion( rec ) );
-    QGraphicsSimpleTextItem::paint( painter, option, widget );
+    QGraphicsTextItem::paint( painter, option, widget );
 }
 
 void
diff --git a/src/context/widgets/TextScrollingWidget.h b/src/context/widgets/TextScrollingWidget.h
index 66b3210..0b1d6e3 100644
--- a/src/context/widgets/TextScrollingWidget.h
+++ b/src/context/widgets/TextScrollingWidget.h
@@ -19,7 +19,7 @@
 
 #include "amarok_export.h"
 
-#include <QGraphicsSimpleTextItem>
+#include <QGraphicsTextItem>
 
 //forward
 class QFontMetrics;
@@ -30,28 +30,34 @@ namespace Plasma
 }
 
 /**
-* \brief An animated QGrahicsSimpleTextItem on hovering
+* \brief An animated QGrahicsTextItem on hovering
 *
 * The text will be automatically truncate to a QrectF and will be animated when hovering
 *
-* \sa QGraphicsSimpleTextItem
+* \sa QGraphicsTextItem
 *
 * \author Simon Esneault <simon.esneault@gmail.com>
 */
 
-class AMAROK_EXPORT TextScrollingWidget : public QObject, public QGraphicsSimpleTextItem
+class AMAROK_EXPORT TextScrollingWidget : public QGraphicsTextItem
 {
     Q_OBJECT
     public:
 
         TextScrollingWidget( QGraphicsItem* parent = 0 );
 
+        void setBrush( const QBrush &brush );
+
         /**
         * Set the Text and more important the QRectF which will define the scrolling area
         */
         void setScrollingText( const QString, QRectF );
 
-        bool isAnimating( );
+        void setText( const QString &text );
+
+        QString text() const;
+
+        bool isAnimating();
 
     public slots:
         void animateFor( qreal anim );
Comment 5 Rick W. Chen 2010-05-28 23:01:08 UTC
commit 8faa6e1454524b604d4114a65b1f86d0e3ee01f3
Author: Rick W. Chen <stuffcorpse@archlinux.us>
Date:   Fri May 21 05:55:28 2010 +1200

    Fix lyrics applet title and ampersands
    
    Commit bc32723 introduced a regression. While the current track applet
    will now correctly show special characters (which was broken by an even
    earlier commit 3d3a77f), the lyrics applet now suffers from the same
    issue. This fixes that by allowing a particular text format to be set
    for the TextScrollingWidget, with plain text as the default.
    
    CCBUG:220714
    CCBUG:222765

diff --git a/src/context/applets/lyrics/LyricsApplet.cpp b/src/context/applets/lyrics/LyricsApplet.cpp
index 3fcf3b2..c1944e4 100644
--- a/src/context/applets/lyrics/LyricsApplet.cpp
+++ b/src/context/applets/lyrics/LyricsApplet.cpp
@@ -78,6 +78,7 @@ void LyricsApplet::init()
     m_titleLabel = new TextScrollingWidget( this );
     QFont bigger = m_titleLabel->font();
     bigger.setPointSize( bigger.pointSize() + 2 );
+    m_titleLabel->setTextFormat( Qt::RichText );
     m_titleLabel->setFont( bigger );
     m_titleLabel->setZValue( m_titleLabel->zValue() + 100 );
     m_titleLabel->setText( i18n( "Lyrics" ) );
diff --git a/src/context/widgets/TextScrollingWidget.cpp b/src/context/widgets/TextScrollingWidget.cpp
index 2d5d5e5..65def77 100644
--- a/src/context/widgets/TextScrollingWidget.cpp
+++ b/src/context/widgets/TextScrollingWidget.cpp
@@ -35,6 +35,7 @@
 TextScrollingWidget::TextScrollingWidget( QGraphicsItem* parent )
     : QGraphicsTextItem( parent )
     , m_fm( 0 )
+    , m_textFormat( Qt::PlainText )
     , m_delta( 0 )
     , m_currentDelta( 0. )
     , m_animfor( 0 )
@@ -53,7 +54,7 @@ TextScrollingWidget::setBrush( const QBrush &brush )
 }
 
 void
-TextScrollingWidget::setScrollingText( const QString text, QRectF rect )
+TextScrollingWidget::setScrollingText( const QString &text, const QRectF &rect )
 {
  //   DEBUG_BLOCK
     if ( !m_fm )
@@ -67,22 +68,60 @@ TextScrollingWidget::setScrollingText( const QString text, QRectF rect )
     Plasma::Animator::self()->stopCustomAnimation( m_animfor );
     m_animating = false ;
 
-    const QRect textRect = m_fm->boundingRect( m_text );
-    m_delta = textRect.width() + 5 > m_rect.width()
-            ? textRect.width() + 8 - m_rect.width() : 0;
-    setText( m_fm->elidedText ( m_text, Qt::ElideRight, (int)m_rect.width() ) );
+    const int textWidth = m_fm->width( m_text );
+    m_delta = textWidth + 5 > m_rect.width() ? textWidth + 8 - m_rect.width() : 0;
+    setText( m_fm->elidedText( m_text, Qt::ElideRight, (int)m_rect.width() ) );
 }
 
 void
 TextScrollingWidget::setText( const QString &text )
 {
-    setPlainText( text );
+    if( requirePlainText() )
+        setPlainText( text );
+    else
+        setHtml( text );
+}
+
+void
+TextScrollingWidget::setTextFormat( Qt::TextFormat fmt )
+{
+    m_textFormat = fmt;
 }
 
 QString
 TextScrollingWidget::text() const
 {
-    return toPlainText();
+    if( requirePlainText() )
+        return toPlainText();
+    else
+        return toHtml();
+}
+
+bool
+TextScrollingWidget::requirePlainText() const
+{
+    bool plain;
+    switch( m_textFormat )
+    {
+    case Qt::RichText:
+        plain = false;
+        break;
+
+    case Qt::AutoText:
+        plain = !Qt::mightBeRichText( m_text );
+        break;
+
+    case Qt::PlainText:
+    default:
+        plain = true;
+    }
+    return plain;
+}
+
+Qt::TextFormat
+TextScrollingWidget::textFormat() const
+{
+    return m_textFormat;
 }
 
 void
@@ -136,7 +175,7 @@ TextScrollingWidget::animationFinished( int id )
         else
         {
             m_animating = false;
-            setText( m_fm->elidedText ( m_text, Qt::ElideRight, (int)( m_rect.width() ) ) );
+            setText( m_fm->elidedText( m_text, Qt::ElideRight, (int)( m_rect.width() ) ) );
         }
     }
 }
diff --git a/src/context/widgets/TextScrollingWidget.h b/src/context/widgets/TextScrollingWidget.h
index 0b1d6e3..6e41be8 100644
--- a/src/context/widgets/TextScrollingWidget.h
+++ b/src/context/widgets/TextScrollingWidget.h
@@ -51,11 +51,13 @@ class AMAROK_EXPORT TextScrollingWidget : public QGraphicsTextItem
         /**
         * Set the Text and more important the QRectF which will define the scrolling area
         */
-        void setScrollingText( const QString, QRectF );
+        void setScrollingText( const QString &text, const QRectF &rect );
 
         void setText( const QString &text );
+        void setTextFormat( Qt::TextFormat fmt );
 
         QString text() const;
+        Qt::TextFormat textFormat() const;
 
         bool isAnimating();
 
@@ -83,11 +85,14 @@ class AMAROK_EXPORT TextScrollingWidget : public QGraphicsTextItem
         QRectF            m_rect;           // box size
         QFontMetrics     *m_fm;             // font metrics which will cut the text.
         QString           m_text;           // full sentence
+        Qt::TextFormat    m_textFormat;     // text format
         int               m_delta;          // complete delta
         float             m_currentDelta;   // current delta
         int               m_animfor;        // anim id for
         int               m_animback;       // anim id back
         bool              m_animating;      // boolean !
+
+        bool requirePlainText() const;
 };
 
 #endif