]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
use inline keyword as suggested at http://www.parashift.com/c%2B%2B-faq-lite/inline...
[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 /**
57 * Reloads the content of all columns. In opposite to non-hierarchical views
58 * it is not enough to reload the KDirLister, instead this method must be explicitly
59 * invoked.
60 */
61 void reload();
62
63 public slots:
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 updating of columns after the model index
111 * \a index has been expanded. Used by DolphinModel::expandToActiveUrl().
112 */
113 void triggerUpdateColumns(const QModelIndex& index);
114
115 /**
116 * Adjusts the root index of all columns to represent the reloaded
117 * model. Used by DolphinModel::triggerUpdateColumns().
118 */
119 void updateColumns();
120
121 /**
122 * Is invoked when the directory lister has started the loading
123 * of the URL \a url and sets the internal m_dirListerCompleted
124 * state to false.
125 */
126 void slotDirListerStarted(const KUrl& url);
127
128 /**
129 * Is invoked when the directory lister has completed the loading
130 * and sets the internal m_dirListerCompleted state to true.
131 */
132 void slotDirListerCompleted();
133
134 private:
135 bool isZoomInPossible() const;
136 bool isZoomOutPossible() const;
137
138 ColumnWidget* activeColumn() const;
139
140 /**
141 * Deactivates the currently active column and activates
142 * the new column indicated by \a index. m_index represents
143 * the active column afterwards. Also the URL of the navigator
144 * will be adjusted to reflect the column URL.
145 */
146 void setActiveColumnIndex(int index);
147
148 void layoutColumns();
149 void updateScrollBar();
150
151 /**
152 * Assures that the currently active column is fully visible
153 * by adjusting the horizontal position of the content.
154 */
155 void assureVisibleActiveColumn();
156
157 /**
158 * Request the activation for the column \a column. It is assured
159 * that the columns gets fully visible by adjusting the horizontal
160 * position of the content.
161 */
162 void requestActivation(ColumnWidget* column);
163
164 private:
165 DolphinController* m_controller;
166 bool m_restoreActiveColumnFocus;
167 bool m_dirListerCompleted;
168 int m_index;
169 int m_contentX;
170 QList<ColumnWidget*> m_columns;
171 QTimeLine* m_animation;
172
173 DolphinModel* m_dolphinModel;
174 QAbstractProxyModel* m_proxyModel;
175
176 friend class ColumnWidget;
177 };
178
179 inline ColumnWidget* DolphinColumnView::activeColumn() const
180 {
181 return m_columns[m_index];
182 }
183
184 #endif