tabbar.h 3.83 KB
Newer Older
1
2
3
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
31
32
33
34
35
36
37
38
/*
  Copyright (C) 2008 by Eike Hein <hein@kde.org>

  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>

class MainWindow;
class Skin;

class KAction;
class KLineEdit;
class KMenu;
class KPushButton;

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


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

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

        void applySkin();


    public slots:
55
        void addTab(int sessionId, const QString& title = 0);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        void removeTab(int sessionId = -1);

        void renameTab(int sessionId = -1, const QString& newTitle = 0);
        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);


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


    private slots:
        void readyTabContextMenu();
        void readySessionMenu();

        void closeTabButtonClicked();


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

109
        void updateMoveActions(int index);
110
111
112
113
114
115
116
        
        int drawButton(int x, int y, int index, QPainter& painter);
        
        void startDrag(int index);
        void drawDropIndicator(int index, bool disabled = false);
        int dropIndex(const QPoint pos);
        bool isSameTab(const QDropEvent*);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

        MainWindow* m_mainWindow;
        Skin* m_skin;

        QToolButton* m_newTabButton;
        KPushButton* m_closeTabButton;

        KMenu* m_tabContextMenu;
        KMenu* m_sessionMenu;

        KLineEdit* m_lineEdit;
        int m_editingSessionId;

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

        int m_selectedSessionId;

        int m_mousePressed;
        int m_mousePressedIndex;
138
139
140
141
        
        QPoint m_startPos;
        QLabel* m_dropIndicator;
        QRect m_dropRect;
142
143
144
};

#endif