1 /* This file is part of the KDE project
2 Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #ifndef KFILEPLACESVIEW_P_H
21 #define KFILEPLACESVIEW_P_H
23 #include <QMouseEvent>
25 class KFilePlacesEventWatcher
31 KFilePlacesEventWatcher(QObject
*parent
= 0)
34 const QModelIndex
&hoveredIndex() const
36 return m_hoveredIndex
;
39 const QModelIndex
&focusedIndex() const
41 return m_focusedIndex
;
45 void entryEntered(const QModelIndex
&index
);
46 void entryLeft(const QModelIndex
&index
);
49 void currentIndexChanged(const QModelIndex
&index
)
51 if (m_focusedIndex
.isValid() && m_focusedIndex
!= m_hoveredIndex
) {
52 emit
entryLeft(m_focusedIndex
);
54 if (index
== m_hoveredIndex
) {
55 m_focusedIndex
= m_hoveredIndex
;
58 if (index
.isValid()) {
59 emit
entryEntered(index
);
61 m_focusedIndex
= index
;
65 virtual bool eventFilter(QObject
*watched
, QEvent
*event
)
67 switch (event
->type()) {
68 case QEvent::MouseMove
: {
69 QAbstractItemView
*view
= qobject_cast
<QAbstractItemView
*>(watched
->parent());
70 const QModelIndex index
= view
->indexAt(static_cast<QMouseEvent
*>(event
)->pos());
71 if (index
!= m_hoveredIndex
) {
72 if (m_hoveredIndex
.isValid() && m_hoveredIndex
!= m_focusedIndex
) {
73 emit
entryLeft(m_hoveredIndex
);
75 if (index
.isValid() && index
!= m_focusedIndex
) {
76 emit
entryEntered(index
);
78 m_hoveredIndex
= index
;
83 if (m_hoveredIndex
.isValid() && m_hoveredIndex
!= m_focusedIndex
) {
84 emit
entryLeft(m_hoveredIndex
);
86 m_hoveredIndex
= QModelIndex();
88 case QEvent::MouseButtonPress
:
89 case QEvent::MouseButtonDblClick
: {
90 // Prevent the selection clearing by clicking on the viewport directly
91 QAbstractItemView
*view
= qobject_cast
<QAbstractItemView
*>(watched
->parent());
92 if (!view
->indexAt(static_cast<QMouseEvent
*>(event
)->pos()).isValid()) {
105 QPersistentModelIndex m_hoveredIndex
;
106 QPersistentModelIndex m_focusedIndex
;