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