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

KFile

  • sources
  • kde-4.14
  • kdelibs
  • 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 
25 class KFilePlacesEventWatcher
26  : public QObject
27 {
28 Q_OBJECT
29 
30 public:
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 
44 Q_SIGNALS:
45  void entryEntered(const QModelIndex &index);
46  void entryLeft(const QModelIndex &index);
47 
48 public 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 
64 protected:
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 
104 private:
105  QPersistentModelIndex m_hoveredIndex;
106  QPersistentModelIndex m_focusedIndex;
107 };
108 
109 #endif
QModelIndex
QEvent
QEvent::type
Type type() const
KFilePlacesEventWatcher::currentIndexChanged
void currentIndexChanged(const QModelIndex &index)
Definition: kfileplacesview_p.h:49
QAbstractItemView
QAbstractItemView::indexAt
virtual QModelIndex indexAt(const QPoint &point) const =0
KFilePlacesEventWatcher::hoveredIndex
const QModelIndex & hoveredIndex() const
Definition: kfileplacesview_p.h:34
QObject::event
virtual bool event(QEvent *e)
KFilePlacesEventWatcher
Definition: kfileplacesview_p.h:25
KFilePlacesEventWatcher::KFilePlacesEventWatcher
KFilePlacesEventWatcher(QObject *parent=0)
Definition: kfileplacesview_p.h:31
QModelIndex::isValid
bool isValid() const
QPersistentModelIndex::isValid
bool isValid() const
QObject
KFilePlacesEventWatcher::focusedIndex
const QModelIndex & focusedIndex() const
Definition: kfileplacesview_p.h:39
KFilePlacesEventWatcher::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: kfileplacesview_p.h:65
KFilePlacesEventWatcher::entryLeft
void entryLeft(const QModelIndex &index)
QPersistentModelIndex
KFilePlacesEventWatcher::entryEntered
void entryEntered(const QModelIndex &index)
QObject::parent
QObject * parent() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:27:26 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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