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
119 DolphinView(QWidget
* parent
,
121 KDirLister
* dirLister
,
123 DolphinSortFilterProxyModel
* proxyModel
);
125 virtual ~DolphinView();
128 * Returns the current active URL, where all actions are applied.
129 * The URL navigator is synchronized with this URL.
131 const KUrl
& url() const;
134 * Returns the root URL of the view, which is defined as the first
135 * visible path of DolphinView::url(). Usually the root URL is
136 * equal to DolphinView::url(), but in the case of the column view
137 * when 2 columns are shown, the root URL might be:
138 * /home/peter/Documents
139 * and DolphinView::url() might return
140 * /home/peter/Documents/Music/
142 KUrl
rootUrl() const;
145 * If \a active is true, the view will marked as active. The active
146 * view is defined as view where all actions are applied to.
148 void setActive(bool active
);
149 bool isActive() const;
152 * Changes the view mode for the current directory to \a mode.
153 * If the view properties should be remembered for each directory
154 * (GeneralSettings::globalViewProps() returns false), then the
155 * changed view mode will be be stored automatically.
157 void setMode(Mode mode
);
161 * Turns on the file preview for the all files of the current directory,
162 * if \a show is true.
163 * If the view properties should be remembered for each directory
164 * (GeneralSettings::globalViewProps() returns false), then the
165 * preview setting will be be stored automatically.
167 void setShowPreview(bool show
);
168 bool showPreview() const;
171 * Shows all hidden files of the current directory,
172 * if \a show is true.
173 * If the view properties should be remembered for each directory
174 * (GeneralSettings::globalViewProps() returns false), then the
175 * show hidden file setting will be be stored automatically.
177 void setShowHiddenFiles(bool show
);
178 bool showHiddenFiles() const;
181 * Summarizes all sorted items by their category \a categorized
183 * If the view properties should be remembered for each directory
184 * (GeneralSettings::globalViewProps() returns false), then the
185 * categorized sorting setting will be be stored automatically.
187 void setCategorizedSorting(bool categorized
);
188 bool categorizedSorting() const;
191 * Returns true, if the categorized sorting is supported by the current
192 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
193 * supports categorizations. To check whether the categorized
194 * sorting is set, use DolphinView::categorizedSorting().
196 bool supportsCategorizedSorting() const;
200 * @see DolphinView::selectedItems()
205 * Inverts the current selection: selected items get unselected,
206 * unselected items get selected.
207 * @see DolphinView::selectedItems()
209 void invertSelection();
211 /** Returns true, if at least one item is selected. */
212 bool hasSelection() const;
214 void clearSelection();
217 * Returns the selected items. The list is empty if no item has been
219 * @see DolphinView::selectedUrls()
221 KFileItemList
selectedItems() const;
224 * Returns a list of URLs for all selected items. An empty list
225 * is returned, if no item is selected.
226 * @see DolphinView::selectedItems()
228 KUrl::List
selectedUrls() const;
231 * Returns the file item for the given model index \a index.
233 KFileItem
* fileItem(const QModelIndex index
) const;
236 * Sets the upper left position of the view content
237 * to (x,y). The content of the view might be larger than the visible area
238 * and hence a scrolling must be done.
240 void setContentsPosition(int x
, int y
);
242 /** Returns the upper left position of the view content. */
243 QPoint
contentsPosition() const;
245 /** Increases the size of the current set view mode. */
248 /** Decreases the size of the current set view mode. */
252 * Returns true, if zooming in is possible. If false is returned,
253 * the minimal zoom size is possible.
255 bool isZoomInPossible() const;
258 * Returns true, if zooming out is possible. If false is returned,
259 * the maximum zoom size is possible.
261 bool isZoomOutPossible() const;
263 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
264 void setSorting(Sorting sorting
);
266 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
267 Sorting
sorting() const;
269 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
270 void setSortOrder(Qt::SortOrder order
);
272 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
273 Qt::SortOrder
sortOrder() const;
275 /** Sets the additional information which should be shown for the items. */
276 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
278 /** Returns the additional information which should be shown for the items. */
279 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
281 /** Reloads the current directory. */
285 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
286 * This method only needs to get invoked if the view settings for the Icons View,
287 * Details View or Columns View have been changed.
293 * Changes the directory to \a url. If the current directory is equal to
294 * \a url, nothing will be done (use DolphinView::reload() instead).
296 void setUrl(const KUrl
& url
);
299 * Request of a selection change. The view will do its best to accommodate
300 * the request, but it is not guaranteed that all items in \a selection
301 * will actually get selected. The view will e.g. not select items which
302 * are not in the currently displayed folder.
304 void changeSelection(const KFileItemList
& selection
);
308 * Is emitted if the view has been activated by e. g. a mouse click.
312 /** Is emitted if URL of the view has been changed to \a url. */
313 void urlChanged(const KUrl
& url
);
316 * Is emitted if the view mode (IconsView, DetailsView,
317 * PreviewsView) has been changed.
321 /** Is emitted if the 'show preview' property has been changed. */
322 void showPreviewChanged();
324 /** Is emitted if the 'show hidden files' property has been changed. */
325 void showHiddenFilesChanged();
327 /** Is emitted if the 'categorized sorting' property has been changed. */
328 void categorizedSortingChanged();
330 /** Is emitted if the sorting by name, size or date has been changed. */
331 void sortingChanged(DolphinView::Sorting sorting
);
333 /** Is emitted if the sort order (ascending or descending) has been changed. */
334 void sortOrderChanged(Qt::SortOrder order
);
336 /** Is emitted if the additional information for an item has been changed. */
337 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
340 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
341 * It the URL is empty, no item information request is pending.
343 void requestItemInfo(const KUrl
& url
);
345 /** Is emitted if the contents has been moved to \a x, \a y. */
346 void contentsMoved(int x
, int y
);
349 * Is emitted whenever the selection has been changed.
351 void selectionChanged(const KFileItemList
& selection
);
354 * Is emitted if a context menu is requested for the item \a item,
355 * which is part of \a url. If the item is 0, the context menu
356 * for the URL should be shown.
358 void requestContextMenu(KFileItem
* item
, const KUrl
& url
);
361 * Is emitted if the URLs \a are dropped to the destination URL
362 * \a destination. No operation is done within the DolphinView, the
363 * receiver of the signal has to take care about the corresponding
366 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
369 * Is emitted if an information message with the content \a msg
372 void infoMessage(const QString
& msg
);
375 * Is emitted if an error message with the content \a msg
378 void errorMessage(const QString
& msg
);
381 /** @see QWidget::mouseReleaseEvent */
382 virtual void mouseReleaseEvent(QMouseEvent
* event
);
386 * Marks the view as active (DolphinView:isActive() will return true)
387 * and emits the 'activated' signal if it is not already active.
392 * If the item specified by \a index is a directory, then this
393 * directory will be loaded. If the item is a file, the corresponding
394 * application will get started.
396 void triggerItem(const QModelIndex
& index
);
399 * Generates a preview image for each file item in \a items.
400 * The current preview settings (maximum size, 'Show Preview' menu)
403 void generatePreviews(const KFileItemList
& items
);
406 * Replaces the icon of the item \a item by the preview pixmap
409 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
411 void emitSelectionChangedSignal();
414 * Opens the context menu on position \a pos. The position
415 * is used to check whether the context menu is related to an
416 * item or to the viewport. If the context menu should be
417 * opened on the viewport, the URL \a url should be taken
418 * as viewport URL (the viewport URL can be different from
419 * DolphinView::url() for e. g. the column view).
421 void openContextMenu(const QPoint
& pos
, const KUrl
& url
);
424 * Drops the URLs \a urls to the index \a index. \a source
425 * indicates the widget where the dragging has been started from.
427 void dropUrls(const KUrl::List
& urls
,
428 const QModelIndex
& index
,
432 * Drops the URLs \a urls at the
433 * destination \a destination.
435 void dropUrls(const KUrl::List
& urls
,
436 const KUrl
& destination
);
438 * Updates the view properties of the current URL to the
439 * sorting given by \a sorting.
441 void updateSorting(DolphinView::Sorting sorting
);
444 * Updates the view properties of the current URL to the
445 * sort order given by \a order.
447 void updateSortOrder(Qt::SortOrder order
);
450 * Emits the signal contentsMoved with the current coordinates
451 * of the viewport as parameters.
453 void emitContentsMoved();
455 /** Applies an item effect to all cut items of the clipboard. */
456 void updateCutItems();
459 * Updates the status bar to show hover information for the
460 * item with the index \a index. If currently other items are selected,
461 * no hover information is shown.
462 * @see DolphinView::clearHoverInformation()
464 void showHoverInformation(const QModelIndex
& index
);
467 * Clears the hover information shown in the status bar.
468 * @see DolphinView::showHoverInformation().
470 void clearHoverInformation();
473 void startDirLister(const KUrl
& url
, bool reload
= false);
476 * Applies the view properties which are defined by the current URL
477 * m_url to the DolphinView properties.
479 void applyViewProperties(const KUrl
& url
);
482 * Creates a new view representing the given view mode (DolphinView::mode()).
483 * The current view will get deleted.
488 * Selects all items by using the selection flags \a flags. This is a helper
489 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
491 void selectAll(QItemSelectionModel::SelectionFlags flags
);
494 * Returns a pointer to the currently used item view, which is either
495 * a ListView or a TreeView.
497 QAbstractItemView
* itemView() const;
500 * Returns true if the index is valid and represents
501 * the column KDirModel::Name.
503 bool isValidNameIndex(const QModelIndex
& index
) const;
506 * Returns true, if the item \a item has been cut into
509 bool isCutItem(const KFileItem
& item
) const;
511 /** Applies an item effect to all cut items. */
512 void applyCutItemEffect();
515 * Returns true, if the ColumnView is activated. As the column view
516 * requires some special handling for iterating through directories,
517 * this method has been introduced for convenience.
519 bool isColumnViewActive() const
521 return m_columnView
!= 0;
526 * Remembers the original pixmap for an item before
527 * the cut effect is applied.
536 bool m_loadingDirectory
;
537 bool m_initializeColumnView
;
540 DolphinMainWindow
* m_mainWindow
;
541 QVBoxLayout
* m_topLayout
;
543 DolphinController
* m_controller
;
544 DolphinIconsView
* m_iconsView
;
545 DolphinDetailsView
* m_detailsView
;
546 DolphinColumnView
* m_columnView
;
547 KFileItemDelegate
* m_fileItemDelegate
;
549 KDirModel
* m_dirModel
;
550 KDirLister
* m_dirLister
;
551 DolphinSortFilterProxyModel
* m_proxyModel
;
553 QList
<CutItem
> m_cutItemsCache
;
556 #endif // DOLPHINVIEW_H