summaryrefslogtreecommitdiffstats
path: root/src/dialogs/dietwizarddialog.h
blob: c8486645016bd892b50b469fb19d92790a80f4ee (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
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
/***************************************************************************
*   Copyright (C) 2003 by                                                 *
*   Unai Garro ([email protected])                             *
*   Cyril Bosselut ([email protected])                               *
*   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 DIETWIZARDDIALOG_H
#define DIETWIZARDDIALOG_H

#include <stdlib.h> // For RAND_MAX

#include <tqcheckbox.h>
#include <tqhbox.h>
#include <tqhgroupbox.h>
#include <tqlabel.h>
#include <tqptrlist.h>
#include <tqpushbutton.h>
#include <tqslider.h>
#include <tqspinbox.h>
#include <tqtabwidget.h>
#include <tqtoolbutton.h>
#include <tqvaluelist.h>
#include <tqvbox.h>
#include <tqvgroupbox.h>
#include <tqwidgetstack.h>

#include <tdelistview.h>

#include "datablocks/constraintlist.h"
#include "datablocks/recipelist.h"
#include "datablocks/elementlist.h"
#include "datablocks/ingredientpropertylist.h"
#include "datablocks/recipe.h"
#include "datablocks/unitratiolist.h"

#include "widgets/dblistviewbase.h"

class KDoubleNumInput;

class DishInput;
class DishTitle;
class MealInput;
class RecipeDB;
class RecipeList;
class CategoryCheckListView;
class PropertyConstraintListView;

/**
@author Unai Garro
*/


class DietWizardDialog: public TQVBox
{

	TQ_OBJECT

public:

	DietWizardDialog( TQWidget *parent, RecipeDB* db );
	~DietWizardDialog();

private:
	//Private variables
	RecipeDB *database;

	int dayNumber;
	int mealNumber;

	RecipeList *dietRList;

	//Widgets
	TQHBox *optionsBox;
	TQVGroupBox *mealsSliderBox;
	TQLabel *mealNumberLabel;
	TQSlider *mealNumberSelector;
	TQVGroupBox *daysSliderBox;
	TQLabel *dayNumberLabel;
	TQSlider *dayNumberSelector;
	TQTabWidget *mealTabs;
	MealInput *mealTab; // points to the current tab
	TQPushButton *okButton;

	//Methods
	bool checkCategories( Recipe &rec, int meal, int dish );
	bool checkConstraints( Recipe &rec, int meal, int dish );
	bool checkLimits( IngredientPropertyList &properties, ConstraintList &constraints );
	void loadConstraints( int meal, int dish, ConstraintList *constraints ) const;
	void loadEnabledCategories( int meal, int dish, ElementList *categories );
	void newTab( const TQString &name );
	bool categoryFiltering( int meal, int dish ) const;
	int getNecessaryFlags() const;

public:
	//Methods
	void reload( ReloadFlags flags = Load );
	RecipeList& dietList( void );

private slots:
	void changeDayNumber( int dn );
	void changeMealNumber( int mn );
	void createDiet( void );
	void clear();
	void createShoppingList( void );
	void populateIteratorList( RecipeList &rl, TQValueList <RecipeList::Iterator> *il );
signals:
	void dietReady( void );
};

class MealInput: public TQWidget
{
	TQ_OBJECT

public:
	// Methods

	MealInput( TQWidget *parent, RecipeDB *database );
	~MealInput();
	void reload( ReloadFlags flag = Load );
	int dishNo( void )
	{
		return dishNumber;
	};
	void setDishNo( int dn );
	void showDish( int dn );

	// Public widgets and variables
	TQValueList <DishInput*> dishInputList; // The list of dishes

private:
	// Widgets
	// Private Variables
	int dishNumber;
	RecipeDB *database;

	// Settings section for the meal
	TQHBox *mealOptions;

	// Dish number setting
	TQHBox *dishNumberBox;
	TQLabel *dishNumberLabel;
	TQSpinBox *dishNumberInput;

	// Move <-> buttons
	TQHGroupBox *toolBar;
	TQToolButton *buttonNext;
	TQToolButton *buttonPrev;

	// Settings for the dish
	TQWidgetStack *dishStack;

public slots:
	void nextDish( void );
	void prevDish( void );

private slots:
	void changeDishNumber( int dn );

};

class DishInput: public TQWidget
{
	TQ_OBJECT

public:
	DishInput( TQWidget *parent, RecipeDB *database, const TQString &title );
	~DishInput();
	// Methods
	bool isCategoryFilteringEnabled( void ) const;
	void loadConstraints( ConstraintList *constraints ) const;
	void loadEnabledCategories( ElementList* categories );
	void reload( ReloadFlags flag = Load );
	void setDishTitle( const TQString & text );
	void clear();


private:
	// Variables
	bool categoryFiltering;
	// Widgets
	TQHGroupBox *listBox;
	DishTitle *dishTitle;
	TQVBox *categoriesBox;
	TQCheckBox *categoriesEnabledBox;
	CategoryCheckListView *categoriesView;
	PropertyConstraintListView *constraintsView;
	KDoubleNumInput *constraintsEditBox1;
	KDoubleNumInput *constraintsEditBox2;
	RecipeDB *database;

private slots:
	void enableCategories( bool enable );
	void insertConstraintsEditBoxes( TQListViewItem* it );
	void hideConstraintInputs();
	void setMinValue( double minValue );
	void setMaxValue( double maxValue );
};

class DishTitle: public TQWidget
{

	TQ_OBJECT

public:
	DishTitle( TQWidget *parent, const TQString &title );
	~DishTitle();
	virtual TQSize sizeHint () const;
	virtual TQSize minimumSizeHint() const;
protected:
	//Variables
	TQString titleText;
	//Methods
	virtual void paintEvent( TQPaintEvent *p );
};

#endif