1 /***************************************************************************
2 * Copyright (C) 2008 by Simon St James <kdedevel@etotheipiplusone.com> *
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 #ifndef FOLDEREXPANDER_H
21 #define FOLDEREXPANDER_H
23 // Needs to be exported as treesidebarpage uses it.
24 #include "libdolphin_export.h"
29 class QAbstractItemView
;
32 class QSortFilterProxyModel
;
36 /* Grants "auto expand"/ "spring-loaded folders" to
37 the provided view. Qt has its own auto-expand
38 mechanism, but this works only for QTreeView and
39 does not play well with our auto-scrolling in
40 the Folders pane. Auto-expansion is enabled by default.
42 If the provided view is a QTreeView, the expanded state
43 is automatically toggled on hover. Otherwise, the enterDir()
44 signal is emitted, and the caller needs to ensure that
45 the requested directory is entered.
47 The FolderExpander becomes a child of the provided view */
50 * Grants auto expanding functionality to the provided item view.
51 * Qt has its own auto expand mechanism, but this works only
52 * for QTreeView. Auto expanding of folders is turned on
55 * If the provided view is an instance of the class QTreeView, the
56 * expanded of the directory is automatically done on hover. Otherwise
57 * the enterDir() signal is emitted and the caller needs to ensure that
58 * the requested directory is entered.
60 * The FolderExpander becomes a child of the provided view.
62 class LIBDOLPHINPRIVATE_EXPORT FolderExpander
: public QObject
67 FolderExpander(QAbstractItemView
* view
, QSortFilterProxyModel
* proxyModel
);
68 virtual ~FolderExpander();
70 void setEnabled(bool enabled
);
75 * Is emitted if the directory \a dirModelIndex should be entered. The
76 * signal is not emitted when a QTreeView is used, as the entering of
77 * the directory is already provided by expanding the tree node.
79 void enterDir(const QModelIndex
& dirModelIndex
);
83 void autoExpandTimeout();
88 QAbstractItemView
* m_view
;
89 QSortFilterProxyModel
* m_proxyModel
;
91 QTimer
* m_autoExpandTriggerTimer
;
92 QPoint m_autoExpandPos
;
94 static const int AUTO_EXPAND_DELAY
= 700;
97 * Watchs the drag/move events for the view to decide
98 * whether auto expanding of a folder should be triggered.
100 bool eventFilter(QObject
* watched
, QEvent
* event
);