1 /***************************************************************************************** 2 begin : Tue Aug 12 2003 3 copyright : (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) 4 2006 - 2019 by Michel Ludwig (michel.ludwig@kdemail.net) 5 *****************************************************************************************/ 6 7 /*************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 #ifndef PROJECTVIEW_H 16 #define PROJECTVIEW_H 17 18 #include <QDropEvent> 19 #include <QTreeWidget> 20 21 #include <KService> 22 23 #include "kileproject.h" 24 25 class QUrl; 26 class QMenu; 27 class KToggleAction; 28 class KileInfo; 29 30 namespace KileType { 31 enum ProjectView {Project = 0, ProjectItem, Bibliography, ProjectExtra, File, Folder}; 32 } 33 34 namespace KileWidget { 35 36 class ProjectViewItem : public QObject, public QTreeWidgetItem 37 { 38 Q_OBJECT 39 40 public: 41 ProjectViewItem(QTreeWidget *parent, KileProjectItem *item, bool ar = false); 42 ProjectViewItem(QTreeWidget *parent, QTreeWidgetItem *after, KileProjectItem *item, bool ar = false); 43 ProjectViewItem(QTreeWidgetItem *parent, KileProjectItem *item, bool ar = false); 44 45 //use this to create folders 46 ProjectViewItem(QTreeWidgetItem *parent, const QString& name); 47 48 //use this to create non-project files 49 ProjectViewItem(QTreeWidget *parent, const QString& name); 50 51 ProjectViewItem(QTreeWidget *parent, const KileProject *project); 52 53 ~ProjectViewItem(); 54 55 KileProjectItem* projectItem(); 56 57 ProjectViewItem* parent(); 58 ProjectViewItem* firstChild(); 59 60 void setInfo(KileDocument::Info *docinfo); 61 KileDocument::Info * getInfo(); 62 63 void setType(KileType::ProjectView type); 64 KileType::ProjectView type() const; 65 66 virtual bool operator<(const QTreeWidgetItem& other) const override; 67 68 void setURL(const QUrl &url); 69 const QUrl &url(); 70 71 void setArchiveState(bool ar); 72 73 void setFolder(int folder); 74 int folder() const; 75 76 public Q_SLOTS: 77 /** 78 * @warning Does nothing if "url" is empty ! 79 **/ 80 void urlChanged(const QUrl &url); 81 void nameChanged(const QString& name); 82 void isrootChanged(bool isroot); 83 84 private Q_SLOTS: 85 /** 86 * Dummy slot, simply forwarding to urlChanged(const QUrl &url). 87 **/ 88 void slotURLChanged(KileDocument::Info*, const QUrl &url); 89 90 91 private: 92 QUrl m_url; 93 KileType::ProjectView m_type; 94 KileDocument::Info *m_docinfo; 95 int m_folder; 96 KileProjectItem *m_projectItem; 97 }; 98 99 class ProjectView : public QTreeWidget 100 { 101 Q_OBJECT 102 103 public: 104 ProjectView(QWidget *parent, KileInfo *ki); 105 106 void addTree(KileProjectItem *item, ProjectViewItem *projvi); 107 108 ProjectViewItem* projectViewItemFor(const QUrl&); 109 ProjectViewItem* itemFor(const QUrl&); 110 ProjectViewItem* parentFor(const KileProjectItem *projitem, ProjectViewItem *projvi); 111 112 public Q_SLOTS: 113 void slotClicked(QTreeWidgetItem* item = Q_NULLPTR); 114 115 void slotFile(int id); 116 void slotProjectItem(int id); 117 void slotProject(int id); 118 119 void slotRun(int id); 120 121 void refreshProjectTree(const KileProject *); 122 void add(const QUrl &url); 123 void add(const KileProject *project); 124 void remove(const QUrl &url); 125 void remove(const KileProject *project); 126 void removeItem(const KileProjectItem *, bool); 127 ProjectViewItem* add(KileProjectItem *item, ProjectViewItem *projvi = Q_NULLPTR); 128 129 Q_SIGNALS: 130 void fileSelected(const KileProjectItem *); 131 void fileSelected(const QUrl&); 132 void saveURL(const QUrl&); 133 void closeURL(const QUrl&); 134 void projectOptions(const QUrl&); 135 void projectArchive(const QUrl&); 136 void addFiles(const QUrl&); 137 void openAllFiles(const QUrl&); 138 void toggleArchive(KileProjectItem*); 139 void closeProject(const QUrl&); 140 void addToProject(const QUrl&); 141 void removeFromProject(KileProjectItem*); 142 void buildProjectTree(const QUrl&); 143 144 protected: 145 virtual void contextMenuEvent(QContextMenuEvent *event) override; 146 virtual void dragEnterEvent(QDragEnterEvent *event) override; 147 virtual void dragMoveEvent(QDragMoveEvent *event) override; 148 virtual void dropEvent(QDropEvent *event) override; 149 150 private: 151 152 KileInfo *m_ki; 153 uint m_nProjects; 154 155 KService::List m_offerList; 156 157 void makeTheConnection(ProjectViewItem *projectViewItem, KileDocument::TextInfo *textInfo = Q_NULLPTR); 158 ProjectViewItem* folder(const KileProjectItem *item, ProjectViewItem *); 159 160 }; 161 162 } 163 164 #endif 165