1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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. *
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. *
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 ***************************************************************************/
22 #ifndef _DOLPHINVIEW_H_
23 #define _DOLPHINVIEW_H_
25 #include <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
30 #include <kurlnavigator.h>
32 #include <QtGui/QKeyEvent>
33 #include <QtCore/QLinkedList>
34 #include <QtGui/QListView>
35 #include <QtGui/QBoxLayout>
36 #include <QtGui/QWidget>
38 class DolphinController
;
40 class KFileItemDelegate
;
44 class DolphinColumnView
;
45 class DolphinDetailsView
;
46 class DolphinDirLister
;
47 class DolphinIconsView
;
48 class DolphinMainWindow
;
49 class DolphinSortFilterProxyModel
;
50 class DolphinStatusBar
;
57 * @short Represents a view for the directory content
58 * including the navigation bar, filter bar and status bar.
60 * View modes for icons, details and columns are supported. Currently
61 * Dolphin allows to have up to two views inside the main window.
63 * @see DolphinIconsView
64 * @see DolphinDetailsView
65 * @see DolphinColumnView
67 * @see DolphinStatusBar
69 class DolphinView
: public QWidget
75 * Defines the view mode for a directory. The view mode
76 * can be defined when constructing a DolphinView. The
77 * view mode is automatically updated if the directory itself
78 * defines a view mode (see class ViewProperties for details).
83 * The directory items are shown as icons including an
88 * The icon, the name and at least the size of the directory
89 * items are shown in a table. It is possible to add columns
90 * for date, group and permissions.
95 * Each folder is shown in a separate column.
98 MaxModeEnum
= ColumnView
101 /** Defines the sort order for the items of a directory. */
111 MaxSortEnum
= SortByType
114 DolphinView(DolphinMainWindow
* mainwindow
,
117 Mode mode
= IconsView
,
118 bool showHiddenFiles
= false);
120 virtual ~DolphinView();
123 * Sets the current active URL.
124 * The signals KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
127 void setUrl(const KUrl
& url
);
129 /** Returns the current active URL. */
130 const KUrl
& url() const;
133 * Returns true if the view is active and hence all actions are
134 * applied to this view.
136 bool isActive() const;
139 * Changes the view mode for the current directory to \a mode.
140 * If the view properties should be remembered for each directory
141 * (GeneralSettings::globalViewProps() returns false), then the
142 * changed view mode will be be stored automatically.
144 void setMode(Mode mode
);
148 * Turns on the file preview for the all files of the current directory,
149 * if \a show is true.
150 * If the view properties should be remembered for each directory
151 * (GeneralSettings::globalViewProps() returns false), then the
152 * preview setting will be be stored automatically.
154 void setShowPreview(bool show
);
155 bool showPreview() const;
158 * Shows all hidden files of the current directory,
159 * if \a show is true.
160 * If the view properties should be remembered for each directory
161 * (GeneralSettings::globalViewProps() returns false), then the
162 * show hidden file setting will be be stored automatically.
164 void setShowHiddenFiles(bool show
);
165 bool showHiddenFiles() const;
168 * Summarizes all sorted items by their category \a categorized
170 * If the view properties should be remembered for each directory
171 * (GeneralSettings::globalViewProps() returns false), then the
172 * categorized sorting setting will be be stored automatically.
174 void setCategorizedSorting(bool categorized
);
175 bool categorizedSorting() const;
178 * Returns true, if the categorized sorting is supported by the current
179 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
180 * supports categorizations. To check whether the categorized
181 * sorting is set, use DolphinView::categorizedSorting().
183 bool supportsCategorizedSorting() const;
186 * Triggers the renaming of the currently selected items, where
187 * the user must input a new name for the items.
189 void renameSelectedItems();
193 * @see DolphinView::selectedItems()
198 * Inverts the current selection: selected items get unselected,
199 * unselected items get selected.
200 * @see DolphinView::selectedItems()
202 void invertSelection();
205 * Goes back one step in the URL history. The signals
206 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
212 * Goes forward one step in the Url history. The signals
213 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
219 * Goes up one step of the Url path. The signals
220 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
226 * Goes to the home URL. The signals KUrlNavigator::urlChanged()
227 * and KUrlNavigator::historyChanged() are submitted.
232 * Sets the URL of the navigation bar to an editable state
233 * if \a editable is true. If \a editable is false, each part of
234 * the location is presented by a button for a fast navigation.
236 void setUrlEditable(bool editable
);
238 /** Returns true, if at least one item is selected. */
239 bool hasSelection() const;
241 void clearSelection();
244 * Returns the selected items. The list is empty if no item has been
246 * @see DolphinView::selectedUrls()
248 KFileItemList
selectedItems() const;
251 * Returns a list of URLs for all selected items. An empty list
252 * is returned, if no item is selected.
253 * @see DolphinView::selectedItems()
255 KUrl::List
selectedUrls() const;
258 * Returns the file item for the given model index \a index.
260 KFileItem
* fileItem(const QModelIndex index
) const;
263 * Renames the filename of the source URL by the new file name.
264 * If the new file name already exists, a dialog is opened which
265 * asks the user to enter a new name.
267 void rename(const KUrl
& source
, const QString
& newName
);
269 DolphinStatusBar
* statusBar() const;
272 * Returns the x-position of the view content.
273 * The content of the view might be larger than the visible area
274 * and hence a scrolling must be done.
276 int contentsX() const;
279 * Returns the y-position of the view content.
280 * The content of the view might be larger than the visible area
281 * and hence a scrolling must be done.
283 int contentsY() const;
286 * Returns true, if the URL shown by the navigation bar is editable.
289 bool isUrlEditable() const;
291 /** Increases the size of the current set view mode. */
294 /** Decreases the size of the current set view mode. */
298 * Returns true, if zooming in is possible. If false is returned,
299 * the minimal zoom size is possible.
301 bool isZoomInPossible() const;
304 * Returns true, if zooming out is possible. If false is returned,
305 * the maximum zoom size is possible.
307 bool isZoomOutPossible() const;
309 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
310 void setSorting(Sorting sorting
);
312 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
313 Sorting
sorting() const;
315 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
316 void setSortOrder(Qt::SortOrder order
);
318 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
319 Qt::SortOrder
sortOrder() const;
321 /** Sets the additional information which should be shown for the items. */
322 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
324 /** Returns the additional information which should be shown for the items. */
325 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
327 /** Returns the KUrlNavigator of the view for read access. */
328 const KUrlNavigator
* urlNavigator() const
330 return m_urlNavigator
;
334 * Triggers to request user information for the item given
335 * by the URL \a url. The signal requestItemInfo is emitted,
336 * which provides a way for widgets to get an indication to update
337 * the item information.
339 void emitRequestItemInfo(const KUrl
& url
);
341 /** Returns true, if the filter bar is visible. */
342 bool isFilterBarVisible() const;
345 * Return the DolphinMainWindow this View belongs to. It is guranteed
348 DolphinMainWindow
* mainWindow() const ;
350 /** Reloads the current directory. */
354 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
355 * This method only needs to get invoked if the view settings for the Icons View,
356 * Details View or Columns View have been changed.
362 * Popups the filter bar above the status bar if \a show is true.
364 void showFilterBar(bool show
);
367 * Updates the number of items (= number of files + number of
368 * directories) in the statusbar. If files are selected, the number
369 * of selected files and the sum of the filesize is shown.
371 void updateStatusBar();
374 * Requests the main window to set this view as active view, which
375 * means that all actions are applied to this view.
377 void requestActivation();
380 * Request of a selection change. The view will do its best to accommodate
381 * the request, but it is not guaranteed that all items in \a selection
382 * will actually get selected. The view will e.g. not select items which
383 * are not in the currently displayed folder.
385 void changeSelection(const KFileItemList
& selection
);
388 /** Is emitted if URL of the view has been changed to \a url. */
389 void urlChanged(const KUrl
& url
);
392 * Is emitted if the view mode (IconsView, DetailsView,
393 * PreviewsView) has been changed.
397 /** Is emitted if the 'show preview' property has been changed. */
398 void showPreviewChanged();
400 /** Is emitted if the 'show hidden files' property has been changed. */
401 void showHiddenFilesChanged();
403 /** Is emitted if the 'categorized sorting' property has been changed. */
404 void categorizedSortingChanged();
406 /** Is emitted if the sorting by name, size or date has been changed. */
407 void sortingChanged(DolphinView::Sorting sorting
);
409 /** Is emitted if the sort order (ascending or descending) has been changed. */
410 void sortOrderChanged(Qt::SortOrder order
);
412 /** Is emitted if the addtional information for an item has been changed. */
413 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
416 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
417 * It the URL is empty, no item information request is pending.
419 void requestItemInfo(const KUrl
& url
);
421 /** Is emitted if the contents has been moved to \a x, \a y. */
422 void contentsMoved(int x
, int y
);
425 * Is emitted whenever the selection has been changed.
427 void selectionChanged(const KFileItemList
& selection
);
430 * Is emitted whenever the filter bar has been turned show or hidden.
432 void showFilterBarChanged(bool shown
);
435 /** @see QWidget::mouseReleaseEvent */
436 virtual void mouseReleaseEvent(QMouseEvent
* event
);
439 void changeDirectory(const KUrl
& url
);
440 void triggerItem(const QModelIndex
& index
);
441 void updateProgress(int percent
);
444 * Updates the number of items (= number of directories + number of files)
445 * and shows this information in the statusbar.
447 void updateItemCount();
450 * Generates a preview image for each file item in \a items.
451 * The current preview settings (maximum size, 'Show Preview' menu)
454 void generatePreviews(const KFileItemList
& items
);
457 * Replaces the icon of the item \a item by the preview pixmap
460 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
463 * Restores the x- and y-position of the contents if the
464 * current view is part of the history.
466 void restoreContentsPos();
468 /** Shows the information \a msg inside the statusbar. */
469 void showInfoMessage(const QString
& msg
);
471 /** Shows the error message \a msg inside the statusbar. */
472 void showErrorMessage(const QString
& msg
);
474 void emitSelectionChangedSignal();
475 void closeFilterBar();
478 * Filters the currently shown items by \a nameFilter. All items
479 * which contain the given filter string will be shown.
481 void changeNameFilter(const QString
& nameFilter
);
484 * Opens the context menu on position \a pos. The position
485 * is used to check whether the context menu is related to an
486 * item or to the viewport.
488 void openContextMenu(const QPoint
& pos
);
491 * Drops the URLs \a urls to the index \a index. \a source
492 * indicates the widget where the dragging has been started from.
494 void dropUrls(const KUrl::List
& urls
,
495 const QModelIndex
& index
,
499 * Drops the URLs \a urls at the
500 * destination \a destination.
502 void dropUrls(const KUrl::List
& urls
,
503 const KUrl
& destination
);
505 * Updates the view properties of the current URL to the
506 * sorting given by \a sorting.
508 void updateSorting(DolphinView::Sorting sorting
);
511 * Updates the view properties of the current URL to the
512 * sort order given by \a order.
514 void updateSortOrder(Qt::SortOrder order
);
517 * Emits the signal contentsMoved with the current coordinates
518 * of the viewport as parameters.
520 void emitContentsMoved();
523 * Updates the activation state of the view by checking whether
524 * the currently active view is this view.
526 void updateActivationState();
528 /** Applies an item effect to all cut items of the clipboard. */
529 void updateCutItems();
532 * Updates the status bar to show hover information for the
533 * item with the index \a index. If currently other items are selected,
534 * no hover information is shown.
535 * @see DolphinView::clearHoverInformation()
537 void showHoverInformation(const QModelIndex
& index
);
540 * Clears the hover information shown in the status bar.
541 * @see DolphinView::showHoverInformation().
543 void clearHoverInformation();
546 void startDirLister(const KUrl
& url
, bool reload
= false);
549 * Returns the default text of the status bar, if no item is
552 QString
defaultStatusBarText() const;
555 * Returns the text for the status bar, if at least one item
558 QString
selectionStatusBarText() const;
561 * Creates a new view representing the given view mode (DolphinView::mode()).
562 * The current view will get deleted.
567 * Selects all items by using the selection flags \a flags. This is a helper
568 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
570 void selectAll(QItemSelectionModel::SelectionFlags flags
);
573 * Returns a pointer to the currently used item view, which is either
574 * a ListView or a TreeView.
576 QAbstractItemView
* itemView() const;
579 * Returns true if the index is valid and represents
580 * the column KDirModel::Name.
582 bool isValidNameIndex(const QModelIndex
& index
) const;
585 * Returns true, if the item \a item has been cut into
588 bool isCutItem(const KFileItem
& item
) const;
590 /** Applies an item effect to all cut items. */
591 void applyCutItemEffect();
594 * Returns true, if the ColumnView is activated. As the column view
595 * requires some special handling for iterating through directories,
596 * this method has been introduced for convenience.
598 bool isColumnViewActive() const
600 return m_columnView
!= 0;
605 * Remembers the original pixmap for an item before
606 * the cut effect is applied.
615 bool m_blockContentsMovedSignal
;
616 bool m_initializeColumnView
;
623 DolphinMainWindow
* m_mainWindow
;
624 QVBoxLayout
* m_topLayout
;
625 KUrlNavigator
* m_urlNavigator
;
627 DolphinController
* m_controller
;
628 DolphinIconsView
* m_iconsView
;
629 DolphinDetailsView
* m_detailsView
;
630 DolphinColumnView
* m_columnView
;
631 KFileItemDelegate
* m_fileItemDelegate
;
633 FilterBar
* m_filterBar
;
634 DolphinStatusBar
* m_statusBar
;
636 KDirModel
* m_dirModel
;
637 DolphinDirLister
* m_dirLister
;
638 DolphinSortFilterProxyModel
* m_proxyModel
;
640 QList
<CutItem
> m_cutItemsCache
;
643 #endif // _DOLPHINVIEW_H_