File: ttlineedit.cpp

package info (click to toggle)
ttfautohint 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,504 kB
  • ctags: 4,347
  • sloc: ansic: 38,386; sh: 5,749; cpp: 4,131; perl: 340; makefile: 309; sed: 39
file content (49 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ttlineedit.cpp

// Copyright (C) 2012-2016 by Werner Lemberg.
//
// This file is part of the ttfautohint library, and may only be used,
// modified, and distributed under the terms given in `COPYING'.  By
// continuing to use, modify, or distribute this file you indicate that you
// have read `COPYING' and understand and accept it fully.
//
// The file `COPYING' mentioned in the previous paragraph is distributed
// with the ttfautohint library.


// Derived class `Tooltip_Line_Edit' is QLineEdit that displays a tooltip
// if the data in the field is wider than the field width.

#include <config.h>

#include "ttlineedit.h"

Tooltip_Line_Edit::Tooltip_Line_Edit(QWidget* parent)
: QLineEdit(parent)
{
  connect(this, SIGNAL(textChanged(QString)),
          this, SLOT(change_tooltip(QString)));
}


void Tooltip_Line_Edit::change_tooltip(QString tip)
{
  QFont font = this->font();
  QFontMetrics metrics(font);

  // get the (sum of the) left and right borders; this is a bit tricky
  // since Qt doesn't have methods to directly access those margin values
  int line_minwidth = minimumSizeHint().width();
  int char_maxwidth = metrics.maxWidth();
  int border = line_minwidth - char_maxwidth;

  int linewidth = this->width();
  int textwidth = metrics.width(tip);

  if (textwidth > linewidth - border)
    this->setToolTip(tip);
  else
    this->setToolTip("");
}

// end of ttlineedit.cpp