From kde-commits Thu Oct 02 20:07:50 2008 From: Marco Martin Date: Thu, 02 Oct 2008 20:07:50 +0000 To: kde-commits Subject: KDE/kdebase/workspace/libs/plasma/widgets Message-Id: <1222978070.232061.17008.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=122297807913858 SVN commit 867107 by mart: 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) M +19 -2 frame.cpp M +1 -0 frame.h --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/frame.cpp #867106:867107 @@ -208,8 +208,8 @@ 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 @@ } } +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 --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/frame.h #867106:867107 @@ -118,6 +118,7 @@ QWidget *widget = 0); void resizeEvent(QGraphicsSceneResizeEvent *event); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const; private: FramePrivate * const d;