konqtabs.h 5.63 KB
Newer Older
1 2
/*  This file is part of the KDE project

Jaison Lee's avatar
Jaison Lee committed
3 4
    Copyright (C) 2002-2003 Konqueror Developers <konq-e@kde.org>
    Copyright (C) 2002-2003 Douglas Hanley <douglash@caltech.edu>
5 6 7 8 9 10 11 12 13 14 15 16 17

    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) any later version.

    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, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Dirk Mueller's avatar
Dirk Mueller committed
19
    MA  02110-1301, USA.
20 21
*/

22 23
#ifndef KONQTABS_H
#define KONQTABS_H
24

Eduardo Robles Elvira's avatar
 
Eduardo Robles Elvira committed
25
#include "konqframe.h"
26
#include "konqframecontainer.h"
27

28
#include "ktabwidget.h"
29
#include <QKeyEvent>
30
#include <QList>
31

32
class QMenu;
33
class QToolButton;
34 35 36 37 38 39 40

class KonqView;
class KonqViewManager;
class KonqFrameContainerBase;
class KonqFrameContainer;
class KConfig;

41 42
class NewTabToolButton;

43
class KONQ_TESTS_EXPORT KonqFrameTabs : public KTabWidget, public KonqFrameContainerBase
44
{
45
    Q_OBJECT
46 47

public:
48 49
    KonqFrameTabs(QWidget *parent, KonqFrameContainerBase *parentContainer,
                  KonqViewManager *viewManager);
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
50
    ~KonqFrameTabs() override;
51

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
52
    bool accept(KonqFrameVisitor *visitor) override;
David Faure's avatar
David Faure committed
53

54
    void saveConfig(KConfigGroup &config, const QString &prefix, const KonqFrameBase::Options &options,
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
55 56
                            KonqFrameBase *docContainer, int id = 0, int depth = 0) override;
    void copyHistory(KonqFrameBase *other) override;
57

58 59 60 61
    const QList<KonqFrameBase *> &childFrameList() const
    {
        return m_childFrameList;
    }
62

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
63 64
    void setTitle(const QString &title, QWidget *sender) override;
    void setTabIcon(const QUrl &url, QWidget *sender) override;
65

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
66
    QWidget *asQWidget() override
67 68 69
    {
        return this;
    }
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
70
    KonqFrameBase::FrameType frameType() const override
71 72 73
    {
        return KonqFrameBase::Tabs;
    }
74

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
75
    void activateChild() override;
76

77 78 79
    /**
     * Insert a new frame into the container.
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
80
    void insertChildFrame(KonqFrameBase *frame, int index = -1) override;
81 82 83 84

    /**
     * Call this before deleting one of our children.
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
85
    void childFrameRemoved(KonqFrameBase *frame) override;
86

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
87
    void replaceChildFrame(KonqFrameBase *oldFrame, KonqFrameBase *newFrame) override;
88

89 90 91 92
    /**
     * Returns the tab at a given index
     * (same as widget(index), but casted to a KonqFrameBase)
     */
93
    KonqFrameBase *tabAt(int index) const;
94

David Faure's avatar
David Faure committed
95 96 97 98
    /**
     * Returns the current tab
     * (same as currentWidget(), but casted to a KonqFrameBase)
     */
99
    KonqFrameBase *currentTab() const;
100

101 102
    void moveTabBackward(int index);
    void moveTabForward(int index);
103

104
    void setLoading(KonqFrameBase *frame, bool loading);
105

106 107 108 109 110
    /**
     * Returns the tab index that contains (directly or indirectly) the frame @p frame,
     * or -1 if the frame is not in the tab widget.
     */
    int tabIndexContaining(KonqFrameBase *frame) const;
111

112 113 114 115 116
    /**
     * Implemented to catch MMB click when KonqSettings::mouseMiddleClickClosesTab()
     * returns true so that the tab can be properly closed without being activated
     * first.
     */
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
117
    bool eventFilter(QObject *, QEvent *) override;
118

Laurent Montel's avatar
Laurent Montel committed
119
public Q_SLOTS:
120 121
    void slotCurrentChanged(int index);
    void setAlwaysTabbedMode(bool);
122
    void forceHideTabBar(bool force);
123

Laurent Montel's avatar
Laurent Montel committed
124
Q_SIGNALS:
125 126
    void removeTabPopup();
    void openUrl(KonqView *view, const QUrl &url);
127

128
private:
129
    void refreshSubPopupMenuTab();
130
    void updateTabBarVisibility();
131
    void initPopupMenu();
132 133 134 135 136 137
    /**
     * Returns the index position of the tab where the frame @p frame is, assuming that
     * it's the active frame in that tab,
     * or -1 if the frame is not in the tab widget or it's not active.
     */
    int tabWhereActive(KonqFrameBase *frame) const;
138

Laurent Montel's avatar
Laurent Montel committed
139
private Q_SLOTS:
140 141
    void slotContextMenu(const QPoint &);
    void slotContextMenu(QWidget *, const QPoint &);
142
    void slotCloseRequest(int);
143 144 145 146 147 148 149 150 151
    void slotMovedTab(int, int);
    void slotMouseMiddleClick();
    void slotMouseMiddleClick(QWidget *);

    void slotTestCanDecode(const QDragMoveEvent *e, bool &accept /* result */);
    void slotReceivedDropEvent(QDropEvent *);
    void slotInitiateDrag(QWidget *);
    void slotReceivedDropEvent(QWidget *, QDropEvent *);
    void slotSubPopupMenuTabActivated(QAction *);
152

153
private:
154 155 156 157 158 159 160 161 162
    QList<KonqFrameBase *> m_childFrameList;

    KonqViewManager *m_pViewManager;
    QMenu *m_pPopupMenu;
    QMenu *m_pSubPopupMenuTab;
    QToolButton *m_rightWidget;
    NewTabToolButton *m_leftWidget;
    bool m_permanentCloseButtons;
    bool m_alwaysTabBar;
163
    bool m_forceHideTabBar;
164
    QMap<QString, QAction *> m_popupActions;
165 166
};

167 168 169 170 171 172
#include <QToolButton>

class NewTabToolButton : public QToolButton // subclass with drag'n'drop functionality for links
{
    Q_OBJECT
public:
173 174 175 176
    NewTabToolButton(QWidget *parent)
        : QToolButton(parent)
    {
        setAcceptDrops(true);
177 178 179
    }

Q_SIGNALS:
180 181
    void testCanDecode(const QDragMoveEvent *event, bool &accept);
    void receivedDropEvent(QDropEvent *event);
182 183

protected:
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
184
    void dragEnterEvent(QDragEnterEvent *event) override
185 186
    {
        bool accept = false;
187 188
        emit testCanDecode(event, accept);
        if (accept) {
189 190 191 192
            event->acceptProposedAction();
        }
    }

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
193
    void dropEvent(QDropEvent *event) override
194
    {
195
        emit receivedDropEvent(event);
196 197 198 199
        event->acceptProposedAction();
    }
};

200
#endif // KONQTABS_H