summaryrefslogtreecommitdiffstats
path: root/atlantikdesigner/designer/group.cpp
blob: 79b0205d2a25d525bef12155da4208b6f5d32c3e (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include <tqcombobox.h>
#include <tqframe.h>
#include <tqvgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqspinbox.h>
#include <tqstring.h>
#include <tqstringlist.h>

#include <kcolorbutton.h>
#include <kdebug.h>
#include <klineedit.h>
#include <klineeditdlg.h>
#include <klistbox.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <kseparator.h>

#include "group.h"

GroupEditor::GroupEditor(ConfigEstateGroupList *newList, TQWidget *parent)
	: KDialogBase(KDialogBase::Plain, i18n("Group Editor"), Ok|Apply|Cancel, Ok, parent, "Group Editor", false, true), mylist(*newList)
{
	setWFlags(WDestructiveClose);
	list = newList;

	TQFrame *page = plainPage();
	TQHBoxLayout *hlayout = new TQHBoxLayout(page, marginHint(), spacingHint());

	groups = new KListBox(page);
	hlayout->addWidget(groups);
	connect(groups, TQT_SIGNAL(highlighted(TQListBoxItem *)), this, TQT_SLOT(updateSettings(TQListBoxItem *)));
	TQStringList newgroups;
	for (ConfigEstateGroupList::Iterator it = list->begin(); it != list->end(); ++it)
		newgroups.append((*it).name());
	groups->insertStringList(newgroups);
	connect(groups, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged()));

	TQVBoxLayout *vlayout = new TQVBoxLayout(hlayout, spacingHint());
	colorGroupBox = new TQVGroupBox(i18n("&Colors"), page);
	vlayout->addWidget(colorGroupBox);

	(void) new TQLabel(i18n("Foreground:"), colorGroupBox);
	fgButton = new KColorButton(colorGroupBox, "Foreground Button");
	connect(fgButton, TQT_SIGNAL(changed(const TQColor &)), this, TQT_SLOT(fgChanged(const TQColor &)));
	connect(fgButton, TQT_SIGNAL(changed(const TQColor &)), this, TQT_SIGNAL(changed()));

	(void) new TQLabel(i18n("Background:"), colorGroupBox);
	bgButton = new KColorButton(colorGroupBox, "Background Button");
	connect(bgButton, TQT_SIGNAL(changed(const TQColor &)), this, TQT_SLOT(bgChanged(const TQColor &)));
	connect(bgButton, TQT_SIGNAL(changed(const TQColor &)), this, TQT_SIGNAL(changed()));

	pricesGroupBox = new TQVGroupBox(i18n("&Prices"), page);
	vlayout->addWidget(pricesGroupBox);

	pricesWidget = new TQWidget(pricesGroupBox);
	TQGridLayout *pricesLayout = new TQGridLayout(pricesWidget, 2, 2, 0, spacingHint());
	pricesLayout->addWidget(new TQLabel(i18n("House price:"), pricesWidget), 0, 0);
	pricesLayout->addWidget(housePrice = new TQSpinBox(0, 3000, 25, pricesWidget), 0, 1);
	housePrice->setSpecialValueText(i18n("None"));
	housePrice->setSuffix(i18n("$"));
	connect(housePrice, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(housePriceChanged(int)));

	pricesLayout->addWidget(new TQLabel(i18n("Global price:"), pricesWidget), 1, 0);
	pricesLayout->addWidget(globalPrice = new TQSpinBox(0, 3000, 25, pricesWidget), 1, 1);
	globalPrice->setSpecialValueText(i18n("None"));
	globalPrice->setSuffix(i18n("$"));
	connect(globalPrice, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(globalPriceChanged(int)));

	dynamicGroupBox = new TQVGroupBox(i18n("&Dynamic Rent"), page);
	vlayout->addWidget(dynamicGroupBox);

	mathWidget = new TQWidget(dynamicGroupBox);
	TQGridLayout *mathLayout = new TQGridLayout(mathWidget, 2, 2, 0, spacingHint());
	mathLayout->addWidget(new TQLabel(i18n("Add rent variable:"), mathWidget), 0, 0);
	mathLayout->addWidget(new TQLabel(i18n("Expression:"), mathWidget), 1, 0);

	TQComboBox *rentVarCombo = new TQComboBox(mathWidget);
	TQStringList vars;
	vars << "DICE";
	vars << "HOUSES";
	vars << "GROUPOWNED";
	rentVarCombo->insertStringList(vars);
	mathLayout->addWidget(rentVarCombo, 0, 1);

	rentMathEdit = new KLineEdit(mathWidget);
	connect(rentMathEdit, TQT_SIGNAL(textChanged(const TQString &)), this, TQT_SLOT(rentMathChanged(const TQString &)));
	connect(rentVarCombo, TQT_SIGNAL(activated(const TQString &)), rentMathEdit, TQT_SLOT(insert(const TQString &)));
	mathLayout->addWidget(rentMathEdit, 1, 1);

	TQHBoxLayout *buttonlayout = new TQHBoxLayout(vlayout, spacingHint());
	KPushButton *addB = new KPushButton(i18n("&Add..."), page);
	buttonlayout->addWidget(addB);
	connect(addB, TQT_SIGNAL(clicked()), this, TQT_SLOT(add()));

	removeB = new KPushButton(i18n("&Remove"), page);
	buttonlayout->addWidget(removeB);
	connect(removeB, TQT_SIGNAL(clicked()), this, TQT_SLOT(remove()));

	selectionChanged();
}

