chalk

layerlist.h
1/*
2 Copyright (c) 2005 Gábor Lehel <illissius@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20
21#ifndef LAYERLIST_H
22#define LAYERLIST_H
23
24#include <tqiconset.h>
25#include <tdelistview.h>
26
27class TQMouseEvent;
28class TQString;
29class TDEPopupMenu;
30class LayerItem;
31class LayerFolder;
32template<class T> class TQPtrList;
33
34class LayerList: public TDEListView
35{
36 TQ_OBJECT
37
38
39public:
40 LayerList( TQWidget *parent = 0, const char *name = 0 );
41 virtual ~LayerList();
42
43 void addProperty( const TQString &name, const TQString &displayName, const TQIconSet &icon = TQIconSet(),
44 bool defaultValue = false, bool validForFolders = true );
45 void addProperty( const TQString &name, const TQString &displayName, TQPixmap enabled, TQPixmap disabled,
46 bool defaultValue = false, bool validForFolders = true );
47
48 bool foldersCanBeActive() const;
49 bool previewsShown() const;
50 int itemHeight() const;
51 int numRows() const;
52
53 LayerItem *layer( int id ) const;
54 LayerItem *folder( int id ) const; //returns 0 if not a folder
55
56 LayerItem *activeLayer() const;
57 int activeLayerID() const;
58
59 TQValueList<LayerItem*> selectedLayers() const;
60 TQValueList<int> selectedLayerIDs() const;
61
62 void makeFolder( int id );
63 bool isFolder( int id ) const;
64 TQString displayName( int id ) const;
65 bool property( int id, const TQString &name ) const;
66
67 struct MenuItems
68 {
69 enum { NewLayer = 0, NewFolder, RemoveLayer, LayerProperties, COUNT };
70 };
71 TDEPopupMenu *contextMenu() const;
72
73public slots:
74 void setFoldersCanBeActive( bool can );
75 void setPreviewsShown( bool show );
76 void setItemHeight( int height );
77 void setNumRows( int rows ); //how many rows of property icons can fit
78
79 void setActiveLayer( LayerItem *layer );
80 void setActiveLayer( int id );
81
82 void setLayerDisplayName( LayerItem *layer, const TQString &displayName );
83 void setLayerDisplayName( int id, const TQString &displayName );
84
85 void setLayerProperty( LayerItem *layer, const TQString &name, bool on );
86 void setLayerProperty( int id, const TQString &name, bool on );
87
88 void toggleLayerProperty( LayerItem *layer, const TQString &name );
89 void toggleLayerProperty( int id, const TQString &name );
90
91 void setLayerPreviewImage( LayerItem *layer, TQImage *image );
92 void setLayerPreviewImage( int id, TQImage *image );
93
94 void layerPreviewChanged( LayerItem *layer );
95 void layerPreviewChanged( int id );
96
97 LayerItem *addLayer( const TQString &displayName, LayerItem *after = 0, int id = -1 );
98 LayerItem *addLayer( const TQString &displayName, int afterID, int id = -1 );
99
100 LayerItem *addLayerToParent( const TQString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 );
101 LayerItem *addLayerToParent( const TQString &displayName, int parentID, int afterID = -1, int id = -1 );
102
103 void moveLayer( LayerItem *layer, LayerItem *parent, LayerItem *after );
104 void moveLayer( int id, int parentID, int afterID );
105
106 void removeLayer( LayerItem *layer );
107 void removeLayer( int id );
108
109signals:
110 void activated( LayerItem *layer );
111 void activated( int id );
112
113 void displayNameChanged( LayerItem *layer, const TQString &displayName );
114 void displayNameChanged( int id, const TQString &displayName );
115
116 void propertyChanged( LayerItem *layer, const TQString &name, bool on );
117 void propertyChanged( int id, const TQString &name, bool on );
118
119 void layerMoved( LayerItem *layer, LayerItem *parent, LayerItem *after );
120 void layerMoved( int id, int parentID, int afterID );
121
122 void requestNewLayer( LayerItem *parent, LayerItem *after );
123 void requestNewLayer( int parentID, int afterID );
124
125 void requestNewFolder( LayerItem *parent, LayerItem *after );
126 void requestNewFolder( int parentID, int afterID );
127
128 void requestRemoveLayer( LayerItem *layer );
129 void requestRemoveLayer( int id );
130
131 void requestRemoveLayers( TQValueList<LayerItem*> layers );
132 void requestRemoveLayers( TQValueList<int> ids );
133
134 void requestLayerProperties( LayerItem *layer );
135 void requestLayerProperties( int id );
136
137public: //convenience
138 LayerItem *firstChild() const;
139 LayerItem *lastChild() const;
140
141protected slots:
142 virtual void constructMenu( LayerItem *layer );
143 virtual void menuActivated( int id, LayerItem *layer );
144
145private:
146 typedef TDEListView super;
147 friend class LayerItem;
148 friend class LayerToolTIp;
149
150 class Private;
151 Private* const d;
152
153private slots:
154 void slotItemRenamed( TQListViewItem *item, const TQString &text, int col );
155 void slotItemMoved( TQPtrList<TQListViewItem>&, TQPtrList<TQListViewItem>&, TQPtrList<TQListViewItem>& );
156 void showContextMenu();
157 void hideTip();
158 void maybeTip();
159
160public: //reimplemented for internal reasons
161 virtual void setCurrentItem( TQListViewItem *i );
162
163protected:
164 virtual void contentsMousePressEvent( TQMouseEvent *e );
165 virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e );
166 virtual void findDrop( const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after );
167};
168
169class LayerItem: public TDEListViewItem
170{
171public:
172 LayerItem( const TQString &displayName, LayerList *parent, LayerItem *after = 0, int id = -1 );
173 LayerItem( const TQString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 );
174 virtual ~LayerItem();
175
176 void makeFolder();
177 bool isFolder() const;
178
179 // Returns true if this item is the given item or the tree rooted at
180 // this item contains the given item.
181 bool contains(const LayerItem *item);
182
183 int id() const;
184
185 TQString displayName() const;
186 void setDisplayName( const TQString &displayName );
187
188 bool isActive() const;
189 void setActive();
190
191 bool property( const TQString &name ) const;
192 void setProperty( const TQString &name, bool on );
193 void toggleProperty( const TQString &name );
194
195 void setPreviewImage( TQImage *image );
196 void previewChanged();
197
198 LayerItem *addLayer( const TQString &displayName, LayerItem *after = 0, int id = -1 );
199
200 LayerItem *prevSibling() const;
201
202public: //convenience
203 LayerItem *nextSibling() const;
204 LayerList *listView() const;
205 LayerItem *firstChild() const;
206 LayerItem *parent() const;
207 void update() const; //like TQWidget::update()
208
209protected:
210 virtual TQRect rect() const;
211
212 int mapXFromListView( int x ) const;
213 int mapYFromListView( int y ) const;
214 TQPoint mapFromListView( const TQPoint &point ) const;
215 TQRect mapFromListView( const TQRect &rect ) const;
216
217 int mapXToListView( int x ) const;
218 int mapYToListView( int y ) const;
219 TQPoint mapToListView( const TQPoint &point ) const;
220 TQRect mapToListView( const TQRect &rect ) const;
221
222 virtual TQRect textRect() const;
223 virtual TQRect iconsRect() const;
224 virtual TQRect previewRect() const;
225
226 virtual void drawText( TQPainter *p, const TQColorGroup &cg, const TQRect &r );
227 virtual void drawIcons( TQPainter *p, const TQColorGroup &cg, const TQRect &r );
228 virtual void drawPreview( TQPainter *p, const TQColorGroup &cg, const TQRect &r );
229
230 bool multiline() const;
231 bool showPreview() const;
232 virtual TQFont font() const;
233 TQFontMetrics fontMetrics() const;
234
235 virtual bool mousePressEvent( TQMouseEvent *e );
236
237 virtual TQString tooltip() const;
238
239 virtual TQImage *previewImage() const;
240 virtual TQImage tooltipPreview() const;
241
242private:
243 typedef TDEListViewItem super;
244 friend class LayerList;
245 friend class LayerToolTip;
246
247 class Private;
248 Private* const d;
249
250 void init();
251
252public: //reimplemented for internal reasons
253 virtual int width( const TQFontMetrics &fm, const TQListView *lv, int c ) const;
254 virtual void paintCell( TQPainter *p, const TQColorGroup &cg, int column, int width, int align );
255 virtual void setup();
256 virtual void setSelected( bool selected );
257};
258
259class LayerFolder: public LayerItem
260{
261public:
262 LayerFolder( const TQString &displayName, LayerList *parent, LayerItem *after = 0, int id = -1 )
263 : LayerItem( displayName, parent, after, id ) { makeFolder(); }
264 LayerFolder( const TQString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 )
265 : LayerItem( displayName, parent, after, id ) { makeFolder(); }
266};
267
268
269#endif