]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qfontexample.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / qfontexample.C
1 /**
2  * \file qfontexample.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "qfontexample.h"
14
15 #include <QPainter>
16 #include <QPaintEvent>
17
18 void QFontExample::set(QFont const & font, QString const & text)
19 {
20         font_ = font;
21         text_ = text;
22         update();
23 }
24
25
26 QSize QFontExample::sizeHint() const
27 {
28         QFontMetrics m(font_);
29         return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
30 }
31
32
33 void QFontExample::paintEvent(QPaintEvent *)
34 {
35         QPainter p;
36         QFontMetrics m(font_);
37
38         p.begin(this);
39         p.setFont(font_);
40         p.drawRect(0, 0, width() - 1, height() - 1);
41         p.drawText(5, 3 + m.ascent(), text_);
42         p.end();
43 }