void GroupEditor::add()
{
	bool ok;
	TQString name = KLineEditDlg::getText(i18n("Add Group"), i18n("Enter the name of the new group:"), TQString(), &ok, this);
	if (ok)
	{
		for (ConfigEstateGroupList::Iterator it =  mylist.begin(); it != mylist.end(); ++it)
		{
			if ((*it).name() == name)
			{
				KMessageBox::information(this, i18n("That group is already on the list."));
				return;
			}
		}

		mylist.append(ConfigEstateGroup(name));
		groups->insertItem(name);

		emit changed();
	}
}

void GroupEditor::remove()
{
	TQString curText = groups->currentText();
	if (!curText.isNull())
	{
		groups->removeItem(groups->currentItem());
		for (ConfigEstateGroupList::Iterator it =  mylist.begin(); it != mylist.end(); ++it)
		{
			if ((*it).name() == curText)
			{
				mylist.remove(it);
				break;
			}
		}

		emit changed();
	}
}

void GroupEditor::updateSettings(TQListBoxItem *item)
{
	if (!mylist.size())
		return;

	if (!item)
		return;

	for (ConfigEstateGroupList::Iterator it =  mylist.begin(); it != mylist.end() ; ++it)
	{
		if ((*it).name() == item->text())
		{
			fgButton->setColor((*it).fgColor());
			bgButton->setColor((*it).bgColor());
			housePrice->setValue((*it).housePrice());
			globalPrice->setValue((*it).globalPrice());
			rentMathEdit->setText((*it).rentMath());
			break;
		}
	}
}

ConfigEstateGroup *GroupEditor::currentGroup()
{
	TQListBoxItem *item = groups->item(groups->currentItem());
	if (!item)
		return 0;

	for (ConfigEstateGroupList::Iterator it =  mylist.begin(); it != mylist.end(); ++it)
		if ((*it).name() == item->text())
			return &(*it);

	return 0;
}

void GroupEditor::fgChanged(const TQColor &color)
{
	ConfigEstateGroup *group = currentGroup();
	if (group)
		group->setFgColor(color);
}

void GroupEditor::bgChanged(const TQColor &color)
{
	ConfigEstateGroup *group = currentGroup();
	if (group)
		group->setBgColor(color);
}

void GroupEditor::housePriceChanged(int newValue)
{
	ConfigEstateGroup *group = currentGroup();
	if (group)
		group->setHousePrice(newValue);
}

void GroupEditor::globalPriceChanged(int newValue)
{
	ConfigEstateGroup *group = currentGroup();
	if (group)
		group->setGlobalPrice(newValue);
}

void GroupEditor::rentMathChanged(const TQString &newValue)
{
	ConfigEstateGroup *group = currentGroup();
	if (group)
	{
		group->setRentMath(newValue);
	}
}

void GroupEditor::slotApply()
{
	*list = mylist;

	KDialogBase::slotApply();

	emit update();
}

void GroupEditor::slotOk()
{
	slotApply();

	KDialogBase::slotOk();
}

void GroupEditor::selectionChanged()
{
	bool issel = groups->currentItem() >= 0;
	colorGroupBox->setEnabled(issel);
	pricesGroupBox->setEnabled(issel);
	dynamicGroupBox->setEnabled(issel);
	removeB->setEnabled(issel);
}

#include "group.moc"