summaryrefslogtreecommitdiffstats
path: root/kolf/editor.cpp
blob: ae9cde32b6bbf048f4f792fed58ee691be522048 (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
#include <kdialog.h>
#include <klistbox.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqwidget.h>
#include <tqframe.h>

#include "editor.h"
#include "game.h"

Editor::Editor(ObjectList *list, TQWidget *parent, const char *name)
	: TQWidget(parent, name)
{
	this->list = list;
	config = 0;

	hlayout = new TQHBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());

	TQVBoxLayout *vlayout = new TQVBoxLayout(hlayout, KDialog::spacingHint());
	vlayout->addWidget(new TQLabel(i18n("Add object:"), this));
	listbox = new KListBox(this, "Listbox");
	vlayout->addWidget(listbox);
	hlayout->setStretchFactor(vlayout, 2);

	TQStringList items;
	Object *obj = 0;
	for (obj = list->first(); obj; obj = list->next())
		items.append(obj->name());

	listbox->insertStringList(items);

	connect(listbox, TQT_SIGNAL(executed(TQListBoxItem *)), TQT_SLOT(listboxExecuted(TQListBoxItem *)));
}

void Editor::listboxExecuted(TQListBoxItem * /*item*/)
{
	int curItem = listbox->currentItem();
	if (curItem < 0)
		return;

	emit addNewItem(list->at(curItem));
}

void Editor::setItem(CanvasItem *item)
{
	delete config;
	config = item->config(this);
	if (!config)
		return;
	config->ctorDone();
	hlayout->addWidget(config);
	hlayout->setStretchFactor(config, 2);
	config->setFrameStyle(TQFrame::Box | TQFrame::Raised);
	config->setLineWidth(1);
	config->show();
	connect(config, TQT_SIGNAL(modified()), this, TQT_SIGNAL(changed()));
}

#include "editor.moc"