-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathluavalueedit.cpp
68 lines (60 loc) · 1.72 KB
/
luavalueedit.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
#include "luavalueedit.h"
#include "luaengine.h"
#include <QHBoxLayout>
#include <QHash>
#include <QPushButton>
#include <QVBoxLayout>
LuaValueEdit::LuaValueEdit(QWidget *parent) : QWidget(parent)
{
this->setupUI();
connect(gL, SIGNAL(LuaStateChange(QString, bool)), this, SLOT(onLuaStateChange(QString, bool)));
}
void LuaValueEdit::setupUI()
{
QVBoxLayout *main_layout = new QVBoxLayout();
this->m_editor = new QTextEdit();
main_layout->addWidget(this->m_editor);
main_layout->setMargin(0);
this->setLayout(main_layout);
connect(this->m_editor, SIGNAL(textChanged()), this, SLOT(onTextChangedEvent()));
}
void LuaValueEdit::saveConfig(QSettings &settings)
{
settings.setValue("gui/content", this->m_editor->toPlainText());
}
void LuaValueEdit::restoreConfig(QSettings &settings)
{
this->m_editor->setPlainText(settings.value("gui/content", "").toString());
}
void LuaValueEdit::onTextChangedEvent()
{
LuaEvent event;
event.Type = LuaEvent::EVENT_SET_TEXT;
event.ExtraType = LuaEvent::EXTRA_HASH;
QHash<QString, QString> res;
QString content = this->m_editor->toPlainText();
QStringList lines = content.split('\n', QString::SkipEmptyParts);
for (int i = 0; i < lines.size(); ++i)
{
QString line = lines.at(i);
if (line.contains('='))
{
QString key = line.left(line.indexOf('='));
QString value = line.mid(line.indexOf('=') + 1);
res.insert(key, value);
}
else
{
res.insert(line, line);
}
}
event.ExtraHash = res;
gL->putEvent(event);
}
void LuaValueEdit::onLuaStateChange(QString, bool isRunning)
{
if (isRunning)
{
this->onTextChangedEvent();
}
}