]> Shamusworld >> Repos - warehouse-man-deluxe/blob - src/editorwindow.cpp
Added level editor.
[warehouse-man-deluxe] / src / editorwindow.cpp
1 //
2 // editorwindow.cpp: Game editor window
3 //
4 // by James Hammons
5 // (C) 2014 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  07/03/2014  Created this file
12 //
13
14 #include "editorwindow.h"
15 #include "editorwidget.h"
16
17
18 EditorWindow::EditorWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
19 {
20         list = new QListWidget;
21         up = new QPushButton("^");
22         down = new QPushButton("v");
23         add = new QPushButton("+");
24         remove = new QPushButton("-");
25         editor = new EditorWidget(parent);
26
27         list->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
28 //      editor->setFocus(); //DISNOWOK
29 //      editor->Load();
30
31         for(unsigned int i=0; i<editor->levelStorage.size(); i++)
32         {
33                 list->addItem(QString(editor->levelStorage[i].name));
34                 QListWidgetItem * item = list->item(i);
35                 item->setFlags(item->flags() | Qt::ItemIsEditable);
36         }
37
38         QHBoxLayout * buttonBox = new QHBoxLayout;
39         QVBoxLayout * listBox = new QVBoxLayout;
40         QHBoxLayout * mainBox = new QHBoxLayout;
41
42         buttonBox->addWidget(up);
43         buttonBox->addWidget(down);
44         buttonBox->addWidget(add);
45         buttonBox->addWidget(remove);
46
47         listBox->addWidget(list);
48         listBox->addLayout(buttonBox);
49
50         mainBox->addLayout(listBox);
51         mainBox->addWidget(editor);
52
53         setLayout(mainBox);
54         setWindowTitle("Editor");
55
56         connect(list, SIGNAL(currentRowChanged(int)), this, SLOT(SetEditorLevel(int)));
57         connect(list->itemDelegate(), SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), this, SLOT(SetNewName(QWidget *, QAbstractItemDelegate::EndEditHint)));
58 }
59
60
61 EditorWindow::~EditorWindow(void)
62 {
63 //      editor->Save();
64         delete editor;
65         delete up;
66         delete down;
67         delete add;
68         delete remove;
69         delete list;
70 }
71
72
73 void EditorWindow::SetEditorLevel(int level)
74 {
75         editor->currentLevel = level;
76         editor->update();
77 }
78
79
80 void EditorWindow::SetNewName(QWidget * widget, QAbstractItemDelegate::EndEditHint)
81 {
82         QString newName = reinterpret_cast<QLineEdit *>(widget)->text();
83         editor->SetNameOnCurrentLevel(newName.toAscii().data());
84 }
85