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