2002-11-18 19:52:29 +00:00
|
|
|
/**
|
|
|
|
* \file qfontexample.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-11-18 19:52:29 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#include <config.h>
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
#include "qfontexample.h"
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
#include <qpainter.h>
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
void QFontExample::set(QFont const & font, QString const & text)
|
|
|
|
{
|
|
|
|
font_ = font;
|
|
|
|
text_ = text;
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
QSize QFontExample::sizeHint() const
|
|
|
|
{
|
2002-12-01 22:59:25 +00:00
|
|
|
QFontMetrics m(font_);
|
2002-11-18 19:52:29 +00:00
|
|
|
return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
|
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
void QFontExample::paintEvent(QPaintEvent *)
|
|
|
|
{
|
2002-12-01 22:59:25 +00:00
|
|
|
QPainter p;
|
2002-11-18 19:52:29 +00:00
|
|
|
QFontMetrics m(font_);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-18 19:52:29 +00:00
|
|
|
p.begin(this);
|
|
|
|
p.setFont(font_);
|
2002-12-01 22:59:25 +00:00
|
|
|
p.drawRect(0, 0, width() - 1, height() - 1);
|
2002-11-18 19:52:29 +00:00
|
|
|
p.drawText(5, 3 + m.ascent(), text_);
|
|
|
|
p.end();
|
|
|
|
}
|