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"
25 #include <kformattedballoontipdelegate.h>
31 K_GLOBAL_STATIC(KFormattedBalloonTipDelegate
, g_delegate
)
33 ToolTipManager::ToolTipManager(QAbstractItemView
* parent
,
34 DolphinSortFilterProxyModel
* model
) :
43 KToolTip::setToolTipDelegate(g_delegate
);
45 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
46 connect(parent
, SIGNAL(entered(const QModelIndex
&)),
47 this, SLOT(requestToolTip(const QModelIndex
&)));
48 connect(parent
, SIGNAL(viewportEntered()),
49 this, SLOT(hideToolTip()));
51 m_timer
= new QTimer(this);
52 m_timer
->setSingleShot(true);
53 connect(m_timer
, SIGNAL(timeout()),
54 this, SLOT(showToolTip()));
56 m_view
->viewport()->installEventFilter(this);
59 ToolTipManager::~ToolTipManager()
63 void ToolTipManager::hideTip()
68 bool ToolTipManager::eventFilter(QObject
* watched
, QEvent
* event
)
70 if ((watched
== m_view
->viewport()) && (event
->type() == QEvent::Leave
)) {
74 return QObject::eventFilter(watched
, event
);
77 void ToolTipManager::requestToolTip(const QModelIndex
& index
)
81 const QRect rect
= m_view
->visualRect(index
);
82 m_pos
= m_view
->viewport()->mapToGlobal(rect
.bottomRight());
84 const QModelIndex dirIndex
= m_proxyModel
->mapToSource(index
);
85 m_item
= m_dolphinModel
->itemForIndex(dirIndex
);
90 void ToolTipManager::hideToolTip()
96 void ToolTipManager::showToolTip()
98 KToolTipItem
* tip
= new KToolTipItem(KIcon(m_item
.iconName()), m_item
.getToolTipText());
99 KToolTip::showTip(m_pos
, tip
);
102 #include "tooltipmanager.moc"