* fix heightForWidth
* provide a maximum width setting svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732528
This commit is contained in:
parent
af2752eb1c
commit
ccd0753a96
@ -9,12 +9,15 @@ namespace Plasma {
|
|||||||
class Label::Private
|
class Label::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private() {}
|
Private()
|
||||||
|
: maximumWidth(9999)
|
||||||
|
{}
|
||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
Qt::Alignment alignment;
|
Qt::Alignment alignment;
|
||||||
QPen textPen;
|
QPen textPen;
|
||||||
QFont textFont;
|
QFont textFont;
|
||||||
|
int maximumWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
Label::Label(Widget *parent)
|
Label::Label(Widget *parent)
|
||||||
@ -42,16 +45,15 @@ bool Label::hasHeightForWidth() const
|
|||||||
|
|
||||||
qreal Label::heightForWidth(qreal w) const
|
qreal Label::heightForWidth(qreal w) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(w);
|
|
||||||
//FIXME: this looks a bit odd?
|
//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
|
QSizeF Label::sizeHint() const
|
||||||
{
|
{
|
||||||
QFontMetricsF m(d->textFont);
|
QFontMetricsF m(d->textFont);
|
||||||
|
return m.boundingRect(QRectF(0, 0, d->maximumWidth, 9999), d->alignment | Qt::TextWordWrap, d->text).size();
|
||||||
return m.boundingRect(QRectF(0,0,9999,9999), d->alignment | Qt::TextWordWrap, d->text).size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::setText(const QString& text)
|
void Label::setText(const QString& text)
|
||||||
@ -84,6 +86,16 @@ QPen Label::pen() const
|
|||||||
return d->textPen;
|
return d->textPen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::setMaximumWidth(int width)
|
||||||
|
{
|
||||||
|
d->maximumWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Label::maximumWidth() const
|
||||||
|
{
|
||||||
|
return d->maximumWidth;
|
||||||
|
}
|
||||||
|
|
||||||
void Label::setFont(const QFont& font)
|
void Label::setFont(const QFont& font)
|
||||||
{
|
{
|
||||||
d->textFont = font;
|
d->textFont = font;
|
||||||
|
@ -44,6 +44,7 @@ class PLASMA_EXPORT Label : public Plasma::Widget
|
|||||||
Q_PROPERTY( QString text READ text WRITE setText )
|
Q_PROPERTY( QString text READ text WRITE setText )
|
||||||
Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
|
Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
|
||||||
Q_PROPERTY( QPen pen READ pen WRITE setPen )
|
Q_PROPERTY( QPen pen READ pen WRITE setPen )
|
||||||
|
Q_PROPERTY( int maximumWidth READ maximumWidth WRITE setMaximumWidth )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -107,6 +108,18 @@ class PLASMA_EXPORT Label : public Plasma::Widget
|
|||||||
*/
|
*/
|
||||||
QPen pen() const;
|
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.
|
* Sets the font used for the text.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user