File indexing completed on 2024-05-19 12:23:32
0001 /* 0002 SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_PLUGIN_BROWSEMANAGER_H 0008 #define KDEVPLATFORM_PLUGIN_BROWSEMANAGER_H 0009 0010 #include <QCursor> 0011 #include <QMap> 0012 #include <QObject> 0013 #include <QPointer> 0014 #include <QUrl> 0015 #include <KTextEditor/Cursor> 0016 0017 class QWidget; 0018 0019 namespace KTextEditor { 0020 class View; 0021 class Document; 0022 } 0023 0024 namespace KDevelop { 0025 class IDocument; 0026 } 0027 0028 class EditorViewWatcher 0029 : public QObject 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 explicit EditorViewWatcher(QObject* parent = nullptr); 0035 QList<KTextEditor::View*> allViews(); 0036 0037 private: 0038 ///Called for every added view. Reimplement this to catch them. 0039 virtual void viewAdded(KTextEditor::View*); 0040 0041 private Q_SLOTS: 0042 void viewDestroyed(QObject* view); 0043 void viewCreated(KTextEditor::Document*, KTextEditor::View*); 0044 void documentCreated(KDevelop::IDocument* document); 0045 0046 private: 0047 void addViewInternal(KTextEditor::View* view); 0048 QList<KTextEditor::View*> m_views; 0049 }; 0050 0051 class ContextBrowserPlugin; 0052 class BrowseManager; 0053 0054 class Watcher 0055 : public EditorViewWatcher 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 explicit Watcher(BrowseManager* manager); 0061 void viewAdded(KTextEditor::View*) override; 0062 0063 private: 0064 BrowseManager* m_manager; 0065 }; 0066 0067 /** 0068 * Integrates the context-browser with the editor views, by listening for navigation events, and implementing html-like source browsing 0069 */ 0070 0071 class BrowseManager 0072 : public QObject 0073 { 0074 Q_OBJECT 0075 0076 public: 0077 explicit BrowseManager(ContextBrowserPlugin* controller); 0078 0079 void viewAdded(KTextEditor::View* view); 0080 0081 ///Installs/uninstalls the event-filter 0082 void applyEventFilter(QWidget* object, bool install); 0083 Q_SIGNALS: 0084 ///Emitted when browsing was started using the magic-modifier 0085 void startDelayedBrowsing(KTextEditor::View* view); 0086 void stopDelayedBrowsing(); 0087 void invokeAction(int index); 0088 0089 public Q_SLOTS: 0090 ///Enabled/disables the browsing mode 0091 void setBrowsing(bool); 0092 0093 private Q_SLOTS: 0094 void eventuallyStartDelayedBrowsing(); 0095 0096 private: 0097 struct JumpLocation 0098 { 0099 QUrl url; 0100 KTextEditor::Cursor cursor; 0101 0102 bool isValid() const { return url.isValid() && cursor.isValid(); } 0103 }; 0104 0105 void resetChangedCursor(); 0106 JumpLocation determineJumpLoc(KTextEditor::Cursor textCursor, const QUrl& viewUrl) const; 0107 void setHandCursor(QWidget* widget); 0108 void avoidMenuAltFocus(); 0109 bool eventFilter(QObject* watched, QEvent* event) override; 0110 ContextBrowserPlugin* m_plugin; 0111 bool m_browsing; 0112 int m_browsingByKey; //Whether the browsing was started because of a key 0113 Watcher m_watcher; 0114 //Maps widgets to their previously set cursors 0115 QMap<QPointer<QWidget>, QCursor> m_oldCursors; 0116 QTimer* m_delayedBrowsingTimer; 0117 QPointer<KTextEditor::View> m_browsingStartedInView; 0118 KTextEditor::Cursor m_buttonPressPosition; 0119 }; 0120 0121 #endif