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
|
/*
sidebar.h
This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include "sidebar.h"
#include "entitywidget.h"
namespace editor
{
SideBar::SideBar(QWidget *parent) : QWidget(parent)
{
// zone name
label_zone = new QLabel(tr("Zone Name"));
label_zone->setAlignment(Qt::AlignHCenter);
// entity type
label_entitytype = new QLabel(tr("[type]"));
label_entitytype->setAlignment(Qt::AlignHCenter);
// entity label
QHBoxLayout *box_entitylabel = new QHBoxLayout();
QLabel *label_entitylabel = new QLabel(tr("label"));
edit_entitylabel = new QLineEdit(tr("entity_label"));
box_entitylabel->addWidget(label_entitylabel);
box_entitylabel->addWidget(edit_entitylabel);
// entity name
QHBoxLayout *box_entityname = new QHBoxLayout();
QLabel *label_entityname = new QLabel(tr("name"));
edit_entityname = new QLineEdit(tr("Entity Name"));
box_entityname->addWidget(label_entityname);
box_entityname->addWidget(edit_entityname);
// entity location
QHBoxLayout *box_entitylocation = new QHBoxLayout();
QLabel *label_entitylocation = new QLabel(tr("location"));
edit_entitylocation_x = new QLineEdit(tr("x"));
edit_entitylocation_y = new QLineEdit(tr("y"));
edit_entitylocation_z = new QLineEdit(tr("z"));
box_entitylocation->addWidget(label_entitylocation);
box_entitylocation->addWidget(edit_entitylocation_x);
box_entitylocation->addWidget(edit_entitylocation_y);
box_entitylocation->addWidget(edit_entitylocation_z);
connect(edit_entitylocation_x, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationX(const QString &)));
connect(edit_entitylocation_y, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationY(const QString &)));
connect(edit_entitylocation_z, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationZ(const QString &)));
// entity properties
QLabel *label_entityproperties = new QLabel(tr("properties"));
text_entityproperties = new QTextEdit();
// entity info
QLabel *label_info = new QLabel(tr("info"));
text_info = new QTextEdit();
// entity subsections
QLabel *label_entitysubsections = new QLabel(tr("subsections"));
text_subsections = new QTextEdit();
// global vertical layout
QVBoxLayout *box_global = new QVBoxLayout();
box_global->addWidget(label_zone);
box_global->addSpacing(8);
box_global->addWidget(label_entitytype);
box_global->addLayout(box_entitylabel);
box_global->addLayout(box_entityname);
box_global->addLayout(box_entitylocation);
box_global->addWidget(label_entityproperties);
box_global->addWidget(text_entityproperties,1);
box_global->addWidget(label_info);
box_global->addWidget(text_info,1);
box_global->addWidget(label_entitysubsections);
box_global->addWidget(text_subsections,1);
setLayout(box_global);
setProperties(0);
}
void SideBar::updateEntityLocationX(const QString &value)
{
if (last_selected) {
bool ok;
float x = value.toFloat(&ok);
if (ok) {
last_selected->set_location(x, last_selected->location()[1], last_selected->location()[2]);
emit entityChanged();
}
}
}
void SideBar::updateEntityLocationY(const QString &value)
{
if (last_selected) {
bool ok;
float y = value.toFloat(&ok);
if (ok) {
last_selected->set_location(last_selected->location()[0], y, last_selected->location()[2]);
emit entityChanged();
}
}
}
void SideBar::updateEntityLocationZ(const QString &value)
{
if (last_selected) {
bool ok;
float z = value.toFloat(&ok);
if (ok) {
last_selected->set_location(last_selected->location()[0], last_selected->location()[1], z);
emit entityChanged();
}
}
}
void SideBar::setProperties(EntityProperties *properties)
{
last_selected = properties;
if (!properties) {
label_entitytype->clear();
edit_entitylabel->setEnabled(false);
edit_entitylabel->clear();
edit_entityname->setEnabled(false);
edit_entityname->clear();
edit_entitylocation_x->setEnabled(false);
edit_entitylocation_x->clear();
edit_entitylocation_y->setEnabled(false);
edit_entitylocation_y->clear();
edit_entitylocation_z->setEnabled(false);
edit_entitylocation_z->clear();
text_entityproperties->setEnabled(false);
text_entityproperties->clear();
text_subsections->setEnabled(false);
text_subsections->clear();
text_info->setEnabled(false);
text_info->clear();
} else {
QString value;
value = '[';
value += properties->type();
value += ']';
label_entitytype->setText(value);
edit_entitylabel->setEnabled(true);
edit_entitylabel->setText(properties->label());
edit_entityname->setEnabled(true);
edit_entityname->setText(properties->name());
edit_entitylocation_x->setEnabled(true);
value.setNum(properties->location()[0]);
edit_entitylocation_x->setText(value);
edit_entitylocation_y->setEnabled(true);
value.setNum(properties->location()[1]);
edit_entitylocation_y->setText(value);
edit_entitylocation_z->setEnabled(true);
value.setNum(properties->location()[2]);
edit_entitylocation_z->setText(value);
text_entityproperties->setEnabled(true);
text_entityproperties->setText(properties->values());
text_subsections->setEnabled(true);
text_subsections->setText(properties->subsections());
text_info->setEnabled(true);
text_info->setText(properties->info());
}
}
void SideBar::setZoneName(const QString &name)
{
label_zone->setText(name);
}
}
|