summaryrefslogtreecommitdiffstats
path: root/krecipes/src/krecipesview.h
blob: 9b933e178e9e9ef1c547c498667af6266d679834 (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
/***************************************************************************
*   Copyright (C) 2003 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 KRECIPESVIEW_H
#define KRECIPESVIEW_H

#include <qbitmap.h>
#include <qbuttongroup.h>
#include <qevent.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtooltip.h>
#include <qhbox.h>
#include <qvaluelist.h>
#include <qvbox.h>
#include <qwidget.h>
#include <qwidgetstack.h>

#include <kiconloader.h>
#include <kpixmap.h>
#include <kpixmapeffect.h>
#include <kimageeffect.h>
#include <kparts/part.h>
#include <kstyle.h>
#include <ktextbrowser.h>

#include "importers/baseimporter.h"
#include "backends/recipedb.h"
#include "krecipesiface.h"

class AuthorsDialog;
class PrepMethodsDialog;
class CategoriesEditorDialog;
class DietWizardDialog;
class IngredientsDialog;
class Menu;
class KreMenu;
class KreMenuButton;
class IngredientMatcherDialog;
class PanelDeco;
class PropertiesDialog;
class QPainter;
class RecipeInputDialog;
class RecipeViewDialog;
class SelectRecipeDialog;
class ShoppingListDialog;
class UnitsDialog;
typedef QValueList <Menu>::Iterator MenuId;


/**
 * This is the main view class for Krecipes.  Most of the non-menu,
 * non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
 * here.
 *
 * This krecipes uses an HTML component as an example.
 *
 * @short Main view
 * @author Unai Garro <ugarro@users.sourceforge.net>
 * @version 0.4
 */


// Declarations



// Some constants
typedef enum KrePanel {SelectP = 0, ShoppingP, DietP, MatcherP, IngredientsP, PropertiesP, UnitsP, PrepMethodsP, CategoriesP, AuthorsP, RecipeEdit, RecipeView };


// Class KrecipesView
class KrecipesView : public QVBox, virtual public KrecipesIface
{
	Q_OBJECT
public:
	/**
	 * Default constructor
	 */
	KrecipesView( QWidget *parent );

	/**
	 * Destructor
	 */
	virtual ~KrecipesView();

	virtual DCOPRef currentDatabase() const;
	RecipeDB *database;

	/**
	 * Print this view to any medium -- paper or not
	 */
	void print();

	virtual void show ( void ); //Needed to make sure that the raise() is done after the construction of all the widgets, otherwise childEvent in the PanelDeco is called only _after_ the raise(), and can't be shown.

signals:
	/**
	 * Use this signal to change the content of the statusbar
	 */
	void signalChangeStatusbar( const QString& text );

	/**
	 * Use this signal to change the content of the caption
	 */
	void signalChangeCaption( const QString& text );

	void panelShown( KrePanel, bool );


public:

	// public widgets
	RecipeInputDialog *inputPanel;
	RecipeViewDialog *viewPanel;
	SelectRecipeDialog *selectPanel;
	IngredientsDialog *ingredientsPanel;
	PropertiesDialog *propertiesPanel;
	UnitsDialog* unitsPanel;
	ShoppingListDialog* shoppingListPanel;
	DietWizardDialog* dietPanel;
	CategoriesEditorDialog *categoriesPanel;
	AuthorsDialog *authorsPanel;
	PrepMethodsDialog *prepMethodsPanel;
	IngredientMatcherDialog *ingredientMatcherPanel;

	// public methods
	void createNewRecipe( void );
	void createNewElement( void );

	void exportRecipes( const QValueList<int> &ids );

private:

	// Internal methods
	QString checkCorrectDBType( KConfig *config );
	void initializeData( const QString &host, const QString &dbName, const QString &user, const QString &pass, int port );
	void initDatabase( KConfig *config );
	bool questionRerunWizard( const QString &message, const QString &error = "" );
	void setupUserPermissions( const QString &host, const QString &client, const QString &dbName, const QString &newUser, const QString &newPass, const QString &adminUser = QString::null, const QString &adminPass = QString::null, int port = 0 );
	void wizard( bool force = false );



	// Widgets
	QHBox *splitter;
	KreMenu *leftPanel;
	MenuId dataMenu;
	PanelDeco *rightPanel;
	QPtrList<KreMenuButton> *buttonsList;
	KreMenuButton *button0;
	KreMenuButton *button1;
	KreMenuButton *button2;
	KreMenuButton *button3;
	KreMenuButton *button4;
	KreMenuButton *button5;
	KreMenuButton *button6;
	KreMenuButton *button7;
	KreMenuButton *button8;
	KreMenuButton *button9;
	QPushButton* contextButton;

	KreMenuButton *recipeButton;
	QWidget *recipeWidget;

	// Internal variables
	QString dbType;
	KrePanel m_activePanel;

	QMap<QWidget*, KrePanel> panelMap;

	// i18n
	void translate();


signals:
	void enableSaveOption( bool en );
	void recipeSelected( bool );

public slots:
	bool save( void );
	void exportRecipe();
	void exportToClipboard();
	void reloadDisplay();
	virtual void reload();
	void activateContextHelp();

private slots:
	void actionRecipe( int recipeID, int action );
	void actionRecipes( const QValueList<int> &ids, int action );
	void addRecipeButton( QWidget *w, const QString &title );
	void closeRecipe( void );
	void showRecipe( int recipeID );
	void showRecipes( const QValueList<int> &recipeIDs );
	void slotSetTitle( const QString& title );
	void slotSetPanel( KrePanel );
	void switchToRecipe( void );
	void createShoppingListFromDiet( void );
	void moveTipButton( int, int );
	void resizeRightPane( int lpw, int lph );
	void panelRaised( QWidget *w, QWidget *old_w );
	void editRecipe();
};


#endif // KRECIPESVIEW_H