]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphindetailsview.h
If 'remember view-properties' is selected, store the .directory files only if the...
[dolphin.git] / src / views / dolphindetailsview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * Copyright (C) 2008 by Simon St. James (kdedevel@etotheipiplusone.com) *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef DOLPHINDETAILSVIEW_H
22 #define DOLPHINDETAILSVIEW_H
23
24 #include <QTreeView>
25 #include <libdolphin_export.h>
26 #include <views/dolphinview.h>
27
28 class DolphinViewController;
29 class DolphinSortFilterProxyModel;
30 class ViewExtensionsFactory;
31
32 /**
33 * @brief Represents the details view which shows the name, size,
34 * date, permissions, owner and group of an item.
35 *
36 * The width of the columns is automatically adjusted in a way
37 * that full available width of the view is used by stretching the width
38 * of the name column.
39 */
40 class LIBDOLPHINPRIVATE_EXPORT DolphinDetailsView : public QTreeView
41 {
42 Q_OBJECT
43
44 public:
45 /**
46 * @param parent Parent widget.
47 * @param dolphinViewController Allows the DolphinDetailsView to control the
48 * DolphinView in a limited way.
49 * @param viewModeController Controller that is used by the DolphinView
50 * to control the DolphinDetailsView. The DolphinDetailsView
51 * only has read access to the controller.
52 * @param model Directory that is shown.
53 */
54 explicit DolphinDetailsView(QWidget* parent,
55 DolphinViewController* dolphinViewController,
56 const ViewModeController* viewModeController,
57 DolphinSortFilterProxyModel* model);
58 virtual ~DolphinDetailsView();
59
60 /**
61 * Returns a set containing the URLs of all expanded items.
62 */
63 QSet<KUrl> expandedUrls() const;
64
65 virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
66
67 protected:
68 virtual bool event(QEvent* event);
69 virtual QStyleOptionViewItem viewOptions() const;
70 virtual void contextMenuEvent(QContextMenuEvent* event);
71 virtual void mousePressEvent(QMouseEvent* event);
72 virtual void mouseMoveEvent(QMouseEvent* event);
73 virtual void mouseReleaseEvent(QMouseEvent* event);
74 virtual void startDrag(Qt::DropActions supportedActions);
75 virtual void dragEnterEvent(QDragEnterEvent* event);
76 virtual void dragLeaveEvent(QDragLeaveEvent* event);
77 virtual void dragMoveEvent(QDragMoveEvent* event);
78 virtual void dropEvent(QDropEvent* event);
79 virtual void paintEvent(QPaintEvent* event);
80 virtual void keyPressEvent(QKeyEvent* event);
81 virtual void keyReleaseEvent(QKeyEvent* event);
82 virtual void resizeEvent(QResizeEvent* event);
83 virtual void wheelEvent(QWheelEvent* event);
84 virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
85 virtual bool eventFilter(QObject* watched, QEvent* event);
86 virtual QModelIndex indexAt (const QPoint& point) const;
87 virtual QRect visualRect(const QModelIndex& index) const;
88 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
89 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
90
91
92 protected slots:
93 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
94
95 private slots:
96 /**
97 * Sets the sort indicator section of the header view
98 * corresponding to \a sorting.
99 */
100 void setSortIndicatorSection(DolphinView::Sorting sorting);
101
102 /**
103 * Sets the sort indicator order of the header view
104 * corresponding to \a sortOrder.
105 */
106 void setSortIndicatorOrder(Qt::SortOrder sortOrder);
107
108 /**
109 * Synchronizes the sorting state of the Dolphin menu 'View -> Sort'
110 * with the current state of the details view.
111 * @param column Index of the current sorting column.
112 */
113 void synchronizeSortingState(int column);
114
115 /**
116 * Is invoked when the mouse cursor has entered an item. The controller
117 * gets informed to emit the itemEntered() signal if the mouse cursor
118 * is above the name column. Otherwise the controller gets informed
119 * to emit the itemViewportEntered() signal (all other columns should
120 * behave as viewport area).
121 */
122 void slotEntered(const QModelIndex& index);
123
124 /**
125 * Updates the destination \a destination from
126 * the elastic band to the current mouse position and triggers
127 * an update.
128 */
129 void updateElasticBand();
130
131 /**
132 * Returns the rectangle for the elastic band dependent from the
133 * origin \a origin, the current destination
134 * \a destination and the viewport position.
135 */
136 QRect elasticBandRect() const;
137
138 void setZoomLevel(int level);
139
140 void slotShowPreviewChanged();
141
142 /**
143 * Opens a context menu at the position \a pos and allows to
144 * configure the visibility of the header columns and whether
145 * expandable folders should be shown.
146 */
147 void configureSettings(const QPoint& pos);
148
149 /**
150 * Updates the visibilty state of columns and their order.
151 */
152 void updateColumnVisibility();
153
154 /**
155 * Resizes all columns in a way to use the whole available width of the view.
156 */
157 void resizeColumns();
158
159 /**
160 * Saves order of the columns as global setting.
161 */
162 void saveColumnPositions();
163
164 /**
165 * Disables the automatical resizing of columns, if the user has resized the columns
166 * with the mouse.
167 */
168 void slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize);
169
170 /**
171 * Changes the alternating row colors setting depending from
172 * the activation state \a active.
173 */
174 void slotActivationChanged(bool active);
175
176 /**
177 * Disables the automatical resizing of the columns. Per default all columns
178 * are resized to use the maximum available width of the view as good as possible.
179 */
180 void disableAutoResizing();
181
182 void requestActivation();
183
184 void slotGlobalSettingsChanged(int category);
185
186 /**
187 * If the elastic band is currently shown, update the elastic band based on
188 * the current mouse position and ensure that the selection is the set of items
189 * intersecting it.
190 */
191 void updateElasticBandSelection();
192
193 /**
194 * If \a expandable is true, the details view acts as tree view.
195 * The current expandable state is remembered in the settings.
196 */
197 void setFoldersExpandable(bool expandable);
198
199 /**
200 * These slots update the list of expanded items.
201 */
202 void slotExpanded(const QModelIndex& index);
203 void slotCollapsed(const QModelIndex& index);
204
205 private:
206 /**
207 * Removes the URLs corresponding to the children of \a index in the rows
208 * between \a start and \a end inclusive from the set of expanded URLs.
209 */
210 void removeExpandedIndexes(const QModelIndex& parent, int start, int end);
211
212 /**
213 * Updates the size of the decoration dependent on the
214 * icon size of the DetailsModeSettings. The controller
215 * will get informed about possible zoom in/zoom out
216 * operations.
217 */
218 void updateDecorationSize(bool showPreview);
219
220 KFileItemDelegate::Information infoForColumn(int columnIndex) const;
221
222 /**
223 * Returns true, if \a pos is within the expanding toggle of a tree.
224 */
225 bool isAboveExpandingToggle(const QPoint& pos) const;
226
227 /**
228 * Sets the maximum size available for editing in the delegate.
229 */
230 void adjustMaximumSizeForEditing(const QModelIndex& index);
231
232 private:
233 bool m_autoResize : 1; // if true, the columns are resized automatically to the available width
234 bool m_expandingTogglePressed : 1;
235 bool m_keyPressed : 1; // true if a key is pressed currently; info used by currentChanged()
236 bool m_useDefaultIndexAt : 1; // true, if QTreeView::indexAt() should be used
237 bool m_ignoreScrollTo : 1; // true if calls to scrollTo(...) should do nothing.
238
239 DolphinViewController* m_dolphinViewController;
240 const ViewModeController* m_viewModeController;
241 ViewExtensionsFactory* m_extensionsFactory;
242 QAction* m_expandableFoldersAction;
243
244 // A set containing the URLs of all currently expanded folders.
245 // We cannot use a QSet<QModelIndex> because a QModelIndex is not guaranteed to remain valid over time.
246 // Also a QSet<QPersistentModelIndex> does not work as expected because it is not guaranteed that
247 // subsequent expand/collapse events of the same file item will yield the same QPersistentModelIndex.
248 QSet<KUrl> m_expandedUrls;
249
250 QFont m_font;
251 QSize m_decorationSize;
252
253 QRect m_dropRect;
254
255 struct ElasticBand
256 {
257 ElasticBand();
258
259 // Elastic band origin and destination coordinates are relative to t
260 // he origin of the view, not the viewport.
261 bool show;
262 QPoint origin;
263 QPoint destination;
264
265 // Optimization mechanisms for use with elastic band selection.
266 // Basically, allow "incremental" updates to the selection based
267 // on the last elastic band shape.
268 QPoint lastSelectionOrigin;
269 QPoint lastSelectionDestination;
270
271 // If true, compute the set of selected elements from scratch (slower)
272 bool ignoreOldInfo;
273
274 // Edges of the filenames that are closest to the edges of oldSelectionRect.
275 // Used to decide whether horizontal changes in the elastic band are likely
276 // to require us to re-check which items are selected.
277 int outsideNearestLeftEdge;
278 int outsideNearestRightEdge;
279 int insideNearestLeftEdge;
280 int insideNearestRightEdge;
281 // The set of items that were selected at the time this band was shown.
282 // NOTE: Unless CTRL was pressed when the band was created, this is always empty.
283 QItemSelection originalSelection;
284 } m_band;
285 };
286
287 #endif