]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
Use hover effect from KFileItemDelegate also for the details view and assure that...
[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 <kfileiconview.h>
28 #include <kio/job.h>
29
30 #include <urlnavigator.h>
31
32 #include <QDropEvent>
33 #include <QLinkedList>
34 #include <QListView>
35 #include <QMouseEvent>
36 #include <QVBoxLayout>
37 #include <QWidget>
38
39 class DolphinController;
40 class FilterBar;
41 class KUrl;
42 class KDirModel;
43 class UrlNavigator;
44 class DolphinDetailsView;
45 class DolphinDirLister;
46 class DolphinIconsView;
47 class DolphinMainWindow;
48 class DolphinSortFilterProxyModel;
49 class DolphinStatusBar;
50 class QModelIndex;
51 class QPainter;
52 class QTimer;
53 class ViewProperties;
54
55 /**
56 * @short Represents a view for the directory content
57 * including the navigation bar, filter bar and status bar.
58 *
59 * View modes for icons and details are supported. Currently
60 * Dolphin allows to have up to two views inside the main window.
61 *
62 * @see DolphinIconsView
63 * @see DolphinDetailsView
64 * @see UrlNavigator
65 * @see DolphinStatusBar
66 */
67 class 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 MaxModeEnum = DetailsView
92 };
93
94 /** Defines the sort order for the items of a directory. */
95 enum Sorting
96 {
97 SortByName = 0,
98 SortBySize,
99 SortByDate,
100 SortByPermissions,
101 SortByOwner,
102 SortByGroup,
103 MaxSortEnum = SortByGroup
104 };
105
106 DolphinView(DolphinMainWindow* mainwindow,
107 QWidget *parent,
108 const KUrl& url,
109 Mode mode = IconsView,
110 bool showHiddenFiles = false);
111
112 virtual ~DolphinView();
113
114 /**
115 * Sets the current active URL.
116 * The signals UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
117 * are emitted.
118 */
119 void setUrl(const KUrl& url);
120
121 /** Returns the current active URL. */
122 const KUrl& url() const;
123
124 /**
125 * Returns true if the view is active and hence all actions are
126 * applied to this view.
127 */
128 bool isActive() const;
129
130 /**
131 * Changes the view mode for the current directory to \a mode.
132 * If the view properties should be remembered for each directory
133 * (GeneralSettings::globalViewProps() returns false), then the
134 * changed view mode will be be stored automatically.
135 */
136 void setMode(Mode mode);
137 Mode mode() const;
138
139 /**
140 * Turns on the file preview for the all files of the current directory,
141 * if \a show is true.
142 * If the view properties should be remembered for each directory
143 * (GeneralSettings::globalViewProps() returns false), then the
144 * preview setting will be be stored automatically.
145 */
146 void setShowPreview(bool show);
147 bool showPreview() const;
148
149 /**
150 * Shows all hidden files of the current directory,
151 * if \a show is true.
152 * If the view properties should be remembered for each directory
153 * (GeneralSettings::globalViewProps() returns false), then the
154 * show hidden file setting will be be stored automatically.
155 */
156 void setShowHiddenFiles(bool show);
157 bool showHiddenFiles() const;
158
159 /**
160 * Triggers the renaming of the currently selected items, where
161 * the user must input a new name for the items.
162 */
163 void renameSelectedItems();
164
165 /**
166 * Selects all items.
167 * @see DolphinView::selectedItems()
168 */
169 void selectAll();
170
171 /**
172 * Inverts the current selection: selected items get unselected,
173 * unselected items get selected.
174 * @see DolphinView::selectedItems()
175 */
176 void invertSelection();
177
178 /**
179 * Goes back one step in the URL history. The signals
180 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
181 * are submitted.
182 */
183 void goBack();
184
185 /**
186 * Goes forward one step in the Url history. The signals
187 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
188 * are submitted.
189 */
190 void goForward();
191
192 /**
193 * Goes up one step of the Url path. The signals
194 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
195 * are submitted.
196 */
197 void goUp();
198
199 /**
200 * Goes to the home URL. The signals UrlNavigator::urlChanged()
201 * and UrlNavigator::historyChanged() are submitted.
202 */
203 void goHome();
204
205 /**
206 * Sets the URL of the navigation bar to an editable state
207 * if \a editable is true. If \a editable is false, each part of
208 * the location is presented by a button for a fast navigation.
209 */
210 void setUrlEditable(bool editable);
211
212 /**
213 * Returns the complete URL history. The index 0 indicates the oldest
214 * history element.
215 * @param index Output parameter which indicates the current
216 * index of the location.
217 */
218 const QLinkedList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
219
220 /**
221 * Returns true, if at least one item is selected.
222 */
223 bool hasSelection() const;
224
225 /**
226 * Returns the selected items. The list is empty if no item has been
227 * selected.
228 * @see DolphinView::selectedUrls()
229 */
230 KFileItemList selectedItems() const;
231
232 /**
233 * Returns a list of URLs for all selected items. An empty list
234 * is returned, if no item is selected.
235 * @see DolphinView::selectedItems()
236 */
237 KUrl::List selectedUrls() const;
238
239 /**
240 * Returns the file item for the given model index \a index.
241 */
242 KFileItem* fileItem(const QModelIndex index) const;
243
244 /**
245 * Renames the filename of the source URL by the new file name.
246 * If the new file name already exists, a dialog is opened which
247 * asks the user to enter a new name.
248 */
249 void rename(const KUrl& source, const QString& newName);
250
251 /** Returns the status bar of the view. */
252 DolphinStatusBar* statusBar() const;
253
254 /**
255 * Returns the x-position of the view content.
256 * The content of the view might be larger than the visible area
257 * and hence a scrolling must be done.
258 */
259 int contentsX() const;
260
261 /**
262 * Returns the y-position of the view content.
263 * The content of the view might be larger than the visible area
264 * and hence a scrolling must be done.
265 */
266 int contentsY() const;
267
268 /**
269 * Returns true, if the URL shown by the navigation bar is editable.
270 * @see UrlNavigator
271 */
272 bool isUrlEditable() const;
273
274 /** Increases the size of the current set view mode. */
275 void zoomIn();
276
277 /** Decreases the size of the current set view mode. */
278 void zoomOut();
279
280 /**
281 * Returns true, if zooming in is possible. If false is returned,
282 * the minimal zoom size is possible.
283 */
284 bool isZoomInPossible() const;
285
286 /**
287 * Returns true, if zooming out is possible. If false is returned,
288 * the maximum zoom size is possible.
289 */
290 bool isZoomOutPossible() const;
291
292 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
293 void setSorting(Sorting sorting);
294
295 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
296 Sorting sorting() const;
297
298 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
299 void setSortOrder(Qt::SortOrder order);
300
301 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
302 Qt::SortOrder sortOrder() const;
303
304 /** Refreshs the view settings by reading out the stored settings. */
305 void refreshSettings();
306
307 /** Returns the UrlNavigator of the view for read access. */
308 const UrlNavigator* urlNavigator() const { return m_urlNavigator; }
309
310 /**
311 * Triggers to request user information for the item given
312 * by the URL \a url. The signal requestItemInfo is emitted,
313 * which provides a way for widgets to get an indication to update
314 * the item information.
315 */
316 void emitRequestItemInfo(const KUrl& url);
317
318 /** Returns true, if the filter bar is visible. */
319 bool isFilterBarVisible() const;
320
321 /**
322 * Return the DolphinMainWindow this View belongs to. It is guranteed
323 * that we have one.
324 */
325 DolphinMainWindow* mainWindow() const ;
326
327 /** Reloads the current directory. */
328 void reload();
329
330 public slots:
331 /**
332 * Popups the filter bar above the status bar if \a show is true.
333 */
334 void showFilterBar(bool show);
335
336 /**
337 * Updates the number of items (= number of files + number of
338 * directories) in the statusbar. If files are selected, the number
339 * of selected files and the sum of the filesize is shown.
340 */
341 void updateStatusBar();
342
343 /**
344 * Requests the main window to set this view as active view, which
345 * means that all actions are applied to this view.
346 */
347 void requestActivation();
348
349 signals:
350 /** Is emitted if URL of the view has been changed to \a url. */
351 void urlChanged(const KUrl& url);
352
353 /**
354 * Is emitted if the view mode (IconsView, DetailsView,
355 * PreviewsView) has been changed.
356 */
357 void modeChanged();
358
359 /** Is emitted if the 'show preview' property has been changed. */
360 void showPreviewChanged();
361
362 /** Is emitted if the 'show hidden files' property has been changed. */
363 void showHiddenFilesChanged();
364
365 /** Is emitted if the sorting by name, size or date has been changed. */
366 void sortingChanged(DolphinView::Sorting sorting);
367
368 /** Is emitted if the sort order (ascending or descending) has been changed. */
369 void sortOrderChanged(Qt::SortOrder order);
370
371 /**
372 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
373 * It the URL is empty, no item information request is pending.
374 */
375 void requestItemInfo(const KUrl& url);
376
377 /** Is emitted if the contents has been moved to \a x, \a y. */
378 void contentsMoved(int x, int y);
379
380 /**
381 * Is emitted whenever the selection has been changed. The current selection can
382 * be retrieved by mainWindow()->activeView()->selectedItems() or by
383 * mainWindow()->activeView()->selectedUrls().
384 */
385 void selectionChanged();
386
387 /**
388 * Is emitted whenever the filter bar has been turned show or hidden.
389 */
390 void showFilterBarChanged(bool shown);
391
392 protected:
393 /** @see QWidget::mouseReleaseEvent */
394 virtual void mouseReleaseEvent(QMouseEvent* event);
395
396 private slots:
397 void loadDirectory(const KUrl& kurl);
398 void triggerItem(const QModelIndex& index);
399 void updateProgress(int percent);
400
401 /**
402 * Updates the number of items (= number of directories + number of files)
403 * and shows this information in the statusbar.
404 */
405 void updateItemCount();
406
407 /**
408 * Generates a preview image for each file item in \a items.
409 * The current preview settings (maximum size, 'Show Preview' menu)
410 * are respected.
411 */
412 void generatePreviews(const KFileItemList& items);
413
414 /**
415 * Replaces the icon of the item \a item by the preview pixmap
416 * \a pixmap.
417 */
418 void showPreview(const KFileItem* item, const QPixmap& pixmap);
419
420 /**
421 * Restores the x- and y-position of the contents if the
422 * current view is part of the history.
423 */
424 void restoreContentsPos();
425
426 /** Shows the information \a msg inside the statusbar. */
427 void showInfoMessage(const QString& msg);
428
429 /** Shows the error message \a msg inside the statusbar. */
430 void showErrorMessage(const QString& msg);
431
432 void emitSelectionChangedSignal();
433 void closeFilterBar();
434
435 /**
436 * Filters the currently shown items by \a nameFilter. All items
437 * which contain the given filter string will be shown.
438 */
439 void changeNameFilter(const QString& nameFilter);
440
441 /**
442 * Opens the context menu on position \a pos. The position
443 * is used to check whether the context menu is related to an
444 * item or to the viewport.
445 */
446 void openContextMenu(const QPoint& pos);
447
448 /**
449 * Drops the URLs \a urls at the position \a pos.
450 * The position is used to check whether the dropping
451 * is done above an item or above the viewport.
452 */
453 void dropUrls(const KUrl::List& urls,
454 const QPoint& pos);
455
456 /**
457 * Drops the URLs \a urls at the
458 * destination \a destination.
459 */
460 void dropUrls(const KUrl::List& urls,
461 const KUrl& destination);
462 /**
463 * Updates the view properties of the current URL to the
464 * sorting given by \a sorting.
465 */
466 void updateSorting(DolphinView::Sorting sorting);
467
468 /**
469 * Updates the view properties of the current URL to the
470 * sort order given by \a order.
471 */
472 void updateSortOrder(Qt::SortOrder order);
473
474 /**
475 * Emits the signal contentsMoved with the current coordinates
476 * of the viewport as parameters.
477 */
478 void emitContentsMoved();
479
480 /**
481 * Updates the activation state of the view by checking whether
482 * the currently active view is this view.
483 */
484 void updateActivationState();
485
486 private:
487 void startDirLister(const KUrl& url, bool reload = false);
488
489 /**
490 * Returns the default text of the status bar, if no item is
491 * selected.
492 */
493 QString defaultStatusBarText() const;
494
495 /**
496 * Returns the text for the status bar, if at least one item
497 * is selected.
498 */
499 QString selectionStatusBarText() const;
500
501 /**
502 * Creates a new view representing the given view mode (DolphinView::viewMode()).
503 * The current view will get deleted.
504 */
505 void createView();
506
507 /**
508 * Selects all items by using the selection flags \a flags. This is a helper
509 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
510 */
511 void selectAll(QItemSelectionModel::SelectionFlags flags);
512
513 /**
514 * Returns a pointer to the currently used item view, which is either
515 * a ListView or a TreeView.
516 */
517 QAbstractItemView* itemView() const;
518
519 /**
520 * Returns true if the index is valid and represents
521 * the column KDirModel::Name.
522 */
523 bool isValidNameIndex(const QModelIndex& index) const;
524
525 private:
526 bool m_showProgress;
527 Mode m_mode;
528
529 int m_iconSize;
530 int m_folderCount;
531 int m_fileCount;
532
533 DolphinMainWindow* m_mainWindow;
534 QVBoxLayout* m_topLayout;
535 UrlNavigator* m_urlNavigator;
536
537 DolphinController* m_controller;
538 DolphinIconsView* m_iconsView;
539 DolphinDetailsView* m_detailsView;
540
541 FilterBar* m_filterBar;
542 DolphinStatusBar* m_statusBar;
543
544 KDirModel* m_dirModel;
545 DolphinDirLister* m_dirLister;
546 DolphinSortFilterProxyModel* m_proxyModel;
547 };
548
549 #endif // _DOLPHINVIEW_H_