3 // Copyright (C) 2012-2013 by Werner Lemberg.
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.
10 // The file `COPYING' mentioned in the previous paragraph is distributed
11 // with the ttfautohint library.
14 // Derived class `Tooltip_Line_Edit' is QLineEdit which displays a tooltip
15 // if the data in the field is wider than the field width.
19 #include "ttlineedit.h"
21 Tooltip_Line_Edit::Tooltip_Line_Edit(QWidget
* 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
);
49 // end of ttlineedit.cpp