* fix heightForWidth

* provide a maximum width setting

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732528
This commit is contained in:
Aaron J. Seigo 2007-11-04 05:34:10 +00:00
parent af2752eb1c
commit ccd0753a96
2 changed files with 30 additions and 5 deletions

View File

@ -9,12 +9,15 @@ namespace Plasma {
class Label::Private
{
public:
Private() {}
Private()
: maximumWidth(9999)
{}
QString text;
Qt::Alignment alignment;
QPen textPen;
QFont textFont;
int maximumWidth;
};
Label::Label(Widget *parent)
@ -42,16 +45,15 @@ bool Label::hasHeightForWidth() const
qreal Label::heightForWidth(qreal w) const
{
Q_UNUSED(w);
//FIXME: this looks a bit odd?
return 0;
QFontMetricsF m(d->textFont);
return m.boundingRect(QRectF(0, 0, w, 9999), d->alignment | Qt::TextWordWrap, d->text).height();
}
QSizeF Label::sizeHint() const
{
QFontMetricsF m(d->textFont);
return m.boundingRect(QRectF(0,0,9999,9999), d->alignment | Qt::TextWordWrap, d->text).size();
return m.boundingRect(QRectF(0, 0, d->maximumWidth, 9999), d->alignment | Qt::TextWordWrap, d->text).size();
}
void Label::setText(const QString& text)
@ -84,6 +86,16 @@ QPen Label::pen() const
return d->textPen;
}
void Label::setMaximumWidth(int width)
{
d->maximumWidth = width;
}
int Label::maximumWidth() const
{
return d->maximumWidth;
}
void Label::setFont(const QFont& font)
{
d->textFont = font;

View File

@ -44,6 +44,7 @@ class PLASMA_EXPORT Label : public Plasma::Widget
Q_PROPERTY( QString text READ text WRITE setText )
Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
Q_PROPERTY( QPen pen READ pen WRITE setPen )
Q_PROPERTY( int maximumWidth READ maximumWidth WRITE setMaximumWidth )
public:
@ -107,6 +108,18 @@ class PLASMA_EXPORT Label : public Plasma::Widget
*/
QPen pen() const;
/**
* Sets the maximum width that this label should extend to
*
* @arg width the new maximum width in pixels
*/
void setMaximumWidth(int width);
/**
* The width in pixels that this label is constrained to
*/
int maximumWidth() const;
/**
* Sets the font used for the text.
*/