forked from yvt/terravox
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheffectcontroller.cpp
More file actions
120 lines (98 loc) · 2.79 KB
/
effectcontroller.cpp
File metadata and controls
120 lines (98 loc) · 2.79 KB
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
#include "effectcontroller.h"
#include "effecteditor.h"
#include <QMessageBox>
#include <QApplication>
#include "terrain.h"
#include "terrainedit.h"
#include "session.h"
#include "emptytooleditor.h"
EffectController::EffectController(QObject *parent) :
ToolController(parent),
editor(nullptr),
session(nullptr)
{
}
EffectController::~EffectController()
{
}
QWidget *EffectController::createEditor(Session *session)
{
Q_ASSERT(!this->editor);
auto *innerEditor = createEffectEditor(session);
if (!innerEditor)
innerEditor = new EmptyToolEditor();
auto *editor = new EffectEditor(innerEditor);
connect(editor, SIGNAL(destroyed(QObject*)), SLOT(editorDestroyed(QObject*)));
connect(editor, SIGNAL(applyEffect()), SLOT(apply()));
connect(editor, SIGNAL(revertEffect()), SLOT(revert()));
this->session = session;
this->editor = editor;
Q_ASSERT(!previewEdit);
previewEdit = session->beginEdit();
preview();
return editor;
}
bool EffectController::leave(std::function<void (bool)> callback)
{
Q_ASSERT(editor);
QMessageBox *msgbox = new QMessageBox(
QMessageBox::NoIcon, QApplication::applicationName(), tr("Effect is being edited."),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, editor->window());
msgbox->setInformativeText(tr("Apply the effect?"));
msgbox->setWindowFlags(Qt::Sheet);
msgbox->setDefaultButton(QMessageBox::Save);
msgbox->show();
auto self = sharedFromThis();
connect(msgbox, &QMessageBox::finished, [this, msgbox, callback, self](int button) {
switch (button) {
case QMessageBox::Yes:
QApplication::setOverrideCursor(Qt::WaitCursor);
apply();
QApplication::restoreOverrideCursor();
callback(true);
break;
case QMessageBox::No:
QApplication::setOverrideCursor(Qt::WaitCursor);
revert();
QApplication::restoreOverrideCursor();
callback(true);
break;
case QMessageBox::Cancel:
callback(false);
break;
}
//msgbox->deleteLater();
});
return false;
}
void EffectController::preview()
{
Q_ASSERT(session);
applyEffect(session->terrain(), previewEdit, session);
}
void EffectController::apply()
{
Q_ASSERT(session);
Q_ASSERT(previewEdit);
preview();
session->endEdit();
previewEdit.reset();
emit applied();
emit done();
}
void EffectController::revert()
{
Q_ASSERT(session);
Q_ASSERT(previewEdit);
session->cancelEdit();
previewEdit.reset();
emit reverted();
emit done();
}
void EffectController::editorDestroyed(QObject *obj)
{
if (editor == obj) {
editor = nullptr;
session = nullptr;
}
}