2 * \file ToolTipFormatter.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Guillaume Munch
8 * Full author contact details are available in file CREDITS.
13 #include "ToolTipFormatter.h"
14 #include "qt_helpers.h"
16 #include <QAbstractItemView>
17 #include <QTextDocument>
18 #include <QTextLayout>
22 //#include "support/debug.h"
23 //#include "support/lstrings.h"
30 ToolTipFormatter::ToolTipFormatter(QObject * parent) : QObject(parent) {}
33 bool ToolTipFormatter::eventFilter(QObject * o, QEvent * e)
35 if (e->type() != QEvent::ToolTip)
38 // Format the tooltip of the widget being considered.
39 QWidget * w = qobject_cast<QWidget *>(o);
42 // Unchanged if empty or already formatted
43 w->setToolTip(formatToolTip(w->toolTip()));
45 // Now, if the tooltip is for an item in a QListView or a QTreeView,
46 // then the widget above was probably not the one with the tooltip.
47 // Check if the parent is a QAbstractItemView.
48 QAbstractItemView * iv = qobject_cast<QAbstractItemView *>(w->parent());
51 // In this case, the item is retrieved from the position of the QHelpEvent
53 QPoint pos = static_cast<QHelpEvent *>(e)->pos();
54 QModelIndex item = iv->indexAt(pos);
55 QVariant data = iv->model()->data(item, Qt::ToolTipRole);
56 if (data.isValid() && data.typeName() == toqstr("QString"))
57 // Unchanged if empty or already formatted
58 iv->model()->setData(item, formatToolTip(data.toString()),
60 // We must let the tooltip event reach its destination.
65 } // namespace frontend
68 #include "moc_ToolTipFormatter.cpp"