Compare commits
No commits in common. "186d64f28ec3dd015951b5497a8061eb43c610db" and "b80eb03f9d61f2de2c017fbb9173b8aebb2a528b" have entirely different histories.
186d64f28e
...
b80eb03f9d
7 changed files with 42 additions and 188 deletions
|
@ -73,7 +73,7 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 studPx = texture(studs, vec3(vTexCoords, vSurfaceZ));
|
vec4 studPx = texture(studs, vec3(vTexCoords, vSurfaceZ));
|
||||||
FragColor = vec4(mix(result, vec3(studPx), studPx.w), 1) * (1-transparency);
|
FragColor = vec4(mix(result, vec3(studPx), studPx.w), 1-transparency);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 calculateDirectionalLight(DirLight light) {
|
vec3 calculateDirectionalLight(DirLight light) {
|
||||||
|
|
|
@ -233,8 +233,6 @@ void renderHandles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2d square overlay
|
// 2d square overlay
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
identityShader->use();
|
identityShader->use();
|
||||||
identityShader->set("aColor", glm::vec3(0.f, 1.f, 1.f));
|
identityShader->set("aColor", glm::vec3(0.f, 1.f, 1.f));
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,6 @@
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <qglobal.h>
|
|
||||||
#include <qwindowdefs.h>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "editorcommon.h"
|
#include "editorcommon.h"
|
||||||
|
@ -24,8 +21,7 @@
|
||||||
#include "physics/simulation.h"
|
#include "physics/simulation.h"
|
||||||
#include "objects/part.h"
|
#include "objects/part.h"
|
||||||
#include "qfiledialog.h"
|
#include "qfiledialog.h"
|
||||||
#include "qclipboard.h"
|
#include "qitemselectionmodel.h"
|
||||||
#include "qmimedata.h"
|
|
||||||
#include "qobject.h"
|
#include "qobject.h"
|
||||||
#include "qsysinfo.h"
|
#include "qsysinfo.h"
|
||||||
|
|
||||||
|
@ -41,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
timer.start(33, this);
|
timer.start(33, this);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
ui->explorerView->buildContextMenu();
|
ConnectSelectionChangeHandler();
|
||||||
|
|
||||||
connect(ui->actionToolSelect, &QAction::triggered, this, [&]() { selectedTool = SelectedTool::SELECT; updateToolbars(); });
|
connect(ui->actionToolSelect, &QAction::triggered, this, [&]() { selectedTool = SelectedTool::SELECT; updateToolbars(); });
|
||||||
connect(ui->actionToolMove, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::MOVE : SelectedTool::SELECT; updateToolbars(); });
|
connect(ui->actionToolMove, &QAction::triggered, this, [&](bool state) { selectedTool = state ? SelectedTool::MOVE : SelectedTool::SELECT; updateToolbars(); });
|
||||||
|
@ -86,78 +82,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
delete ui->explorerView->selectionModel();
|
delete ui->explorerView->selectionModel();
|
||||||
ui->explorerView->reset();
|
ui->explorerView->reset();
|
||||||
ui->explorerView->setModel(new ExplorerModel(dataModel));
|
ui->explorerView->setModel(new ExplorerModel(dataModel));
|
||||||
});
|
ConnectSelectionChangeHandler();
|
||||||
|
|
||||||
connect(ui->actionDelete, &QAction::triggered, this, [&]() {
|
|
||||||
for (InstanceRefWeak inst : getSelection()) {
|
|
||||||
if (inst.expired()) continue;
|
|
||||||
inst.lock()->SetParent(std::nullopt);
|
|
||||||
}
|
|
||||||
setSelection(std::vector<InstanceRefWeak> {});
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->actionCopy, &QAction::triggered, this, [&]() {
|
|
||||||
pugi::xml_document rootDoc;
|
|
||||||
for (InstanceRefWeak inst : getSelection()) {
|
|
||||||
if (inst.expired()) continue;
|
|
||||||
inst.lock()->Serialize(&rootDoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostringstream encoded;
|
|
||||||
rootDoc.save(encoded);
|
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData;
|
|
||||||
mimeData->setData("application/xml", QByteArray::fromStdString(encoded.str()));
|
|
||||||
QApplication::clipboard()->setMimeData(mimeData);
|
|
||||||
});
|
|
||||||
connect(ui->actionCut, &QAction::triggered, this, [&]() {
|
|
||||||
pugi::xml_document rootDoc;
|
|
||||||
for (InstanceRefWeak inst : getSelection()) {
|
|
||||||
if (inst.expired()) continue;
|
|
||||||
inst.lock()->Serialize(&rootDoc);
|
|
||||||
inst.lock()->SetParent(std::nullopt);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostringstream encoded;
|
|
||||||
rootDoc.save(encoded);
|
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData;
|
|
||||||
mimeData->setData("application/xml", QByteArray::fromStdString(encoded.str()));
|
|
||||||
QApplication::clipboard()->setMimeData(mimeData);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->actionPaste, &QAction::triggered, this, [&]() {
|
|
||||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
|
||||||
if (!mimeData || !mimeData->hasFormat("application/xml")) return;
|
|
||||||
QByteArray bytes = mimeData->data("application/xml");
|
|
||||||
std::string encoded = bytes.toStdString();
|
|
||||||
|
|
||||||
pugi::xml_document rootDoc;
|
|
||||||
rootDoc.load_string(encoded.c_str());
|
|
||||||
|
|
||||||
for (pugi::xml_node instNode : rootDoc.children()) {
|
|
||||||
InstanceRef inst = Instance::Deserialize(&instNode);
|
|
||||||
workspace()->AddChild(inst);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->actionPasteInto, &QAction::triggered, this, [&]() {
|
|
||||||
if (getSelection().size() != 1 || getSelection()[0].expired()) return;
|
|
||||||
|
|
||||||
InstanceRef selectedParent = getSelection()[0].lock();
|
|
||||||
|
|
||||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
|
||||||
if (!mimeData || !mimeData->hasFormat("application/xml")) return;
|
|
||||||
QByteArray bytes = mimeData->data("application/xml");
|
|
||||||
std::string encoded = bytes.toStdString();
|
|
||||||
|
|
||||||
pugi::xml_document rootDoc;
|
|
||||||
rootDoc.load_string(encoded.c_str());
|
|
||||||
|
|
||||||
for (pugi::xml_node instNode : rootDoc.children()) {
|
|
||||||
InstanceRef inst = Instance::Deserialize(&instNode);
|
|
||||||
selectedParent->AddChild(inst);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update handles
|
// Update handles
|
||||||
|
@ -202,6 +127,17 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
syncPartPhysics(ui->mainWidget->lastPart);
|
syncPartPhysics(ui->mainWidget->lastPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::ConnectSelectionChangeHandler() {
|
||||||
|
// connect(ui->explorerView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [&](const QItemSelection &selected, const QItemSelection &deselected) {
|
||||||
|
// if (selected.count() == 0) return;
|
||||||
|
|
||||||
|
// std::optional<InstanceRef> inst = selected.count() == 0 ? std::nullopt
|
||||||
|
// : std::make_optional(((Instance*)selected.indexes()[0].internalPointer())->shared_from_this());
|
||||||
|
|
||||||
|
// ui->propertiesView->setSelected(inst);
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
static std::chrono::time_point lastTime = std::chrono::steady_clock::now();
|
static std::chrono::time_point lastTime = std::chrono::steady_clock::now();
|
||||||
void MainWindow::timerEvent(QTimerEvent* evt) {
|
void MainWindow::timerEvent(QTimerEvent* evt) {
|
||||||
if (evt->timerId() != timer.timerId()) {
|
if (evt->timerId() != timer.timerId()) {
|
||||||
|
|
|
@ -44,5 +44,6 @@ private:
|
||||||
|
|
||||||
void updateToolbars();
|
void updateToolbars();
|
||||||
void timerEvent(QTimerEvent*) override;
|
void timerEvent(QTimerEvent*) override;
|
||||||
|
void ConnectSelectionChangeHandler();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -115,12 +115,6 @@
|
||||||
<addaction name="actionToolScale"/>
|
<addaction name="actionToolScale"/>
|
||||||
<addaction name="actionToolRotate"/>
|
<addaction name="actionToolRotate"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionDelete"/>
|
|
||||||
<addaction name="actionCopy"/>
|
|
||||||
<addaction name="actionCut"/>
|
|
||||||
<addaction name="actionPaste"/>
|
|
||||||
<addaction name="actionPasteInto"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="actionGridSnap1"/>
|
<addaction name="actionGridSnap1"/>
|
||||||
<addaction name="actionGridSnap05"/>
|
<addaction name="actionGridSnap05"/>
|
||||||
<addaction name="actionGridSnapOff"/>
|
<addaction name="actionGridSnapOff"/>
|
||||||
|
@ -321,91 +315,6 @@
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionCopy">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="edit-copy"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Copy</string>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Copy objects to clipboard</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+C</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionCut">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="edit-cut"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Cut</string>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Cut objects into clipboard</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+X</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionPaste">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="edit-paste"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Paste</string>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Paste objects from clipboard</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+V</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionPasteInto">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="edit-paste"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Paste Into</string>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Paste objects from clipboard into selected object</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+Shift+V</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionDelete">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="edit-delete"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Delete Object</string>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Delete selected objects</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Del</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
#include "explorerview.h"
|
#include "explorerview.h"
|
||||||
#include "explorermodel.h"
|
#include "explorermodel.h"
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "../ui_mainwindow.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "objects/base/instance.h"
|
#include "objects/base/instance.h"
|
||||||
|
#include "objects/workspace.h"
|
||||||
#include "qabstractitemmodel.h"
|
#include "qabstractitemmodel.h"
|
||||||
#include <qaction.h>
|
#include "qaction.h"
|
||||||
#include <qnamespace.h>
|
#include "qnamespace.h"
|
||||||
#include <qitemselectionmodel.h>
|
#include <qitemselectionmodel.h>
|
||||||
|
|
||||||
#define M_mainWindow dynamic_cast<MainWindow*>(window())
|
|
||||||
|
|
||||||
ExplorerView::ExplorerView(QWidget* parent):
|
ExplorerView::ExplorerView(QWidget* parent):
|
||||||
QTreeView(parent),
|
QTreeView(parent),
|
||||||
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(dataModel))) {
|
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(dataModel))) {
|
||||||
|
@ -60,6 +57,8 @@ ExplorerView::ExplorerView(QWidget* parent):
|
||||||
this->selectionModel()->select(index, QItemSelectionModel::SelectionFlag::Select);
|
this->selectionModel()->select(index, QItemSelectionModel::SelectionFlag::Select);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
buildContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExplorerView::~ExplorerView() {
|
ExplorerView::~ExplorerView() {
|
||||||
|
@ -68,17 +67,19 @@ ExplorerView::~ExplorerView() {
|
||||||
void ExplorerView::keyPressEvent(QKeyEvent* event) {
|
void ExplorerView::keyPressEvent(QKeyEvent* event) {
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
case Qt::Key_Delete:
|
case Qt::Key_Delete:
|
||||||
M_mainWindow->ui->actionDelete->trigger();
|
actionDelete->trigger();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExplorerView::buildContextMenu() {
|
void ExplorerView::buildContextMenu() {
|
||||||
contextMenu.addAction(M_mainWindow->ui->actionDelete);
|
// This will leak memory. Anyway...
|
||||||
contextMenu.addSeparator();
|
contextMenu.addAction(this->actionDelete = new QAction(QIcon("assets/icons/editor/delete"), "Delete"));
|
||||||
contextMenu.addAction(M_mainWindow->ui->actionCopy);
|
|
||||||
contextMenu.addAction(M_mainWindow->ui->actionCut);
|
connect(actionDelete, &QAction::triggered, this, [&]() {
|
||||||
contextMenu.addAction(M_mainWindow->ui->actionPaste);
|
QModelIndexList selectedIndexes = this->selectionModel()->selectedIndexes();
|
||||||
contextMenu.addAction(M_mainWindow->ui->actionPasteInto);
|
for (QModelIndex index : selectedIndexes) {
|
||||||
|
model.fromIndex(index)->SetParent(std::nullopt);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
|
@ -20,9 +20,18 @@ public:
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent*) override;
|
void keyPressEvent(QKeyEvent*) override;
|
||||||
// void dropEvent(QDropEvent*) override;
|
// void dropEvent(QDropEvent*) override;
|
||||||
|
|
||||||
void buildContextMenu();
|
|
||||||
private:
|
private:
|
||||||
ExplorerModel model;
|
ExplorerModel model;
|
||||||
QMenu contextMenu;
|
QMenu contextMenu;
|
||||||
|
|
||||||
|
// TODO: Move these to a separate top-level namespace so these can be
|
||||||
|
// accessed from multiple locations
|
||||||
|
QAction* actionDelete;
|
||||||
|
QAction* actionCopy;
|
||||||
|
QAction* actionCut;
|
||||||
|
QAction* actionPaste;
|
||||||
|
QAction* actionPasteInto;
|
||||||
|
QAction* actionSelectChildren;
|
||||||
|
|
||||||
|
void buildContextMenu();
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue