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