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, where all actions are applied. The
124 * URL navigator is synchronized with this URL. The signals
125 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
127 * @see DolphinView::urlNavigator()
129 void setUrl(const KUrl
& url
);
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 * Returns true if the view is active and hence all actions are
150 * applied to this view.
152 bool isActive() const;
155 * Changes the view mode for the current directory to \a mode.
156 * If the view properties should be remembered for each directory
157 * (GeneralSettings::globalViewProps() returns false), then the
158 * changed view mode will be be stored automatically.
160 void setMode(Mode mode
);
164 * Turns on the file preview for the all files of the current directory,
165 * if \a show is true.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * preview setting will be be stored automatically.
170 void setShowPreview(bool show
);
171 bool showPreview() const;
174 * Shows all hidden files of the current directory,
175 * if \a show is true.
176 * If the view properties should be remembered for each directory
177 * (GeneralSettings::globalViewProps() returns false), then the
178 * show hidden file setting will be be stored automatically.
180 void setShowHiddenFiles(bool show
);
181 bool showHiddenFiles() const;
184 * Summarizes all sorted items by their category \a categorized
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * categorized sorting setting will be be stored automatically.
190 void setCategorizedSorting(bool categorized
);
191 bool categorizedSorting() const;
194 * Returns true, if the categorized sorting is supported by the current
195 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
196 * supports categorizations. To check whether the categorized
197 * sorting is set, use DolphinView::categorizedSorting().
199 bool supportsCategorizedSorting() const;
202 * Triggers the renaming of the currently selected items, where
203 * the user must input a new name for the items.
205 void renameSelectedItems();
209 * @see DolphinView::selectedItems()
214 * Inverts the current selection: selected items get unselected,
215 * unselected items get selected.
216 * @see DolphinView::selectedItems()
218 void invertSelection();
221 * Goes back one step in the URL history. The signals
222 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
228 * Goes forward one step in the Url history. The signals
229 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
235 * Goes up one step of the Url path. The signals
236 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
242 * Goes to the home URL. The signals KUrlNavigator::urlChanged()
243 * and KUrlNavigator::historyChanged() are submitted.
248 * Sets the URL of the navigation bar to an editable state
249 * if \a editable is true. If \a editable is false, each part of
250 * the location is presented by a button for a fast navigation.
252 void setUrlEditable(bool editable
);
254 /** Returns true, if at least one item is selected. */
255 bool hasSelection() const;
257 void clearSelection();
260 * Returns the selected items. The list is empty if no item has been
262 * @see DolphinView::selectedUrls()
264 KFileItemList
selectedItems() const;
267 * Returns a list of URLs for all selected items. An empty list
268 * is returned, if no item is selected.
269 * @see DolphinView::selectedItems()
271 KUrl::List
selectedUrls() const;
274 * Returns the file item for the given model index \a index.
276 KFileItem
* fileItem(const QModelIndex index
) const;
279 * Renames the filename of the source URL by the new file name.
280 * If the new file name already exists, a dialog is opened which
281 * asks the user to enter a new name.
283 void rename(const KUrl
& source
, const QString
& newName
);
285 DolphinStatusBar
* statusBar() const;
288 * Returns the x-position of the view content.
289 * The content of the view might be larger than the visible area
290 * and hence a scrolling must be done.
292 int contentsX() const;
295 * Returns the y-position of the view content.
296 * The content of the view might be larger than the visible area
297 * and hence a scrolling must be done.
299 int contentsY() const;
302 * Returns true, if the URL shown by the navigation bar is editable.
305 bool isUrlEditable() const;
307 /** Increases the size of the current set view mode. */
310 /** Decreases the size of the current set view mode. */
314 * Returns true, if zooming in is possible. If false is returned,
315 * the minimal zoom size is possible.
317 bool isZoomInPossible() const;
320 * Returns true, if zooming out is possible. If false is returned,
321 * the maximum zoom size is possible.
323 bool isZoomOutPossible() const;
325 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
326 void setSorting(Sorting sorting
);
328 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
329 Sorting
sorting() const;
331 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
332 void setSortOrder(Qt::SortOrder order
);
334 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
335 Qt::SortOrder
sortOrder() const;
337 /** Sets the additional information which should be shown for the items. */
338 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
340 /** Returns the additional information which should be shown for the items. */
341 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
343 /** Returns the KUrlNavigator of the view for read access. */
344 const KUrlNavigator
* urlNavigator() const
346 return m_urlNavigator
;
349 /** Returns true, if the filter bar is visible. */
350 bool isFilterBarVisible() const;
353 * Return the DolphinMainWindow this View belongs to. It is guranteed
356 DolphinMainWindow
* mainWindow() const ;
358 /** Reloads the current directory. */
362 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
363 * This method only needs to get invoked if the view settings for the Icons View,
364 * Details View or Columns View have been changed.
370 * Popups the filter bar above the status bar if \a show is true.
372 void showFilterBar(bool show
);
375 * Updates the number of items (= number of files + number of
376 * directories) in the statusbar. If files are selected, the number
377 * of selected files and the sum of the filesize is shown.
379 void updateStatusBar();
382 * Requests the main window to set this view as active view, which
383 * means that all actions are applied to this view.
385 void requestActivation();
388 * Request of a selection change. The view will do its best to accommodate
389 * the request, but it is not guaranteed that all items in \a selection
390 * will actually get selected. The view will e.g. not select items which
391 * are not in the currently displayed folder.
393 void changeSelection(const KFileItemList
& selection
);
396 /** Is emitted if URL of the view has been changed to \a url. */
397 void urlChanged(const KUrl
& url
);
400 * Is emitted if the view mode (IconsView, DetailsView,
401 * PreviewsView) has been changed.
405 /** Is emitted if the 'show preview' property has been changed. */
406 void showPreviewChanged();
408 /** Is emitted if the 'show hidden files' property has been changed. */
409 void showHiddenFilesChanged();
411 /** Is emitted if the 'categorized sorting' property has been changed. */
412 void categorizedSortingChanged();
414 /** Is emitted if the sorting by name, size or date has been changed. */
415 void sortingChanged(DolphinView::Sorting sorting
);
417 /** Is emitted if the sort order (ascending or descending) has been changed. */
418 void sortOrderChanged(Qt::SortOrder order
);
420 /** Is emitted if the addtional information for an item has been changed. */
421 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
424 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
425 * It the URL is empty, no item information request is pending.
427 void requestItemInfo(const KUrl
& url
);
429 /** Is emitted if the contents has been moved to \a x, \a y. */
430 void contentsMoved(int x
, int y
);
433 * Is emitted whenever the selection has been changed.
435 void selectionChanged(const KFileItemList
& selection
);
438 * Is emitted whenever the filter bar has been turned show or hidden.
440 void showFilterBarChanged(bool shown
);
443 /** @see QWidget::mouseReleaseEvent */
444 virtual void mouseReleaseEvent(QMouseEvent
* event
);
447 void changeDirectory(const KUrl
& url
);
448 void triggerItem(const QModelIndex
& index
);
449 void updateProgress(int percent
);
452 * Updates the number of items (= number of directories + number of files)
453 * and shows this information in the statusbar.
455 void updateItemCount();
458 * Generates a preview image for each file item in \a items.
459 * The current preview settings (maximum size, 'Show Preview' menu)
462 void generatePreviews(const KFileItemList
& items
);
465 * Replaces the icon of the item \a item by the preview pixmap
468 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
471 * Restores the x- and y-position of the contents if the
472 * current view is part of the history.
474 void restoreContentsPos();
476 /** Shows the information \a msg inside the statusbar. */
477 void showInfoMessage(const QString
& msg
);
479 /** Shows the error message \a msg inside the statusbar. */
480 void showErrorMessage(const QString
& msg
);
482 void emitSelectionChangedSignal();
483 void closeFilterBar();
486 * Filters the currently shown items by \a nameFilter. All items
487 * which contain the given filter string will be shown.
489 void changeNameFilter(const QString
& nameFilter
);
492 * Opens the context menu on position \a pos. The position
493 * is used to check whether the context menu is related to an
494 * item or to the viewport.
496 void openContextMenu(const QPoint
& pos
);
499 * Drops the URLs \a urls to the index \a index. \a source
500 * indicates the widget where the dragging has been started from.
502 void dropUrls(const KUrl::List
& urls
,
503 const QModelIndex
& index
,
507 * Drops the URLs \a urls at the
508 * destination \a destination.
510 void dropUrls(const KUrl::List
& urls
,
511 const KUrl
& destination
);
513 * Updates the view properties of the current URL to the
514 * sorting given by \a sorting.
516 void updateSorting(DolphinView::Sorting sorting
);
519 * Updates the view properties of the current URL to the
520 * sort order given by \a order.
522 void updateSortOrder(Qt::SortOrder order
);
525 * Emits the signal contentsMoved with the current coordinates
526 * of the viewport as parameters.
528 void emitContentsMoved();
531 * Updates the activation state of the view by checking whether
532 * the currently active view is this view.
534 void updateActivationState();
536 /** Applies an item effect to all cut items of the clipboard. */
537 void updateCutItems();
540 * Updates the status bar to show hover information for the
541 * item with the index \a index. If currently other items are selected,
542 * no hover information is shown.
543 * @see DolphinView::clearHoverInformation()
545 void showHoverInformation(const QModelIndex
& index
);
548 * Clears the hover information shown in the status bar.
549 * @see DolphinView::showHoverInformation().
551 void clearHoverInformation();
554 void startDirLister(const KUrl
& url
, bool reload
= false);
557 * Returns the default text of the status bar, if no item is
560 QString
defaultStatusBarText() const;
563 * Returns the text for the status bar, if at least one item
566 QString
selectionStatusBarText() const;
569 * Creates a new view representing the given view mode (DolphinView::mode()).
570 * The current view will get deleted.
575 * Selects all items by using the selection flags \a flags. This is a helper
576 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
578 void selectAll(QItemSelectionModel::SelectionFlags flags
);
581 * Returns a pointer to the currently used item view, which is either
582 * a ListView or a TreeView.
584 QAbstractItemView
* itemView() const;
587 * Returns true if the index is valid and represents
588 * the column KDirModel::Name.
590 bool isValidNameIndex(const QModelIndex
& index
) const;
593 * Returns true, if the item \a item has been cut into
596 bool isCutItem(const KFileItem
& item
) const;
598 /** Applies an item effect to all cut items. */
599 void applyCutItemEffect();
602 * Returns true, if the ColumnView is activated. As the column view
603 * requires some special handling for iterating through directories,
604 * this method has been introduced for convenience.
606 bool isColumnViewActive() const
608 return m_columnView
!= 0;
613 * Remembers the original pixmap for an item before
614 * the cut effect is applied.
623 bool m_blockContentsMovedSignal
;
624 bool m_initializeColumnView
;
631 DolphinMainWindow
* m_mainWindow
;
632 QVBoxLayout
* m_topLayout
;
633 KUrlNavigator
* m_urlNavigator
;
635 DolphinController
* m_controller
;
636 DolphinIconsView
* m_iconsView
;
637 DolphinDetailsView
* m_detailsView
;
638 DolphinColumnView
* m_columnView
;
639 KFileItemDelegate
* m_fileItemDelegate
;
641 FilterBar
* m_filterBar
;
642 DolphinStatusBar
* m_statusBar
;
644 KDirModel
* m_dirModel
;
645 DolphinDirLister
* m_dirLister
;
646 DolphinSortFilterProxyModel
* m_proxyModel
;
648 QList
<CutItem
> m_cutItemsCache
;
651 #endif // _DOLPHINVIEW_H_