]> cloud.milkyroute.net Git - dolphin.git/blob - src/folderexpander.h
Sourcecode hierarchy cleanup: Create folder "views" and move view related sources...
[dolphin.git] / src / folderexpander.h
1 /***************************************************************************
2 * Copyright (C) 2008 by Simon St James <kdedevel@etotheipiplusone.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef FOLDEREXPANDER_H
21 #define FOLDEREXPANDER_H
22
23 // Needs to be exported as FoldersPanel uses it.
24 #include "libdolphin_export.h"
25
26 #include <QObject>
27 #include <QPoint>
28
29 class QAbstractItemView;
30 class QTreeView;
31 class QTimer;
32 class QSortFilterProxyModel;
33 class QModelIndex;
34
35 /**
36 * Grants auto expanding functionality to the provided item view.
37 * Qt has its own auto expand mechanism, but this works only
38 * for QTreeView. Auto expanding of folders is turned on
39 * per default.
40 *
41 * If the provided view is an instance of the class QTreeView, the
42 * expansion of the directory is automatically done on hover. Otherwise
43 * the enterDir() signal is emitted and the caller needs to ensure that
44 * the requested directory is entered.
45 *
46 * The FolderExpander becomes a child of the provided view.
47 */
48 class LIBDOLPHINPRIVATE_EXPORT FolderExpander : public QObject
49 {
50 Q_OBJECT
51
52 public:
53 FolderExpander(QAbstractItemView* view, QSortFilterProxyModel* proxyModel);
54 virtual ~FolderExpander();
55
56 void setEnabled(bool enabled);
57 bool enabled() const;
58
59 signals:
60 /**
61 * Is emitted if the directory \a dirModelIndex should be entered. The
62 * signal is not emitted when a QTreeView is used, as the entering of
63 * the directory is already provided by expanding the tree node.
64 */
65 void enterDir(const QModelIndex& dirModelIndex);
66
67
68 private slots:
69 void viewScrolled();
70 void autoExpandTimeout();
71
72 private:
73 bool m_enabled;
74
75 QAbstractItemView* m_view;
76 QSortFilterProxyModel* m_proxyModel;
77
78 QTimer* m_autoExpandTriggerTimer;
79 QPoint m_autoExpandPos;
80
81 static const int AUTO_EXPAND_DELAY = 700;
82
83 /**
84 * Watchs the drag/move events for the view to decide
85 * whether auto expanding of a folder should be triggered.
86 */
87 bool eventFilter(QObject* watched, QEvent* event);
88 };
89 #endif