tabbar.h 4.18 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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

  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-
  ved by the membership of KDE e.V.), which shall act as a proxy 
  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>

31

32
33
34
35
36
37
38
39
class MainWindow;
class Skin;

class KLineEdit;
class KMenu;
class KPushButton;

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


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

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

        void applySkin();


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

79
80
81
82
        void requestTerminalHighlight(int terminalId);
        void requestRemoveTerminalHighlight();
        void tabContextMenuClosed();

83
84
85
86
87
88
89
90

    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*);
91
92
93
94
95
        virtual void mouseMoveEvent(QMouseEvent*);
        virtual void dragMoveEvent(QDragMoveEvent*);
        virtual void dragEnterEvent(QDragEnterEvent*);
        virtual void dragLeaveEvent(QDragLeaveEvent*);
        virtual void dropEvent(QDropEvent*);
96
97
98
99
100
101
102
103
        virtual void mouseDoubleClickEvent(QMouseEvent*);
        virtual void contextMenuEvent(QContextMenuEvent*);
        virtual void leaveEvent(QEvent*);


    private slots:
        void readySessionMenu();

104
105
        void contextMenuActionHovered(QAction* action);

106
107
        void closeTabButtonClicked();

108
109
        void interactiveRenameDone();

110
111
112
113
114
115

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

116
117
        void readyTabContextMenu();

118
        void updateMoveActions(int index);
119
120
        void updateToggleActions(int sessionId);
        void updateToggleKeyboardInputMenu(int sessionId = -1);
121

122
        int drawButton(int x, int y, int index, QPainter& painter);
123

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

        MainWindow* m_mainWindow;
        Skin* m_skin;

        QToolButton* m_newTabButton;
        KPushButton* m_closeTabButton;

        KMenu* m_tabContextMenu;
136
        KMenu* m_toggleKeyboardInputMenu;
137
138
139
        KMenu* m_sessionMenu;

        KLineEdit* m_lineEdit;
140
        int m_renamingSessionId;
141
142
143
144
145
146
147
148
149

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

        int m_selectedSessionId;

        int m_mousePressed;
        int m_mousePressedIndex;
150

151
152
153
        QPoint m_startPos;
        QLabel* m_dropIndicator;
        QRect m_dropRect;
154
155
156
};

#endif