]> cloud.milkyroute.net Git - dolphin.git/blob - src/treeviewsidebarpage.h
fix crash when opening a lot of columns and going back very fast by clicking on each...
[dolphin.git] / src / treeviewsidebarpage.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 TREEVIEWSIDEBARPAGE_H
21 #define TREEVIEWSIDEBARPAGE_H
22
23 #include <kurl.h>
24 #include <sidebarpage.h>
25
26 class KDirLister;
27 class DolphinModel;
28
29 class DolphinSortFilterProxyModel;
30 class SidebarTreeView;
31 class QModelIndex;
32
33 /**
34 * @brief Shows a tree view of the directories starting from
35 * the currently selected place.
36 *
37 * The tree view is always synchronized with the currently active view
38 * from the main window.
39 */
40 class TreeViewSidebarPage : public SidebarPage
41 {
42 Q_OBJECT
43
44 public:
45 TreeViewSidebarPage(QWidget* parent = 0);
46 virtual ~TreeViewSidebarPage();
47
48 /** @see QWidget::sizeHint() */
49 virtual QSize sizeHint() const;
50
51 void setShowHiddenFiles(bool show);
52 bool showHiddenFiles() const;
53
54 void rename(const KFileItem& item);
55
56 signals:
57 /**
58 * Is emitted if the an URL change is requested.
59 */
60 void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
61
62 /**
63 * This signal is emitted when the sidebar requests a change in the
64 * current selection. The file-management view recieving this signal is
65 * not required to select all listed files, limiting the selection to
66 * e.g. the current folder. The new selection will be reported via the
67 * setSelection slot.
68 */
69 void changeSelection(const KFileItemList& selection);
70
71 /**
72 * This signal is emitted whenever a drop action on this widget needs the
73 * MainWindow's attention.
74 */
75 void urlsDropped(const KUrl::List& urls, const KUrl& destination);
76
77 public slots:
78 /**
79 * Changes the current selection inside the tree to \a url.
80 */
81 virtual void setUrl(const KUrl& url);
82
83 protected:
84 /** @see QWidget::showEvent() */
85 virtual void showEvent(QShowEvent* event);
86
87 /** @see QWidget::contextMenuEvent() */
88 virtual void contextMenuEvent(QContextMenuEvent* event);
89
90 private slots:
91 /**
92 * Updates the active view to the URL
93 * which is given by the item with the index \a index.
94 */
95 void updateActiveView(const QModelIndex& index);
96
97 /**
98 * Is emitted if the URLs \a urls have been dropped
99 * to the index \a index. */
100 void dropUrls(const KUrl::List& urls,
101 const QModelIndex& index);
102
103 /**
104 * Invokes expandToLeafDir() asynchronously (the expanding
105 * may not be done in the context of this slot).
106 */
107 void triggerExpanding();
108
109 /**
110 * Invokes loadSubTree() asynchronously (the loading
111 * may not be done in the context of this slot).
112 */
113 void triggerLoadSubTree();
114
115 /**
116 * Expands all directories to make m_leafDir visible and
117 * adjusts the selection.
118 */
119 void expandToLeafDir();
120
121 /**
122 * Loads the sub tree to make m_leafDir visible. Is invoked
123 * indirectly by loadTree() after the directory lister has
124 * finished loading the root items.
125 */
126 void loadSubTree();
127
128 /**
129 * Assures that the leaf folder gets visible.
130 */
131 void scrollToLeaf();
132
133 void updateMouseButtons();
134
135 private:
136 /**
137 * Initializes the base URL of the tree and expands all
138 * directories until \a url.
139 * @param url URL of the leaf directory that should get expanded.
140 */
141 void loadTree(const KUrl& url);
142
143 /**
144 * Selects the current leaf directory m_leafDir and assures
145 * that the directory is visible if the leaf has been set by
146 * TreeViewSidebarPage::setUrl().
147 */
148 void selectLeafDirectory();
149
150 private:
151 bool m_setLeafVisible;
152 Qt::MouseButtons m_mouseButtons;
153 KDirLister* m_dirLister;
154 DolphinModel* m_dolphinModel;
155 DolphinSortFilterProxyModel* m_proxyModel;
156 SidebarTreeView* m_treeView;
157 KUrl m_leafDir;
158 };
159
160 #endif // TREEVIEWSIDEBARPAGE_H