35
34
#include <QBoxLayout>
36
35
#include <QKeyEvent>
37
36
#include <QLinkedList>
42
40
typedef KIO::FileUndoManager::CommandType CommandType;
44
class DolphinColumnViewContainer;
45
class DolphinDetailsView;
46
class DolphinDetailsViewExpander;
47
class DolphinIconsView;
49
class DolphinSortFilterProxyModel;
50
class DolphinViewController;
42
class DolphinDirLister;
43
class DolphinItemListContainer;
52
45
class KActionCollection;
55
class ViewModeController;
50
class VersionControlObserver;
56
51
class ViewProperties;
52
class QGraphicsSceneDragDropEvent;
60
56
* @short Represents a view for the directory content.
62
* View modes for icons, details and columns are supported. It's
58
* View modes for icons, compact and details are supported. It's
63
59
* possible to adjust:
66
62
* - show hidden files
69
* @see DolphinIconsView
70
* @see DolphinDetailsView
71
* @see DolphinColumnView
73
66
class LIBDOLPHINPRIVATE_EXPORT DolphinView : public QWidget
79
* Defines the view mode for a directory. The view mode
80
* can be defined when constructing a DolphinView. The
72
* Defines the view mode for a directory. The
81
73
* view mode is automatically updated if the directory itself
82
74
* defines a view mode (see class ViewProperties for details).
87
* The directory items are shown as icons including an
79
* The items are shown as icons with a name-label below.
93
* The icon, the name and at least the size of the directory
94
* items are shown in a table. It is possible to add columns
95
* for date, group and permissions.
84
* The icon, the name and the size of the items are
85
* shown per default as a table.
100
* Each folder is shown in a separate column.
90
* The items are shown as icons with the name-label aligned
103
MaxModeEnum = ColumnView
106
96
/** Defines the sort order for the items of a directory. */
159
151
void setMode(Mode mode);
160
152
Mode mode() const;
162
/** See setShowPreview */
163
bool showPreview() const;
165
/** See setShowHiddenFiles */
166
bool showHiddenFiles() const;
168
/** See setCategorizedSorting */
169
bool categorizedSorting() const;
172
* Returns true, if the categorized sorting is supported by the current
173
* used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
174
* supports categorizations. To check whether the categorized
175
* sorting is set, use DolphinView::categorizedSorting().
177
bool supportsCategorizedSorting() const;
180
* Returns the root item which represents the current URL. Note that the returned
181
* item can be null (KFileItem::isNull() will return true) in case that the directory
182
* has not been loaded.
184
KFileItem rootItem() const;
155
* Turns on the file preview for the all files of the current directory,
156
* if \a show is true.
157
* If the view properties should be remembered for each directory
158
* (GeneralSettings::globalViewProps() returns false), then the
159
* preview setting will be stored automatically.
161
void setPreviewsShown(bool show);
162
bool previewsShown() const;
165
* Shows all hidden 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
* show hidden file setting will be stored automatically.
171
void setHiddenFilesShown(bool show);
172
bool hiddenFilesShown() const;
175
* Turns on sorting by groups if \a enable is true.
177
void setGroupedSorting(bool grouped);
178
bool groupedSorting() const;
187
181
* Returns the items of the view.
235
235
bool isZoomOutPossible() const;
237
/** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
237
/** Sets the sorting criterion (e.g., SortByName, SortBySize,...) of the items inside a directory (see DolphinView::Sorting). */
238
238
void setSorting(Sorting sorting);
240
/** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
240
/** Returns the sorting criterion (e.g., SortByName, SortBySize,...) of the items inside a directory (see DolphinView::Sorting). */
241
241
Sorting sorting() const;
243
243
/** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
244
244
void setSortOrder(Qt::SortOrder order);
246
/** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
246
/** Returns the currently used sort order (Qt::Ascending or Qt::Descending). */
247
247
Qt::SortOrder sortOrder() const;
249
249
/** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */
397
401
void pasteIntoFolder();
400
* Turns on the file preview for the all files of the current directory,
401
* if \a show is true.
402
* If the view properties should be remembered for each directory
403
* (GeneralSettings::globalViewProps() returns false), then the
404
* preview setting will be stored automatically.
406
void setShowPreview(bool show);
409
* Shows all hidden files of the current directory,
410
* if \a show is true.
411
* If the view properties should be remembered for each directory
412
* (GeneralSettings::globalViewProps() returns false), then the
413
* show hidden file setting will be stored automatically.
415
void setShowHiddenFiles(bool show);
418
* Summarizes all sorted items by their category \a categorized
420
* If the view properties should be remembered for each directory
421
* (GeneralSettings::globalViewProps() returns false), then the
422
* categorized sorting setting will be stored automatically.
424
void setCategorizedSorting(bool categorized);
403
/** Activates the view if the item list container gets focus. */
404
virtual bool eventFilter(QObject* watched, QEvent* event);
430
410
void activated();
432
/** Is emitted if URL of the view has been changed to \a url. */
413
* Is emitted if the URL of the view will be changed to \a url.
414
* After the URL has been changed the signal urlChanged() will
417
void urlAboutToBeChanged(const KUrl& url);
419
/** Is emitted if the URL of the view has been changed to \a url. */
433
420
void urlChanged(const KUrl& url);
436
423
* Is emitted when clicking on an item with the left mouse button.
438
void itemTriggered(const KFileItem& item);
425
void itemActivated(const KFileItem& item);
441
428
* Is emitted if items have been added or deleted.
451
438
* Is emitted if the view mode (IconsView, DetailsView,
452
439
* PreviewsView) has been changed.
441
void modeChanged(DolphinView::Mode current, DolphinView::Mode previous);
456
443
/** Is emitted if the 'show preview' property has been changed. */
457
void showPreviewChanged();
444
void previewsShownChanged(bool shown);
459
446
/** Is emitted if the 'show hidden files' property has been changed. */
460
void showHiddenFilesChanged();
447
void hiddenFilesShownChanged(bool shown);
462
/** Is emitted if the 'categorized sorting' property has been changed. */
463
void categorizedSortingChanged();
449
/** Is emitted if the 'grouped sorting' property has been changed. */
450
void groupedSortingChanged(bool groupedSorting);
465
452
/** Is emitted if the sorting by name, size or date has been changed. */
466
453
void sortingChanged(DolphinView::Sorting sorting);
472
459
void sortFoldersFirstChanged(bool foldersFirst);
474
461
/** Is emitted if the additional information shown for this view has been changed. */
475
void additionalInfoChanged();
462
void additionalInfoListChanged(const QList<DolphinView::AdditionalInfo>& current,
463
const QList<DolphinView::AdditionalInfo>& previous);
477
465
/** Is emitted if the zoom level has been changed by zooming in or out. */
478
void zoomLevelChanged(int level);
466
void zoomLevelChanged(int current, int previous);
481
469
* Is emitted if information of an item is requested to be shown e. g. in the panel.
571
* If the item \a item is a directory, then this
572
* directory will be loaded. If the item is a file, the corresponding
573
* application will get started.
575
void triggerItem(const KFileItem& index);
561
void slotItemActivated(int index);
562
void slotItemsActivated(const QSet<int>& indexes);
563
void slotItemMiddleClicked(int index);
564
void slotItemContextMenuRequested(int index, const QPointF& pos);
565
void slotViewContextMenuRequested(const QPointF& pos);
566
void slotHeaderContextMenuRequested(const QPointF& pos);
567
void slotItemHovered(int index);
568
void slotItemUnhovered(int index);
569
void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
570
void slotModelChanged(KItemModelBase* current, KItemModelBase* previous);
578
573
* Emits the signal \a selectionChanged() with a small delay. This is
579
* because getting all file items for the signal can be an expensive
574
* because getting all file items for the selection can be an expensive
580
575
* operation. Fast selection changes are collected in this case and
581
576
* the signal is emitted only after no selection change has been done
582
577
* within a small delay.
584
void slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
579
void slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous);
587
582
* Is called by emitDelayedSelectionChangedSignal() and emits the
590
585
void emitSelectionChangedSignal();
593
* Opens the context menu on position \a pos. The position
594
* is used to check whether the context menu is related to an
595
* item or to the viewport.
597
void openContextMenu(const QPoint& pos, const QList<QAction*>& customActions);
600
* Drops dragged URLs to the destination path \a destPath. If
601
* the URLs are dropped above an item inside the destination path,
602
* the item is indicated by \a destItem.
604
void dropUrls(const KFileItem& destItem,
605
const KUrl& destPath,
609
588
* Updates the view properties of the current URL to the
610
589
* sorting given by \a sorting.
656
629
void slotDirListerStarted(const KUrl& url);
659
* Invoked when the directory lister has completed the loading of
660
* items. Assures that pasted items and renamed items get seleced.
662
void slotDirListerCompleted();
665
* Invoked when the loading of the directory is finished.
666
* Restores the active item and the scroll position if possible.
632
* Invoked when the file item model indicates that the directory lister has completed the loading
633
* of items, and that expanded folders have been restored (if the view mode is 'Details', and the
634
* view state is restored after navigating back or forward in history). Assures that pasted items
635
* and renamed items get seleced.
668
637
void slotLoadingCompleted();
673
642
void slotRefreshItems();
645
* Is invoked when the sort order has been changed by the user by clicking
646
* on a header item. The view properties of the directory will get updated.
648
void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous);
651
* Is invoked when the sort role has been changed by the user by clicking
652
* on a header item. The view properties of the directory will get updated.
654
void slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous);
657
* Is invoked when the visible roles have been changed by the user by dragging
658
* a header item. The view properties of the directory will get updated.
660
void slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
661
const QList<QByteArray>& previous);
676
664
* Observes the item with the URL \a url. As soon as the directory
677
665
* model indicates that the item is available, the item will
678
* get selected and it is assure that the item stays visible.
666
* get selected and it is assured that the item stays visible.
680
668
* @see selectAndScrollToCreatedItem()
747
726
* Is invoked after a paste operation or a drag & drop
748
* operation and adds the filenames of all URLs from \a mimeData to
749
* m_newFileNames. This allows to select all newly added
750
* items in slotDirListerCompleted().
752
void addNewFileNames(const QMimeData* mimeData);
755
* Helper method for DolphinView::setItemSelectionEnabled(): Returns the selection for
756
* all items of \p parent that match with the regular expression defined by \p pattern.
758
QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const;
760
void connectViewAccessor();
761
void disconnectViewAccessor();
727
* operation and URLs from \a mimeData as selected.
728
* This allows to select all newly pasted
729
* items in restoreViewState().
731
void markPastedUrlsAsSelected(const QMimeData* mimeData);
764
734
* Updates m_isFolderWritable dependent on whether the folder represented by
768
738
void updateWritableState();
740
QByteArray sortRoleForSorting(Sorting sorting) const;
741
Sorting sortingForSortRole(const QByteArray& sortRole) const;
772
* Abstracts the access to the different view implementations
773
* for icons-, details- and column-view.
775
class LIBDOLPHINPRIVATE_EXPORT ViewAccessor
781
void createView(QWidget* parent,
782
DolphinViewController* dolphinViewController,
783
const ViewModeController* viewModeController,
788
* Must be invoked before the URL has been changed and allows view implementations
789
* like the column view to create a new column.
791
void prepareUrlChange(const KUrl& url);
793
QAbstractItemView* itemView() const;
794
KFileItemDelegate* itemDelegate() const;
797
* Returns the widget that should be added to the layout as target. Usually
798
* the item view itself is returned, but in the case of the column view
799
* a container widget is returned.
801
QWidget* layoutTarget() const;
803
void setRootUrl(const KUrl& rootUrl);
804
KUrl rootUrl() const;
806
bool supportsCategorizedSorting() const;
807
bool itemsExpandable() const;
808
QSet<KUrl> expandedUrls() const;
809
const DolphinDetailsViewExpander* setExpandedUrls(const QSet<KUrl>& urlsToExpand);
812
* Returns true, if a reloading of the items is required
813
* when the additional information properties have been changed
816
bool reloadOnAdditionalInfoChange() const;
818
DolphinModel* dirModel() const;
819
DolphinSortFilterProxyModel* proxyModel() const;
820
KDirLister* dirLister() const;
824
DolphinIconsView* m_iconsView;
825
DolphinDetailsView* m_detailsView;
826
DolphinColumnViewContainer* m_columnsContainer;
827
DolphinModel* m_dolphinModel;
828
DolphinSortFilterProxyModel* m_proxyModel;
829
QAbstractItemView* m_dragSource;
830
QPointer<DolphinDetailsViewExpander> m_detailsViewExpander;
833
friend class DolphinDetailsViewTest;
837
bool m_showPreview : 1;
838
bool m_storedCategorizedSorting : 1;
839
bool m_tabsForFiles : 1;
840
bool m_isContextMenuOpen : 1; // TODO: workaround for Qt-issue 207192
841
bool m_assureVisibleCurrentIndex : 1;
842
bool m_expanderActive : 1;
843
bool m_isFolderWritable : 1;
746
bool m_assureVisibleCurrentIndex;
747
bool m_isFolderWritable;
748
bool m_dragging; // True if a dragging is done. Required to be able to decide whether a
749
// tooltip may be shown when hovering an item.
753
QList<AdditionalInfo> m_additionalInfoList;
847
755
QVBoxLayout* m_topLayout;
849
DolphinViewController* m_dolphinViewController;
850
ViewModeController* m_viewModeController;
851
ViewAccessor m_viewAccessor;
757
DolphinDirLister* m_dirLister;
758
DolphinItemListContainer* m_container;
760
ToolTipManager* m_toolTipManager;
853
762
QTimer* m_selectionChangedTimer;
855
KUrl m_activeItemUrl;
764
KUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
856
765
QPoint m_restoredContentsPosition;
857
766
KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
858
KFileItemList m_selectedItems; // this is used for making the View to remember selections after F5
861
* Remembers the filenames that have been added by a paste operation
862
* or a drag & drop operation. Allows to select the items in
863
* slotDirListerCompleted().
865
QSet<QString> m_newFileNames;
768
QList<KUrl> m_selectedUrls; // Used for making the view to remember selections after F5
770
VersionControlObserver* m_versionControlObserver;
867
772
// For unit tests
868
773
friend class TestBase;