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