return a size hint based on font metrics

svn path=/trunk/KDE/kdelibs/; revision=1046144
This commit is contained in:
Marco Martin 2009-11-07 16:44:56 +00:00
parent 4f6ff5ef68
commit a5f39f0f06
2 changed files with 34 additions and 22 deletions

View File

@ -212,6 +212,15 @@ void FlashingLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
} }
} }
QSizeF FlashingLabel::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
if (which == Qt::PreferredSize) {
QFontMetrics fm(d->font);
return fm.boundingRect(d->text).size();
}
return QGraphicsWidget::sizeHint(which, constraint);
}
void FlashingLabelPrivate::renderPixmap(const QSize &size) void FlashingLabelPrivate::renderPixmap(const QSize &size)
{ {
if (renderedPixmap.size() != size) { if (renderedPixmap.size() != size) {

View File

@ -38,35 +38,38 @@ class FlashingLabelPrivate;
*/ */
class PLASMA_EXPORT FlashingLabel : public QGraphicsWidget class PLASMA_EXPORT FlashingLabel : public QGraphicsWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FlashingLabel(QGraphicsItem *parent = 0); explicit FlashingLabel(QGraphicsItem *parent = 0);
virtual ~FlashingLabel(); virtual ~FlashingLabel();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void setFont(const QFont &); void setFont(const QFont &);
void setColor(const QColor &); void setColor(const QColor &);
void setDuration(int duration); void setDuration(int duration);
void flash(const QString &text, int duration = 0, void flash(const QString &text, int duration = 0,
const QTextOption &option = QTextOption(Qt::AlignCenter)); const QTextOption &option = QTextOption(Qt::AlignCenter));
void flash(const QPixmap &pixmap, int duration = 0, void flash(const QPixmap &pixmap, int duration = 0,
Qt::Alignment align = Qt::AlignCenter); Qt::Alignment align = Qt::AlignCenter);
void setAutohide(bool autohide); void setAutohide(bool autohide);
bool autohide() const; bool autohide() const;
public Q_SLOTS: protected:
void kill(); QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
protected Q_SLOTS: public Q_SLOTS:
void fadeIn(); void kill();
void fadeOut();
private: protected Q_SLOTS:
Q_PRIVATE_SLOT(d, void elementAnimationFinished(int)) void fadeIn();
FlashingLabelPrivate *const d; void fadeOut();
private:
Q_PRIVATE_SLOT(d, void elementAnimationFinished(int))
FlashingLabelPrivate *const d;
}; };
} }