-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjectpopup.cpp
213 lines (183 loc) · 5.2 KB
/
objectpopup.cpp
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
#include "objectpopup.h"
#include "glsettings.h"
#include "object.h"
ObjectPopup::ObjectPopup(QWidget* parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
{
append = false;
//Object detail popup
//setup layouts/widgets
mainLayout = new QGridLayout;
nameLabel = new QLabel("Name/ID:");
instancesLabel = new QLabel("Instances:");
bufferLabel = new QLabel("Buffers:");
textureLabel = new QLabel("Texture:");
shaderLabel = new QLabel("Shader:");
fboLabel = new QLabel("FBO:");
nameBox = new QLineEdit;
instancesBox = new QSpinBox;
instancesBox->setMinimum(1);
instancesBox->setMaximum(999999);
instancesBox->setKeyboardTracking(false);
bufferBoxModel = new QStandardItemModel;
for(int i = 0; i < GLSettings::BufferList.size(); i++)
{
QStandardItem* item = new QStandardItem();
item->setText(GLSettings::BufferList.at(i)->bName);
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
bufferBoxModel->setItem(i, item);
itemList.push_back(item);
}
bufferBox = new QComboBox;
bufferBox->setModel(bufferBoxModel);
connect(bufferBoxModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(BuffersChanged(const QModelIndex&, const QModelIndex&)));
textureBox = new QComboBox;
textureBox->addItem("N/A");
for each (Texture *t in GLSettings::TextureList)
{
textureBox->addItem(t->Name());
}
shaderBox = new QComboBox;
for each (Shader *s in GLWidget::ShaderList)
{
shaderBox->addItem(s->name);
}
fboBox = new QComboBox;
fboBox->addItem("N/A");
for each (GLuint i in GLWidget::FBOList)
{
fboBox->addItem(QString::number(i));
}
buttons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
connect(buttons, SIGNAL(accepted()), this, SLOT(Save()));
connect(buttons, SIGNAL(rejected()), this, SLOT(close()));
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameBox, 0, 1);
mainLayout->addWidget(instancesLabel, 1, 0);
mainLayout->addWidget(instancesBox, 1, 1);
mainLayout->addWidget(bufferLabel, 2, 0);
mainLayout->addWidget(bufferBox, 2, 1);
mainLayout->addWidget(textureLabel, 3, 0);
mainLayout->addWidget(textureBox, 3, 1);
mainLayout->addWidget(shaderLabel, 4, 0);
mainLayout->addWidget(shaderBox, 4, 1);
mainLayout->addWidget(fboLabel, 5, 0);
mainLayout->addWidget(fboBox, 5, 1);
mainLayout->addWidget(buttons, 6, 1);
setLayout(mainLayout);
}
ObjectPopup::ObjectPopup(QWidget* parent, Object *o) : ObjectPopup(parent)
{
/*append = true;
appObj = o;
nameBox->setText(o->name);
instancesBox->setValue(o->instances);
buffers = o->buffers;
textureBox->setCurrentIndex((o->texture != nullptr) ? textureBox->findText(o->texture->Name()) : 0);
shaderBox->setCurrentIndex(shaderBox->findText(o->shader->name));
for each (QStandardItem *item in itemList)
{
for(int i = 0; i < buffers.size(); ++i)
{
if(item->text() == buffers.at(i)->bName)
{
item->setData(Qt::Checked, Qt::CheckStateRole);
}
}
}
fboBox->setCurrentIndex((o->FBO() != 0) ? fboBox->findText(QString::number(o->FBO())) : 0);*/
}
ObjectPopup::~ObjectPopup()
{
delete mainLayout;
}
bool ObjectPopup::Validation()
{
bool result = true;
if(nameBox->text().isEmpty())
{
nameBox->setStyleSheet("border: 2px solid red");
result = false;
}
else
{
nameBox->setStyleSheet("");
}
if(bufferIDs.empty())
{
bufferBox->setStyleSheet("border: 2px solid red");
result = false;
}
else
{
bufferBox->setStyleSheet("");
}
return result;
}
//Remove buffer if deleted
//or prevent buffer deletion if tied to object
void ObjectPopup::BuffersChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
std::cout << "Item " << topLeft.row() << " " << std::endl;
QStandardItem* item = itemList[topLeft.row()];
if(item->checkState() == Qt::Unchecked)
{
std::cout << "Unchecked!" << std::endl;
for(int i = 0; i < bufferIDs.size(); ++i)
{
if(bufferIDs.at(i) == item->row())
{
bufferIDs.erase(bufferIDs.begin() + i);
--i;
}
}
}
else if(item->checkState() == Qt::Checked)
{
std::cout << "Checked!" << std::endl;
/*for each(CUGLBuffer* b in GLSettings::BufferList)
{
if(b->bName == item->text())
{
bool dupe = false;
for(int i = 0; i < buffers.size(); ++i)
{
if(b == buffers.at(i))
dupe = true;
}
if(!dupe)
buffers.push_back(b);
}
}*/
bufferIDs.push_back(item->row());
}
}
void ObjectPopup::Save()
{
if(Validation())
{
QString name = nameBox->text();
int instances = instancesBox->value();
int texID = textureBox->currentIndex() - 1;
if(!append)
{
//change buffers to bufIDs
Object* o = new Object(name, instances, &bufferIDs, texID, shaderBox->currentIndex());
if(fboBox->currentIndex() != 0)
o->FBO(GLWidget::FBOList.at(fboBox->currentIndex() - 1)); //move to constructor
GLSettings::ObjectList.push_back(o);
static_cast<ObjectTab*>(parent())->AddToTable(o);
}
else
{
/*appObj->name = name;
appObj->instances = instances;
appObj->buffers = buffers;
appObj->texture = tex;
appObj->shader = GLWidget::ShaderList.at(shaderBox->currentIndex());
if(fboBox->currentIndex() != 0)
appObj->FBO(GLWidget::FBOList.at(fboBox->currentIndex() - 1));*/
}
close();
}
}