Added Alignment and Pen options and getters/setters.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=692757
This commit is contained in:
Matias Valdenegro Toro 2007-07-26 07:25:21 +00:00
parent 28b20a150a
commit ff936c2a57
2 changed files with 46 additions and 3 deletions

View File

@ -11,12 +11,16 @@ class Label::Private
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()
@ -55,14 +59,33 @@ 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);
/* TODO: Add config parameters, like text color, text alignment, and brush. */
p->setPen(QPen(Qt::black, 1));
p->drawText(localGeometry(), Qt::AlignCenter | Qt::TextWordWrap, d->text);
p->setPen(d->textPen);
p->drawText(localGeometry(), d->alignment | Qt::TextWordWrap, d->text);
}
}

View File

@ -78,6 +78,26 @@ class PLASMA_EXPORT Label : public Plasma::Widget
*/
QString text() const;
/**
* Sets the alignment of the displayed text.
*/
void setAlignment(Qt::Alignment align);
/**
* Returns the alignment of the displayed text.
*/
Qt::Alignment alignment() const;
/**
* Sets the pen used to paint the text.
*/
void setPen(const QPen& pen);
/**
* Returns the pen used to paint the text.
*/
QPen pen() const;
/**
* Paint function.
*/