plasma-framework/widgets/label.cpp
Matias Valdenegro Toro ff936c2a57 Added Alignment and Pen options and getters/setters.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=692757
2007-07-26 07:25:21 +00:00

92 lines
1.3 KiB
C++

#include "label.h"
#include <QPainter>
#include <QFontMetricsF>
namespace Plasma {
class Label::Private
{
public:
Private() {}
QString text;
Qt::Alignment alignment;
QPen textPen;
};
Label::Label(Widget *parent)
: Widget(parent),
d(new Private)
{
setAlignment(Qt::AlignHCenter);
setPen(QPen(Qt::black, 1));
}
Label::~Label()
{
}
Qt::Orientations Label::expandingDirections() const
{
return Qt::Horizontal | Qt::Vertical;
}
bool Label::hasHeightForWidth() const
{
return true;
}
qreal Label::heightForWidth(qreal w) const
{
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;
}
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;
}
void Label::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
p->setPen(d->textPen);
p->drawText(localGeometry(), d->alignment | Qt::TextWordWrap, d->text);
}
}