2007-07-23 00:16:40 +02:00
|
|
|
#include "label.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QFontMetricsF>
|
2007-08-17 20:57:28 +02:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2007-07-23 00:16:40 +02:00
|
|
|
|
|
|
|
namespace Plasma {
|
|
|
|
|
|
|
|
class Label::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private() {}
|
|
|
|
|
|
|
|
QString text;
|
2007-07-26 09:25:21 +02:00
|
|
|
Qt::Alignment alignment;
|
|
|
|
QPen textPen;
|
2007-10-17 17:11:29 +02:00
|
|
|
QFont textFont;
|
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
|
|
|
|
{
|
2007-10-17 17:11:29 +02:00
|
|
|
QFontMetricsF m(d->textFont);
|
2007-07-23 00:16:40 +02:00
|
|
|
|
2007-10-16 13:54:37 +02:00
|
|
|
return m.boundingRect(QRectF(0,0,9999,9999), d->alignment | Qt::TextWordWrap, d->text).size();
|
2007-07-23 00:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-17 17:11:29 +02:00
|
|
|
void Label::setFont(const QFont& font)
|
|
|
|
{
|
|
|
|
d->textFont = font;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFont Label::font() const
|
|
|
|
{
|
|
|
|
return d->textFont;
|
|
|
|
}
|
|
|
|
|
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);
|
2007-10-17 17:11:29 +02:00
|
|
|
p->setFont(d->textFont);
|
2007-08-17 20:55:55 +02:00
|
|
|
p->drawText(option->rect, d->alignment | Qt::TextWordWrap, d->text);
|
2007-07-23 00:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|