Implemented edit sprite button in object properties dialog
This commit is contained in:
@ -7,15 +7,17 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#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<Ui::ObjectPropertiesDialog>()},
|
||||
m_object{object},
|
||||
m_projectModel{projectModel},
|
||||
m_mainWindow{mainWindow},
|
||||
m_events{m_object.events},
|
||||
m_eventsModel{std::make_unique<ObjectEventsModel>(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()
|
||||
|
@ -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;
|
||||
|
||||
|
@ -165,6 +165,62 @@ MainWindow::MainWindow(const QString &filePath, QWidget *parent) :
|
||||
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)
|
||||
{
|
||||
m_ui->mdiArea->closeAllSubWindows();
|
||||
@ -871,48 +927,7 @@ bool MainWindow::doubleClickedFor(const QModelIndex &index)
|
||||
if (!entry)
|
||||
return true;
|
||||
|
||||
auto &propertyWindows = propertyWindowsFor<T>();
|
||||
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();
|
||||
}
|
||||
openPropertiesWindowFor(*entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ public:
|
||||
explicit MainWindow(const QString &filePath, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
template<typename T>
|
||||
void openPropertiesWindowFor(T &entry);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
|
Reference in New Issue
Block a user