1/* This file is part of the KDE libraries
2 Copyright (C) 2003 Stephan Binner <binner@kde.org>
3 Copyright (C) 2003 Zack Rusin <zack@kde.org>
4 Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KTABBAR_H
23#define KTABBAR_H
24
25#include <kdeui_export.h>
26
27#include <QtGui/QTabBar>
28
29/**
30 * A QTabBar with extended features.
31 *
32 * \image html ktabbar.png "KDE Tab Bar"
33 */
34class KDEUI_EXPORT KTabBar: public QTabBar //krazy:exclude=qclasses
35{
36 Q_OBJECT
37
38 public:
39 /**
40 * Creates a new tab bar.
41 *
42 * @param parent The parent widget.
43 */
44 explicit KTabBar( QWidget* parent = 0 );
45
46 /**
47 * Destroys the tab bar.
48 */
49 virtual ~KTabBar();
50
51 /**
52 * Sets the tab reordering enabled or disabled. If enabled,
53 * the user can reorder the tabs by drag and drop the tab
54 * headers with the middle mouse button.
55 *
56 * @deprecated Use QTabBar::setMovable() instead.
57 *
58 * Note, however, that QTabBar::setMovable(true) disables
59 * dragging tabs out of the KTabBar (e.g., dragging the tab
60 * URL from Konqueror to another application)!
61 */
62#ifndef KDE_NO_DEPRECATED
63 KDE_DEPRECATED void setTabReorderingEnabled( bool enable );
64#endif
65
66 /**
67 * Returns whether tab reordering is enabled.
68 *
69 * @deprecated Use QTabBar::isMovable() instead.
70 */
71#ifndef KDE_NO_DEPRECATED
72 KDE_DEPRECATED bool isTabReorderingEnabled() const;
73#endif
74
75 /**
76 * If enabled, a close button is shown above the tab icon.
77 * The signal KTabBar::closeRequest() is emitted, if the
78 * close button has been clicked. Note that the tab must have
79 * an icon to use this feature.
80 *
81 * @deprecated Use QTabBar::setTabsClosable() instead.
82 */
83#ifndef KDE_NO_DEPRECATED
84 KDE_DEPRECATED void setHoverCloseButton( bool );
85#endif
86
87 /** @deprecated Use QTabBar::tabsClosable() instead. */
88#ifndef KDE_NO_DEPRECATED
89 KDE_DEPRECATED bool hoverCloseButton() const;
90#endif
91
92 /**
93 * If enabled, the close button cannot get clicked until a
94 * minor delay has been passed. This prevents that user
95 * accidentally closes a tab.
96 *
97 * @deprecated Use QTabBar::setTabsClosable() instead.
98 */
99#ifndef KDE_NO_DEPRECATED
100 KDE_DEPRECATED void setHoverCloseButtonDelayed( bool );
101#endif
102
103 /** @deprecated Use QTabBar::tabsClosable() instead. */
104#ifndef KDE_NO_DEPRECATED
105 KDE_DEPRECATED bool hoverCloseButtonDelayed() const;
106#endif
107
108 /**
109 * If enabled, a close button is available for each tab. The
110 * signal KTabBar::closeRequest() is emitted, if the close button
111 * has been clicked.
112 *
113 * @since 4.1
114 *
115 * @deprecated Use QTabBar::setTabsClosable() instead.
116 */
117#ifndef KDE_NO_DEPRECATED
118 KDE_DEPRECATED void setCloseButtonEnabled( bool );
119#endif
120
121 /**
122 * Returns true if the close button is shown on tabs.
123 *
124 * @since 4.1
125 *
126 * @deprecated Use QTabBar::tabsClosable() instead.
127 */
128#ifndef KDE_NO_DEPRECATED
129 KDE_DEPRECATED bool isCloseButtonEnabled() const;
130#endif
131
132 /**
133 * Sets the 'activate previous tab on close' feature enabled
134 * or disabled. If enabled, as soon as you close a tab, the
135 * previously selected tab is activated again.
136 *
137 * @deprecated Use QTabBar::setSelectionBehaviorOnRemove() instead.
138 */
139#ifndef KDE_NO_DEPRECATED
140 KDE_DEPRECATED void setTabCloseActivatePrevious( bool );
141#endif
142
143 /**
144 * Returns whether the 'activate previous tab on close' feature
145 * is enabled.
146 *
147 * @deprecated Use QTabBar::selectionBehaviorOnRemove() instead.
148 */
149#ifndef KDE_NO_DEPRECATED
150 KDE_DEPRECATED bool tabCloseActivatePrevious() const;
151#endif
152
153 /**
154 * Selects the tab which has a tab header at
155 * given @param position.
156 *
157 * @param position the coordinates of the tab
158 */
159 int selectTab( const QPoint &position ) const;
160
161 Q_SIGNALS:
162 /**
163 * A right mouse button click was performed over the tab with the @param index.
164 * The signal is emitted on the press of the mouse button.
165 */
166 void contextMenu( int index, const QPoint& globalPos );
167 /**
168 * A right mouse button click was performed over the empty area on the tab bar.
169 * The signal is emitted on the press of the mouse button.
170 */
171 void emptyAreaContextMenu( const QPoint& globalPos );
172 /** @deprecated use tabDoubleClicked(int) and newTabRequest() instead. */
173#ifndef KDE_NO_DEPRECATED
174 QT_MOC_COMPAT void mouseDoubleClick( int );
175#endif
176 /**
177 * A double left mouse button click was performed over the tab with the @param index.
178 * The signal is emitted on the second press of the mouse button, before the release.
179 */
180 void tabDoubleClicked( int index );
181 /**
182 * A double left mouse button click was performed over the empty area on the tab bar.
183 * The signal is emitted on the second press of the mouse button, before the release.
184 */
185 void newTabRequest();
186 /**
187 * A double middle mouse button click was performed over the tab with the @param index.
188 * The signal is emitted on the release of the mouse button.
189 */
190 void mouseMiddleClick( int index );
191 void initiateDrag( int );
192 void testCanDecode( const QDragMoveEvent*, bool& );
193 void receivedDropEvent( int, QDropEvent* );
194 /**
195 * Used internally by KTabBar's/KTabWidget's middle-click tab moving mechanism.
196 * Tells the KTabWidget which owns the KTabBar to move a tab.
197 */
198 void moveTab( int, int );
199 /** @deprecated Use QTabBar::tabCloseRequested(int) instead. */
200#ifndef KDE_NO_DEPRECATED
201 QT_MOC_COMPAT void closeRequest( int );
202#endif
203#ifndef QT_NO_WHEELEVENT
204 void wheelDelta( int );
205#endif
206
207 protected:
208 virtual void mouseDoubleClickEvent( QMouseEvent *event );
209 virtual void mousePressEvent( QMouseEvent *event );
210 virtual void mouseMoveEvent( QMouseEvent *event );
211 virtual void mouseReleaseEvent( QMouseEvent *event );
212#ifndef QT_NO_WHEELEVENT
213 virtual void wheelEvent( QWheelEvent *event );
214#endif
215
216 virtual void dragEnterEvent( QDragEnterEvent *event );
217 virtual void dragMoveEvent( QDragMoveEvent *event );
218 virtual void dropEvent( QDropEvent *event );
219
220 virtual void paintEvent( QPaintEvent *event );
221 virtual void leaveEvent( QEvent *event );
222 virtual QSize tabSizeHint( int index ) const;
223
224 protected Q_SLOTS:
225 /** @deprecated */
226#ifndef KDE_NO_DEPRECATED
227 QT_MOC_COMPAT void closeButtonClicked();
228#endif
229 /** @deprecated */
230#ifndef KDE_NO_DEPRECATED
231 QT_MOC_COMPAT void enableCloseButton();
232#endif
233 virtual void activateDragSwitchTab();
234
235 protected:
236 virtual void tabLayoutChange();
237
238 private:
239 QPoint closeButtonPos( int tabIndex ) const;
240 QRect closeButtonRect( int tabIndex ) const;
241
242 private:
243 class Private;
244 Private* const d;
245};
246
247#endif
248