summaryrefslogtreecommitdiffstats
path: root/src/widgets/recipelistview.h
blob: 642f768194e0e887e5a87658927a6bad49a59514 (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
/***************************************************************************
*   Copyright (C) 2004 by                                                 *
*   Jason Kivlighn ([email protected])                                  *
*   Unai Garro ([email protected])                             *
*                                                                         *
*   Copyright (C) 2006 Jason Kivlighn ([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 RECIPELISTVIEW_H
#define RECIPELISTVIEW_H

#include <tqdragobject.h>

#include "categorylistview.h"
#include "datablocks/recipe.h"

class TQDragObject;
class TQDropEvent;

class KProgressDialog;

class RecipeDB;

#define RECIPELISTITEM_RTTI 1000

#define RECIPEITEMMIMETYPE "data/x-kde.recipe.item"

class RecipeListItem : public TQListViewItem
{
public:
	RecipeListItem( TQListView* qlv, const Recipe &r ) : TQListViewItem( qlv )
	{
		init( r );
	}

	RecipeListItem( TQListView* qlv, TQListViewItem *after, const Recipe &r ) : TQListViewItem( qlv, after )
	{
		init( r );
	}

	RecipeListItem( CategoryListItem* it, const Recipe &r ) : TQListViewItem( it )
	{
		init( r );
	}

	RecipeListItem( CategoryListItem* it, TQListViewItem *after, const Recipe &r ) : TQListViewItem( it, after )
	{
		init( r );
	}

	RecipeListItem( TQListViewItem* it, const Recipe &r ) : TQListViewItem( it )
	{
		init( r );
	}

	int rtti() const
	{
		return RECIPELISTITEM_RTTI;
	}

	~RecipeListItem( void )
	{
		delete recipeStored;
	}

	int recipeID() const
	{
		return recipeStored->recipeID;
	}
	TQString title() const
	{
		return recipeStored->title;
	}

	void setRecipeID( int id )
	{
		recipeStored->recipeID = id;
	}
	void setTitle( const TQString &title )
	{
		recipeStored->title = title;
	}

protected:
	Recipe *recipeStored;

public:
	virtual TQString text( int column ) const
	{
		switch ( column ) {
		case 0:
			return ( recipeStored->title );
			break;
		case 1:
			return ( TQString::number( recipeStored->recipeID ) );
			break;
		default:
			return ( TQString::null );
		}
	}

private:
	void init( const Recipe &r )
	{
		recipeStored = new Recipe();

		//note: we only store the title and id
		recipeStored->recipeID = r.recipeID;
		recipeStored->title = r.title;
	}
};

class RecipeItemDrag : public TQStoredDrag
{
public:
	RecipeItemDrag( RecipeListItem *recipeItem, TQWidget *dragSource = 0, const char *name = 0 );
	static bool canDecode( TQMimeSource* e );
	static bool decode( const TQMimeSource* e, RecipeListItem& item );
};

class RecipeListView : public StdCategoryListView
{
	TQ_OBJECT

public:
	RecipeListView( TQWidget *parent, RecipeDB *db );

public slots:
	void populateAll( TQListViewItem *parent = 0 );

protected slots:
	virtual void createRecipe( const Recipe &, int parent_id );
	virtual void createRecipe( const Element &recipe, const ElementList &categories );
	virtual void modifyRecipe( const Element &recipe, const ElementList &categories );
	virtual void removeRecipe( int );
	virtual void removeRecipe( int, int );

protected:
	virtual void init();
	virtual void createElement( TQListViewItem * );
	virtual void removeCategory( int id );
	virtual TQDragObject *dragObject();
	virtual bool acceptDrag( TQDropEvent *event ) const;
	virtual void populate( TQListViewItem *item );
	virtual TQString tooltip(TQListViewItem *item, int column) const;

	friend class RecipeListToolTip;

	void load(int limit, int offset);

private:
	void moveChildrenToRoot( TQListViewItem * );

	bool flat_list;
	TQListViewItem *m_uncat_item;
	TQListViewItem *lastElementCurrLevel;

	KProgressDialog *m_progress_dlg;
};

#endif //RECIPELISTVIEW_H