1/***************************************************************************
2 kmultitabbar.h - description
3 -------------------
4 begin : 2001
5 copyright : (C) 2001,2002,2003 by Joseph Wenninger <jowenn@kde.org>
6 ***************************************************************************/
7
8/***************************************************************************
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23 ***************************************************************************/
24
25#ifndef _KMultitabbar_h_
26#define _KMultitabbar_h_
27
28#include <QtGui/QLayout>
29#include <QtCore/QString>
30#include <QtCore/QList>
31#include <QtGui/QPushButton>
32
33#include <kdeui_export.h>
34
35class QPixmap;
36class QPainter;
37class QMenu;
38class QStyleOptionToolButton;
39
40class KMultiTabBarPrivate;
41class KMultiTabBarTabPrivate;
42class KMultiTabBarButtonPrivate;
43class KMultiTabBarInternal;
44
45/**
46 * A Widget for horizontal and vertical tabs.
47 * (Note that in Qt4, QTabBar can be vertical as well)
48 *
49 * It is possible to add normal buttons to the top/left
50 * The handling if only one tab at a time or multiple tabs
51 * should be raisable is left to the "user".
52 *
53 * \image html kmultitabbar.png "KDE Multi Tab Bar Widget"
54 *
55 * @author Joseph Wenninger
56 */
57class KDEUI_EXPORT KMultiTabBar: public QWidget
58{
59 Q_OBJECT
60 Q_ENUMS(KMultiTabBarPosition KMultiTabBarStyle)
61 Q_PROPERTY(KMultiTabBarPosition position READ position WRITE setPosition)
62 Q_PROPERTY(KMultiTabBarStyle tabStyle READ tabStyle WRITE setStyle)
63public:
64 enum KMultiTabBarPosition { Left, Right, Top, Bottom };
65
66 /**
67 * The list of available styles for KMultiTabBar
68 * - VSNET - Visual Studio .Net like, always shows icon, only show the text of active tabs
69 * - KDEV3ICON - Kdevelop 3 like, always shows the text and icons
70 */
71 enum KMultiTabBarStyle{VSNET=0, KDEV3ICON=2,STYLELAST=0xffff};
72
73 explicit KMultiTabBar(KMultiTabBarPosition pos, QWidget *parent=0 );
74 virtual ~KMultiTabBar();
75
76 /**
77 * append a new button to the button area. The button can later on be accessed with button(ID)
78 * eg for connecting signals to it
79 * @param pic a pixmap for the button
80 * @param id an arbitraty ID value. It will be emitted in the clicked signal for identifying the button
81 * if more than one button is connected to a signals.
82 * @param popup A popup menu which should be displayed if the button is clicked
83 * @param not_used_yet will be used for a popup text in the future
84 */
85 int appendButton(const QPixmap &pic,int id=-1,QMenu* popup=0,const QString& not_used_yet=QString());
86 /**
87 * remove a button with the given ID
88 */
89 void removeButton(int id);
90 /**
91 * append a new tab to the tab area. It can be accessed lateron with tabb(id);
92 * @param pic a bitmap for the tab
93 * @param id an arbitrary ID which can be used later on to identify the tab
94 * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint
95 */
96 int appendTab(const QPixmap &pic,int id=-1,const QString& text=QString());
97 /**
98 * remove a tab with a given ID
99 */
100 void removeTab(int id);
101 /**
102 * set a tab to "raised"
103 * @param id The ID of the tab to manipulate
104 * @param state true == activated/raised, false == not active
105 */
106 void setTab(int id ,bool state);
107 /**
108 * return the state of a tab, identified by its ID
109 */
110 bool isTabRaised(int id) const;
111 /**
112 * get a pointer to a button within the button area identified by its ID
113 */
114 class KMultiTabBarButton *button(int id) const;
115
116 /**
117 * get a pointer to a tab within the tab area, identiifed by its ID
118 */
119 class KMultiTabBarTab *tab(int id) const;
120
121 /**
122 * set the real position of the widget.
123 * @param pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right
124 */
125 void setPosition(KMultiTabBarPosition pos);
126
127 /**
128 * get the tabbar position.
129 * @return position
130 */
131 KMultiTabBarPosition position() const;
132
133 /**
134 * set the display style of the tabs
135 */
136 void setStyle(KMultiTabBarStyle style);
137
138 /**
139 * get the display style of the tabs
140 * @return display style
141 */
142 KMultiTabBarStyle tabStyle() const;
143
144protected:
145 friend class KMultiTabBarButton;
146 virtual void fontChange( const QFont& );
147 void updateSeparator();
148private:
149 KMultiTabBarPrivate * const d;
150};
151
152/**
153 * Use KMultiTabBar::appendButton to append a button, which creates a KMultiTabBarButton instance
154 */
155class KDEUI_EXPORT KMultiTabBarButton: public QPushButton
156{
157 Q_OBJECT
158public:
159 int id() const;
160 virtual ~KMultiTabBarButton();
161
162public Q_SLOTS:
163 void setText(const QString &text);
164
165Q_SIGNALS:
166 /**
167 * this is emitted if the button is clicked
168 * @param id the ID identifying the button
169 */
170 void clicked(int id);
171protected Q_SLOTS:
172 virtual void slotClicked();
173
174protected:
175 virtual void hideEvent( class QHideEvent*);
176 virtual void showEvent( class QShowEvent*);
177 virtual void paintEvent( class QPaintEvent*);
178
179 /** Should not be created directly. Use KMultiTabBar::appendButton
180 */
181 KMultiTabBarButton(const QPixmap& pic, const QString&, int id, QWidget *parent);
182private:
183 friend class KMultiTabBar;
184
185 int m_id;
186 KMultiTabBarButtonPrivate * const d;
187};
188
189/**
190 * Use KMultiTabBar::appendTab to append a tab, which creates a KMultiTabBarTab instance
191 */
192class KDEUI_EXPORT KMultiTabBarTab: public KMultiTabBarButton
193{
194 Q_OBJECT
195public:
196 virtual ~KMultiTabBarTab();
197 virtual QSize sizeHint() const;
198 virtual QSize minimumSizeHint() const;
199
200public Q_SLOTS:
201 /**
202 * this is used internaly, but can be used by the user, if (s)he wants to
203 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
204 */
205 void setPosition(KMultiTabBar::KMultiTabBarPosition);
206
207 /**
208 * this is used internaly, but can be used by the user, if (s)he wants to
209 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
210 */
211 void setStyle(KMultiTabBar::KMultiTabBarStyle);
212
213 /**
214 * set the active state of the tab
215 * @param state true==active false==not active
216 */
217 void setState(bool state);
218
219 void setIcon(const QString&);
220 void setIcon(const QPixmap&);
221protected:
222 virtual void paintEvent(QPaintEvent *);
223private:
224 KMultiTabBar::KMultiTabBarPosition m_position;
225 KMultiTabBar::KMultiTabBarStyle m_style;
226
227 void computeMargins (int* hMargin, int* vMargin) const;
228 QSize computeSizeHint(bool withText) const;
229 bool shouldDrawText() const;
230 bool isVertical() const;
231 QPixmap iconPixmap() const;
232
233 void initStyleOption(QStyleOptionToolButton* opt) const;
234
235 friend class KMultiTabBarInternal;
236 /**
237 * This class should never be created except with the appendTab call of KMultiTabBar
238 */
239 KMultiTabBarTab(const QPixmap& pic, const QString&, int id, QWidget *parent,
240 KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style);
241 KMultiTabBarTabPrivate * const d;
242};
243
244#endif
245// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;
246