KoKoolBar.h
1/*
2 This file is part of the KDE project
3 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __ko_koolbar_h__
22#define __ko_koolbar_h__
23
24#include <tqframe.h>
25#include <tqpixmap.h>
26#include <tqintdict.h>
27#include <koffice_export.h>
28class TQPushButton;
29class TQPixmap;
30class KoKoolBar;
31class KoKoolBarGroup;
32
33class KoKoolBarItem : public TQObject
34{
35private:
36 TQ_OBJECT
37
38public:
39 KoKoolBarItem( KoKoolBarGroup *_grp, const TQPixmap& _pix, const TQString& _text = TQString() );
40
41 int id() const { return m_id; }
42 void press();
43 bool isEnabled() const { return m_bEnabled; }
44 void setEnabled( bool _e ) { m_bEnabled = _e; }
45
46 int height() const { return m_iHeight; }
47 TQPixmap pixmap() const { return m_pixmap; }
48 void setText( const TQString & text ) { m_strText = text; }
49 TQString text() const { return m_strText; }
50
51signals:
52 void pressed( int _group, int _id );
53 void pressed();
54protected:
55 void calc( TQWidget* );
56
57 int m_iHeight;
58 KoKoolBarGroup* m_pGroup;
59 TQString m_strText;
60 TQPixmap m_pixmap;
61 int m_id;
62 bool m_bEnabled;
63 class KoKoolBarItemPrivate;
64 KoKoolBarItemPrivate *d;
65};
66
67class KoKoolBarGroup : public TQObject
68{
69 TQ_OBJECT
70
71public:
72 KoKoolBarGroup( KoKoolBar *_bar, const TQString& _text );
73 ~KoKoolBarGroup();
74
75 void append( KoKoolBarItem *_i ) { m_mapItems.insert( _i->id(), _i ); }
76 void remove( int _id );
77
78 KoKoolBar* bar() const { return m_pBar; }
79 TQPushButton* button() const { return m_pButton; }
80 int id() const { return m_id; }
81 bool isEnabled() const { return m_bEnabled; }
82 void setEnabled( bool _e ) { m_bEnabled = _e; }
83 KoKoolBarItem* item( int _id ) const { return m_mapItems[ _id ]; }
84 int items() const { return m_mapItems.size(); }
85 TQIntDictIterator<KoKoolBarItem> iterator() const { return TQIntDictIterator<KoKoolBarItem>( m_mapItems ); }
86
87public slots:
88 void pressed();
89
90protected:
91 TQIntDict<KoKoolBarItem> m_mapItems;
92 KoKoolBar* m_pBar;
93 TQString m_strText;
94 int m_id;
95 TQPushButton* m_pButton;
96 bool m_bEnabled;
97 class KoKoolBarGroupPrivate;
98 KoKoolBarGroupPrivate *d;
99};
100
101class KoKoolBarBox : public TQFrame
102{
103 TQ_OBJECT
104
105public:
106 KoKoolBarBox( KoKoolBar *_bar );
107
108 void setActiveGroup( KoKoolBarGroup *_grp );
109 int maxHeight() const;
110
111 void sizeChanged() { resizeEvent(0L); }
112
113protected slots:
114 void scrollUp();
115 void scrollDown();
116
117protected:
118 virtual void resizeEvent( TQResizeEvent *_ev );
119 virtual void drawContents( TQPainter * );
120 virtual void mousePressEvent( TQMouseEvent *_ev )
121 { KoKoolBarItem *item = findByPos( _ev->pos().y() + m_iYOffset ); if ( !item ) return; item->press(); }
122
123 KoKoolBarItem* findByPos( int _abs_y ) const;
124
125 bool needsScrolling() const;
126 bool isAtBottom() const;
127 bool isAtTop() const;
128 void updateScrollButtons();
129
130 KoKoolBar *m_pBar;
131 int m_iYOffset;
132 int m_iYIcon;
133 KoKoolBarGroup *m_pGroup;
134 TQPushButton* m_pButtonUp;
135 TQPushButton* m_pButtonDown;
136 class KoKoolBarBoxPrivate;
137 KoKoolBarBoxPrivate *d;
138};
139
140class KOFFICEUI_EXPORT KoKoolBar : public TQWidget
141{
142 TQ_OBJECT
143
144public:
145 KoKoolBar( TQWidget *_parent = 0L, const char *_name = 0L );
146 virtual ~KoKoolBar() { };
147
148 virtual int insertGroup( const TQString& _text );
149 virtual int insertItem( int _grp, const TQPixmap& _pix, const TQString& _text = TQString(),
150 TQObject *_obj = 0L, const char *_slot = 0L );
151 virtual void removeGroup( int _grp );
152 virtual void removeItem( int _grp, int _id );
153 virtual void renameItem( int _grp, int _id, const TQString & _text );
154 virtual void setActiveGroup( int _grp );
155 virtual int activeGroup() const { return m_iActiveGroup; }
156 virtual void enableItem( int _grp, int _id, bool _enable );
157 virtual void enableGroup( int _grp, bool _enable );
158
159protected:
160 virtual void resizeEvent( TQResizeEvent *_ev );
161
162 TQIntDict<KoKoolBarGroup> m_mapGroups;
163
164 int m_iActiveGroup;
165 KoKoolBarBox* m_pBox;
166 class KoKoolBarPrivate;
167 KoKoolBarPrivate *d;
168};
169
170#endif