implement a sizehint that permits to use the frame just as a simple

header (i.e when empty return the height of the title font+margins)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=867107
This commit is contained in:
Marco Martin 2008-10-02 20:07:49 +00:00
parent 1f7a0f7560
commit 5c45bf09e8
2 changed files with 20 additions and 2 deletions

View File

@ -208,8 +208,8 @@ void Frame::paint(QPainter *painter,
if (!d->text.isNull()) {
QFontMetricsF fm(QApplication::font());
QRectF textRect = contentsRect();
textRect.translate(0, -fm.height());
QRectF textRect = d->svg->contentsRect();
textRect.setHeight(fm.height());
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
}
@ -232,6 +232,23 @@ void Frame::resizeEvent(QGraphicsSceneResizeEvent *event)
}
}
QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
if (!d->image && !layout()) {
QFontMetricsF fm(QApplication::font());
qreal left, top, right, bottom;
d->svg->getMargins(left, top, right, bottom);
hint.setHeight(fm.height() + top + bottom);
}
return hint;
}
} // namespace Plasma
#include <frame.moc>

View File

@ -118,6 +118,7 @@ protected:
QWidget *widget = 0);
void resizeEvent(QGraphicsSceneResizeEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
private:
FramePrivate * const d;