1 /***************************************************************************
2  *   Copyright (C) 2006 by Vladimir Kuznetsov                              *
3  *   vovanec@gmail.com                                                     *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
17  ***************************************************************************/
18 
19 #ifndef TAB_WIDGET
20 #define TAB_WIDGET
21 
22 #include <QTabWidget>
23 #include <QMap>
24 #include <QAction>
25 
26 #ifdef HAVE_QDBUS
27     #include <QtDBus/QtDBus>
28     #include "dbusaddressable.h"
29 #endif
30 
31 #include "terminalconfig.h"
32 #include "properties.h"
33 
34 class TabBar;
35 class TermWidgetHolder;
36 class QAction;
37 class QActionGroup;
38 class TabSwitcher;
39 
40 class TabWidget : public QTabWidget
41 {
42 Q_OBJECT
43 public:
44     TabWidget(QWidget* parent = nullptr);
45     ~TabWidget() override;
46 
47     TermWidgetHolder * terminalHolder();
48 
49     void showHideTabBar();
50     const QList<QWidget*>& history() const;
51 
52 public slots:
53     int addNewTab(TerminalConfig cfg);
54     void removeTab(int);
55     void switchTab(int);
56     void onAction();
57     void saveCurrentChanged(int);
58     void removeCurrentTab();
59     int switchToRight();
60     int switchToLeft();
61     void removeFinished();
62     void moveLeft();
63     void moveRight();
64     void renameSession(int);
65     void renameCurrentSession();
66     void setTitleColor(int);
67 
68     void switchLeftSubterminal();
69     void switchRightSubterminal();
70     void switchTopSubterminal();
71     void switchBottomSubterminal();
72 
73     void splitHorizontally();
74     void splitVertically();
75     void splitCollapse();
76 
77     void copySelection();
78     void pasteClipboard();
79     void pasteSelection();
80     void zoomIn();
81     void zoomOut();
82     void zoomReset();
83 
84     void changeTabPosition(QAction *);
85     void changeScrollPosition(QAction *);
86     void changeKeyboardCursorShape(QAction *);
87     void propertiesChanged();
88 
89     void clearActiveTerminal();
90 
91     void saveSession();
92     void loadSession();
93 
94     void preset2Horizontal();
95     void preset2Vertical();
96     void preset4Terminals();
97 
98     void switchToNext();
99     void switchToPrev();
100 signals:
101     void closeTabNotification(bool);
102     void tabRenameRequested(int);
103     void tabTitleColorChangeRequested(int);
104     void currentTitleChanged(int);
105 
106 protected:
107     enum Direction{Left = 1, Right};
108     void contextMenuEvent(QContextMenuEvent * event) override;
109     void move(Direction);
110     /*! Event filter for TabWidget's QTabBar. It's installed on tabBar()
111         in the constructor.
112         It's purpose is to handle doubleclicks on QTabBar for session
113         renaming or new tab opening
114      */
115     bool eventFilter(QObject *obj, QEvent *event) override;
116 protected slots:
117     void updateTabIndices();
118     void onTermTitleChanged(const QString& title, const QString& icon);
119 
120 private:
121     int tabNumerator;
122     /* re-order naming of the tabs then removeCurrentTab() */
123     void renameTabsAfterRemove();
124     int switchTo(int index);
125 
126     TabBar *mTabBar;
127     QScopedPointer<TabSwitcher> mSwitcher;
128     QList<QWidget*> mHistory;
129 
130     QMetaObject::Connection mFocusConnection;
131 };
132 
133 #endif
134