File indexing completed on 2024-04-21 16:33:20
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 PANELMANAGER_H 0010 #define PANELMANAGER_H 0011 0012 #include "abstractpanelmanager.h" 0013 0014 // QtWidgets 0015 #include <QGridLayout> 0016 #include <QHBoxLayout> 0017 #include <QLayout> 0018 #include <QWidget> 0019 0020 #include <KConfigCore/KConfigGroup> 0021 0022 #include "paneltabbar.h" 0023 0024 class QStackedWidget; 0025 class QToolButton; 0026 class ListPanel; 0027 class KrMainWindow; 0028 class TabActions; 0029 0030 /** 0031 * Implements tabbed-browsing by managing a list of tabs and corresponding panels. 0032 */ 0033 class PanelManager : public QWidget, public AbstractPanelManager 0034 { 0035 Q_OBJECT 0036 Q_CLASSINFO("D-Bus Interface", "org.krusader.PanelManager") 0037 0038 public: 0039 /** 0040 * PanelManager is created where once panels were created. It accepts three references to pointers 0041 * (self, other, active), which enables it to manage pointers held by the panels transparently. 0042 * It also receives a bool (left) which is true if the manager is the left one, or false otherwise. 0043 */ 0044 PanelManager(QWidget *parent, KrMainWindow *mainWindow, bool left); 0045 0046 void saveSettings(KConfigGroup config, bool saveHistory); 0047 void loadSettings(KConfigGroup config); 0048 int findTab(QUrl url); 0049 int tabCount() 0050 { 0051 return _tabbar->count(); 0052 } 0053 int activeTab(); 0054 void setActiveTab(int index); 0055 void moveTabToOtherSide(); 0056 void moveTabToLeft(); 0057 void moveTabToRight(); 0058 /** Refresh all tabs after config changes. */ 0059 void reloadConfig(); 0060 void layoutTabs(); 0061 void setLeft(bool left) 0062 { 0063 _left = left; 0064 } 0065 void setOtherManager(PanelManager *other) 0066 { 0067 _otherManager = other; 0068 } 0069 0070 // AbstractPanelManager implementation 0071 bool isLeft() const override 0072 { 0073 return _left; 0074 } 0075 AbstractPanelManager *otherManager() const override 0076 { 0077 return _otherManager; 0078 } 0079 KrPanel *currentPanel() const override; 0080 void newTab(const QUrl &url, int insertIndex) override 0081 { 0082 slotNewTab(url, true, insertIndex); 0083 } 0084 void duplicateTab(const QUrl &url, KrPanel *nextTo) override 0085 { 0086 slotDuplicateTab(url, nextTo); 0087 } 0088 /** 0089 * Undo the closing of a tab. The `action` argument is utilized to 0090 * retrieve information about the previously closed tab. 0091 */ 0092 void undoCloseTab(const QAction *action); 0093 /** 0094 * Delete what is stored about all the closed tabs. 0095 */ 0096 void delAllClosedTabs(); 0097 /** 0098 * Delete what is stored about a closed tab. 0099 */ 0100 void delClosedTab(QAction *action); 0101 0102 signals: 0103 void draggingTab(PanelManager *from, QMouseEvent *); 0104 void draggingTabFinished(PanelManager *from, QMouseEvent *); 0105 void setActiveManager(PanelManager *manager); 0106 void pathChanged(ListPanel *panel); 0107 0108 public slots: 0109 /** 0110 * Called externally to start a new tab. Example of usage would be the "open in a new tab" 0111 * action, from the context-menu. 0112 */ 0113 0114 Q_SCRIPTABLE void newTab(const QString &url) 0115 { 0116 slotNewTab(QUrl::fromUserInput(url, QString(), QUrl::AssumeLocalFile)); 0117 } 0118 Q_SCRIPTABLE void newTabs(const QStringList &urls); 0119 0120 void slotNewTab(const QUrl &url, bool setCurrent = true, int insertIndex = -1); 0121 void slotNewTabButton(); 0122 void slotNewTab(int insertIndex = -1); 0123 void slotDuplicateTab(const QUrl &url, KrPanel *nextTo, int insertIndex = -1); 0124 void slotDuplicateTabLMB(); 0125 void slotLockTab(); 0126 void slotPinTab(); 0127 void slotNextTab(); 0128 void slotPreviousTab(); 0129 void slotCloseTab(); 0130 void slotCloseTab(int index); 0131 void slotUndoCloseTab(); //! Undo the last tab closing 0132 void slotRecreatePanels(); 0133 void slotCloseInactiveTabs(); 0134 void slotCloseDuplicatedTabs(); 0135 0136 protected slots: 0137 void slotCurrentTabChanged(int index); 0138 void activate(); 0139 void slotDraggingTab(QMouseEvent *e) 0140 { 0141 emit draggingTab(this, e); 0142 } 0143 void slotDraggingTabFinished(QMouseEvent *e) 0144 { 0145 emit draggingTabFinished(this, e); 0146 } 0147 0148 private: 0149 void deletePanel(ListPanel *p); 0150 void updateTabbarPos(); 0151 void tabsCountChanged(); 0152 ListPanel *addPanel(bool setCurrent = true, const KConfigGroup &cfg = KConfigGroup(), int insertIndex = -1); 0153 ListPanel *duplicatePanel(const KConfigGroup &cfg, KrPanel *nextTo, int insertIndex = -1); 0154 ListPanel *createPanel(const KConfigGroup &cfg); 0155 void connectPanel(ListPanel *p); 0156 void disconnectPanel(ListPanel *p); 0157 0158 PanelManager *_otherManager; 0159 TabActions *_actions; 0160 QGridLayout *_layout; 0161 QHBoxLayout *_barLayout; 0162 bool _left; 0163 PanelTabBar *_tabbar; 0164 QStackedWidget *_stack; 0165 QToolButton *_newTab; 0166 ListPanel *_currentPanel; 0167 }; 0168 0169 #endif // _PANEL_MANAGER_H