1 | /* |
2 | Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu> |
3 | Copyright 2010 Stefan Majewsky <majewsky@gmx.net> |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #include "editor.h" |
21 | #include "game.h" |
22 | #include "itemfactory.h" |
23 | |
24 | #include <QBoxLayout> |
25 | #include <QLabel> |
26 | #include <KDialog> |
27 | #include <KListWidget> |
28 | |
29 | Editor::Editor(const Kolf::ItemFactory& factory, QWidget *parent) |
30 | : QWidget(parent) |
31 | , m_factory(factory) |
32 | { |
33 | config = 0; |
34 | |
35 | hlayout = new QHBoxLayout(this); |
36 | hlayout->setMargin( KDialog::marginHint() ); |
37 | hlayout->setSpacing( KDialog::spacingHint() ); |
38 | |
39 | QVBoxLayout *vlayout = new QVBoxLayout; |
40 | vlayout->setSpacing( KDialog::spacingHint() ); |
41 | hlayout->addLayout( vlayout ); |
42 | vlayout->addWidget(new QLabel(i18n("Add object:" ), this)); |
43 | m_typeList = new KListWidget(this); |
44 | vlayout->addWidget(m_typeList); |
45 | hlayout->setStretchFactor(vlayout, 2); |
46 | |
47 | //populate type list |
48 | foreach (const Kolf::ItemMetadata& metadata, factory.knownTypes()) |
49 | { |
50 | QListWidgetItem* item = new QListWidgetItem(metadata.name); |
51 | item->setData(Qt::UserRole, metadata.identifier); |
52 | m_typeList->addItem(item); |
53 | } |
54 | connect(m_typeList, SIGNAL(executed(QListWidgetItem*)), SLOT(listboxExecuted(QListWidgetItem*))); |
55 | } |
56 | |
57 | void Editor::listboxExecuted(QListWidgetItem* item) |
58 | { |
59 | emit addNewItem(item->data(Qt::UserRole).toString()); //data(UserRole) contains the type identifier |
60 | } |
61 | |
62 | void Editor::setItem(CanvasItem *item) |
63 | { |
64 | delete config; |
65 | config = item->config(this); |
66 | if (!config) |
67 | return; |
68 | config->ctorDone(); |
69 | hlayout->addWidget(config); |
70 | hlayout->setStretchFactor(config, 2); |
71 | config->setFrameStyle(QFrame::Box | QFrame::Raised); |
72 | config->setLineWidth(1); |
73 | config->show(); |
74 | connect(config, SIGNAL(modified()), this, SIGNAL(changed())); |
75 | } |
76 | |
77 | #include "editor.moc" |
78 | |