]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
prevent crash in model when invoking KDirModel::expandToUrl() before the directory...
[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 <QAbstractItemView>
24 #include <QList>
25 #include <QStyleOption>
26
27 class ColumnWidget;
28 class DolphinController;
29 class DolphinModel;
30 class KUrl;
31 class QAbstractProxyModel;
32 class QTimeLine;
33
34 /**
35 * @brief Represents the view, where each directory is show as separate column.
36 *
37 * @see DolphinIconsView
38 * @see DolphinDetailsView
39 */
40 class DolphinColumnView : public QAbstractItemView
41 {
42 Q_OBJECT
43
44 public:
45 explicit DolphinColumnView(QWidget* parent, DolphinController* controller);
46 virtual ~DolphinColumnView();
47
48 virtual QModelIndex indexAt(const QPoint& point) const;
49 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
50 virtual QRect visualRect(const QModelIndex& index) const;
51 virtual void setModel(QAbstractItemModel* model);
52
53 /** Inverts the selection of the currently active column. */
54 void invertSelection();
55
56 public slots:
57 /**
58 * Reloads the content of all columns. In opposite to non-hierarchical views
59 * it is not enough to reload the KDirLister, instead this method must be explicitly
60 * invoked.
61 */
62 void reload();
63
64 /**
65 * Shows the column which represents the URL \a url. If the column
66 * is already shown, it gets activated, otherwise it will be created.
67 */
68 void showColumn(const KUrl& url);
69
70 /** @see QAbstractItemView::selectAll() */
71 virtual void selectAll();
72
73 protected:
74 virtual bool isIndexHidden(const QModelIndex& index) const;
75 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
76 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
77 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
78 virtual int horizontalOffset() const;
79 virtual int verticalOffset() const;
80
81 virtual void mousePressEvent(QMouseEvent* event);
82 virtual void resizeEvent(QResizeEvent* event);
83
84 private slots:
85 void zoomIn();
86 void zoomOut();
87
88 /**
89 * Moves the content of the columns view to represent
90 * the scrollbar position \a x.
91 */
92 void moveContentHorizontally(int x);
93
94 /**
95 * Updates the size of the decoration dependent on the
96 * icon size of the ColumnModeSettings. The controller
97 * will get informed about possible zoom in/zoom out
98 * operations.
99 */
100 void updateDecorationSize();
101
102 /**
103 * Expands the directory model the the currently active URL.
104 * Used by DolphinColumnView::reload() after the directory
105 * lister has been loaded.
106 */
107 void expandToActiveUrl();
108
109 /**
110 * Triggers the reloading of columns after the model index
111 * \a index has been expanded. Used by DolphinModel::expandToActiveUrl().
112 */
113 void triggerReloadColumns(const QModelIndex& index);
114
115 /**
116 * Adjusts the root index of all columns to represent the reloaded
117 * model. Used by DolphinModel::triggerReloadColumns().
118 */
119 void reloadColumns();
120
121 void triggerItem(const QModelIndex& index);
122
123 private:
124 bool isZoomInPossible() const;
125 bool isZoomOutPossible() const;
126
127 inline ColumnWidget* activeColumn() const;
128
129 /**
130 * Deactivates the currently active column and activates
131 * the new column indicated by \a index. m_index represents
132 * the active column afterwards. Also the URL of the navigator
133 * will be adjusted to reflect the column URL.
134 */
135 void setActiveColumnIndex(int index);
136
137 void layoutColumns();
138 void updateScrollBar();
139
140 /**
141 * Assures that the currently active column is fully visible
142 * by adjusting the horizontal position of the content.
143 */
144 void assureVisibleActiveColumn();
145
146 /**
147 * Request the activation for the column \a column. It is assured
148 * that the columns gets fully visible by adjusting the horizontal
149 * position of the content.
150 */
151 void requestActivation(ColumnWidget* column);
152
153 private:
154 DolphinController* m_controller;
155 bool m_restoreActiveColumnFocus;
156 bool m_initializedDirLister;
157 int m_index;
158 int m_contentX;
159 QList<ColumnWidget*> m_columns;
160 QTimeLine* m_animation;
161
162 DolphinModel* m_dolphinModel;
163 QAbstractProxyModel* m_proxyModel;
164
165 friend class ColumnWidget;
166 };
167
168 ColumnWidget* DolphinColumnView::activeColumn() const
169 {
170 return m_columns[m_index];
171 }
172
173 #endif