]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.h
I'm very sorry for breaking the build: I forgot to add the new files :-(
[dolphin.git] / src / 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 <dolphinview.h>
25 #include <QTreeView>
26 #include <libdolphin_export.h>
27
28 class DolphinController;
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 explicit DolphinDetailsView(QWidget* parent,
46 DolphinController* controller,
47 DolphinSortFilterProxyModel* model);
48 virtual ~DolphinDetailsView();
49
50 /**
51 * Returns a set containing the URLs of all expanded items.
52 */
53 QSet<KUrl> expandedUrls() const;
54
55 protected:
56 virtual bool event(QEvent* event);
57 virtual QStyleOptionViewItem viewOptions() const;
58 virtual void contextMenuEvent(QContextMenuEvent* event);
59 virtual void mousePressEvent(QMouseEvent* event);
60 virtual void mouseMoveEvent(QMouseEvent* event);
61 virtual void mouseReleaseEvent(QMouseEvent* event);
62 virtual void startDrag(Qt::DropActions supportedActions);
63 virtual void dragEnterEvent(QDragEnterEvent* event);
64 virtual void dragLeaveEvent(QDragLeaveEvent* event);
65 virtual void dragMoveEvent(QDragMoveEvent* event);
66 virtual void dropEvent(QDropEvent* event);
67 virtual void paintEvent(QPaintEvent* event);
68 virtual void keyPressEvent(QKeyEvent* event);
69 virtual void keyReleaseEvent(QKeyEvent* event);
70 virtual void resizeEvent(QResizeEvent* event);
71 virtual void wheelEvent(QWheelEvent* event);
72 virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
73 virtual bool eventFilter(QObject* watched, QEvent* event);
74 virtual QModelIndex indexAt (const QPoint& point) const;
75 virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
76 virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
77
78 private slots:
79 /**
80 * Sets the sort indicator section of the header view
81 * corresponding to \a sorting.
82 */
83 void setSortIndicatorSection(DolphinView::Sorting sorting);
84
85 /**
86 * Sets the sort indicator order of the header view
87 * corresponding to \a sortOrder.
88 */
89 void setSortIndicatorOrder(Qt::SortOrder sortOrder);
90
91 /**
92 * Synchronizes the sorting state of the Dolphin menu 'View -> Sort'
93 * with the current state of the details view.
94 * @param column Index of the current sorting column.
95 */
96 void synchronizeSortingState(int column);
97
98 /**
99 * Is invoked when the mouse cursor has entered an item. The controller
100 * gets informed to emit the itemEntered() signal if the mouse cursor
101 * is above the name column. Otherwise the controller gets informed
102 * to emit the itemViewportEntered() signal (all other columns should
103 * behave as viewport area).
104 */
105 void slotEntered(const QModelIndex& index);
106
107 /**
108 * Updates the destination \a destination from
109 * the elastic band to the current mouse position and triggers
110 * an update.
111 */
112 void updateElasticBand();
113
114 /**
115 * Returns the rectangle for the elastic band dependent from the
116 * origin \a origin, the current destination
117 * \a destination and the viewport position.
118 */
119 QRect elasticBandRect() const;
120
121 void setZoomLevel(int level);
122
123 void slotShowPreviewChanged();
124
125 /**
126 * Opens a context menu at the position \a pos and allows to
127 * configure the visibility of the header columns and whether
128 * expandable folders should be shown.
129 */
130 void configureSettings(const QPoint& pos);
131
132 /**
133 * Updates the visibilty state of columns and their order.
134 */
135 void updateColumnVisibility();
136
137 /**
138 * Saves order of the columns as global setting.
139 */
140 void saveColumnPositions();
141
142 /**
143 * Disables the automatical resizing of columns, if the user has resized the columns
144 * with the mouse.
145 */
146 void slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize);
147
148 /**
149 * Changes the alternating row colors setting depending from
150 * the activation state \a active.
151 */
152 void slotActivationChanged(bool active);
153
154 /**
155 * Disables the automatical resizing of the columns. Per default all columns
156 * are resized to use the maximum available width of the view as good as possible.
157 */
158 void disableAutoResizing();
159
160 void requestActivation();
161
162 void slotGlobalSettingsChanged(int category);
163
164 /**
165 * If the elastic band is currently shown, update the elastic band based on
166 * the current mouse position and ensure that the selection is the set of items
167 * intersecting it.
168 */
169 void updateElasticBandSelection();
170
171 /**
172 * If \a expandable is true, the details view acts as tree view.
173 * The current expandable state is remembered in the settings.
174 */
175 void setFoldersExpandable(bool expandable);
176
177 /**
178 * These slots update the list of expanded items.
179 */
180 void slotExpanded(const QModelIndex& index);
181 void slotCollapsed(const QModelIndex& index);
182
183 protected slots:
184
185 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
186
187 private:
188 /**
189 * Removes the URLs corresponding to the children of \a index in the rows
190 * between \a start and \a end inclusive from the set of expanded URLs.
191 */
192 void removeExpandedIndexes(const QModelIndex& parent, int start, int end);
193
194 /**
195 * Updates the size of the decoration dependent on the
196 * icon size of the DetailsModeSettings. The controller
197 * will get informed about possible zoom in/zoom out
198 * operations.
199 */
200 void updateDecorationSize(bool showPreview);
201
202 KFileItemDelegate::Information infoForColumn(int columnIndex) const;
203
204 /**
205 * Resizes all columns in a way to use the whole available width of the view.
206 */
207 void resizeColumns();
208
209 QRect nameColumnRect(const QModelIndex& index) const;
210
211 /**
212 * Returns true, if \a pos is within the expanding toggle of a tree.
213 */
214 bool isAboveExpandingToggle(const QPoint& pos) const;
215
216 private:
217 bool m_autoResize : 1; // if true, the columns are resized automatically to the available width
218 bool m_expandingTogglePressed : 1;
219 bool m_keyPressed : 1; // true if a key is pressed currently; info used by currentChanged()
220 bool m_useDefaultIndexAt : 1; // true, if QTreeView::indexAt() should be used
221 bool m_ignoreScrollTo : 1; // true if calls to scrollTo(...) should do nothing.
222
223 DolphinController* m_controller;
224 ViewExtensionsFactory* m_extensionsFactory;
225 QAction* m_expandableFoldersAction;
226
227 // A set containing the URLs of all currently expanded folders.
228 // We cannot use a QSet<QModelIndex> because a QModelIndex is not guaranteed to remain valid over time.
229 // Also a QSet<QPersistentModelIndex> does not work as expected because it is not guaranteed that
230 // subsequent expand/collapse events of the same file item will yield the same QPersistentModelIndex.
231 QSet<KUrl> m_expandedUrls;
232
233 QFont m_font;
234 QSize m_decorationSize;
235
236 QRect m_dropRect;
237
238 struct ElasticBand
239 {
240 ElasticBand();
241
242 // Elastic band origin and destination coordinates are relative to t
243 // he origin of the view, not the viewport.
244 bool show;
245 QPoint origin;
246 QPoint destination;
247
248 // Optimization mechanisms for use with elastic band selection.
249 // Basically, allow "incremental" updates to the selection based
250 // on the last elastic band shape.
251 QPoint lastSelectionOrigin;
252 QPoint lastSelectionDestination;
253
254 // If true, compute the set of selected elements from scratch (slower)
255 bool ignoreOldInfo;
256
257 // Edges of the filenames that are closest to the edges of oldSelectionRect.
258 // Used to decide whether horizontal changes in the elastic band are likely
259 // to require us to re-check which items are selected.
260 int outsideNearestLeftEdge;
261 int outsideNearestRightEdge;
262 int insideNearestLeftEdge;
263 int insideNearestRightEdge;
264 // The set of items that were selected at the time this band was shown.
265 // NOTE: Unless CTRL was pressed when the band was created, this is always empty.
266 QItemSelection originalSelection;
267 } m_band;
268 };
269
270 #endif