tabbar.h 4.6 KB
Newer Older
1
/*
Eike Hein's avatar
Eike Hein committed
2
  Copyright (C) 2008-2014 by Eike Hein <hein@kde.org>
Eike Hein's avatar
Eike Hein committed
3
  Copyright (C) 2009 by Juan Carlos Torres <carlosdgtorres@gmail.com>
4
5
6
7
8
9

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as
  published by the Free Software Foundation; either version 2 of
  the License or (at your option) version 3 or any later version
  accepted by the membership of KDE e.V. (or its successor appro-
10
  ved by the membership of KDE e.V.), which shall act as a proxy
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  defined in Section 14 of version 3 of the license.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see http://www.gnu.org/licenses/.
*/


#ifndef TABBAR_H
#define TABBAR_H

#include <QList>
#include <QHash>
#include <QWidget>

30

31
32
33
class MainWindow;
class Skin;

Eike Hein's avatar
Eike Hein committed
34
35
36
class QLineEdit;
class QMenu;
class QPushButton;
37
class QToolButton;
38
class QLabel;
39
40
41
42
43
44
45
46
47
48
49
50
51
52


class TabBar : public QWidget
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.yakuake")

    public:
        explicit TabBar(MainWindow* mainWindow);
        ~TabBar();

        void applySkin();


Eike Hein's avatar
Eike Hein committed
53
54
    public Q_SLOTS:
        void addTab(int sessionId, const QString& title);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        void removeTab(int sessionId = -1);

        void interactiveRename(int sessionId);

        void selectTab(int sessionId);
        void selectNextTab();
        void selectPreviousTab();

        void moveTabLeft(int sessionId = -1);
        void moveTabRight(int sessionId = -1);

        Q_SCRIPTABLE QString tabTitle(int sessionId);
        Q_SCRIPTABLE void setTabTitle(int sessionId, const QString& newTitle);

        Q_SCRIPTABLE int sessionAtTab(int index);


Eike Hein's avatar
Eike Hein committed
72
    Q_SIGNALS:
73
74
75
76
        void newTabRequested();
        void tabSelected(int sessionId);
        void tabClosed(int sessionId);

77
78
79
        void requestTerminalHighlight(int terminalId);
        void requestRemoveTerminalHighlight();
        void tabContextMenuClosed();
Eike Hein's avatar
Eike Hein committed
80
        void lastTabClosed();
81

82
83

    protected:
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        void resizeEvent(QResizeEvent*) override;
        void paintEvent(QPaintEvent*) override;
        void wheelEvent(QWheelEvent*) override;
        void keyPressEvent(QKeyEvent*) override;
        void mousePressEvent(QMouseEvent*) override;
        void mouseReleaseEvent(QMouseEvent*) override;
        void mouseMoveEvent(QMouseEvent*) override;
        void dragMoveEvent(QDragMoveEvent*) override;
        void dragEnterEvent(QDragEnterEvent*) override;
        void dragLeaveEvent(QDragLeaveEvent*) override;
        void dropEvent(QDropEvent*) override;
        void mouseDoubleClickEvent(QMouseEvent*) override;
        void contextMenuEvent(QContextMenuEvent*) override;
        void leaveEvent(QEvent*) override;
98

99
100
        void setTabTitleInteractive(int sessionId, const QString& newTitle);

101

Eike Hein's avatar
Eike Hein committed
102
    private Q_SLOTS:
103
104
        void readySessionMenu();

105
106
        void contextMenuActionHovered(QAction* action);

107
108
        void closeTabButtonClicked();

109
110
        void interactiveRenameDone();

111
112
113
114
115
116

    private:
        QString standardTabTitle();
        QString makeTabTitle(int number);
        int tabAt(int x);

117
118
        void readyTabContextMenu();

119
        void updateMoveActions(int index);
120
121
        void updateToggleActions(int sessionId);
        void updateToggleKeyboardInputMenu(int sessionId = -1);
122
123
        void updateToggleMonitorSilenceMenu(int sessionId = -1);
        void updateToggleMonitorActivityMenu(int sessionId = -1);
124

125
126
        int drawTab(int x, int y, int index, QPainter& painter);
        void moveNewTabButton();
127

128
129
130
131
        void startDrag(int index);
        void drawDropIndicator(int index, bool disabled = false);
        int dropIndex(const QPoint pos);
        bool isSameTab(const QDropEvent*);
132
133
134
135
136

        MainWindow* m_mainWindow;
        Skin* m_skin;

        QToolButton* m_newTabButton;
Eike Hein's avatar
Eike Hein committed
137
        QPushButton* m_closeTabButton;
138

Eike Hein's avatar
Eike Hein committed
139
140
141
142
143
        QMenu* m_tabContextMenu;
        QMenu* m_toggleKeyboardInputMenu;
        QMenu* m_toggleMonitorActivityMenu;
        QMenu* m_toggleMonitorSilenceMenu;
        QMenu* m_sessionMenu;
144

Eike Hein's avatar
Eike Hein committed
145
        QLineEdit* m_lineEdit;
146
        int m_renamingSessionId;
147
148
149

        QList<int> m_tabs;
        QHash<int, QString> m_tabTitles;
150
        QHash<int, bool> m_tabTitlesSetInteractive;
151
152
153
154
        QList<int> m_tabWidths;

        int m_selectedSessionId;

Shubham  .'s avatar
Shubham . committed
155
        bool m_mousePressed;
156
        int m_mousePressedIndex;
157

158
159
160
        QPoint m_startPos;
        QLabel* m_dropIndicator;
        QRect m_dropRect;
161
162
163
};

#endif