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

KFile

kfileplacesview_p.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #ifndef KFILEPLACESVIEW_P_H
00021 #define KFILEPLACESVIEW_P_H
00022 
00023 #include <QMouseEvent>
00024 
00025 class KFilePlacesEventWatcher
00026     : public QObject
00027 {
00028 Q_OBJECT
00029 
00030 public:
00031     KFilePlacesEventWatcher(QObject *parent = 0)
00032         : QObject(parent) {}
00033 
00034     const QModelIndex &hoveredIndex() const
00035     {
00036         return m_hoveredIndex;
00037     }
00038 
00039     const QModelIndex &focusedIndex() const
00040     {
00041         return m_focusedIndex;
00042     }
00043 
00044 Q_SIGNALS:
00045     void entryEntered(const QModelIndex &index);
00046     void entryLeft(const QModelIndex &index);
00047 
00048 public Q_SLOTS:
00049     void currentIndexChanged(const QModelIndex &index)
00050     {
00051         if (m_focusedIndex.isValid() && m_focusedIndex != m_hoveredIndex) {
00052             emit entryLeft(m_focusedIndex);
00053         }
00054         if (index == m_hoveredIndex) {
00055             m_focusedIndex = m_hoveredIndex;
00056             return;
00057         }
00058         if (index.isValid()) {
00059             emit entryEntered(index);
00060         }
00061         m_focusedIndex = index;
00062     }
00063 
00064 protected:
00065     virtual bool eventFilter(QObject *watched, QEvent *event)
00066     {
00067         switch (event->type()) {
00068             case QEvent::MouseMove: {
00069                     QAbstractItemView *view = qobject_cast<QAbstractItemView*>(watched->parent());
00070                     const QModelIndex index = view->indexAt(static_cast<QMouseEvent*>(event)->pos());
00071                     if (index != m_hoveredIndex) {
00072                         if (m_hoveredIndex.isValid() && m_hoveredIndex != m_focusedIndex) {
00073                             emit entryLeft(m_hoveredIndex);
00074                         }
00075                         if (index.isValid() && index != m_focusedIndex) {
00076                             emit entryEntered(index);
00077                         }
00078                         m_hoveredIndex = index;
00079                     }
00080                 }
00081                 break;
00082             case QEvent::Leave:
00083                 if (m_hoveredIndex.isValid() && m_hoveredIndex != m_focusedIndex) {
00084                     emit entryLeft(m_hoveredIndex);
00085                 }
00086                 m_hoveredIndex = QModelIndex();
00087                 break;
00088             case QEvent::MouseButtonPress:
00089             case QEvent::MouseButtonDblClick: {
00090                     // Prevent the selection clearing by clicking on the viewport directly
00091                     QAbstractItemView *view = qobject_cast<QAbstractItemView*>(watched->parent());
00092                     if (!view->indexAt(static_cast<QMouseEvent*>(event)->pos()).isValid()) {
00093                         return true;
00094                     }
00095                 }
00096                 break;
00097             default:
00098                 return false;
00099         }
00100 
00101         return false;
00102     }
00103 
00104 private:
00105     QPersistentModelIndex m_hoveredIndex;
00106     QPersistentModelIndex m_focusedIndex;
00107 };
00108 
00109 #endif

KFile

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal