tabbar.h 4.45 KB
Newer Older
1
/*
2
  Copyright (C) 2008-2009 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
  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


27
28
#include <kdeversion.h>

29
30
31
32
#include <QList>
#include <QHash>
#include <QWidget>

33

34
35
36
37
38
39
40
41
class MainWindow;
class Skin;

class KLineEdit;
class KMenu;
class KPushButton;

class QToolButton;
42
class QLabel;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57


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

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

        void applySkin();


    public slots:
58
        void addTab(int sessionId, const QString& title = 0);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        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);


    signals:
        void newTabRequested();
        void tabSelected(int sessionId);
        void tabClosed(int sessionId);

81
82
83
        void requestTerminalHighlight(int terminalId);
        void requestRemoveTerminalHighlight();
        void tabContextMenuClosed();
Eike Hein's avatar
Eike Hein committed
84
        void lastTabClosed();
85

86
87
88
89
90
91
92
93

    protected:
        virtual void resizeEvent(QResizeEvent*);
        virtual void paintEvent(QPaintEvent*);
        virtual void wheelEvent(QWheelEvent*);
        virtual void keyPressEvent(QKeyEvent*);
        virtual void mousePressEvent(QMouseEvent*);
        virtual void mouseReleaseEvent(QMouseEvent*);
94
95
96
97
98
        virtual void mouseMoveEvent(QMouseEvent*);
        virtual void dragMoveEvent(QDragMoveEvent*);
        virtual void dragEnterEvent(QDragEnterEvent*);
        virtual void dragLeaveEvent(QDragLeaveEvent*);
        virtual void dropEvent(QDropEvent*);
99
100
101
102
103
104
105
106
        virtual void mouseDoubleClickEvent(QMouseEvent*);
        virtual void contextMenuEvent(QContextMenuEvent*);
        virtual void leaveEvent(QEvent*);


    private slots:
        void readySessionMenu();

107
108
        void contextMenuActionHovered(QAction* action);

109
110
        void closeTabButtonClicked();

111
112
        void interactiveRenameDone();

113
114
115
116
117
118

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

119
120
        void readyTabContextMenu();

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

127
        int drawButton(int x, int y, int index, QPainter& painter);
128

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

        MainWindow* m_mainWindow;
        Skin* m_skin;

        QToolButton* m_newTabButton;
        KPushButton* m_closeTabButton;

        KMenu* m_tabContextMenu;
141
        KMenu* m_toggleKeyboardInputMenu;
142
        KMenu* m_toggleMonitorActivityMenu;
Eike Hein's avatar
Eike Hein committed
143
        KMenu* m_toggleMonitorSilenceMenu;
144
145
146
        KMenu* m_sessionMenu;

        KLineEdit* m_lineEdit;
147
        int m_renamingSessionId;
148
149
150
151
152
153
154
155
156

        QList<int> m_tabs;
        QHash<int, QString> m_tabTitles;
        QList<int> m_tabWidths;

        int m_selectedSessionId;

        int m_mousePressed;
        int m_mousePressedIndex;
157

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

#endif