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 <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
32 #include <QLinkedList>
36 class DolphinController
;
38 class KFileItemDelegate
;
41 class DolphinColumnView
;
42 class DolphinDetailsView
;
43 class DolphinIconsView
;
44 class DolphinMainWindow
;
45 class DolphinSortFilterProxyModel
;
50 * @short Represents a view for the directory content.
52 * View modes for icons, details and columns are supported. It's
59 * @see DolphinIconsView
60 * @see DolphinDetailsView
61 * @see DolphinColumnView
63 class DolphinView
: public QWidget
69 * Defines the view mode for a directory. The view mode
70 * can be defined when constructing a DolphinView. The
71 * view mode is automatically updated if the directory itself
72 * defines a view mode (see class ViewProperties for details).
77 * The directory items are shown as icons including an
82 * The icon, the name and at least the size of the directory
83 * items are shown in a table. It is possible to add columns
84 * for date, group and permissions.
89 * Each folder is shown in a separate column.
92 MaxModeEnum
= ColumnView
95 /** Defines the sort order for the items of a directory. */
105 MaxSortEnum
= SortByType
109 * @param parent Parent widget of the view.
110 * @param url Specifies the content which should be shown.
111 * @param dirLister Used directory lister. The lister is not owned
112 * by the view and won't get deleted.
113 * @param dirModel Used directory model. The model is not owned
114 * by the view and won't get deleted.
115 * @param proxyModel Used proxy model which specifies the sorting. The
116 * model is not owned by the view and won't get
118 * @param mode Used display mode (IconsView, DetailsView or ColumnsView).
119 * @param showHiddenFiles If true, hidden files will be shown in the view.
121 DolphinView(QWidget
* parent
,
123 KDirLister
* dirLister
,
125 DolphinSortFilterProxyModel
* proxyModel
,
126 Mode mode
= IconsView
,
127 bool showHiddenFiles
= false);
129 virtual ~DolphinView();
132 * Returns the current active URL, where all actions are applied.
133 * The URL navigator is synchronized with this URL.
135 const KUrl
& url() const;
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/
146 KUrl
rootUrl() const;
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.
152 void setActive(bool active
);
153 bool isActive() const;
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.
161 void setMode(Mode mode
);
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.
171 void setShowPreview(bool show
);
172 bool showPreview() const;
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.
181 void setShowHiddenFiles(bool show
);
182 bool showHiddenFiles() const;
185 * Summarizes all sorted items by their category \a categorized
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.
191 void setCategorizedSorting(bool categorized
);
192 bool categorizedSorting() const;
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().
200 bool supportsCategorizedSorting() const;
204 * @see DolphinView::selectedItems()
209 * Inverts the current selection: selected items get unselected,
210 * unselected items get selected.
211 * @see DolphinView::selectedItems()
213 void invertSelection();
215 /** Returns true, if at least one item is selected. */
216 bool hasSelection() const;
218 void clearSelection();
221 * Returns the selected items. The list is empty if no item has been
223 * @see DolphinView::selectedUrls()
225 KFileItemList
selectedItems() const;
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()
232 KUrl::List
selectedUrls() const;
235 * Returns the file item for the given model index \a index.
237 KFileItem
* fileItem(const QModelIndex index
) const;
240 * Returns the x-position of the view content.
241 * The content of the view might be larger than the visible area
242 * and hence a scrolling must be done.
244 int contentsX() const;
247 * Returns the y-position of the view content.
248 * The content of the view might be larger than the visible area
249 * and hence a scrolling must be done.
251 int contentsY() const;
253 /** Increases the size of the current set view mode. */
256 /** Decreases the size of the current set view mode. */
260 * Returns true, if zooming in is possible. If false is returned,
261 * the minimal zoom size is possible.
263 bool isZoomInPossible() const;
266 * Returns true, if zooming out is possible. If false is returned,
267 * the maximum zoom size is possible.
269 bool isZoomOutPossible() const;
271 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
272 void setSorting(Sorting sorting
);
274 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
275 Sorting
sorting() const;
277 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
278 void setSortOrder(Qt::SortOrder order
);
280 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
281 Qt::SortOrder
sortOrder() const;
283 /** Sets the additional information which should be shown for the items. */
284 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
286 /** Returns the additional information which should be shown for the items. */
287 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
289 /** Reloads the current directory. */
293 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
294 * This method only needs to get invoked if the view settings for the Icons View,
295 * Details View or Columns View have been changed.
301 * Changes the directory to \a url. If the current directory is equal to
302 * \a url, nothing will be done (use DolphinView::reload() instead).
304 void setUrl(const KUrl
& url
);
307 * Request of a selection change. The view will do its best to accommodate
308 * the request, but it is not guaranteed that all items in \a selection
309 * will actually get selected. The view will e.g. not select items which
310 * are not in the currently displayed folder.
312 void changeSelection(const KFileItemList
& selection
);
316 * Is emitted if the view has been activated by e. g. a mouse click.
320 /** Is emitted if URL of the view has been changed to \a url. */
321 void urlChanged(const KUrl
& url
);
324 * Is emitted if the view mode (IconsView, DetailsView,
325 * PreviewsView) has been changed.
329 /** Is emitted if the 'show preview' property has been changed. */
330 void showPreviewChanged();
332 /** Is emitted if the 'show hidden files' property has been changed. */
333 void showHiddenFilesChanged();
335 /** Is emitted if the 'categorized sorting' property has been changed. */
336 void categorizedSortingChanged();
338 /** Is emitted if the sorting by name, size or date has been changed. */
339 void sortingChanged(DolphinView::Sorting sorting
);
341 /** Is emitted if the sort order (ascending or descending) has been changed. */
342 void sortOrderChanged(Qt::SortOrder order
);
344 /** Is emitted if the additional information for an item has been changed. */
345 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
348 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
349 * It the URL is empty, no item information request is pending.
351 void requestItemInfo(const KUrl
& url
);
353 /** Is emitted if the contents has been moved to \a x, \a y. */
354 void contentsMoved(int x
, int y
);
357 * Is emitted whenever the selection has been changed.
359 void selectionChanged(const KFileItemList
& selection
);
362 * Is emitted if a context menu is requested for the item \a item,
363 * which is part of \a url. If the item is 0, the context menu
364 * for the URL should be shown.
366 void requestContextMenu(KFileItem
* item
, const KUrl
& url
);
369 * Is emitted if the URLs \a are dropped to the destination URL
370 * \a destination. No operation is done within the DolphinView, the
371 * receiver of the signal has to take care about the corresponding
374 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
377 /** @see QWidget::mouseReleaseEvent */
378 virtual void mouseReleaseEvent(QMouseEvent
* event
);
382 * Marks the view as active (DolphinView:isActive() will return true)
383 * and emits the 'activated' signal if it is not already active.
388 * If the item specified by \a index is a directory, then this
389 * directory will be loaded. If the item is a file, the corresponding
390 * application will get started.
392 void triggerItem(const QModelIndex
& index
);
395 * Generates a preview image for each file item in \a items.
396 * The current preview settings (maximum size, 'Show Preview' menu)
399 void generatePreviews(const KFileItemList
& items
);
402 * Replaces the icon of the item \a item by the preview pixmap
405 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
408 * Restores the x- and y-position of the contents if the
409 * current view is part of the history.
411 void restoreContentsPos();
413 void emitSelectionChangedSignal();
416 * Opens the context menu on position \a pos. The position
417 * is used to check whether the context menu is related to an
418 * item or to the viewport.
420 void openContextMenu(const QPoint
& pos
);
423 * Drops the URLs \a urls to the index \a index. \a source
424 * indicates the widget where the dragging has been started from.
426 void dropUrls(const KUrl::List
& urls
,
427 const QModelIndex
& index
,
431 * Drops the URLs \a urls at the
432 * destination \a destination.
434 void dropUrls(const KUrl::List
& urls
,
435 const KUrl
& destination
);
437 * Updates the view properties of the current URL to the
438 * sorting given by \a sorting.
440 void updateSorting(DolphinView::Sorting sorting
);
443 * Updates the view properties of the current URL to the
444 * sort order given by \a order.
446 void updateSortOrder(Qt::SortOrder order
);
449 * Emits the signal contentsMoved with the current coordinates
450 * of the viewport as parameters.
452 void emitContentsMoved();
454 /** Applies an item effect to all cut items of the clipboard. */
455 void updateCutItems();
458 * Updates the status bar to show hover information for the
459 * item with the index \a index. If currently other items are selected,
460 * no hover information is shown.
461 * @see DolphinView::clearHoverInformation()
463 void showHoverInformation(const QModelIndex
& index
);
466 * Clears the hover information shown in the status bar.
467 * @see DolphinView::showHoverInformation().
469 void clearHoverInformation();
472 void startDirLister(const KUrl
& url
, bool reload
= false);
475 * Creates a new view representing the given view mode (DolphinView::mode()).
476 * The current view will get deleted.
481 * Selects all items by using the selection flags \a flags. This is a helper
482 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
484 void selectAll(QItemSelectionModel::SelectionFlags flags
);
487 * Returns a pointer to the currently used item view, which is either
488 * a ListView or a TreeView.
490 QAbstractItemView
* itemView() const;
493 * Returns true if the index is valid and represents
494 * the column KDirModel::Name.
496 bool isValidNameIndex(const QModelIndex
& index
) const;
499 * Returns true, if the item \a item has been cut into
502 bool isCutItem(const KFileItem
& item
) const;
504 /** Applies an item effect to all cut items. */
505 void applyCutItemEffect();
508 * Returns true, if the ColumnView is activated. As the column view
509 * requires some special handling for iterating through directories,
510 * this method has been introduced for convenience.
512 bool isColumnViewActive() const
514 return m_columnView
!= 0;
519 * Remembers the original pixmap for an item before
520 * the cut effect is applied.
529 bool m_blockContentsMovedSignal
;
530 bool m_initializeColumnView
;
533 DolphinMainWindow
* m_mainWindow
;
534 QVBoxLayout
* m_topLayout
;
536 DolphinController
* m_controller
;
537 DolphinIconsView
* m_iconsView
;
538 DolphinDetailsView
* m_detailsView
;
539 DolphinColumnView
* m_columnView
;
540 KFileItemDelegate
* m_fileItemDelegate
;
542 KDirModel
* m_dirModel
;
543 KDirLister
* m_dirLister
;
544 DolphinSortFilterProxyModel
* m_proxyModel
;
546 QList
<CutItem
> m_cutItemsCache
;
549 #endif // DOLPHINVIEW_H