]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiFontExample.cpp
Make code a bit easier to read
[lyx.git] / src / frontends / qt / GuiFontExample.cpp
1 /**
2  * \file GuiFontExample.cpp
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 "GuiFontExample.h"
14 #include "GuiFontMetrics.h"
15
16 #include <QPainter>
17 #include <QPaintEvent>
18
19
20 //namespace lyx {
21
22 void GuiFontExample::set(QFont const & font, QString const & text)
23 {
24         font_ = font;
25         text_ = text;
26         update();
27 }
28
29
30 QSize GuiFontExample::sizeHint() const
31 {
32         lyx::frontend::GuiFontMetrics m(font_);
33         return QSize(m.width(text_) + 10, m.maxHeight() + 6);
34 }
35
36
37 void GuiFontExample::paintEvent(QPaintEvent *)
38 {
39         QPainter p;
40         lyx::frontend::GuiFontMetrics m(font_);
41
42         p.begin(this);
43         p.setFont(font_);
44         p.drawRect(0, 0, width() - 1, height() - 1);
45         p.drawText(5, 3 + m.maxAscent(), text_);
46         p.end();
47 }
48
49
50 //} // namespace lyx