File indexing completed on 2024-04-28 04:58:27
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0003 SPDX-FileCopyrightText: 2000 Carsten Pfeiffer <pfeiffer@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KONQ_SIDEBARTREE_H 0009 #define KONQ_SIDEBARTREE_H 0010 0011 #include <k3listview.h> 0012 #include "kf5compat.h" //For NavigationExtension 0013 #include "konq_sidebartreetoplevelitem.h" 0014 #include <QMap> 0015 #include <QPoint> 0016 #include <Qt3Support/Q3StrList> 0017 0018 //Added by qt3to4: 0019 #include <QPixmap> 0020 #include <QByteRef> 0021 #include <QKeyEvent> 0022 #include <Qt3Support/Q3PtrList> 0023 #include <QEvent> 0024 0025 class KonqSidebarOldTreeModule; 0026 class KonqSidebarTreeModule; 0027 class KonqSidebarTreeItem; 0028 class KActionCollection; 0029 0030 class QTimer; 0031 0032 class KonqSidebarTree_Internal; 0033 0034 enum ModuleType { VIRT_Link = 0, // a single .desktop file 0035 VIRT_Folder = 1 0036 }; // a directory which is parsed for .desktop files 0037 0038 typedef KonqSidebarTreeModule *(*getModule)(KonqSidebarTree *, const bool); 0039 0040 struct DirTreeConfigData { // TODO make base class with two subclasses? 0041 QUrl dir; // only used for VIRT_Folder 0042 ModuleType type; 0043 QString relDir; // only used for VIRT_Folder 0044 }; 0045 0046 enum DropAcceptType { 0047 SidebarTreeMode, // used if the drop is accepted by a KonqSidebarTreeItem. otherwise 0048 K3ListViewMode // use K3ListView's dnd implementation. accepts mime types set with setDropFormats() 0049 }; 0050 0051 /** 0052 * The multi-purpose tree view. 0053 * It parses its configuration (desktop files), each one corresponding to 0054 * a toplevel item, and creates the modules that will handle the contents 0055 * of those items. 0056 */ 0057 class KonqSidebarTree : public K3ListView // PORTING NOTE: DO NOT PORT TO QTreeWidget. See http://kde.aliax.net/mockups/konqueror/ first. 0058 { 0059 Q_OBJECT 0060 public: 0061 KonqSidebarTree(KonqSidebarOldTreeModule *parent, QWidget *parentWidget, ModuleType moduleType, const QString &path); 0062 virtual ~KonqSidebarTree(); 0063 0064 void followURL(const QUrl &url); 0065 0066 /** 0067 * @return the current (i.e. selected) item 0068 */ 0069 KonqSidebarTreeItem *currentItem() const; 0070 0071 void startAnimation(KonqSidebarTreeItem *item, const char *iconBaseName = "kde", uint iconCount = 6, const QPixmap *originalPixmap = 0L); 0072 void stopAnimation(KonqSidebarTreeItem *item); 0073 0074 KonqSidebarOldTreeModule *sidebarModule() 0075 { 0076 return m_sidebarModule; 0077 } 0078 0079 KActionCollection *actionCollection() 0080 { 0081 return m_collection; 0082 } 0083 0084 void lockScrolling(bool lock) 0085 { 0086 m_scrollingLocked = lock; 0087 } 0088 0089 bool isOpeningFirstChild() const 0090 { 0091 return m_bOpeningFirstChild; 0092 } 0093 0094 void enableActions(bool copy, bool cut, bool paste); 0095 0096 void itemDestructed(KonqSidebarTreeItem *item); 0097 0098 void setDropFormats(const QStringList &formats); // used in K3ListView mode 0099 0100 // Show context menu for toplevel items 0101 void showToplevelContextMenu(); 0102 0103 // Add an URL 0104 void addUrl(KonqSidebarTreeTopLevelItem *item, const QUrl &url); 0105 0106 public slots: 0107 // Connected to KDirNotify dbus signals 0108 void slotFilesAdded(const QString &dir); 0109 void slotFilesRemoved(const QStringList &urls); 0110 void slotFilesChanged(const QStringList &urls); 0111 0112 virtual void setContentsPos(int x, int y); 0113 0114 protected: 0115 virtual void contentsDragEnterEvent(QDragEnterEvent *e); 0116 virtual void contentsDragMoveEvent(QDragMoveEvent *e); 0117 virtual void contentsDragLeaveEvent(QDragLeaveEvent *e); 0118 virtual void contentsDropEvent(QDropEvent *ev); 0119 virtual bool acceptDrag(QDropEvent *e) const; // used in K3ListView mode 0120 0121 virtual bool eventFilter(QObject *obj, QEvent *ev); 0122 virtual void leaveEvent(QEvent *); 0123 0124 virtual Q3DragObject *dragObject(); 0125 0126 private slots: 0127 void slotDoubleClicked(Q3ListViewItem *item); 0128 void slotExecuted(Q3ListViewItem *item); 0129 void slotMouseButtonPressed(int _button, Q3ListViewItem *_item, const QPoint &, int col); 0130 void slotMouseButtonClicked(int _button, Q3ListViewItem *_item, const QPoint &, int col); 0131 void slotSelectionChanged(); 0132 0133 void slotAnimation(); 0134 0135 void slotAutoOpenFolder(); 0136 0137 void rescanConfiguration(); 0138 0139 void slotItemRenamed(Q3ListViewItem *, const QString &, int); 0140 0141 void slotCreateFolder(); 0142 void slotDelete(); 0143 void slotTrash(); 0144 void slotRename(); 0145 void slotProperties(); 0146 void slotOpenNewWindow(); 0147 void slotOpenTab(); 0148 void slotCopyLocation(); 0149 0150 private: 0151 void clearTree(); 0152 void scanDir(KonqSidebarTreeItem *parent, const QString &path, bool isRoot = false); 0153 void loadTopLevelGroup(KonqSidebarTreeItem *parent, const QString &path); 0154 void loadTopLevelItem(KonqSidebarTreeItem *parent, const QString &path); 0155 0156 void loadModuleFactories(); 0157 0158 bool overrideShortcut(const QKeyEvent *e); 0159 0160 private: 0161 Q3PtrList<KonqSidebarTreeTopLevelItem> m_topLevelItems; 0162 KonqSidebarTreeTopLevelItem *m_currentTopLevelItem; 0163 0164 Q3PtrList<KonqSidebarTreeModule> m_lstModules; 0165 0166 KonqSidebarOldTreeModule *m_sidebarModule; 0167 0168 struct AnimationInfo { 0169 AnimationInfo(const char *_iconBaseName, uint _iconCount, const QPixmap &_originalPixmap) 0170 : iconBaseName(_iconBaseName), iconCount(_iconCount), iconNumber(1), originalPixmap(_originalPixmap) {} 0171 AnimationInfo() : iconCount(0) {} 0172 QByteArray iconBaseName; 0173 uint iconCount; 0174 uint iconNumber; 0175 QPixmap originalPixmap; 0176 }; 0177 typedef QMap<KonqSidebarTreeItem *, AnimationInfo> MapCurrentOpeningFolders; 0178 MapCurrentOpeningFolders m_mapCurrentOpeningFolders; 0179 0180 QTimer *m_animationTimer; 0181 0182 Q3ListViewItem *m_currentBeforeDropItem; // The item that was current before the drag-enter event happened 0183 Q3ListViewItem *m_dropItem; // The item we are moving the mouse over (during a drag) 0184 Q3StrList m_lstDropFormats; 0185 0186 QTimer *m_autoOpenTimer; 0187 0188 // The base URL for our configuration directory 0189 //QUrl m_dirtreeDir; 0190 DirTreeConfigData m_dirtreeDir; 0191 0192 bool m_scrollingLocked; 0193 0194 getModule getPluginFactory(const QString &name); 0195 0196 QMap<QString, QString> pluginInfo; 0197 QMap<QString, getModule> pluginFactories; 0198 0199 bool m_bOpeningFirstChild; 0200 KActionCollection *m_collection; 0201 0202 KonqSidebarTree_Internal *d; 0203 0204 Q_SIGNALS: 0205 void copy(); 0206 void cut(); 0207 void paste(); 0208 0209 #ifndef Q_MOC_RUN 0210 #undef signals 0211 #define signals public 0212 #endif 0213 signals: 0214 #ifndef Q_MOC_RUN 0215 #undef signals 0216 #define signals protected 0217 #endif 0218 void openUrlRequest(const QUrl &url, const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 0219 const BrowserArguments &browserArgs = BrowserArguments()); 0220 void createNewWindow(const QUrl &url, const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 0221 const BrowserArguments &browserArgs = BrowserArguments()); 0222 }; 0223 0224 #endif // KONQ_SIDEBARTREE_H