2 * \file GuiFontExample.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "support/qstring_helpers.h"
16 #include "GuiFontExample.h"
17 #include "GuiFontMetrics.h"
20 #include <QPaintEvent>
25 void GuiFontExample::set(QFont const & font, QString const & 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));
40 QSize GuiFontExample::sizeHint() const
42 return QSize(string_width_ + 10,
43 string_ascent_ + string_descent_ + 6);
47 void GuiFontExample::paintEvent(QPaintEvent *)
53 int const h = height() - 1;
54 p.drawRect(0, 0, width() - 1, h);
55 p.drawText(5, (h / 2) + (string_descent_ / 2), text_);
60 int GuiFontExample::minWidth() const