1 /*******************************************************************************
2 * Copyright (C) 2008 by Konstantin Heil <konst.heil@stud.uni-heidelberg.de> *
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. *
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. *
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 *******************************************************************************/
20 #include "tooltipmanager.h"
22 #include "dolphinmodel.h"
23 #include "dolphinsortfilterproxymodel.h"
29 ToolTipManager::ToolTipManager(QAbstractItemView
* parent
,
30 DolphinSortFilterProxyModel
* model
) :
40 KToolTip::setToolTipDelegate(&m_delegate
);
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()));
48 m_timer
= new QTimer(this);
49 m_timer
->setSingleShot(true);
50 connect(m_timer
, SIGNAL(timeout()),
51 this, SLOT(showToolTip()));
53 m_view
->viewport()->installEventFilter(this);
56 ToolTipManager::~ToolTipManager()
60 void ToolTipManager::hideTip()
65 bool ToolTipManager::eventFilter(QObject
* watched
, QEvent
* event
)
67 if ((watched
== m_view
->viewport()) && (event
->type() == QEvent::Leave
)) {
71 return QObject::eventFilter(watched
, event
);
74 void ToolTipManager::requestToolTip(const QModelIndex
& index
)
78 const QRect rect
= m_view
->visualRect(index
);
79 m_pos
= m_view
->viewport()->mapToGlobal(rect
.bottomRight());
81 const QModelIndex dirIndex
= m_proxyModel
->mapToSource(index
);
82 m_item
= m_dolphinModel
->itemForIndex(dirIndex
);
87 void ToolTipManager::hideToolTip()
93 void ToolTipManager::showToolTip()
95 KToolTipItem
* tip
= new KToolTipItem(KIcon(m_item
.iconName()), m_item
.getToolTipText());
96 KToolTip::showTip(m_pos
, tip
);
99 #include "tooltipmanager.moc"