File indexing completed on 2024-05-12 09:58:06
0001 /* 0002 SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KRVIEWER_H 0010 #define KRVIEWER_H 0011 0012 // QtCore 0013 #include <QEvent> 0014 #include <QList> 0015 #include <QPointer> 0016 #include <QUrl> 0017 // QtGui 0018 #include <QFocusEvent> 0019 #include <QKeyEvent> 0020 // QtWidgets 0021 #include <QAction> 0022 #include <QMenu> 0023 #include <QTabWidget> 0024 0025 #include <KParts/BrowserExtension> 0026 #include <KParts/MainWindow> 0027 #include <KParts/PartManager> 0028 0029 #include "../krglobal.h" 0030 #include "viewertabbar.h" 0031 0032 class PanelViewerBase; 0033 0034 class KrViewer : public KParts::MainWindow 0035 { 0036 Q_OBJECT 0037 public: 0038 virtual ~KrViewer(); 0039 0040 enum Mode { Generic, Text, Hex, Lister, Default }; 0041 0042 static void view(QUrl url, QWidget *parent = krMainWindow); 0043 static void view(QUrl url, Mode mode, bool new_window, QWidget *parent = krMainWindow); 0044 static void edit(QUrl url, QWidget *parent); 0045 static void edit(const QUrl &url, Mode mode = Text, int new_window = -1, QWidget *parent = krMainWindow); 0046 static void configureDeps(); 0047 0048 virtual bool eventFilter(QObject *watched, QEvent *e) override; 0049 0050 public slots: 0051 void createGUI(KParts::Part *); 0052 void configureShortcuts(); 0053 0054 void viewGeneric(); 0055 void viewText(); 0056 void viewHex(); 0057 void viewLister(); 0058 void editText(); 0059 0060 void print(); 0061 void copy(); 0062 0063 void tabChanged(int index); 0064 void tabURLChanged(PanelViewerBase *pvb, const QUrl &url); 0065 void tabCloseRequest(int index, bool force = false); 0066 void tabCloseRequest(); 0067 0068 void nextTab(); 0069 void prevTab(); 0070 void detachTab(); 0071 0072 void checkModified(); 0073 0074 protected: 0075 virtual bool queryClose() override; 0076 virtual void changeEvent(QEvent *e) override; 0077 virtual void resizeEvent(QResizeEvent *e) override; 0078 virtual void focusInEvent(QFocusEvent *) override 0079 { 0080 if (viewers.removeAll(this)) 0081 viewers.prepend(this); 0082 } // move to first 0083 0084 private slots: 0085 void openUrlFinished(PanelViewerBase *pvb, bool success); 0086 0087 private: 0088 explicit KrViewer(QWidget *parent = nullptr); 0089 void addTab(PanelViewerBase *pvb); 0090 void updateActions(); 0091 void refreshTab(PanelViewerBase *pvb); 0092 void viewInternal(QUrl url, Mode mode, QWidget *parent = krMainWindow); 0093 void editInternal(QUrl url, Mode mode, QWidget *parent = krMainWindow); 0094 void addPart(KParts::ReadOnlyPart *part); 0095 void removePart(KParts::ReadOnlyPart *part); 0096 bool isPartAdded(KParts::Part *part); 0097 0098 static KrViewer *getViewer(bool new_window); 0099 static QString makeTabText(PanelViewerBase *pvb); 0100 static QString makeTabToolTip(PanelViewerBase *pvb); 0101 static QIcon makeTabIcon(PanelViewerBase *pvb); 0102 0103 KParts::PartManager manager; 0104 QMenu *viewerMenu; 0105 ViewerTabWidget tabWidget; 0106 QPointer<QWidget> returnFocusTo; 0107 0108 QAction *detachAction; 0109 QAction *printAction; 0110 QAction *copyAction; 0111 QAction *quitAction; 0112 0113 QAction *configKeysAction; 0114 QAction *tabCloseAction; 0115 QAction *tabNextAction; 0116 QAction *tabPrevAction; 0117 0118 static QList<KrViewer *> viewers; // the first viewer is the active one 0119 QList<int> reservedKeys; // the reserved key sequences 0120 QList<QAction *> reservedKeyActions; // the IDs of the reserved keys 0121 0122 int sizeX; 0123 int sizeY; 0124 }; 0125 0126 class Invoker : public QObject 0127 { 0128 Q_OBJECT 0129 0130 public: 0131 Invoker(QObject *recv, const char *slot) 0132 { 0133 connect(this, SIGNAL(invokeSignal()), recv, slot); 0134 } 0135 0136 void invoke() 0137 { 0138 emit invokeSignal(); 0139 } 0140 0141 signals: 0142 void invokeSignal(); 0143 }; 0144 0145 #endif