]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiFontExample.cpp
Update sk.po
[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  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/qstring_helpers.h"
15
16 #include "GuiFontExample.h"
17 #include "GuiFontMetrics.h"
18
19 #include <QPainter>
20 #include <QPaintEvent>
21
22
23 //namespace lyx {
24
25 void GuiFontExample::set(QFont const & font, QString const & text)
26 {
27         font_ = font;
28         text_ = text;
29         lyx::frontend::GuiFontMetrics m(font_);
30         // store width, ascent and descent of the font name
31         string_width_ = m.width(text_);
32         for (auto const c : lyx::fromqstr(text)) {
33                 string_ascent_ = std::max(string_ascent_, m.ascent(c));
34                 string_descent_ = std::max(string_ascent_, m.descent(c));
35         }
36         update();
37 }
38
39
40 QSize GuiFontExample::sizeHint() const
41 {
42         return QSize(string_width_ + 10,
43                      string_ascent_ + string_descent_ + 6);
44 }
45
46
47 void GuiFontExample::paintEvent(QPaintEvent *)
48 {
49         QPainter p;
50
51         p.begin(this);
52         p.setFont(font_);
53         int const h = height() - 1;
54         p.drawRect(0, 0, width() - 1, h);
55         p.drawText(5, (h / 2) + (string_descent_ / 2), text_);
56         p.end();
57 }
58
59
60 int GuiFontExample::minWidth() const
61 {
62         return string_width_;
63 }
64
65
66 //} // namespace lyx