summaryrefslogtreecommitdiffstats
path: root/src/dialogs/recipeinputdialog.h
blob: dd9a623309184d09eef4ad110ed4e0b3080de3da (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
223
224
225
226
227
228
/***************************************************************************
*   Copyright (C) 2003-2005 by                                            *
*   Unai Garro (ugarro@users.sourceforge.net)                             *
*   Cyril Bosselut (bosselut@b1project.com)                               *
*   Jason Kivlighn (jkivlighn@gmail.com)                                  *
*                                                                         *
*   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 RECIPEINPUTDIALOG_H
#define RECIPEINPUTDIALOG_H

#include <kdialog.h>
#include <ktextedit.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <tdelistview.h>
#include <knuminput.h>
#include <kpushbutton.h>
#include <kiconloader.h>
#include <kled.h>

#include <tqlabel.h>
#include <tqgroupbox.h>
#include <tqmap.h>
#include <tqobject.h>
#include <tqtabwidget.h>
#include <tqtoolbutton.h>
#include <tqvbox.h>

#include "datablocks/elementlist.h"

class TQTabWidget;
class TQTimeEdit;
class TQDragEvent;
class TQButtonGroup;
class TQWidgetStack;
class TQTextEdit;

class KreTextEdit;
class KWidgetListbox;
class KDialogBase;

class ImageDropLabel;
class Recipe;
class ElementList;
class RecipeDB;
class FractionInput;
class Ingredient;
class Rating;
class RatingDisplayWidget;
class IngredientInputWidget;
class ClickableLed;

/**
@author Unai Garro
*/
class RecipeInputDialog: public TQVBox
{
	TQ_OBJECT

public:

	RecipeInputDialog( TQWidget* parent, RecipeDB* db );
	void loadRecipe( int recipeID );
	~RecipeInputDialog();
	void newRecipe( void );
	bool everythingSaved();
	void reload( void );
	int loadedRecipeID() const;

private:

	// Internal Data
	Recipe *loadedRecipe; //Loaded Recipe
	RecipeDB *database;
	bool changedSignalEnabled;
	bool unsavedChanges;

	// Widgets
	TQTabWidget* tabWidget;
	TQGroupBox* recipeTab;
	TQGroupBox* instructionsTab;

	//Recipe Photo
	ImageDropLabel *photoLabel;
	TQPixmap sourcePhoto;
	TQPushButton *changePhotoButton;

	//Recipe Body
	KreTextEdit* instructionsEdit;
	TQLabel* titleLabel;
	KLineEdit* titleEdit;

	//Additional recipe data
	TQLabel* yieldLabel;
	FractionInput* yieldNumInput;
	KLineEdit* yieldTypeEdit;
	TQTimeEdit *prepTimeEdit;
	TQLabel* authorLabel;
	KLineEdit* authorShow;
	TQPushButton* addAuthorButton;
	TQLabel* categoryLabel;
	KLineEdit* categoryShow;
	TQPushButton* addCategoryButton;

	//Ingredient inputs
	TDEListView* ingredientList;
	TQGroupBox *ingredientGBox;
	IngredientInputWidget *ingInput;
	ClickableLed *propertyStatusLed;
	TQLabel *propertyStatusLabel;
	TQPushButton *propertyStatusButton;
	TQTextEdit *statusTextView;
	KDialogBase *propertyStatusDialog;

	// Buttons to move ingredients up & down...
	KPushButton* upButton;
	KPushButton* downButton;
	KPushButton* removeButton;
	KPushButton* addButton;
	KPushButton* ingParserButton;

	//Function buttons
	TQGroupBox* functionsBox;
	TQToolButton* saveButton;
	TQToolButton* closeButton;
	TQToolButton* showButton;
	TQToolButton* resizeButton;

	TQToolButton* spellCheckButton;

	KWidgetListbox *ratingListDisplayWidget;

	TQMap<int,TQString> propertyStatusMapRed;
	TQMap<int,TQString> propertyStatusMapYellow;

	// Internal functions
	int createNewYieldIfNecessary( const TQString &yield );
	void saveRecipe( void );
	void showCategories( void );
	void showAuthors( void );
	int ingItemIndex( TQListView *listview, const TQListViewItem *item ) const;
	void addRating( const Rating &rating, RatingDisplayWidget *item );
	TQString statusMessage() const;
	TQString conversionPath( const TQString &ingUnit, const TQString &toUnit, const TQString &fromUnit, const TQString &propUnit ) const;

	// Signals & Slots

private slots:
	void changePhoto( void );
	void clearPhoto( void );
	void moveIngredientUp( void );
	void moveIngredientDown( void );
	void removeIngredient( void );
	void syncListView( TQListViewItem* it, const TQString &new_text, int col );
	void recipeChanged( void );
	void recipeChanged( const TQString &t );
	void enableChangedSignal( bool en = true );
	void addCategory( void );
	void addAuthor( void );
	void enableSaveButton( bool enabled );
	void closeOptions( void );
	void showRecipe( void );
	void prepTitleChanged( const TQString &title );
	void recipeRemoved( int id );
	void slotIngredientParser();
	void slotAddRating();
	void slotEditRating();
	void slotRemoveRating();
	void addIngredient( const Ingredient &ing, bool noHeader = false );
	void addIngredientHeader( const Element &header );
	void updatePropertyStatus();
	void updatePropertyStatus( const Ingredient &ing, bool updateIndicator );
	void showStatusIndicator();

public slots:
	bool save ( void ); // Activated when krecipes.cpp sends signal save()
	void spellCheck( void );
	void resizeRecipe( void );

signals:
	void changed( void );
	void closeRecipe( void );
	void createButton( TQWidget* w, const TQString &title );
	void enableSaveOption( bool en = true );
	void showRecipe( int recipeID ); //Indicates krecipesview to show it
	void titleChanged( const TQString &title );


};

class ClickableLed : public KLed
{
TQ_OBJECT

public:
	ClickableLed( TQWidget *parent );

protected:
	virtual void mouseReleaseEvent( TQMouseEvent* );

signals:
	void clicked();
};

class ImageDropLabel : public TQLabel
{
	TQ_OBJECT

public:
	ImageDropLabel( TQWidget *parent, TQPixmap &_sourcePhoto );

signals:
	void changed();

protected:
	void dragEnterEvent( TQDragEnterEvent* event );
	void dropEvent( TQDropEvent* event );

private:
	TQPixmap &sourcePhoto;
};

#endif