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