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
282
283
284
285
286
287
288
|
/***************************************************************************
* Copyright (C) 2004 by *
* Jason Kivlighn ([email protected]) *
* Unai Garro ([email protected]) *
* *
* 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. *
***************************************************************************/
#ifndef CATEGORYLISTVIEW_H
#define CATEGORYLISTVIEW_H
#include <tqmap.h>
#include <tqpixmap.h>
#include "dblistviewbase.h"
#include "datablocks/elementlist.h"
class TDEPopupMenu;
class RecipeDB;
class CategoryTree;
class CategoryCheckListView;
#define CATEGORYCHECKLISTITEM_RTTI 1005
#define CATEGORYLISTITEM_RTTI 1001
#define PSEUDOLISTITEM_RTTI 1008
/** Category listitems inherit this class to provide a common interface for accessing this information.
*/
class CategoryItemInfo
{
public:
CategoryItemInfo( const Element &category ) : ctyStored( category ), populated(false){}
bool isPopulated() const { return populated; }
void setPopulated( bool b ){ populated = b; }
Element element() const
{
return ctyStored;
}
int categoryId() const
{
return ctyStored.id;
}
TQString categoryName() const
{
return ctyStored.name;
}
protected:
Element ctyStored;
private:
bool populated;
};
class CategoryCheckListItem : public TQCheckListItem, public CategoryItemInfo
{
public:
CategoryCheckListItem( CategoryCheckListView* klv, const Element &category, bool exclusive = true );
CategoryCheckListItem( TQListViewItem* it, const Element &category, bool exclusive = true );
CategoryCheckListItem( CategoryCheckListView* klv, TQListViewItem* it, const Element &category, bool exclusive = true );
virtual TQString text( int column ) const;
virtual void setText( int column, const TQString &text );
int rtti() const
{
return CATEGORYCHECKLISTITEM_RTTI;
}
protected:
virtual void stateChange( bool );
void setChildrenState( bool );
void setParentsState( bool );
bool locked;
bool exclusive;
private:
CategoryCheckListView *m_listview;
};
class CategoryListItem : public TQListViewItem, public CategoryItemInfo
{
public:
CategoryListItem( TQListView* klv, const Element &category );
CategoryListItem( TQListViewItem* it, const Element &category );
CategoryListItem( TQListView* klv, TQListViewItem* it, const Element &category );
virtual TQString text( int column ) const;
virtual void setText( int column, const TQString &text );
int rtti() const
{
return CATEGORYLISTITEM_RTTI;
}
};
class CategoryListView : public DBListViewBase
{
TQ_OBJECT
public:
CategoryListView( TQWidget *parent, RecipeDB * );
void populateAll( TQListViewItem *parent = 0 );
public slots:
void open( TQListViewItem *item );
protected:
virtual void init();
virtual void load( int limit, int offset );
/** so that it allows dropping into
* subchildren that aren't expandable. The code is taken from TDE's TDEListView with
* one line commented out.
*/
void findDrop( const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after )
{
TQPoint p ( contentsToViewport( pos ) );
// Get the position to put it in
TQListViewItem *atpos = itemAt( p );
TQListViewItem *above;
if ( !atpos ) // put it at the end
above = lastItem();
else {
// Get the closest item before us ('atpos' or the one above, if any)
if ( p.y() - itemRect( atpos ).topLeft().y() < ( atpos->height() / 2 ) )
above = atpos->itemAbove();
else
above = atpos;
}
if ( above ) {
// if above has children, I might need to drop it as the first item there
if ( above->firstChild() && above->isOpen() ) {
parent = above;
after = 0;
return ;
}
// Now, we know we want to go after "above". But as a child or as a sibling ?
// We have to ask the "above" item if it accepts children.
// ### NOTE: Here is the one line commented out so that "above" always accepts children
//if (above->isExpandable())
{
// The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children
if ( p.x() >= depthToPixels( above->depth() + 1 ) ||
( above->isOpen() && above->childCount() > 0 ) )
{
parent = above;
after = 0L;
return ;
}
}
// Ok, there's one more level of complexity. We may want to become a new
// sibling, but of an upper-level group, rather than the "above" item
TQListViewItem * betterAbove = above->parent();
TQListViewItem * last = above;
while ( betterAbove ) {
// We are allowed to become a sibling of "betterAbove" only if we are
// after its last child
if ( last->nextSibling() == 0 ) {
if ( p.x() < depthToPixels ( betterAbove->depth() + 1 ) )
above = betterAbove; // store this one, but don't stop yet, there may be a better one
else
break; // not enough on the left, so stop
last = betterAbove;
betterAbove = betterAbove->parent(); // up one level
}
else
break; // we're among the child of betterAbove, not after the last one
}
}
// set as sibling
after = above;
parent = after ? after->parent() : 0L ;
}
protected slots:
virtual void removeCategory( int id ) = 0;
virtual void createCategory( const Element &category, int parent_id ) = 0;
virtual void modifyCategory( const Element &category );
virtual void modifyCategory( int id, int parent_id );
virtual void mergeCategories( int id1, int id2 );
virtual void checkCreateCategory( const Element &, int parent_id );
virtual void populate( TQListViewItem *item );
TQMap<int, TQListViewItem*> items_map;
private:
TQListViewItem *m_item_to_delete;
};
class StdCategoryListView : public CategoryListView
{
TQ_OBJECT
public:
StdCategoryListView( TQWidget *parent, RecipeDB *, bool editable = false );
~StdCategoryListView();
protected:
virtual void removeCategory( int id );
virtual void createCategory( const Element &category, int parent_id );
void setPixmap( const TQPixmap &pixmap );
private slots:
void preparePopup();
void showPopup( TDEListView *, TQListViewItem *, const TQPoint & );
void createNew();
void remove
();
void rename();
void cut();
void paste();
void pasteAsSub();
void changeCategoryParent( TQListViewItem *item, TQListViewItem * /*afterFirst*/, TQListViewItem * /*afterNow*/ );
void modCategory( TQListViewItem* i );
void saveCategory( TQListViewItem* i );
private:
bool checkBounds( const TQString &name );
TDEPopupMenu *kpop;
TQListViewItem *clipboard_item;
TQListViewItem *clipboard_parent;
TQPixmap m_folder_icon;
};
class CategoryCheckListView : public CategoryListView
{
TQ_OBJECT
public:
CategoryCheckListView( TQWidget *parent, RecipeDB *, bool exclusive=true, const ElementList &init_items_checked = ElementList() );
virtual void stateChange( CategoryCheckListItem*, bool );
ElementList selections() const{ return m_selections; }
protected:
virtual void removeCategory( int id );
virtual void createCategory( const Element &category, int parent_id );
virtual void load( int limit, int offset );
bool exclusive;
private:
ElementList m_selections;
};
class PseudoListItem : public TQListViewItem
{
public:
PseudoListItem( TQListView* lv ) : TQListViewItem(lv){}
PseudoListItem( TQListViewItem* it ) : TQListViewItem(it){}
protected:
int rtti() const { return PSEUDOLISTITEM_RTTI; }
};
#endif //CATEGORYLISTVIEW_H
|