File indexing completed on 2024-04-14 15:17:40

0001 /**************************************************************************
0002 *   Copyright (C) 2004 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)   *
0003 *             (C) 2006-2022 by Michel Ludwig (michel.ludwig@kdemail.net)  *
0004 ***************************************************************************/
0005 
0006 /***************************************************************************
0007  *                                                                         *
0008  *   This program is free software; you can redistribute it and/or modify  *
0009  *   it under the terms of the GNU General Public License as published by  *
0010  *   the Free Software Foundation; either version 2 of the License, or     *
0011  *   (at your option) any later version.                                   *
0012  *                                                                         *
0013  ***************************************************************************/
0014 
0015 #ifndef KILEVIEWKILEVIEWMANAGER_H
0016 #define KILEVIEWKILEVIEWMANAGER_H
0017 
0018 #include <okular/interfaces/viewerinterface.h>
0019 
0020 #include <KTextEditor/Cursor>
0021 #include <KTextEditor/ModificationInterface>
0022 #include <KTextEditor/View>
0023 #include <KXmlGuiWindow>
0024 
0025 #include <QAction>
0026 #include <QDragMoveEvent>
0027 #include <QDropEvent>
0028 #include <QList>
0029 #include <QObject>
0030 #include <QIcon>
0031 #include <QPointer>
0032 #include <QTabWidget>
0033 
0034 class QSplitter;
0035 class QStackedWidget;
0036 class QTabBar;
0037 class QToolButton;
0038 class QUrl;
0039 
0040 class KActionCollection;
0041 class KToggleAction;
0042 class KXMLGUIClient;
0043 
0044 class KileInfo;
0045 
0046 namespace KParts {
0047 class ReadOnlyPart;
0048 }
0049 
0050 namespace KileWidget {
0051 class ProjectView;
0052 }
0053 
0054 namespace KTextEditor {
0055 class Document;
0056 class View;
0057 }
0058 
0059 namespace KileDocument {
0060 class Info;
0061 class TextInfo;
0062 }
0063 
0064 namespace KileView
0065 {
0066 
0067 class DocumentViewerWindow : public KMainWindow
0068 {
0069     Q_OBJECT
0070 
0071 public:
0072     explicit DocumentViewerWindow(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
0073     virtual ~DocumentViewerWindow();
0074 
0075 Q_SIGNALS:
0076     void visibilityChanged(bool shown);
0077 
0078 protected:
0079     virtual void showEvent(QShowEvent *event) override;
0080     virtual void closeEvent(QCloseEvent *event) override;
0081 };
0082 
0083 //TODO inherit from KParts::Manager
0084 class Manager
0085     : public QObject
0086 {
0087     Q_OBJECT
0088 
0089 public:
0090     explicit Manager(KileInfo *ki, KActionCollection *actionCollection, QObject *parent = Q_NULLPTR, const char *name = Q_NULLPTR);
0091 
0092     ~Manager();
0093 
0094 public:
0095     void setClient(KXMLGUIClient *client);
0096 
0097     KTextEditor::View* currentTextView() const;
0098     KTextEditor::View* textView(int index) const;
0099     KTextEditor::View* textView(KileDocument::TextInfo *info) const;
0100     int textViewCount() const;
0101     int tabIndexOf(KTextEditor::View* view) const;
0102     unsigned int getTabCount() const;
0103 
0104     QWidget* createTabs(QWidget *parent);
0105     void setTabsAndEditorVisible(bool b);
0106     KTextEditor::View* createTextView(KileDocument::TextInfo *info, int index = -1);
0107 
0108 //  void setProjectView(KileWidget::ProjectView *view) { m_projectview = view; }
0109 //  KileWidget::ProjectView *projectView() { return m_projectview; } commented out by tbraun, better use signal/slot stuff
0110 
0111     static void installEventFilter(KTextEditor::View *view, QObject *eventFilter);
0112     static void removeEventFilter(KTextEditor::View *view, QObject *eventFilter);
0113 
0114     void installContextMenu(KTextEditor::View *view);
0115 
0116     inline KParts::ReadOnlyPart* viewerPart() const {
0117         return m_viewerPart.data();
0118     }
0119 
0120     inline Okular::ViewerInterface* viewerInterfaceForViewerPart() const {
0121         return dynamic_cast<Okular::ViewerInterface*>(m_viewerPart.data());
0122     }
0123 
0124     void readConfig(QSplitter *splitter);
0125     void writeConfig();
0126 
0127     bool isViewerPartShown() const;
0128     void setupViewerPart(QSplitter *splitter);
0129     bool openInDocumentViewer(const QUrl &url);
0130     void clearLastShownSourceLocationInDocumentViewer();
0131     void showSourceLocationInDocumentViewer(const QString& fileName, int line, int column);
0132     void setLivePreviewModeForDocumentViewer(bool b);
0133 
0134     KToolBar* getViewerControlToolBar();
0135 
0136     bool isSynchronisingCursorWithDocumentViewer() const;
0137 
0138 Q_SIGNALS:
0139     void activateView(QWidget*, bool);
0140     void startQuickPreview(int);
0141     void currentViewChanged(QWidget*);
0142     void textViewActivated(KTextEditor::View *view);
0143     void textViewCreated(KTextEditor::View *view);
0144     void textViewClosed(KTextEditor::View *view, bool wasActiveView);
0145     void updateModeStatus();
0146     void updateCaption();
0147 
0148     void informationMessage(KTextEditor::View*, const QString&);
0149     void cursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
0150     void viewModeChanged(KTextEditor::View*, KTextEditor::View::ViewMode);
0151     void selectionChanged(KTextEditor::View *view);
0152 
0153     void documentViewerWindowVisibilityChanged(bool shown);
0154 
0155 public Q_SLOTS:
0156     KTextEditor::View* switchToTextView(const QUrl &url, bool requestFocus = false);
0157     KTextEditor::View* switchToTextView(KTextEditor::Document *doc, bool requestFocus = false);
0158     void switchToTextView(KTextEditor::View *view, bool requestFocus = false);
0159 
0160     void removeView(KTextEditor::View *view);
0161 
0162     void updateStructure(bool parse = false, KileDocument::Info *docinfo = Q_NULLPTR);
0163 
0164     void gotoNextView();
0165     void gotoPrevView();
0166 
0167     void reflectDocumentModificationStatus(KTextEditor::Document*,
0168                                            bool,
0169                                            KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
0170 
0171     void convertSelectionToLaTeX();
0172     void pasteAsLaTeX();
0173     void quickPreviewPopup();
0174 
0175     void moveTabLeft(QWidget *widget = Q_NULLPTR);
0176     void moveTabRight(QWidget *widget = Q_NULLPTR);
0177 
0178     void setDocumentViewerVisible(bool b);
0179 
0180     void handleCursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &pos);
0181 
0182 private Q_SLOTS:
0183     void tabContext(const QPoint& pos);
0184     void closeTab(int index);
0185     void currentTabChanged(int index);
0186     void handleCursorPositionChangedTimeout();
0187 
0188 private:
0189     KTextEditor::View * textViewAtTab(int index) const;
0190 
0191     void createViewerControlToolBar();
0192 
0193 public:
0194     bool viewForLocalFilePresent(const QString& localFileName);
0195 
0196 protected:
0197     void setTabIcon(QWidget *view, const QIcon& icon);
0198 
0199     void createViewerPart(KActionCollection *actionCollection);
0200     void destroyDocumentViewerWindow();
0201 
0202 protected Q_SLOTS:
0203     void testCanDecodeURLs(const QDragEnterEvent *e, bool &accept);
0204     void testCanDecodeURLs(const QDragMoveEvent *e, bool &accept);
0205     void replaceLoadedURL(QWidget *w, QDropEvent *e);
0206     void onTextEditorPopupMenuRequest();
0207 
0208     /**
0209      * Updates the labels of every tab that contains a view for 'changedDoc' to reflect there
0210      * the name of 'changedDoc'.
0211      **/
0212     void updateTabTexts(KTextEditor::Document* changedDoc);
0213 
0214     void handleActivatedSourceReference(const QString& absFileName, int line, int col);
0215 
0216     void showCursorPositionInDocumentViewer();
0217     void synchronizeViewWithCursorActionToggled(bool b);
0218 
0219 private:
0220     KileInfo *m_ki;
0221     QWidget *m_tabsAndEditorWidget;
0222     QTabBar *m_tabBar;
0223     QToolButton *m_documentListButton;
0224     QObject *m_receiver;
0225     KXMLGUIClient *m_client;
0226     DocumentViewerWindow *m_viewerPartWindow;
0227     QStackedWidget *m_widgetStack;
0228     QAction *m_pasteAsLaTeXAction;
0229     QAction *m_convertToLaTeXAction;
0230     QAction *m_quickPreviewAction;
0231     QAction *m_showCursorPositionInViewerAction;
0232     QPointer<KParts::ReadOnlyPart> m_viewerPart;
0233     QPointer<KToolBar> m_viewerControlToolBar;
0234     QTimer *m_cursorPositionChangedTimer, *m_clearLastShownSourceLocationTimer;
0235     KToggleAction *m_synchronizeViewWithCursorAction;
0236 };
0237 
0238 /**
0239  * Little helper widget to overcome the limitation that QTabWidget doesn't honour drop events when
0240  * there are no tabs: the DropWidget is shown instead of QTabWidget when there are no tabs.
0241  */
0242 class DropWidget : public QWidget {
0243     Q_OBJECT
0244 
0245 public:
0246     explicit DropWidget(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = Qt::WindowFlags());
0247     virtual ~DropWidget();
0248 
0249     virtual void dragEnterEvent(QDragEnterEvent *e) override;
0250     virtual void dropEvent(QDropEvent *e) override;
0251 
0252     virtual void mouseDoubleClickEvent(QMouseEvent *e) override;
0253 
0254 Q_SIGNALS:
0255     void testCanDecode(const QDragEnterEvent *, bool &);
0256     void receivedDropEvent(QDropEvent *);
0257     void mouseDoubleClick();
0258 };
0259 
0260 }
0261 
0262 void focusTextView(KTextEditor::View *view);
0263 
0264 #endif