]> cloud.milkyroute.net Git - dolphin.git/blob - src/tooltipmanager.cpp
allow Konqueror to open also files inside a new tab, not only directories
[dolphin.git] / src / tooltipmanager.cpp
1 /*******************************************************************************
2 * Copyright (C) 2008 by Konstantin Heil <konst.heil@stud.uni-heidelberg.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, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 *******************************************************************************/
19
20 #include "tooltipmanager.h"
21
22 #include "dolphinmodel.h"
23 #include "dolphinsortfilterproxymodel.h"
24 #include "ktooltip.h"
25 #include "kicon.h"
26
27 #include <QTimer>
28
29 ToolTipManager::ToolTipManager(QAbstractItemView* parent,
30 DolphinSortFilterProxyModel* model) :
31 QObject(parent),
32 m_view(parent),
33 m_dolphinModel(0),
34 m_proxyModel(model),
35 m_timer(0),
36 m_item(),
37 m_pos(),
38 m_delegate()
39 {
40 KToolTip::setToolTipDelegate(&m_delegate);
41
42 m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
43 connect(parent, SIGNAL(entered(const QModelIndex&)),
44 this, SLOT(requestToolTip(const QModelIndex&)));
45 connect(parent, SIGNAL(viewportEntered()),
46 this, SLOT(hideToolTip()));
47
48 m_timer = new QTimer(this);
49 m_timer->setSingleShot(true);
50 connect(m_timer, SIGNAL(timeout()),
51 this, SLOT(showToolTip()));
52
53 m_view->viewport()->installEventFilter(this);
54 }
55
56 ToolTipManager::~ToolTipManager()
57 {
58 }
59
60 void ToolTipManager::hideTip()
61 {
62 hideToolTip();
63 }
64
65 bool ToolTipManager::eventFilter(QObject* watched, QEvent* event)
66 {
67 if ((watched == m_view->viewport()) && (event->type() == QEvent::Leave)) {
68 hideToolTip();
69 }
70
71 return QObject::eventFilter(watched, event);
72 }
73
74 void ToolTipManager::requestToolTip(const QModelIndex& index)
75 {
76 KToolTip::hideTip();
77
78 const QRect rect = m_view->visualRect(index);
79 m_pos = m_view->viewport()->mapToGlobal(rect.bottomRight());
80
81 const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
82 m_item = m_dolphinModel->itemForIndex(dirIndex);
83
84 m_timer->start(500);
85 }
86
87 void ToolTipManager::hideToolTip()
88 {
89 m_timer->stop();
90 KToolTip::hideTip();
91 }
92
93 void ToolTipManager::showToolTip()
94 {
95 KToolTipItem* tip = new KToolTipItem(KIcon(m_item.iconName()), m_item.getToolTipText());
96 KToolTip::showTip(m_pos, tip);
97 }
98
99 #include "tooltipmanager.moc"