summaryrefslogtreecommitdiffstats
path: root/kftpgrabber/src/widgets/multitabbar.h
blob: f5483a8b5057514a124a15a3e3eee34de3d9300d (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
 * This file is part of the KFTPGrabber project
 *
 * Copyright (C) 2003-2005 by the KFTPGrabber developers
 * Copyright (C) 2003-2005 Jernej Kos <kostko@jweb-network.net>
 * Copyright (C) 2001-2003 by Joseph Wenninger <jowenn@kde.org>
 * Copyright (C) 2005 by Mark Kretschmann <markey@web.de>
 *
 * 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
 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
 * NON-INFRINGEMENT.  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
 * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations
 * including the two.
 * You must obey the GNU General Public License in all respects
 * for all of the code used other than OpenSSL.  If you modify
 * file(s) with this exception, you may extend this exception to your
 * version of the file(s), but you are not obligated to do so.  If you
 * do not wish to do so, delete this exception statement from your
 * version.  If you delete this exception statement from all source
 * files in the program, then also delete it here.
 */

#ifndef KFTPWIDGETSMULTITABBAR_H
#define KFTPWIDGETSMULTITABBAR_H

#include <ntqscrollview.h>
#include <ntqvbox.h>
#include <ntqhbox.h>
#include <ntqlayout.h>
#include <ntqstring.h>
#include <ntqptrlist.h>
#include <ntqpushbutton.h>

class TQPixmap;
class TQPainter;
class TQFrame;

namespace KFTPWidgets {

class MultiTabBarPrivate;
class MultiTabBarTabPrivate;
class MultiTabBarButtonPrivate;
class MultiTabBarInternal;

/**
 * A Widget for horizontal and vertical tabs.
 * It is possible to add normal buttons to the top/left
 * The handling if only one tab at a time or multiple tabs
 * should be raisable is left to the "user".
 *
 * @author Joseph Wenninger
 */
class MultiTabBar: public TQWidget
{
Q_OBJECT
friend class MultiTabBarButton;
public:
    enum MultiTabBarMode { Horizontal, Vertical };
    enum MultiTabBarPosition { Left, Right, Top, Bottom };
    
    /**
    * VSNET == Visual Studio .Net like (only show the text of active tabs
    * KDEV3 == Kdevelop 3 like (always show the text)
    * KONTQSBC == konqy's classic sidebar style (unthemed), this one is disabled
    *   at the moment, but will be renabled soon too
    * AMAROK == A nice clean style by the amaroK team
    */
    enum MultiTabBarStyle { VSNET = 0, KDEV3 = 1, KONTQSBC = 2, KDEV3ICON = 3, AMAROK = 4, STYLELAST = 0xffff };
    
    MultiTabBar(MultiTabBarMode bm, TQWidget *parent = 0, const char *name = 0);
    virtual ~MultiTabBar();
    
    /**
     * append  a new button to the button area. The button can later on be accessed with button(ID)
     * eg for connecting signals to it
     *
     * @param pic a pixmap for the button
     * @param id an arbitraty ID value. It will be emitted in the clicked signal for identifying the button
     * if more than one button is connected to a signals.
     * @param popup A popup menu which should be displayed if the button is clicked
     * @param not_used_yet will be used for a popup text in the future
     */
    int appendButton(const TQPixmap &pic, int id = -1, TQPopupMenu* popup = 0, const TQString& not_used_yet = TQString::null);
    
    /**
     * remove a button with the given ID
     */
    void removeButton(int id);
    
    /**
    * append a new tab to the tab area. It can be accessed lateron with tabb(id);
    * @param pic a bitmap for the tab
    * @param id an arbitrary ID which can be used later on to identify the tab
    * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint
    */
    int appendTab( const TQPixmap &pic, int id = -1, const TQString& text = TQString::null );
    
    /**
    * remove a tab with a given ID
    */
    void removeTab( int id );
    /**
    * set a tab to "raised"
    * @param id The ID of the tab to manipulate
    * @param state true == activated/raised, false == not active
    */
    void setTab( int id , bool state );
    /**
    * return the state of a tab, identified by it's ID
    */
    bool isTabRaised( int id ) const;
    /**
    * get a pointer to a button within the button area identified by its ID
    */
    class MultiTabBarButton *button( int id ) const;
    
    /**
    * get a pointer to a tab within the tab area, identiifed by its ID
    */
    class MultiTabBarTab *tab( int id ) const;
    /**
    * set the real position of the widget.
    * @param pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right
    */
    void setPosition( MultiTabBarPosition pos );
    /**
    * set the display style of the tabs
    */
    void setStyle( MultiTabBarStyle style );
    /**
    * be carefull, don't delete tabs yourself and don't delete the list itself
    */
    TQPtrList<MultiTabBarTab>* tabs();
    /**
    * be carefull, don't delete buttons yourself and don't delete the list itself
    */
    TQPtrList<MultiTabBarButton>* buttons();
    
    /**
    * might vanish, not sure yet
    */
    void showActiveTabTexts( bool show = true );
protected:
    virtual void fontChange( const TQFont& );
    void updateSeparator();
private:
    class MultiTabBarInternal *m_internal;
    TQBoxLayout *m_l;
    TQFrame *m_btnTabSep;
    TQPtrList<MultiTabBarButton> m_buttons;
    MultiTabBarPosition m_position;
    MultiTabBarPrivate *d;
};

/**
 * This class should never be created except with the appendButton call of MultiTabBar
 */
class MultiTabBarButton: public TQPushButton
{
Q_OBJECT
public:
    MultiTabBarButton(MultiTabBarInternal *tb, const TQPixmap& pic, const TQString&, TQPopupMenu *popup,
                      int id, TQWidget *parent, MultiTabBar::MultiTabBarPosition pos, MultiTabBar::MultiTabBarStyle style);
    MultiTabBarButton(MultiTabBarInternal *tb, const TQString&, TQPopupMenu *popup,
                      int id, TQWidget *parent, MultiTabBar::MultiTabBarPosition pos, MultiTabBar::MultiTabBarStyle style);
    virtual ~MultiTabBarButton();
    
    int id() const;
public slots:
    /**
    * this is used internaly, but can be used by the user, if (s)he wants to
    * It the according call of MultiTabBar is invoked though this modifications will be overwritten
    */
    void setPosition( MultiTabBar::MultiTabBarPosition );
    /**
    * this is used internaly, but can be used by the user, if (s)he wants to
    * It the according call of MultiTabBar is invoked though this modifications will be overwritten
    */
    void setStyle( MultiTabBar::MultiTabBarStyle );

    /**
    * modify the text of the button
    */
    void setText( const TQString & );

    TQSize sizeHint() const;
protected:
    static const int ANIM_INTERVAL = 18;
    static const int ANIM_MAX = 20;

    MultiTabBarInternal *m_tb;
    
    MultiTabBar::MultiTabBarPosition m_position;
    MultiTabBar::MultiTabBarStyle m_style;
    
    TQString m_text;
    int m_id;
    bool m_animEnter;
    int m_animCount;
    class TQTimer *m_animTimer;
    
    virtual void hideEvent(class TQHideEvent*);
    virtual void showEvent(class TQShowEvent*);
    virtual void enterEvent(class TQEvent*);
    virtual void leaveEvent(class TQEvent*);
private:
    MultiTabBarButtonPrivate *d;
signals:
    /**
     * this is emitted if  the button is clicked
     * @param id the ID identifying the button
     */
    void clicked(int id);
protected slots:
    virtual void slotClicked();
    virtual void slotAnimTimer();
};

/**
 * This class should never be created except with the appendTab call of MultiTabBar
 */
class MultiTabBarTab: public MultiTabBarButton
{
Q_OBJECT
friend class MultiTabBarInternal;
public:
    MultiTabBarTab(MultiTabBarInternal *tb, const TQPixmap &pic, const TQString&, int id, TQWidget *parent,
                   MultiTabBar::MultiTabBarPosition pos, MultiTabBar::MultiTabBarStyle style);
    virtual ~MultiTabBarTab();
    /**
    * set the active state of the tab
    * @param  state true==active false==not active
    */
    void setState( bool state );
    /**
    * choose if the text should always be displayed
    * this is only used in classic mode if at all
    */
    void showActiveTabText( bool show );
    void resize() { setSize( neededSize() ); }
private:
    bool m_showActiveTabText;
    int m_expandedSize;
    
    MultiTabBarTabPrivate *d;
protected:
    void setSize( int );
    int neededSize();
    void updateState();
    virtual void drawButton( TQPainter * );
    virtual void drawButtonLabel( TQPainter * );
    void drawButtonStyled( TQPainter * );
    void drawButtonClassic( TQPainter * );
    void drawButtonAmarok( TQPainter * );
    TQColor blendColors( const TQColor& color1, const TQColor& color2, int percent );
protected slots:
    virtual void slotClicked();
    void setTabsPosition( MultiTabBar::MultiTabBarPosition );
public slots:
    virtual void setIcon( const TQString& );
    virtual void setIcon( const TQPixmap& );
};

}

#endif