koshell

iconsidepane.h
1/*
2 This file is part of the KDE KOffice project.
3
4 Copyright (C) 2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2005 Fredrik Edemar <f_edemar@linux.se>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22#ifndef KOFFICE_ICONSIDEPANEBASE_H
23#define KOFFICE_ICONSIDEPANEBASE_H
24
25#include <tdeactioncollection.h>
26#include <tdelistbox.h>
27
28#include <tqbuttongroup.h>
29#include <tqlayout.h>
30#include <tqtooltip.h>
31#include <tqvbox.h>
32#include <tqwidgetstack.h>
33
34#include "koshellsettings.h"
35
36
37class Navigator;
38class IconSidePane;
39
40enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 };
41
46class EntryItem : public TQListBoxItem
47{
48 public:
49 EntryItem( Navigator *, int _id, const TQString &_text, const TQString & _pix );
50 ~EntryItem();
51
52
53 const TQPixmap *pixmap() const { return &mPixmap; }
54
55 int id() { return mId; }
56
57 void setNewText( const TQString &_text );
58
59 void setHover( bool );
60 void setPaintActive( bool );
61 bool paintActive() const { return mPaintActive; }
62
66 virtual int width( const TQListBox * ) const;
70 virtual int height( const TQListBox * ) const;
71
72 protected:
73 void reloadPixmap();
74
75 virtual void paint( TQPainter *p );
76
77 private:
78 TQPixmap mPixmap;
79 TQString mPixmapName;
80 int const mId;
81 Navigator* navigator() const;
82 bool mHasHover;
83 bool mPaintActive;
84};
85
90class EntryItemToolTip : public TQToolTip
91{
92 public:
93 EntryItemToolTip( TQListBox* parent )
94 : TQToolTip( parent->viewport() ), mListBox( parent )
95 {}
96 protected:
97 void maybeTip( const TQPoint& p ) {
98 // We only show tooltips when there are no texts shown
99 if ( KoShellSettings::sidePaneShowText() ) return;
100 if ( !mListBox ) return;
101 TQListBoxItem* item = mListBox->itemAt( p );
102 if ( !item ) return;
103 const TQRect itemRect = mListBox->itemRect( item );
104 if ( !itemRect.isValid() ) return;
105
106 const EntryItem *entryItem = static_cast<EntryItem*>( item );
107 TQString tipStr = entryItem->text();
108 tip( itemRect, tipStr );
109 }
110 private:
111 TQListBox* mListBox;
112};
113
117class Navigator : public TDEListBox
118{
119 TQ_OBJECT
120
121 public:
122 Navigator(bool _selectable, TDEPopupMenu*, IconSidePane *, TQWidget *parent = 0, const char *name = 0 );
123
124 int insertItem(const TQString &_text, const TQString &_pix);
125
126 TQSize sizeHint() const;
127 IconViewMode viewMode();
128 bool showText();
129 bool showIcons();
130 void calculateMinWidth();
131 bool leftMouseButtonPressed(){return mLeftMouseButtonPressed;}
132 int minWidth() { return mMinWidth; }
133 void resetWidth() { mMinWidth = 0; }
134
135 signals:
136 void itemSelected( int );
137 void updateAllWidgets();
138
139 protected:
140 void resizeEvent( TQResizeEvent * );
141 void enterEvent( TQEvent* );
142 void mouseReleaseEvent(TQMouseEvent *e);
143 void mousePressEvent(TQMouseEvent *e);
144
145 void setHoverItem( TQListBoxItem*, bool );
146 void setPaintActiveItem( TQListBoxItem*, bool );
147
148 protected slots:
149 void slotExecuted( TQListBoxItem * );
150 void slotMouseOn( TQListBoxItem *item );
151 void slotMouseOff();
152 void slotShowRMBMenu( TQListBoxItem *, const TQPoint& );
153
154 private:
155 IconSidePane *mSidePane;
156 int mMinWidth;
157 TQListBoxItem *executedItem;
158 bool mLeftMouseButtonPressed;
159 TDEPopupMenu *mPopupMenu;
160 bool mSelectable;
161 TQListBoxItem* mMouseOn;
162};
163
164class IconSidePane :public TQVBox
165{
166 TQ_OBJECT
167
168 public:
169 IconSidePane( TQWidget *parent, const char *name = 0 );
170 ~IconSidePane();
171
172 void setActionCollection( TDEActionCollection *actionCollection );
173 TDEActionCollection *actionCollection() const;
174
175 int insertItem(const TQString & _pix, const TQString &_text);
176 int insertItem(int _grp, const TQString & _pix, const TQString &_text);
177 int insertGroup(const TQString &_text, bool _selectable, TQObject *_obj = 0L, const char *_slot = 0L);
178 void renameItem( int _grp, int _id, const TQString & _text );
179 void removeItem( int _grp, int _id );
180 void selectGroup(int);
181 Navigator *group(int);
182
183 IconViewMode sizeIntToEnum(int size) const;
184 IconViewMode viewMode() { return mViewMode; }
185 void setViewMode(int choice){mViewMode = sizeIntToEnum(choice);}
186 bool showText() { return mShowText; }
187 void toogleText(){mShowText=!mShowText;}
188 bool showIcons() { return mShowIcons; }
189 void toogleIcons(){mShowIcons=!mShowIcons;}
190 TQButtonGroup *buttonGroup() { return m_buttongroup; }
191 int minWidth();
192 void resetWidth();
193
194 public slots:
195 void itemSelected(int);
196 void updateAllWidgets();
197
198 private slots:
199 void buttonClicked();
200
201 private:
202 TQWidgetStack *mWidgetstack;
203 TQValueList<int> mWidgetStackIds;
204 Navigator *mCurrentNavigator;
205 TQButtonGroup *m_buttongroup;
206 TDEActionCollection *mActionCollection;
207 TDEPopupMenu *mPopupMenu;
208
209 IconViewMode mViewMode;
210 bool mShowIcons;
211 bool mShowText;
212};
213
214
215#endif
virtual int width(const TQListBox *) const
returns the width of this item.
virtual int height(const TQListBox *) const
returns the height of this item.
Navigation pane showing all parts relevant to the user.