• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KFile

  • kfile
kfileplacesview_p.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org>
3
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.
7
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.
12
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.
17
18*/
19
20#ifndef KFILEPLACESVIEW_P_H
21#define KFILEPLACESVIEW_P_H
22
23#include <QMouseEvent>
24
25class KFilePlacesEventWatcher
26 : public QObject
27{
28Q_OBJECT
29
30public:
31 KFilePlacesEventWatcher(QObject *parent = 0)
32 : QObject(parent) {}
33
34 const QModelIndex &hoveredIndex() const
35 {
36 return m_hoveredIndex;
37 }
38
39 const QModelIndex &focusedIndex() const
40 {
41 return m_focusedIndex;
42 }
43
44Q_SIGNALS:
45 void entryEntered(const QModelIndex &index);
46 void entryLeft(const QModelIndex &index);
47
48public Q_SLOTS:
49 void currentIndexChanged(const QModelIndex &index)
50 {
51 if (m_focusedIndex.isValid() && m_focusedIndex != m_hoveredIndex) {
52 emit entryLeft(m_focusedIndex);
53 }
54 if (index == m_hoveredIndex) {
55 m_focusedIndex = m_hoveredIndex;
56 return;
57 }
58 if (index.isValid()) {
59 emit entryEntered(index);
60 }
61 m_focusedIndex = index;
62 }
63
64protected:
65 virtual bool eventFilter(QObject *watched, QEvent *event)
66 {
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);
74 }
75 if (index.isValid() && index != m_focusedIndex) {
76 emit entryEntered(index);
77 }
78 m_hoveredIndex = index;
79 }
80 }
81 break;
82 case QEvent::Leave:
83 if (m_hoveredIndex.isValid() && m_hoveredIndex != m_focusedIndex) {
84 emit entryLeft(m_hoveredIndex);
85 }
86 m_hoveredIndex = QModelIndex();
87 break;
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()) {
93 return true;
94 }
95 }
96 break;
97 default:
98 return false;
99 }
100
101 return false;
102 }
103
104private:
105 QPersistentModelIndex m_hoveredIndex;
106 QPersistentModelIndex m_focusedIndex;
107};
108
109#endif
KFilePlacesEventWatcher
Definition: kfileplacesview_p.h:27
KFilePlacesEventWatcher::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: kfileplacesview_p.h:65
KFilePlacesEventWatcher::entryLeft
void entryLeft(const QModelIndex &index)
KFilePlacesEventWatcher::KFilePlacesEventWatcher
KFilePlacesEventWatcher(QObject *parent=0)
Definition: kfileplacesview_p.h:31
KFilePlacesEventWatcher::currentIndexChanged
void currentIndexChanged(const QModelIndex &index)
Definition: kfileplacesview_p.h:49
KFilePlacesEventWatcher::hoveredIndex
const QModelIndex & hoveredIndex() const
Definition: kfileplacesview_p.h:34
KFilePlacesEventWatcher::focusedIndex
const QModelIndex & focusedIndex() const
Definition: kfileplacesview_p.h:39
KFilePlacesEventWatcher::entryEntered
void entryEntered(const QModelIndex &index)
QObject
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KFile

Skip menu "KFile"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal