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