]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
Refactor the folder expansion system. Main effect: instead of having a list of m_exp...
[dolphin.git] / src / dolphincolumnview.h
1 /***************************************************************************
2 * Copyright (C) 2007 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 DOLPHINCOLUMNVIEW_H
21 #define DOLPHINCOLUMNVIEW_H
22
23 #include "dolphinview.h"
24
25 #include <kurl.h>
26
27 #include <QAbstractItemView>
28 #include <QList>
29 #include <QString>
30 #include <QStyleOption>
31
32 class DolphinColumnWidget;
33 class DolphinController;
34 class DolphinModel;
35 class QAbstractProxyModel;
36 class QFrame;
37 class QTimeLine;
38
39 /**
40 * @brief Represents the view, where each directory is show as separate column.
41 *
42 * @see DolphinIconsView
43 * @see DolphinDetailsView
44 */
45 class DolphinColumnView : public QAbstractItemView
46 {
47 Q_OBJECT
48
49 public:
50 explicit DolphinColumnView(QWidget* parent, DolphinController* controller);
51 virtual ~DolphinColumnView();
52
53 /** @see QAbstractItemView::indexAt() */
54 virtual QModelIndex indexAt(const QPoint& point) const;
55
56 /**
57 * Returns the item on the position \a pos. The KFileItem instance
58 * is null if no item is below the position.
59 */
60 KFileItem itemAt(const QPoint& point) const;
61
62 /** @see QAbstractItemView::scrollTo() */
63 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
64
65 /** @see QAbstractItemView::visualRect() */
66 virtual QRect visualRect(const QModelIndex& index) const;
67
68 /** Inverts the selection of the currently active column. */
69 void invertSelection();
70
71 /**
72 * Reloads the content of all columns. In opposite to non-hierarchical views
73 * it is not enough to reload the KDirLister, instead this method must be explicitly
74 * invoked.
75 */
76 void reload();
77
78 /**
79 * Adjusts the root URL of the first column and removes all
80 * other columns.
81 */
82 void setRootUrl(const KUrl& url);
83
84 /** Returns the URL of the first column. */
85 KUrl rootUrl() const;
86
87 /**
88 * Filters the currently shown items by \a nameFilter. All items
89 * which contain the given filter string will be shown.
90 */
91 void setNameFilter(const QString& nameFilter);
92
93 /**
94 * Returns the currently used name filter. All items
95 * which contain the name filter will be shown.
96 */
97 QString nameFilter() const;
98
99 /**
100 * Shows the column which represents the URL \a url. If the column
101 * is already shown, it gets activated, otherwise it will be created.
102 */
103 void showColumn(const KUrl& url);
104
105 /**
106 * Does an inline editing for the item \a item
107 * inside the active column.
108 */
109 void editItem(const KFileItem& item);
110
111 /**
112 * Returns the selected items of the active column.
113 */
114 KFileItemList selectedItems() const;
115
116 /**
117 * Returns the MIME data for the selected items
118 * of the active column.
119 */
120 QMimeData* selectionMimeData() const;
121
122 public slots:
123 /** @see QAbstractItemView::selectAll() */
124 virtual void selectAll();
125
126 signals:
127 /**
128 * Requests that the given column be deleted at the discretion
129 * of the receiver of the signal.
130 */
131 void requestColumnDeletion(QAbstractItemView* column);
132
133 protected:
134 virtual bool isIndexHidden(const QModelIndex& index) const;
135 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
136 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
137 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
138 virtual int horizontalOffset() const;
139 virtual int verticalOffset() const;
140
141 virtual void mousePressEvent(QMouseEvent* event);
142 virtual void resizeEvent(QResizeEvent* event);
143 virtual void wheelEvent(QWheelEvent* event);
144
145 private slots:
146 void setZoomLevel(int level);
147
148 /**
149 * Moves the content of the columns view to represent
150 * the scrollbar position \a x.
151 */
152 void moveContentHorizontally(int x);
153
154 /**
155 * Updates the size of the decoration dependent on the
156 * icon size of the ColumnModeSettings. The controller
157 * will get informed about possible zoom in/zoom out
158 * operations.
159 */
160 void updateDecorationSize(bool showPreview);
161
162 /**
163 * Updates the background color of the columns to respect
164 * the current activation state \a active.
165 */
166 void updateColumnsBackground(bool active);
167
168 void slotSortingChanged(DolphinView::Sorting sorting);
169 void slotSortOrderChanged(Qt::SortOrder order);
170 void slotShowHiddenFilesChanged();
171 void slotShowPreviewChanged();
172
173 private:
174 DolphinColumnWidget* activeColumn() const;
175
176 /**
177 * Deactivates the currently active column and activates
178 * the new column indicated by \a index. m_index represents
179 * the active column afterwards. Also the URL of the navigator
180 * will be adjusted to reflect the column URL.
181 */
182 void setActiveColumnIndex(int index);
183
184 void layoutColumns();
185 void updateScrollBar();
186
187 /**
188 * Assures that the currently active column is fully visible
189 * by adjusting the horizontal position of the content.
190 */
191 void assureVisibleActiveColumn();
192
193 /**
194 * Request the activation for the column \a column. It is assured
195 * that the columns gets fully visible by adjusting the horizontal
196 * position of the content.
197 */
198 void requestActivation(DolphinColumnWidget* column);
199
200 /** Removes all columns except of the root column. */
201 void removeAllColumns();
202
203 /**
204 * Returns the position of the point \a point relative to the column
205 * \a column.
206 */
207 QPoint columnPosition(DolphinColumnWidget* column, const QPoint& point) const;
208
209 /**
210 * Deletes the column. If the itemview of the controller is set to the column,
211 * the controllers itemview is set to 0.
212 */
213 void deleteColumn(DolphinColumnWidget* column);
214
215 private:
216 DolphinController* m_controller;
217 bool m_active;
218 int m_index;
219 int m_contentX;
220 QList<DolphinColumnWidget*> m_columns;
221 QFrame* m_emptyViewport;
222 QTimeLine* m_animation;
223 QString m_nameFilter;
224
225 friend class DolphinColumnWidget;
226 };
227
228 inline DolphinColumnWidget* DolphinColumnView::activeColumn() const
229 {
230 return m_columns[m_index];
231 }
232
233 #endif