tabbar.h 4.65 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
  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
19
  along with this program. If not, see https://www.gnu.org/licenses/.
20 21 22 23 24 25 26 27 28 29
*/


#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
        void tabTitleEdited(int sessionId, QString title);
82

83 84

    protected:
85 86 87 88 89 90 91 92 93 94 95 96 97 98
        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;
99

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

102

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

106 107
        void contextMenuActionHovered(QAction* action);

108 109
        void closeTabButtonClicked();

110 111
        void interactiveRenameDone();

112 113 114 115 116 117

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

118 119
        void readyTabContextMenu();

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

126 127
        int drawTab(int x, int y, int index, QPainter& painter);
        void moveNewTabButton();
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

        MainWindow* m_mainWindow;
        Skin* m_skin;

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

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

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

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

        int m_selectedSessionId;

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

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

#endif