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 ***************************************************************************/
25 #include <config-nepomuk.h>
27 #include "libdolphin_export.h"
29 #include <kparts/part.h>
30 #include <kfileitem.h>
31 #include <kfileitemdelegate.h>
36 #include <QLinkedList>
40 class DolphinController
;
42 class KFileItemDelegate
;
45 class DolphinColumnView
;
46 class DolphinDetailsView
;
47 class DolphinIconsView
;
48 class DolphinMainWindow
;
49 class DolphinSortFilterProxyModel
;
54 * @short Represents a view for the directory content.
56 * View modes for icons, details and columns are supported. It's
63 * @see DolphinIconsView
64 * @see DolphinDetailsView
65 * @see DolphinColumnView
67 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
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).
81 * The directory items are shown as icons including an
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.
93 * Each folder is shown in a separate column.
96 MaxModeEnum
= ColumnView
99 /** Defines the sort order for the items of a directory. */
111 MaxSortEnum
= SortByTags
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
125 DolphinView(QWidget
* parent
,
127 KDirLister
* dirLister
,
128 DolphinModel
* dolphinModel
,
129 DolphinSortFilterProxyModel
* proxyModel
);
131 virtual ~DolphinView();
134 * Returns the current active URL, where all actions are applied.
135 * The URL navigator is synchronized with this URL.
137 const KUrl
& url() const;
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/
148 KUrl
rootUrl() const;
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.
154 void setActive(bool active
);
155 bool isActive() const;
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.
163 void setMode(Mode mode
);
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.
173 void setShowPreview(bool show
);
174 bool showPreview() const;
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.
183 void setShowHiddenFiles(bool show
);
184 bool showHiddenFiles() const;
187 * Summarizes all sorted items by their category \a categorized
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.
193 void setCategorizedSorting(bool categorized
);
194 bool categorizedSorting() const;
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().
202 bool supportsCategorizedSorting() const;
206 * @see DolphinView::selectedItems()
211 * Inverts the current selection: selected items get unselected,
212 * unselected items get selected.
213 * @see DolphinView::selectedItems()
215 void invertSelection();
217 /** Returns true, if at least one item is selected. */
218 bool hasSelection() const;
220 void clearSelection();
223 * Returns the selected items. The list is empty if no item has been
225 * @see DolphinView::selectedUrls()
227 KFileItemList
selectedItems() const;
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()
234 KUrl::List
selectedUrls() const;
237 * Returns the file item for the given model index \a index.
239 KFileItem
fileItem(const QModelIndex
& index
) const;
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.
246 void setContentsPosition(int x
, int y
);
248 /** Returns the upper left position of the view content. */
249 QPoint
contentsPosition() const;
251 /** Increases the size of the current set view mode. */
254 /** Decreases the size of the current set view mode. */
258 * Returns true, if zooming in is possible. If false is returned,
259 * the minimal zoom size is possible.
261 bool isZoomInPossible() const;
264 * Returns true, if zooming out is possible. If false is returned,
265 * the maximum zoom size is possible.
267 bool isZoomOutPossible() const;
269 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
270 void setSorting(Sorting sorting
);
272 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
273 Sorting
sorting() const;
275 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
276 void setSortOrder(Qt::SortOrder order
);
278 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
279 Qt::SortOrder
sortOrder() const;
281 /** Sets the additional information which should be shown for the items. */
282 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
284 /** Returns the additional information which should be shown for the items. */
285 KFileItemDelegate::InformationList
additionalInfo() const;
287 /** Reloads the current directory. */
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.
298 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
299 * properties from \a url are used for adjusting the view mode and the other properties.
300 * If \a rootUrl is not empty, the view properties from the root URL are considered
301 * instead. Specifying a root URL is only required if a view having a different root URL
302 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
303 * is enough for changing the current URL.
305 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
308 * Filters the currently shown items by \a nameFilter. All items
309 * which contain the given filter string will be shown.
311 void setNameFilter(const QString
& nameFilter
);
314 * Calculates the number of currently shown files into
315 * \a fileCount and the number of folders into \a folderCount.
316 * It is recommend using this method instead of asking the
317 * directory lister or the model directly, as it takes
318 * filtering and hierarchical previews into account.
320 void calculateItemCount(int& fileCount
, int& folderCount
);
324 * Changes the directory to \a url. If the current directory is equal to
325 * \a url, nothing will be done (use DolphinView::reload() instead).
327 void setUrl(const KUrl
& url
);
330 * Request of a selection change. The view will do its best to accommodate
331 * the request, but it is not guaranteed that all items in \a selection
332 * will actually get selected. The view will e.g. not select items which
333 * are not in the currently displayed folder.
335 void changeSelection(const KFileItemList
& selection
);
340 * Is emitted if the view has been activated by e. g. a mouse click.
344 /** Is emitted if URL of the view has been changed to \a url. */
345 void urlChanged(const KUrl
& url
);
348 * Is emitted when clicking on an item
350 void itemTriggered(const KFileItem
& item
);
353 * Is emitted if the view mode (IconsView, DetailsView,
354 * PreviewsView) has been changed.
358 /** Is emitted if the 'show preview' property has been changed. */
359 void showPreviewChanged();
361 /** Is emitted if the 'show hidden files' property has been changed. */
362 void showHiddenFilesChanged();
364 /** Is emitted if the 'categorized sorting' property has been changed. */
365 void categorizedSortingChanged();
367 /** Is emitted if the sorting by name, size or date has been changed. */
368 void sortingChanged(DolphinView::Sorting sorting
);
370 /** Is emitted if the sort order (ascending or descending) has been changed. */
371 void sortOrderChanged(Qt::SortOrder order
);
373 /** Is emitted if the additional information for an item has been changed. */
374 void additionalInfoChanged(KFileItemDelegate::InformationList info
);
377 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
378 * If item is null, no item information request is pending.
380 void requestItemInfo(const KFileItem
& item
);
382 /** Is emitted if the contents has been moved to \a x, \a y. */
383 void contentsMoved(int x
, int y
);
386 * Is emitted whenever the selection has been changed.
388 void selectionChanged(const KFileItemList
& selection
);
391 * Is emitted if a context menu is requested for the item \a item,
392 * which is part of \a url. If the item is 0, the context menu
393 * for the URL should be shown.
395 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
398 * Is emitted if the URLs \a are dropped to the destination URL
399 * \a destination. No operation is done within the DolphinView, the
400 * receiver of the signal has to take care about the corresponding
403 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
406 * Is emitted if an information message with the content \a msg
409 void infoMessage(const QString
& msg
);
412 * Is emitted if an error message with the content \a msg
415 void errorMessage(const QString
& msg
);
418 * Is emitted after DolphinView::setUrl() has been invoked and
419 * the path \a url is currently loaded. If this signal is emitted,
420 * it is assured that the view contains already the correct root
421 * URL and property settings.
423 void startedPathLoading(const KUrl
& url
);
426 /** @see QWidget::mouseReleaseEvent */
427 virtual void mouseReleaseEvent(QMouseEvent
* event
);
431 * Marks the view as active (DolphinView:isActive() will return true)
432 * and emits the 'activated' signal if it is not already active.
437 * If the item \a item is a directory, then this
438 * directory will be loaded. If the item is a file, the corresponding
439 * application will get started.
441 void triggerItem(const KFileItem
& index
);
444 * Generates a preview image for each file item in \a items.
445 * The current preview settings (maximum size, 'Show Preview' menu)
448 void generatePreviews(const KFileItemList
& items
);
451 * Replaces the icon of the item \a item by the preview pixmap
454 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
456 void emitSelectionChangedSignal();
459 * Opens the context menu on position \a pos. The position
460 * is used to check whether the context menu is related to an
461 * item or to the viewport.
463 void openContextMenu(const QPoint
& pos
);
466 * Drops the URLs \a urls to the destination path \a destPath. If
467 * the URLs are dropped above an item inside the destination path,
468 * the item is indicated by \a destIndex. \a source
469 * indicates the widget where the dragging has been started from.
471 void dropUrls(const KUrl::List
& urls
,
472 const KUrl
& destPath
,
473 const QModelIndex
& destIndex
,
477 * Drops the URLs \a urls at the
478 * destination \a destination.
480 void dropUrls(const KUrl::List
& urls
,
481 const KUrl
& destination
);
483 * Updates the view properties of the current URL to the
484 * sorting given by \a sorting.
486 void updateSorting(DolphinView::Sorting sorting
);
489 * Updates the view properties of the current URL to the
490 * sort order given by \a order.
492 void updateSortOrder(Qt::SortOrder order
);
495 * Emits the signal contentsMoved with the current coordinates
496 * of the viewport as parameters.
498 void emitContentsMoved();
500 /** Applies an item effect to all cut items of the clipboard. */
501 void updateCutItems();
504 * Updates the status bar to show hover information for the
505 * item \a item. If currently other items are selected,
506 * no hover information is shown.
507 * @see DolphinView::clearHoverInformation()
509 void showHoverInformation(const KFileItem
& item
);
512 * Clears the hover information shown in the status bar.
513 * @see DolphinView::showHoverInformation().
515 void clearHoverInformation();
518 void loadDirectory(const KUrl
& url
, bool reload
= false);
521 * Returns the URL where the view properties should be stored. Usually
522 * DolphinView::url() is returned, but in the case of a Column View the
523 * view properties are always stored in the directory represented by the
524 * first column. It is recommendend whenever using the ViewProperties class
525 * to use DolphinView::viewPropertiesUrl() as URL.
527 KUrl
viewPropertiesUrl() const;
530 * Applies the view properties which are defined by the current URL
531 * m_url to the DolphinView properties.
533 void applyViewProperties(const KUrl
& url
);
536 * Creates a new view representing the given view mode (DolphinView::mode()).
537 * The current view will get deleted.
542 * Returns a pointer to the currently used item view, which is either
543 * a ListView or a TreeView.
545 QAbstractItemView
* itemView() const;
548 * Returns true if the index is valid and represents
549 * the column DolphinModel::Name.
551 bool isValidNameIndex(const QModelIndex
& index
) const;
554 * Returns true, if the item \a item has been cut into
557 bool isCutItem(const KFileItem
& item
) const;
559 /** Applies an item effect to all cut items. */
560 void applyCutItemEffect();
563 * Returns true, if the ColumnView is activated. As the column view
564 * requires some special handling for iterating through directories,
565 * this method has been introduced for convenience.
567 bool isColumnViewActive() const
569 return m_columnView
!= 0;
574 * Remembers the original pixmap for an item before
575 * the cut effect is applied.
584 bool m_loadingDirectory
;
585 bool m_storedCategorizedSorting
;
588 DolphinMainWindow
* m_mainWindow
;
589 QVBoxLayout
* m_topLayout
;
591 DolphinController
* m_controller
;
592 DolphinIconsView
* m_iconsView
;
593 DolphinDetailsView
* m_detailsView
;
594 DolphinColumnView
* m_columnView
;
595 KFileItemDelegate
* m_fileItemDelegate
;
597 DolphinModel
* m_dolphinModel
;
598 KDirLister
* m_dirLister
;
599 DolphinSortFilterProxyModel
* m_proxyModel
;
601 QList
<CutItem
> m_cutItemsCache
;
606 #endif // DOLPHINVIEW_H