Synchronize with FreeType.
[ttfautohint.git] / frontend / ttlineedit.cpp
bloba1cdf209d7f153c80ad5c6f0cdad1a56e5c38080
1 // ttlineedit.cpp
3 // Copyright (C) 2012-2014 by Werner Lemberg.
4 //
5 // This file is part of the ttfautohint library, and may only be used,
6 // modified, and distributed under the terms given in `COPYING'. By
7 // continuing to use, modify, or distribute this file you indicate that you
8 // have read `COPYING' and understand and accept it fully.
9 //
10 // The file `COPYING' mentioned in the previous paragraph is distributed
11 // with the ttfautohint library.
14 // Derived class `Tooltip_Line_Edit' is QLineEdit that displays a tooltip
15 // if the data in the field is wider than the field width.
17 #include <config.h>
19 #include "ttlineedit.h"
21 Tooltip_Line_Edit::Tooltip_Line_Edit(QWidget* parent)
22 : QLineEdit(parent)
24 connect(this, SIGNAL(textChanged(QString)),
25 this, SLOT(change_tooltip(QString)));
29 void Tooltip_Line_Edit::change_tooltip(QString tip)
31 QFont font = this->font();
32 QFontMetrics metrics(font);
34 // get the (sum of the) left and right borders; this is a bit tricky
35 // since Qt doesn't have methods to directly access those margin values
36 int line_minwidth = minimumSizeHint().width();
37 int char_maxwidth = metrics.maxWidth();
38 int border = line_minwidth - char_maxwidth;
40 int linewidth = this->width();
41 int textwidth = metrics.width(tip);
43 if (textwidth > linewidth - border)
44 this->setToolTip(tip);
45 else
46 this->setToolTip("");
49 // end of ttlineedit.cpp