1 /***************************************************************************** 2 * Copyright (C) 2010 Jan Lepper <dehtris@yahoo.de> * 3 * Copyright (C) 2010-2019 Krusader Krew [https://krusader.org] * 4 * * 5 * This file is part of Krusader [https://krusader.org]. * 6 * * 7 * Krusader is free software: you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation, either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 * Krusader is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15 * GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License * 18 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * 19 *****************************************************************************/ 20 21 #ifndef KRFILETREEVIEW_H 22 #define KRFILETREEVIEW_H 23 24 #include <QList> 25 #include <QModelIndex> 26 #include <QTreeView> 27 #include <QUrl> 28 #include <QWidget> 29 30 #include <KConfigCore/KSharedConfig> 31 #include <KIOFileWidgets/KDirSortFilterProxyModel> 32 #include <KIOFileWidgets/KFilePlacesModel> 33 #include <KIOWidgets/KDirModel> 34 35 /** 36 * Show folders in a tree view. 37 * 38 * A context menu with settings is accessible through the header. 39 * 40 * Supports dragging from this view and dropping files on it. 41 */ 42 class KrFileTreeView : public QTreeView 43 { 44 friend class KrDirModel; 45 Q_OBJECT 46 47 public: 48 explicit KrFileTreeView(QWidget *parent = 0); ~KrFileTreeView()49 virtual ~KrFileTreeView() {} 50 51 void setCurrentUrl(const QUrl &url); 52 53 void saveSettings(KConfigGroup cfg) const; 54 void restoreSettings(const KConfigGroup &cfg); 55 56 signals: 57 void urlActivated(const QUrl &url); 58 59 private slots: 60 void slotActivated(const QModelIndex &index); 61 void slotExpanded(const QModelIndex&); 62 void showHeaderContextMenu(); 63 void slotCustomContextMenuRequested(const QPoint &point); 64 65 protected: 66 void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; 67 68 private: 69 QUrl urlForProxyIndex(const QModelIndex &index) const; 70 void dropMimeData(const QList<QUrl> & lst, const QUrl &url) const; 71 void copyToClipBoard(const KFileItem &fileItem, bool cut) const; 72 void deleteFile(const KFileItem &fileItem, bool moveToTrash = true) const; 73 bool briefMode() const; 74 void setBriefMode(bool brief); // show only column with directory names 75 void setTree(bool startFromCurrent, bool startFromPlace); 76 void setTreeRoot(const QUrl &rootBase); 77 bool isVisible(const QUrl &url); 78 79 KDirModel *mSourceModel; 80 KDirSortFilterProxyModel *mProxyModel; 81 KFilePlacesModel *mFilePlacesModel; 82 QUrl mCurrentUrl; 83 QUrl mCurrentTreeBase; 84 85 bool mStartTreeFromCurrent; // NAND... 86 bool mStartTreeFromPlace; 87 }; 88 89 #endif // KRFILETREEVIEW_H 90