1 | /* |
2 | * Copyright (C) by Christian Kamm <mail@ckamm.de> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * for more details. |
13 | */ |
14 | |
15 | #include <QObject> |
16 | #include <QPoint> |
17 | |
18 | class QTreeView; |
19 | class QModelIndex; |
20 | |
21 | namespace OCC { |
22 | |
23 | /** |
24 | * @brief Updates tooltips of items in a QTreeView when they change. |
25 | * @ingroup gui |
26 | * |
27 | * Usually tooltips are not updated as they change. Since we want to |
28 | * use tooltips to show rapidly updating progress information, we |
29 | * need to make sure that that information is displayed to the user |
30 | * as it changes. |
31 | * |
32 | * To accomplish that, the eventFilter() stores the tooltip's position |
33 | * and the dataChanged() slot updates the tooltip if Qt::ToolTipRole |
34 | * gets updated while a tooltip is shown. |
35 | */ |
36 | class ToolTipUpdater : public QObject |
37 | { |
38 | Q_OBJECT |
39 | public: |
40 | ToolTipUpdater(QTreeView *treeView); |
41 | |
42 | protected: |
43 | bool eventFilter(QObject *obj, QEvent *ev) Q_DECL_OVERRIDE; |
44 | |
45 | private slots: |
46 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); |
47 | |
48 | private: |
49 | QTreeView *_treeView; |
50 | QPoint _toolTipPos; |
51 | }; |
52 | |
53 | } // namespace OCC |
54 | |