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
|
/***************************************************************************
* Copyright (C) 2003 by *
* 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 INGREDIENTMATCHERDIALOG_H
#define INGREDIENTMATCHERDIALOG_H
#include "datablocks/element.h"
#include "datablocks/ingredientlist.h"
#include "datablocks/recipe.h"
#include "widgets/recipelistview.h"
#include "widgets/dblistviewbase.h"
#include <tqfontmetrics.h>
#include <tqlabel.h>
#include <tqlistview.h>
#include <tqpushbutton.h>
#include <tqhbox.h>
#include <tqvbox.h>
#include <kstringhandler.h>
#include <tdelocale.h>
class KreListView;
class KIntSpinBox;
class RecipeDB;
class MixedNumber;
/**
@author Unai Garro
*/
class CustomRecipeListItem : public RecipeListItem
{
public:
CustomRecipeListItem( TQListView* qlv, const Recipe &r, const IngredientList &il ) : RecipeListItem( qlv, r )
{
ingredientListStored = new TQStringList();
IngredientList::ConstIterator ili;
for ( ili = il.begin();ili != il.end();++ili ) {
if ( (*ili).substitutes.count() > 0 ) {
TQStringList subs;
subs << ( *ili ).name;
for ( TQValueList<IngredientData>::const_iterator it = (*ili).substitutes.begin(); it != (*ili).substitutes.end(); ++it ) {
subs << (*it).name;
}
ingredientListStored->append( subs.join(TQString(" %1 ").arg(i18n("OR"))) );
}
else
ingredientListStored->append( ( *ili ).name );
}
moveItem( qlv->lastItem() );
}
CustomRecipeListItem( TQListView* qlv, const Recipe &r ) : RecipeListItem( qlv, r )
{
ingredientListStored = 0;
moveItem( qlv->lastItem() );
}
~CustomRecipeListItem( void )
{
delete ingredientListStored;
}
private:
TQStringList *ingredientListStored;
public:
virtual TQString text( int column ) const
{
if ( column == 2 && ingredientListStored )
return ingredientListStored->join ( "," );
else
return ( RecipeListItem::text( column ) );
}
};
class SectionItem: public TQListViewItem
{
public:
SectionItem( TQListView* qlv, TQString sectionText ) : TQListViewItem( qlv, qlv->lastItem() )
{
mText = sectionText;
}
~SectionItem( void )
{}
virtual void paintCell ( TQPainter * p, const TQColorGroup & cg, int column, int width, int align );
private:
TQString mText;
public:
virtual TQString text( int column ) const
{
if ( column == 0 )
return ( mText );
else
return ( TQString::null );
}
};
class IngredientMatcherDialog: public TQWidget
{
TQ_OBJECT
public:
IngredientMatcherDialog( TQWidget *parent, RecipeDB* db );
~IngredientMatcherDialog();
void reload( ReloadFlags flag = Load );
signals:
void recipeSelected( int, int );
private:
//Private variables
RecipeDB *database;
//Widgets
KreListView *allIngListView;
KreListView *ingListView;
KreListView *recipeListView;
TQHBox *missingBox;
TQLabel *missingNumberLabel;
KIntSpinBox *missingNumberSpinBox;
TQPushButton *okButton;
TQPushButton *clearButton;
TQPushButton *addButton;
TQPushButton *removeButton;
IngredientList m_ingredientList;
TQMap<TQListViewItem*, IngredientList::iterator> m_item_ing_map;
private slots:
void findRecipes( void );
void unselectIngredients();
void addIngredient();
void removeIngredient();
void itemRenamed( TQListViewItem*, const TQPoint &, int col );
};
#endif
|