From ff936c2a57439d0d7a1dd53a15028c03b616e17b Mon Sep 17 00:00:00 2001 From: Matias Valdenegro Toro Date: Thu, 26 Jul 2007 07:25:21 +0000 Subject: [PATCH] Added Alignment and Pen options and getters/setters. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=692757 --- widgets/label.cpp | 29 ++++++++++++++++++++++++++--- widgets/label.h | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/widgets/label.cpp b/widgets/label.cpp index 231769716..277e14894 100644 --- a/widgets/label.cpp +++ b/widgets/label.cpp @@ -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); } } diff --git a/widgets/label.h b/widgets/label.h index d8d0a2bf8..daacb65ca 100644 --- a/widgets/label.h +++ b/widgets/label.h @@ -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. */