2007-07-23 00:16:40 +02:00
|
|
|
#include "label.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QFontMetricsF>
|
|
|
|
|
|
|
|
namespace Plasma {
|
|
|
|
|
|
|
|
class Label::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private() {}
|
|
|
|
|
|
|
|
QString text;
|
2007-07-26 09:25:21 +02:00
|
|
|
Qt::Alignment alignment;
|
|
|
|
QPen textPen;
|
2007-07-23 00:16:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Label::Label(Widget *parent)
|
2007-08-03 18:00:10 +02:00
|
|
|
: Plasma::Widget(parent),
|
2007-07-23 00:16:40 +02:00
|
|
|
d(new Private)
|
|
|
|
{
|
2007-07-26 09:25:21 +02:00
|
|
|
setAlignment(Qt::AlignHCenter);
|
|
|
|
setPen(QPen(Qt::black, 1));
|
2007-07-23 00:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Label::~Label()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Orientations Label::expandingDirections() const
|
|
|
|
{
|
|
|
|
return Qt::Horizontal | Qt::Vertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Label::hasHeightForWidth() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Label::heightForWidth(qreal w) const
|
|
|
|
{
|
2007-07-28 11:22:20 +02:00
|
|
|
Q_UNUSED(w);
|
|
|
|
//FIXME: this looks a bit odd?
|
2007-07-23 00:16:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Label::sizeHint() const
|
|
|
|
{
|
|
|
|
QFontMetricsF m(QFont("Arial", 12));
|
|
|
|
|
|
|
|
return m.boundingRect(d->text).size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Label::setText(const QString& text)
|
|
|
|
{
|
|
|
|
d->text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Label::text() const
|
|
|
|
{
|
|
|
|
return d->text;
|
|
|
|
}
|
|
|
|
|
2007-07-26 09:25:21 +02:00
|
|
|
void Label::setAlignment(Qt::Alignment align)
|
|
|
|
{
|
|
|
|
d->alignment = align;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment Label::alignment() const
|
|
|
|
{
|
|
|
|
return d->alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Label::setPen(const QPen& pen)
|
|
|
|
{
|
|
|
|
d->textPen = pen;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPen Label::pen() const
|
|
|
|
{
|
|
|
|
return d->textPen;
|
|
|
|
}
|
|
|
|
|
2007-08-01 22:51:27 +02:00
|
|
|
void Label::paintWidget(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-07-23 00:16:40 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
2007-07-26 09:25:21 +02:00
|
|
|
p->setPen(d->textPen);
|
|
|
|
p->drawText(localGeometry(), d->alignment | Qt::TextWordWrap, d->text);
|
2007-07-23 00:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|