-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodecreationdialog.cpp
93 lines (72 loc) · 2.4 KB
/
nodecreationdialog.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
#include "nodecreationdialog.h"
#include "mixernode.h"
#include "vstnode.h"
#include "midiinputnode.h"
#include "core.h"
namespace En
{
NodeCreationDialog::NodeCreationDialog(NodeGroup* nodeGroup, QPointF pos, QWidget* parent)
: QDialog(parent, Qt::Tool)
, m_nodeGroup(nodeGroup)
, m_createdNode(0)
{
setWindowTitle("Create Node");
QHBoxLayout* layout = new QHBoxLayout(this);
NodeCreationWidget* creationWidget = new NodeCreationWidget(m_nodeGroup, pos, this);
QLabel* label = new QLabel(tr("Create Node:"));
layout->addWidget(label);
layout->addWidget(creationWidget);
connect(creationWidget, SIGNAL(nodeCreated(Node*)), SLOT(nodeCreated(Node*)));
//creationWidget->setFocus();
}
void NodeCreationDialog::nodeCreated(Node *newNode)
{
m_createdNode = newNode;
accept();
}
NodeCreationWidget::NodeCreationWidget(NodeGroup* nodeGroup, QPointF pos, QWidget* parent)
: QLineEdit(parent)
, m_nodeGroup(nodeGroup)
, m_pos(pos)
{
connect(this, SIGNAL(returnPressed()), SLOT(createNode()));
// TODO: escape handling
m_factories["Mixer"] = new MixerNode::Factory();
m_factories["MIDI Input"] = new MidiInputNode::Factory();
Core* core = Core::instance();
Q_FOREACH (QString name, core->vstInfoMap().keys()) {
m_factories[name] = new VstNode::Factory(name);
}
QCompleter* comp = new QCompleter(m_factories.keys(), this);
// argh, this disables the popup. lame.
//comp->setCompletionMode(QCompleter::InlineCompletion);
comp->setCaseSensitivity(Qt::CaseInsensitive);
setCompleter(comp);
}
NodeCreationWidget::~NodeCreationWidget()
{
Q_FOREACH (Node::Factory* factory, m_factories) {
delete factory;
}
}
void NodeCreationWidget::createNode()
{
QString name = this->text().trimmed();
// if there's exactly 1 item in the completion, just run with it. bit crappy, but useful.
if (completer()->completionCount() == 1) {
completer()->setCurrentRow(0);
name = completer()->currentCompletion();
}
//qDebug() << "Creating node for:" << name;
FactoryMap::Iterator it = m_factories.find(name);
if (it == m_factories.end()) {
//qDebug() << "nope";
// TODO: some kind of error feedback
return;
}
Node* node = it.value()->create(m_nodeGroup->host());
node->setPosition(m_pos);
m_nodeGroup->addNode(node);
emit nodeCreated(node);
}
}