]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
Group classes into folders, Dolphin is too big in the meantime for having a flat...
[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 protected:
127 virtual bool isIndexHidden(const QModelIndex& index) const;
128 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
129 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
130 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
131 virtual int horizontalOffset() const;
132 virtual int verticalOffset() const;
133
134 virtual void mousePressEvent(QMouseEvent* event);
135 virtual void resizeEvent(QResizeEvent* event);
136 virtual void wheelEvent(QWheelEvent* event);
137
138 private slots:
139 void setZoomLevel(int level);
140
141 /**
142 * Moves the content of the columns view to represent
143 * the scrollbar position \a x.
144 */
145 void moveContentHorizontally(int x);
146
147 /**
148 * Updates the size of the decoration dependent on the
149 * icon size of the ColumnModeSettings. The controller
150 * will get informed about possible zoom in/zoom out
151 * operations.
152 */
153 void updateDecorationSize(bool showPreview);
154
155 /**
156 * Updates the background color of the columns to respect
157 * the current activation state \a active.
158 */
159 void updateColumnsBackground(bool active);
160
161 void slotSortingChanged(DolphinView::Sorting sorting);
162 void slotSortOrderChanged(Qt::SortOrder order);
163 void slotShowHiddenFilesChanged();
164 void slotShowPreviewChanged();
165
166 private:
167 DolphinColumnWidget* activeColumn() const;
168
169 /**
170 * Deactivates the currently active column and activates
171 * the new column indicated by \a index. m_index represents
172 * the active column afterwards. Also the URL of the navigator
173 * will be adjusted to reflect the column URL.
174 */
175 void setActiveColumnIndex(int index);
176
177 void layoutColumns();
178 void updateScrollBar();
179
180 /**
181 * Assures that the currently active column is fully visible
182 * by adjusting the horizontal position of the content.
183 */
184 void assureVisibleActiveColumn();
185
186 /**
187 * Request the activation for the column \a column. It is assured
188 * that the columns gets fully visible by adjusting the horizontal
189 * position of the content.
190 */
191 void requestActivation(DolphinColumnWidget* column);
192
193 /** Removes all columns except of the root column. */
194 void removeAllColumns();
195
196 /**
197 * Returns the position of the point \a point relative to the column
198 * \a column.
199 */
200 QPoint columnPosition(DolphinColumnWidget* column, const QPoint& point) const;
201
202 /**
203 * Deletes the column. If the itemview of the controller is set to the column,
204 * the controllers itemview is set to 0.
205 */
206 void deleteColumn(DolphinColumnWidget* column);
207
208 private:
209 DolphinController* m_controller;
210 bool m_active;
211 int m_index;
212 int m_contentX;
213 QList<DolphinColumnWidget*> m_columns;
214 QFrame* m_emptyViewport;
215 QTimeLine* m_animation;
216 QString m_nameFilter;
217
218 friend class DolphinColumnWidget;
219 };
220
221 inline DolphinColumnWidget* DolphinColumnView::activeColumn() const
222 {
223 return m_columns[m_index];
224 }
225
226 #endif