2011-03-02 16:57:41 +01:00
|
|
|
#include "squeezelabel.h"
|
|
|
|
|
|
|
|
SqueezeLabel::SqueezeLabel(QWidget *parent)
|
|
|
|
: QLabel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:26:36 +02:00
|
|
|
void SqueezeLabel::setText(const QString &txt)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-05-25 14:26:36 +02:00
|
|
|
m_originalText = txt;
|
2011-05-25 14:30:43 +02:00
|
|
|
QFontMetrics fm = fontMetrics();
|
|
|
|
QString elided = fm.elidedText(m_originalText, Qt::ElideMiddle, width());
|
|
|
|
QLabel::setText(elided);
|
2011-05-25 14:26:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SqueezeLabel::originalText()
|
|
|
|
{
|
|
|
|
return m_originalText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SqueezeLabel::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QLabel::resizeEvent(event);
|
|
|
|
QFontMetrics fm = fontMetrics();
|
2011-05-25 14:30:43 +02:00
|
|
|
QString elided = fm.elidedText(m_originalText, Qt::ElideMiddle, width());
|
2011-05-25 14:26:36 +02:00
|
|
|
QLabel::setText(elided);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|