Hammer leeo's new ideas for the playlist item svg's into shape so we can
[amarok.git] / src / playlist / PlaylistTextItem.cpp
blobd9f7f9f742c79ada6e950d18911074043b6b837d
1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License version 2 *
6 * as published by the Free Software Foundation. *
7 ***************************************************************************/
9 #include "PlaylistTextItem.h"
11 #include <QFontMetricsF>
13 QFontMetricsF* Playlist::TextItem::s_fm = 0;
16 Playlist::TextItem::TextItem( QGraphicsItem* parent )
17 : QGraphicsTextItem( parent )
19 if( !s_fm )
21 s_fm = new QFontMetricsF( QFont() );
23 //setDefaultTextColor( Qt::white );
27 ///method assumes text is currently not being edited
28 void
29 Playlist::TextItem::setEditableText( const QString& text, qreal width )
31 m_fullText = text;
32 m_width = width;
33 setPlainText( s_fm->elidedText( text, Qt::ElideRight, width ) );
36 ///Prepare for editing, requires discarding the eliding.
37 void
38 Playlist::TextItem::focusInEvent( QFocusEvent *event )
40 setPlainText( m_fullText );
41 QGraphicsTextItem::focusInEvent( event );
44 ///Editing finished, restore eliding and notify folks of what the new text is
45 void
46 Playlist::TextItem::focusOutEvent( QFocusEvent *event )
48 QGraphicsTextItem::focusOutEvent( event );
49 m_fullText = toPlainText();
50 setEditableText( m_fullText, m_width );
53 #include "PlaylistTextItem.moc"