File indexing completed on 2024-04-28 13:45:13
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 Based on original code from Sebastian Trueg <trueg@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #ifndef PANELTABBAR_H 0012 #define PANELTABBAR_H 0013 0014 // QtCore 0015 #include <QTimer> 0016 #include <QUrl> 0017 // QtGui 0018 #include <QDragEnterEvent> 0019 #include <QDragMoveEvent> 0020 // QtWidgets 0021 #include <QTabBar> 0022 0023 class QMouseEvent; 0024 class QAction; 0025 class KActionMenu; 0026 class KrPanel; 0027 class ListPanel; 0028 class TabActions; 0029 0030 /** 0031 * This class extends QTabBar such that right-clicking on a tab pops-up a menu 0032 * containing relevant actions for the tab. It also emits signals (caught by PanelManager) 0033 * to create a new tab, close the current tab and change a panel when a tab was clicked 0034 */ 0035 class PanelTabBar : public QTabBar 0036 { 0037 Q_OBJECT 0038 public: 0039 PanelTabBar(QWidget *parent, TabActions *actions); 0040 0041 public slots: 0042 /** 0043 * called by PanelManager with an already created panel, and creates the corresponding tab 0044 */ 0045 int addPanel(ListPanel *panel, bool setCurrent = true, int insertIndex = -1); 0046 0047 ListPanel *getPanel(int tabIdx); 0048 void changePanel(int tabIdx, ListPanel *panel); 0049 void layoutTabs(); 0050 0051 /** 0052 * when the user changes the current path in a panel, this method updates the tab accordingly 0053 */ 0054 void updateTab(ListPanel *panel); 0055 /** 0056 * actually removes the current tab WITHOUT actually deleting the panel. 0057 * returns a pointer to the panel which is going to be displayed next. 0058 * panelToDelete returns a reference to the pointer of the soon-to-die panel, to 0059 * be used by PanelManager. 0060 */ 0061 ListPanel *removeCurrentPanel(ListPanel *&panelToDelete); // returns the panel focused after removing the current 0062 ListPanel *removePanel(int index, ListPanel *&panelToDelete); 0063 0064 signals: 0065 /** 0066 * emitted when the user right-clicks and selected "close" 0067 */ 0068 void closeCurrentTab(); 0069 /** 0070 * emitted when the user press Ctrl+LMB 0071 */ 0072 void duplicateCurrentTab(); 0073 /** 0074 * emitted when the user right-clicks and selects an action that creates a new tab 0075 */ 0076 void newTab(const QUrl &path); 0077 0078 void draggingTab(QMouseEvent *); 0079 void draggingTabFinished(QMouseEvent *); 0080 0081 protected: 0082 void mouseMoveEvent(QMouseEvent *e) override; 0083 void mousePressEvent(QMouseEvent *) override; 0084 void mouseDoubleClickEvent(QMouseEvent *) override; 0085 void mouseReleaseEvent(QMouseEvent *) override; 0086 void insertAction(QAction *); 0087 QString squeeze(const QUrl &url, int tabIndex = -1); 0088 void dragEnterEvent(QDragEnterEvent *) override; 0089 void dragLeaveEvent(QDragLeaveEvent *) override; 0090 void dragMoveEvent(QDragMoveEvent *) override; 0091 void resizeEvent(QResizeEvent *e) override; 0092 0093 protected slots: 0094 void duplicateTab(); 0095 0096 private: 0097 void setIcon(int index, ListPanel *panel); 0098 void handleDragEvent(int tabIndex); 0099 void setPanelTextToTab(int tabIndex, ListPanel *panel); 0100 0101 KActionMenu *_panelActionMenu; 0102 bool _left; 0103 int _maxTabLength; 0104 bool _tabClicked, _tabDoubleClicked, _draggingTab, _doubleClickClose; 0105 0106 QTimer *_dragTimer; 0107 int _dragTabIndex; 0108 }; 0109 0110 #endif