]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
simplify code + fix activation issue when reloading columns
[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 /**
54 * Reloads the content of all columns. In opposite to non-hierarchical views
55 * it is not enough to reload the KDirLister, instead this method must be explicitly
56 * invoked.
57 */
58 void reload();
59
60 public slots:
61 /**
62 * Shows the column which represents the URL \a url. If the column
63 * is already shown, it gets activated, otherwise it will be created.
64 */
65 void showColumn(const KUrl& url);
66
67 protected:
68 virtual bool isIndexHidden(const QModelIndex& index) const;
69 virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
70 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
71 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
72 virtual int horizontalOffset() const;
73 virtual int verticalOffset() const;
74
75 virtual void mousePressEvent(QMouseEvent* event);
76 virtual void resizeEvent(QResizeEvent* event);
77
78 private slots:
79 void zoomIn();
80 void zoomOut();
81
82 /**
83 * Moves the content of the columns view to represent
84 * the scrollbar position \a x.
85 */
86 void moveContentHorizontally(int x);
87
88 /**
89 * Updates the size of the decoration dependent on the
90 * icon size of the ColumnModeSettings. The controller
91 * will get informed about possible zoom in/zoom out
92 * operations.
93 */
94 void updateDecorationSize();
95
96 /**
97 * Expands the directory model the the currently active URL.
98 * Used by DolphinColumnView::reload() after the directory
99 * lister has been loaded.
100 */
101 void expandToActiveUrl();
102
103 /**
104 * Triggers the reloading of columns after the model index
105 * \a index has been expanded. Used by DolphinModel::expandToActiveUrl().
106 */
107 void triggerReloadColumns(const QModelIndex& index);
108
109 /**
110 * Adjusts the root index of all columns to represent the reloaded
111 * model. Used by DolphinModel::triggerReloadColumns().
112 */
113 void reloadColumns();
114
115 private:
116 bool isZoomInPossible() const;
117 bool isZoomOutPossible() const;
118
119 inline ColumnWidget* activeColumn() const;
120
121 /**
122 * Deactivates the currently active column and activates
123 * the new column indicated by \a index. m_index represents
124 * the active column afterwards. Also the URL of the navigator
125 * will be adjusted to reflect the column URL.
126 */
127 void setActiveColumnIndex(int index);
128
129 void layoutColumns();
130 void updateScrollBar();
131
132 /**
133 * Assures that the currently active column is fully visible
134 * by adjusting the horizontal position of the content.
135 */
136 void assureVisibleActiveColumn();
137
138 /**
139 * Request the activation for the column \a column. It is assured
140 * that the columns gets fully visible by adjusting the horizontal
141 * position of the content.
142 */
143 void requestActivation(ColumnWidget* column);
144
145 /**
146 * Deletes all inactive child columns, that are a child of
147 * the currently active column.
148 */
149 void deleteInactiveChildColumns();
150
151 private:
152 DolphinController* m_controller;
153 bool m_restoreActiveColumnFocus;
154 int m_index;
155 int m_contentX;
156 QList<ColumnWidget*> m_columns;
157 QTimeLine* m_animation;
158
159 DolphinModel* m_dolphinModel;
160 QAbstractProxyModel* m_proxyModel;
161
162 friend class ColumnWidget;
163 };
164
165 ColumnWidget* DolphinColumnView::activeColumn() const
166 {
167 return m_columns[m_index];
168 }
169
170 #endif