diff --git a/src/editor/dialogs/objectpropertiesdialog.cpp b/src/editor/dialogs/objectpropertiesdialog.cpp index 9258639..ed1fae6 100644 --- a/src/editor/dialogs/objectpropertiesdialog.cpp +++ b/src/editor/dialogs/objectpropertiesdialog.cpp @@ -7,15 +7,17 @@ #include +#include "mainwindow.h" #include "models/projecttreemodel.h" #include "models/objecteventsmodel.h" #include "addeventdialog.h" -ObjectPropertiesDialog::ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, QWidget *parent) : - QDialog{parent}, +ObjectPropertiesDialog::ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, MainWindow *mainWindow) : + QDialog{mainWindow}, m_ui{std::make_unique()}, m_object{object}, m_projectModel{projectModel}, + m_mainWindow{mainWindow}, m_events{m_object.events}, m_eventsModel{std::make_unique(m_events)}, m_menuSprites{new QMenu{this}}, @@ -177,7 +179,22 @@ void ObjectPropertiesDialog::newSprite() void ObjectPropertiesDialog::editSprite() { - QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented")); + if (!m_mainWindow) + { + qCritical() << "no mainWindow available"; + return; + } + + auto &sprites = m_projectModel.project()->sprites; + const auto iter = std::find_if(std::begin(sprites), std::end(sprites), + [&](const Sprite &sprite){ return sprite.name == m_spriteName; }); + if (iter == std::end(sprites)) + { + qCritical() << "sprite" << m_spriteName << "not found"; + return; + } + + m_mainWindow->openPropertiesWindowFor(*iter); } void ObjectPropertiesDialog::showInformation() diff --git a/src/editor/dialogs/objectpropertiesdialog.h b/src/editor/dialogs/objectpropertiesdialog.h index 031a377..8f6fc61 100644 --- a/src/editor/dialogs/objectpropertiesdialog.h +++ b/src/editor/dialogs/objectpropertiesdialog.h @@ -11,13 +11,14 @@ class QMenu; namespace Ui { class ObjectPropertiesDialog; } class ProjectTreeModel; class ObjectEventsModel; +class MainWindow; class ObjectPropertiesDialog : public QDialog { Q_OBJECT public: - explicit ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, QWidget *parent = nullptr); + explicit ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, MainWindow *mainWindow); ~ObjectPropertiesDialog(); void accept() override; @@ -56,6 +57,7 @@ private: Object &m_object; ProjectTreeModel &m_projectModel; + MainWindow * const m_mainWindow; Object::events_container_t m_events; diff --git a/src/editor/mainwindow.cpp b/src/editor/mainwindow.cpp index d7010c5..c4f7c66 100644 --- a/src/editor/mainwindow.cpp +++ b/src/editor/mainwindow.cpp @@ -165,6 +165,62 @@ MainWindow::MainWindow(const QString &filePath, QWidget *parent) : loadFile(m_filePath); } +template +void MainWindow::openPropertiesWindowFor(T &entry) +{ + auto &propertyWindows = propertyWindowsFor(); + if (const auto iter = propertyWindows.find(&entry); iter != std::cend(propertyWindows)) + { + m_ui->mdiArea->setActiveSubWindow(iter->second); + return; + } + + auto dialog = new PropertiesDialogFor{entry, *m_projectTreeModel, this}; + auto subwindow = m_ui->mdiArea->addSubWindow(dialog); + auto action = m_ui->menuWindow->addAction(dialog->windowTitle()); + m_actionGroupWindows->addAction(action); + action->setCheckable(true); + connect(action, &QAction::triggered, + m_ui->mdiArea, [mdiArea=m_ui->mdiArea,subwindow,action](){ + mdiArea->setActiveSubWindow(subwindow); + action->setChecked(subwindow->windowState().testFlag(Qt::WindowActive)); + }); + connect(subwindow, &QMdiSubWindow::windowStateChanged, + action, [action](Qt::WindowStates oldState, Qt::WindowStates newState){ + Q_UNUSED(oldState) + action->setChecked(newState.testFlag(Qt::WindowActive)); + }); + connect(dialog, &QWidget::windowTitleChanged, action, &QAction::setText); + connect(dialog, &QDialog::finished, + this, [this,&propertyWindows,subwindow](int result){ + if (result == QDialog::Accepted) + changed(); + for (auto iter = std::begin(propertyWindows); iter != std::end(propertyWindows); ) + { + if (iter->second == subwindow) + iter = propertyWindows.erase(iter); + else + iter++; + } + }); + connect(dialog, &QDialog::finished, + subwindow, &QObject::deleteLater); + connect(dialog, &QDialog::finished, + action, &QObject::deleteLater); + propertyWindows[&entry] = subwindow; + dialog->show(); +} + +template void MainWindow::openPropertiesWindowFor(Sprite &entry); +template void MainWindow::openPropertiesWindowFor(Sound &entry); +template void MainWindow::openPropertiesWindowFor(Background &entry); +template void MainWindow::openPropertiesWindowFor(Path &entry); +template void MainWindow::openPropertiesWindowFor