]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
don't reset the x-position to 0 in the Column View, if a new directory is loaded
[dolphin.git] / src / dolphinview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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
22 #ifndef DOLPHINVIEW_H
23 #define DOLPHINVIEW_H
24
25 #include <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
28 #include <kio/job.h>
29
30 #include <QBoxLayout>
31 #include <QKeyEvent>
32 #include <QLinkedList>
33 #include <QListView>
34 #include <QWidget>
35
36 class DolphinController;
37 class KDirLister;
38 class KFileItemDelegate;
39 class KUrl;
40 class KDirModel;
41 class DolphinColumnView;
42 class DolphinDetailsView;
43 class DolphinIconsView;
44 class DolphinMainWindow;
45 class DolphinSortFilterProxyModel;
46 class QModelIndex;
47 class ViewProperties;
48
49 /**
50 * @short Represents a view for the directory content.
51 *
52 * View modes for icons, details and columns are supported. It's
53 * possible to adjust:
54 * - sort order
55 * - sort type
56 * - show hidden files
57 * - show previews
58 *
59 * @see DolphinIconsView
60 * @see DolphinDetailsView
61 * @see DolphinColumnView
62 */
63 class DolphinView : public QWidget
64 {
65 Q_OBJECT
66
67 public:
68 /**
69 * Defines the view mode for a directory. The view mode
70 * can be defined when constructing a DolphinView. The
71 * view mode is automatically updated if the directory itself
72 * defines a view mode (see class ViewProperties for details).
73 */
74 enum Mode
75 {
76 /**
77 * The directory items are shown as icons including an
78 * icon name. */
79 IconsView = 0,
80
81 /**
82 * The icon, the name and at least the size of the directory
83 * items are shown in a table. It is possible to add columns
84 * for date, group and permissions.
85 */
86 DetailsView = 1,
87
88 /**
89 * Each folder is shown in a separate column.
90 */
91 ColumnView = 2,
92 MaxModeEnum = ColumnView
93 };
94
95 /** Defines the sort order for the items of a directory. */
96 enum Sorting
97 {
98 SortByName = 0,
99 SortBySize,
100 SortByDate,
101 SortByPermissions,
102 SortByOwner,
103 SortByGroup,
104 SortByType,
105 MaxSortEnum = SortByType
106 };
107
108 /**
109 * @param parent Parent widget of the view.
110 * @param url Specifies the content which should be shown.
111 * @param dirLister Used directory lister. The lister is not owned
112 * by the view and won't get deleted.
113 * @param dirModel Used directory model. The model is not owned
114 * by the view and won't get deleted.
115 * @param proxyModel Used proxy model which specifies the sorting. The
116 * model is not owned by the view and won't get
117 * deleted.
118 * @param mode Used display mode (IconsView, DetailsView or ColumnsView).
119 * @param showHiddenFiles If true, hidden files will be shown in the view.
120 */
121 DolphinView(QWidget* parent,
122 const KUrl& url,
123 KDirLister* dirLister,
124 KDirModel* dirModel,
125 DolphinSortFilterProxyModel* proxyModel,
126 Mode mode);
127
128 virtual ~DolphinView();
129
130 /**
131 * Returns the current active URL, where all actions are applied.
132 * The URL navigator is synchronized with this URL.
133 */
134 const KUrl& url() const;
135
136 /**
137 * Returns the root URL of the view, which is defined as the first
138 * visible path of DolphinView::url(). Usually the root URL is
139 * equal to DolphinView::url(), but in the case of the column view
140 * when 2 columns are shown, the root URL might be:
141 * /home/peter/Documents
142 * and DolphinView::url() might return
143 * /home/peter/Documents/Music/
144 */
145 KUrl rootUrl() const;
146
147 /**
148 * If \a active is true, the view will marked as active. The active
149 * view is defined as view where all actions are applied to.
150 */
151 void setActive(bool active);
152 bool isActive() const;
153
154 /**
155 * Changes the view mode for the current directory to \a mode.
156 * If the view properties should be remembered for each directory
157 * (GeneralSettings::globalViewProps() returns false), then the
158 * changed view mode will be be stored automatically.
159 */
160 void setMode(Mode mode);
161 Mode mode() const;
162
163 /**
164 * Turns on the file preview for the all files of the current directory,
165 * if \a show is true.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * preview setting will be be stored automatically.
169 */
170 void setShowPreview(bool show);
171 bool showPreview() const;
172
173 /**
174 * Shows all hidden files of the current directory,
175 * if \a show is true.
176 * If the view properties should be remembered for each directory
177 * (GeneralSettings::globalViewProps() returns false), then the
178 * show hidden file setting will be be stored automatically.
179 */
180 void setShowHiddenFiles(bool show);
181 bool showHiddenFiles() const;
182
183 /**
184 * Summarizes all sorted items by their category \a categorized
185 * is true.
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * categorized sorting setting will be be stored automatically.
189 */
190 void setCategorizedSorting(bool categorized);
191 bool categorizedSorting() const;
192
193 /**
194 * Returns true, if the categorized sorting is supported by the current
195 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
196 * supports categorizations. To check whether the categorized
197 * sorting is set, use DolphinView::categorizedSorting().
198 */
199 bool supportsCategorizedSorting() const;
200
201 /**
202 * Selects all items.
203 * @see DolphinView::selectedItems()
204 */
205 void selectAll();
206
207 /**
208 * Inverts the current selection: selected items get unselected,
209 * unselected items get selected.
210 * @see DolphinView::selectedItems()
211 */
212 void invertSelection();
213
214 /** Returns true, if at least one item is selected. */
215 bool hasSelection() const;
216
217 void clearSelection();
218
219 /**
220 * Returns the selected items. The list is empty if no item has been
221 * selected.
222 * @see DolphinView::selectedUrls()
223 */
224 KFileItemList selectedItems() const;
225
226 /**
227 * Returns a list of URLs for all selected items. An empty list
228 * is returned, if no item is selected.
229 * @see DolphinView::selectedItems()
230 */
231 KUrl::List selectedUrls() const;
232
233 /**
234 * Returns the file item for the given model index \a index.
235 */
236 KFileItem* fileItem(const QModelIndex index) const;
237
238 /**
239 * Sets the upper left position of the view content
240 * to (x,y). The content of the view might be larger than the visible area
241 * and hence a scrolling must be done.
242 */
243 void setContentsPosition(int x, int y);
244
245 /** Returns the upper left position of the view content. */
246 QPoint contentsPosition() const;
247
248 /** Increases the size of the current set view mode. */
249 void zoomIn();
250
251 /** Decreases the size of the current set view mode. */
252 void zoomOut();
253
254 /**
255 * Returns true, if zooming in is possible. If false is returned,
256 * the minimal zoom size is possible.
257 */
258 bool isZoomInPossible() const;
259
260 /**
261 * Returns true, if zooming out is possible. If false is returned,
262 * the maximum zoom size is possible.
263 */
264 bool isZoomOutPossible() const;
265
266 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
267 void setSorting(Sorting sorting);
268
269 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
270 Sorting sorting() const;
271
272 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
273 void setSortOrder(Qt::SortOrder order);
274
275 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
276 Qt::SortOrder sortOrder() const;
277
278 /** Sets the additional information which should be shown for the items. */
279 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info);
280
281 /** Returns the additional information which should be shown for the items. */
282 KFileItemDelegate::AdditionalInformation additionalInfo() const;
283
284 /** Reloads the current directory. */
285 void reload();
286
287 /**
288 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
289 * This method only needs to get invoked if the view settings for the Icons View,
290 * Details View or Columns View have been changed.
291 */
292 void refresh();
293
294 public slots:
295 /**
296 * Changes the directory to \a url. If the current directory is equal to
297 * \a url, nothing will be done (use DolphinView::reload() instead).
298 */
299 void setUrl(const KUrl& url);
300
301 /**
302 * Request of a selection change. The view will do its best to accommodate
303 * the request, but it is not guaranteed that all items in \a selection
304 * will actually get selected. The view will e.g. not select items which
305 * are not in the currently displayed folder.
306 */
307 void changeSelection(const KFileItemList& selection);
308
309 signals:
310 /**
311 * Is emitted if the view has been activated by e. g. a mouse click.
312 */
313 void activated();
314
315 /** Is emitted if URL of the view has been changed to \a url. */
316 void urlChanged(const KUrl& url);
317
318 /**
319 * Is emitted if the view mode (IconsView, DetailsView,
320 * PreviewsView) has been changed.
321 */
322 void modeChanged();
323
324 /** Is emitted if the 'show preview' property has been changed. */
325 void showPreviewChanged();
326
327 /** Is emitted if the 'show hidden files' property has been changed. */
328 void showHiddenFilesChanged();
329
330 /** Is emitted if the 'categorized sorting' property has been changed. */
331 void categorizedSortingChanged();
332
333 /** Is emitted if the sorting by name, size or date has been changed. */
334 void sortingChanged(DolphinView::Sorting sorting);
335
336 /** Is emitted if the sort order (ascending or descending) has been changed. */
337 void sortOrderChanged(Qt::SortOrder order);
338
339 /** Is emitted if the additional information for an item has been changed. */
340 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
341
342 /**
343 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
344 * It the URL is empty, no item information request is pending.
345 */
346 void requestItemInfo(const KUrl& url);
347
348 /** Is emitted if the contents has been moved to \a x, \a y. */
349 void contentsMoved(int x, int y);
350
351 /**
352 * Is emitted whenever the selection has been changed.
353 */
354 void selectionChanged(const KFileItemList& selection);
355
356 /**
357 * Is emitted if a context menu is requested for the item \a item,
358 * which is part of \a url. If the item is 0, the context menu
359 * for the URL should be shown.
360 */
361 void requestContextMenu(KFileItem* item, const KUrl& url);
362
363 /**
364 * Is emitted if the URLs \a are dropped to the destination URL
365 * \a destination. No operation is done within the DolphinView, the
366 * receiver of the signal has to take care about the corresponding
367 * operation.
368 */
369 void urlsDropped(const KUrl::List& urls, const KUrl& destination);
370
371 /**
372 * Is emitted if an information message with the content \a msg
373 * should be shown.
374 */
375 void infoMessage(const QString& msg);
376
377 /**
378 * Is emitted if an error message with the content \a msg
379 * should be shown.
380 */
381 void errorMessage(const QString& msg);
382
383 protected:
384 /** @see QWidget::mouseReleaseEvent */
385 virtual void mouseReleaseEvent(QMouseEvent* event);
386
387 private slots:
388 /**
389 * Marks the view as active (DolphinView:isActive() will return true)
390 * and emits the 'activated' signal if it is not already active.
391 */
392 void activate();
393
394 /**
395 * If the item specified by \a index is a directory, then this
396 * directory will be loaded. If the item is a file, the corresponding
397 * application will get started.
398 */
399 void triggerItem(const QModelIndex& index);
400
401 /**
402 * Generates a preview image for each file item in \a items.
403 * The current preview settings (maximum size, 'Show Preview' menu)
404 * are respected.
405 */
406 void generatePreviews(const KFileItemList& items);
407
408 /**
409 * Replaces the icon of the item \a item by the preview pixmap
410 * \a pixmap.
411 */
412 void showPreview(const KFileItem& item, const QPixmap& pixmap);
413
414 void emitSelectionChangedSignal();
415
416 /**
417 * Opens the context menu on position \a pos. The position
418 * is used to check whether the context menu is related to an
419 * item or to the viewport.
420 */
421 void openContextMenu(const QPoint& pos);
422
423 /**
424 * Drops the URLs \a urls to the index \a index. \a source
425 * indicates the widget where the dragging has been started from.
426 */
427 void dropUrls(const KUrl::List& urls,
428 const QModelIndex& index,
429 QWidget* source);
430
431 /**
432 * Drops the URLs \a urls at the
433 * destination \a destination.
434 */
435 void dropUrls(const KUrl::List& urls,
436 const KUrl& destination);
437 /**
438 * Updates the view properties of the current URL to the
439 * sorting given by \a sorting.
440 */
441 void updateSorting(DolphinView::Sorting sorting);
442
443 /**
444 * Updates the view properties of the current URL to the
445 * sort order given by \a order.
446 */
447 void updateSortOrder(Qt::SortOrder order);
448
449 /**
450 * Emits the signal contentsMoved with the current coordinates
451 * of the viewport as parameters.
452 */
453 void emitContentsMoved();
454
455 /** Applies an item effect to all cut items of the clipboard. */
456 void updateCutItems();
457
458 /**
459 * Updates the status bar to show hover information for the
460 * item with the index \a index. If currently other items are selected,
461 * no hover information is shown.
462 * @see DolphinView::clearHoverInformation()
463 */
464 void showHoverInformation(const QModelIndex& index);
465
466 /**
467 * Clears the hover information shown in the status bar.
468 * @see DolphinView::showHoverInformation().
469 */
470 void clearHoverInformation();
471
472 private:
473 void startDirLister(const KUrl& url, bool reload = false);
474
475 /**
476 * Creates a new view representing the given view mode (DolphinView::mode()).
477 * The current view will get deleted.
478 */
479 void createView();
480
481 /**
482 * Selects all items by using the selection flags \a flags. This is a helper
483 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
484 */
485 void selectAll(QItemSelectionModel::SelectionFlags flags);
486
487 /**
488 * Returns a pointer to the currently used item view, which is either
489 * a ListView or a TreeView.
490 */
491 QAbstractItemView* itemView() const;
492
493 /**
494 * Returns true if the index is valid and represents
495 * the column KDirModel::Name.
496 */
497 bool isValidNameIndex(const QModelIndex& index) const;
498
499 /**
500 * Returns true, if the item \a item has been cut into
501 * the clipboard.
502 */
503 bool isCutItem(const KFileItem& item) const;
504
505 /** Applies an item effect to all cut items. */
506 void applyCutItemEffect();
507
508 /**
509 * Returns true, if the ColumnView is activated. As the column view
510 * requires some special handling for iterating through directories,
511 * this method has been introduced for convenience.
512 */
513 bool isColumnViewActive() const
514 {
515 return m_columnView != 0;
516 }
517
518 private:
519 /**
520 * Remembers the original pixmap for an item before
521 * the cut effect is applied.
522 */
523 struct CutItem
524 {
525 KUrl url;
526 QPixmap pixmap;
527 };
528
529 bool m_active;
530 bool m_loadingDirectory;
531 bool m_initializeColumnView;
532 Mode m_mode;
533
534 DolphinMainWindow* m_mainWindow;
535 QVBoxLayout* m_topLayout;
536
537 DolphinController* m_controller;
538 DolphinIconsView* m_iconsView;
539 DolphinDetailsView* m_detailsView;
540 DolphinColumnView* m_columnView;
541 KFileItemDelegate* m_fileItemDelegate;
542
543 KDirModel* m_dirModel;
544 KDirLister* m_dirLister;
545 DolphinSortFilterProxyModel* m_proxyModel;
546
547 QList<CutItem> m_cutItemsCache;
548 };
549
550 #endif // DOLPHINVIEW_H