Implemented edit sprite button in object properties dialog
This commit is contained in:
@@ -7,15 +7,17 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "models/projecttreemodel.h"
|
#include "models/projecttreemodel.h"
|
||||||
#include "models/objecteventsmodel.h"
|
#include "models/objecteventsmodel.h"
|
||||||
#include "addeventdialog.h"
|
#include "addeventdialog.h"
|
||||||
|
|
||||||
ObjectPropertiesDialog::ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, QWidget *parent) :
|
ObjectPropertiesDialog::ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, MainWindow *mainWindow) :
|
||||||
QDialog{parent},
|
QDialog{mainWindow},
|
||||||
m_ui{std::make_unique<Ui::ObjectPropertiesDialog>()},
|
m_ui{std::make_unique<Ui::ObjectPropertiesDialog>()},
|
||||||
m_object{object},
|
m_object{object},
|
||||||
m_projectModel{projectModel},
|
m_projectModel{projectModel},
|
||||||
|
m_mainWindow{mainWindow},
|
||||||
m_events{m_object.events},
|
m_events{m_object.events},
|
||||||
m_eventsModel{std::make_unique<ObjectEventsModel>(m_events)},
|
m_eventsModel{std::make_unique<ObjectEventsModel>(m_events)},
|
||||||
m_menuSprites{new QMenu{this}},
|
m_menuSprites{new QMenu{this}},
|
||||||
@@ -177,7 +179,22 @@ void ObjectPropertiesDialog::newSprite()
|
|||||||
|
|
||||||
void ObjectPropertiesDialog::editSprite()
|
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()
|
void ObjectPropertiesDialog::showInformation()
|
||||||
|
@@ -11,13 +11,14 @@ class QMenu;
|
|||||||
namespace Ui { class ObjectPropertiesDialog; }
|
namespace Ui { class ObjectPropertiesDialog; }
|
||||||
class ProjectTreeModel;
|
class ProjectTreeModel;
|
||||||
class ObjectEventsModel;
|
class ObjectEventsModel;
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
class ObjectPropertiesDialog : public QDialog
|
class ObjectPropertiesDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
explicit ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, MainWindow *mainWindow);
|
||||||
~ObjectPropertiesDialog();
|
~ObjectPropertiesDialog();
|
||||||
|
|
||||||
void accept() override;
|
void accept() override;
|
||||||
@@ -56,6 +57,7 @@ private:
|
|||||||
|
|
||||||
Object &m_object;
|
Object &m_object;
|
||||||
ProjectTreeModel &m_projectModel;
|
ProjectTreeModel &m_projectModel;
|
||||||
|
MainWindow * const m_mainWindow;
|
||||||
|
|
||||||
Object::events_container_t m_events;
|
Object::events_container_t m_events;
|
||||||
|
|
||||||
|
@@ -165,6 +165,62 @@ MainWindow::MainWindow(const QString &filePath, QWidget *parent) :
|
|||||||
loadFile(m_filePath);
|
loadFile(m_filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void MainWindow::openPropertiesWindowFor(T &entry)
|
||||||
|
{
|
||||||
|
auto &propertyWindows = propertyWindowsFor<T>();
|
||||||
|
if (const auto iter = propertyWindows.find(&entry); iter != std::cend(propertyWindows))
|
||||||
|
{
|
||||||
|
m_ui->mdiArea->setActiveSubWindow(iter->second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dialog = new PropertiesDialogFor<T>{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>(Sprite &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Sound>(Sound &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Background>(Background &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Path>(Path &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Script>(Script &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Font>(Font &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<TimeLine>(TimeLine &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Object>(Object &entry);
|
||||||
|
template void MainWindow::openPropertiesWindowFor<Room>(Room &entry);
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
m_ui->mdiArea->closeAllSubWindows();
|
m_ui->mdiArea->closeAllSubWindows();
|
||||||
@@ -871,48 +927,7 @@ bool MainWindow::doubleClickedFor(const QModelIndex &index)
|
|||||||
if (!entry)
|
if (!entry)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto &propertyWindows = propertyWindowsFor<T>();
|
openPropertiesWindowFor(*entry);
|
||||||
if (const auto iter = propertyWindows.find(entry); iter != std::cend(propertyWindows))
|
|
||||||
{
|
|
||||||
m_ui->mdiArea->setActiveSubWindow(iter->second);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto dialog = new PropertiesDialogFor<T>{*entry, *m_projectTreeModel};
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,9 @@ public:
|
|||||||
explicit MainWindow(const QString &filePath, QWidget *parent = nullptr);
|
explicit MainWindow(const QString &filePath, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void openPropertiesWindowFor(T &entry);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user