Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion modules/uikit/includes/editor/uiedit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef UIEDIT_H
#define UIEDIT_H

#include <QMenu>

#include <editor/asseteditor.h>

#include <pugixml.hpp>
Expand All @@ -21,6 +23,8 @@ class UiEdit : public AssetEditor {
UiEdit();
~UiEdit();

static TString propertyTag(const MetaProperty &property, const TString &tag);

private slots:
void onActivated() override;

Expand All @@ -35,12 +39,17 @@ private slots:
void onCopyAction() override;
void onPasteAction() override;

void onWidgetDelete();
void onWidgetDuplicate();

private:
void loadAsset(AssetConverterSettings *settings) override;
void saveAsset(const TString &path) override;

void changeEvent(QEvent *event) override;

QMenu *objectContextMenu(Object *object) override;

bool isCopyActionAvailable() const override;
bool isPasteActionAvailable() const override;

Expand All @@ -51,13 +60,15 @@ private slots:

void saveElementHelper(pugi::xml_node &parent, Widget *widget);

TString propertyTag(const MetaProperty &property, const TString &tag) const;
QAction *createAction(const QString &name, const char *member, bool single, const QKeySequence &shortcut = 0);

private:
std::map<TString, Widget *> m_widgets;

Ui::UiEdit *ui;

QMenu m_widgetMenu;

World *m_world;

Scene *m_scene;
Expand Down
77 changes: 2 additions & 75 deletions modules/uikit/includes/editor/widgetcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class WidgetController : public CameraController {

UndoStack *undoRedo() const { return m_editor->undoRedo(); }

static TString findFreeObjectName(const TString &name, Object *parent);

signals:
void sceneUpdated();
void objectsSelected(Object::ObjectList objects);
Expand Down Expand Up @@ -81,79 +83,4 @@ public slots:

};

class UndoObject : public UndoCommand {
public:
UndoObject(WidgetController *ctrl, const TString &name, UndoCommand *group = nullptr) :
UndoCommand(name, group),
m_controller(ctrl) {

}

protected:
WidgetController *m_controller;

};

class SelectObjects : public UndoObject {
public:
SelectObjects(const std::list<uint32_t> &objects, WidgetController *ctrl, const TString &name = QObject::tr("Selection Change").toStdString(), UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
std::list<uint32_t> m_objects;

};

class ChangeProperty : public UndoObject {
public:
ChangeProperty(const Object::ObjectList &objects, const TString &property, const Variant &value, WidgetController *ctrl, const TString &name, UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
TString m_property;
Variant m_value;
std::list<uint32_t> m_objects;

};

class CreateObject : public UndoObject {
public:
CreateObject(const TString &type, Scene *scene, WidgetController *ctrl, UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
std::list<uint32_t> m_objects;
TString m_type;

};

class DeleteObject : public UndoObject {
public:
DeleteObject(const Object::ObjectList &objects, WidgetController *ctrl, const TString &name = QObject::tr("Delete Widget").toStdString(), UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
VariantList m_dump;
std::list<uint32_t> m_objects;
std::list<uint32_t> m_indices;

};

class PasteObject : public UndoObject {
public:
PasteObject(WidgetController *ctrl, const TString &name = QObject::tr("Paste Widget").toStdString(), UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
Variant m_data;
std::unordered_map<uint32_t, uint32_t> m_uuidPairs;
uint32_t m_objectId;

};

#endif // WIDGETCONTROLLER_H
36 changes: 36 additions & 0 deletions modules/uikit/src/editor/actions/changeproperty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "changeproperty.h"

ChangeProperty::ChangeProperty(const Object::ObjectList &objects, const TString &property, const Variant &value, WidgetController *ctrl, const TString &name, UndoCommand *group) :
UndoCommand(name, group),
m_value(value),
m_property(property),
m_controller(ctrl) {

for(auto it : objects) {
m_objects.push_back(it->uuid());
}
}

void ChangeProperty::undo() {
ChangeProperty::redo();
}

void ChangeProperty::redo() {
std::list<Object *> objects;

Variant value(m_value);

for(auto it : m_objects) {
Object *object = Engine::findObject(it);
if(object) {
m_value = object->property(m_property.data());
object->setProperty(m_property.data(), value);

objects.push_back(object);
}
}

if(!objects.empty()) {
emit m_controller->propertyChanged(objects, m_property, value);
}
}
23 changes: 23 additions & 0 deletions modules/uikit/src/editor/actions/changeproperty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CHANGEPROPERTY_H
#define CHANGEPROPERTY_H

#include "../widgetcontroller.h"

class ChangeProperty : public UndoCommand {
public:
ChangeProperty(const Object::ObjectList &objects, const TString &property, const Variant &value, WidgetController *ctrl, const TString &name, UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
TString m_property;

Variant m_value;

std::list<uint32_t> m_objects;

WidgetController *m_controller;

};

#endif // CHANGEPROPERTY_H
50 changes: 50 additions & 0 deletions modules/uikit/src/editor/actions/createwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "createwidget.h"

#include <actor.h>
#include "components/widget.h"

CreateWidget::CreateWidget(const TString &type, Scene *scene, WidgetController *ctrl, UndoCommand *group) :
UndoCommand(TString("Create ") + type, group),
m_type(type),
m_controller(ctrl) {

}

void CreateWidget::undo() {
for(auto uuid : m_objects) {
Object *object = Engine::findObject(uuid);
if(object) {
delete object;
}
}

m_controller->clear(false);
m_controller->selectActors(m_selected);

emit m_controller->sceneUpdated();
}

void CreateWidget::redo() {
m_objects.clear();
m_selected.clear();

for(auto it : m_controller->selected()) {
m_selected.push_back(it->uuid());
}

Widget *root = m_controller->root();
Object *parent = root->actor();
if(!m_controller->selected().empty()) {
parent = m_controller->selected().front();
}

Object *object = Engine::composeActor(m_type, m_type, parent);
if(object) {
m_objects.push_back(object->uuid());
}

m_controller->clear(false);
m_controller->selectActors(m_objects);

emit m_controller->sceneUpdated();
}
22 changes: 22 additions & 0 deletions modules/uikit/src/editor/actions/createwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CREATEWIDGET_H
#define CREATEWIDGET_H

#include "../widgetcontroller.h"

class CreateWidget : public UndoCommand {
public:
CreateWidget(const TString &type, Scene *scene, WidgetController *ctrl, UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
std::list<uint32_t> m_objects;
std::list<uint32_t> m_selected;

TString m_type;

WidgetController *m_controller;

};

#endif // CREATEWIDGET_H
42 changes: 42 additions & 0 deletions modules/uikit/src/editor/actions/deletewiget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "deletewiget.h"

DeleteObject::DeleteObject(const Object::ObjectList &objects, WidgetController *ctrl, const TString &name, UndoCommand *group) :
UndoCommand(name, group),
m_controller(ctrl) {

for(auto it : objects) {
m_objects.push_back(it->uuid());
}
}

void DeleteObject::undo() {
m_objects.clear();

for(auto &ref : m_dump) {
Object *object = Engine::toObject(ref);
if(object) {
m_objects.push_back(object->uuid());
}
}

m_controller->clear(false);
m_controller->selectActors(m_objects);

emit m_controller->sceneUpdated();
}

void DeleteObject::redo() {
m_dump.clear();

for(auto it : m_objects) {
Object *object = Engine::findObject(it);
if(object) {
m_dump.push_back(Engine::toVariant(object));
delete object;
}
}

m_controller->clear(true);

emit m_controller->sceneUpdated();
}
21 changes: 21 additions & 0 deletions modules/uikit/src/editor/actions/deletewiget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef DELETEWIGET_H
#define DELETEWIGET_H

#include "../widgetcontroller.h"

class DeleteObject : public UndoCommand {
public:
DeleteObject(const Object::ObjectList &objects, WidgetController *ctrl, const TString &name = "Delete Widget", UndoCommand *group = nullptr);
void undo() override;
void redo() override;

protected:
VariantList m_dump;

std::list<uint32_t> m_objects;

WidgetController *m_controller;

};

#endif // DELETEWIGET_H
Loading
Loading