1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu> *
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
)
21 s_fm
= new QFontMetricsF( QFont() );
23 //setDefaultTextColor( Qt::white );
27 ///method assumes text is currently not being edited
29 Playlist::TextItem::setEditableText( const QString
& text
, qreal width
)
33 setPlainText( s_fm
->elidedText( text
, Qt::ElideRight
, width
) );
36 ///Prepare for editing, requires discarding the eliding.
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
46 Playlist::TextItem::focusOutEvent( QFocusEvent
*event
)
48 QGraphicsTextItem::focusOutEvent( event
);
49 m_fullText
= toPlainText();
50 setEditableText( m_fullText
, m_width
);
53 #include "PlaylistTextItem.moc"