Added dialog to add events to object

This commit is contained in:
feedc0de committed 2022-01-13 14:41:17 +01:00
1 parent 7fdcd5386d
commit 8d45958d45
22 files changed
+474 -124

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
#include "addeventdialog.h"
#include "ui_addeventdialog.h"
#include <QMessageBox>
AddEventDialog::AddEventDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::AddEventDialog>()}
{
m_ui->setupUi(this);
#ifdef Q_OS_LINUX
setWindowFlags((windowFlags() & ~Qt::Dialog) | Qt::Window);
#endif
setWindowFlag(Qt::WindowCloseButtonHint);
if (auto button = m_ui->buttonBox->button(QDialogButtonBox::Ok))
button->setIcon(QIcon{":/qtgameengine/icons/ok.png"});
if (auto button = m_ui->buttonBox->button(QDialogButtonBox::Cancel))
button->setIcon(QIcon{":/qtgameengine/icons/delete.png"});
connect(m_ui->pushButtonCreate, &QAbstractButton::clicked,
this, [this](){ m_eventType = Object::EventType::Create; accept(); });
connect(m_ui->pushButtonStep, &QAbstractButton::clicked,
this, [this](){ m_eventType = Object::EventType::Step; accept(); });
connect(m_ui->pushButtonDestroy, &QAbstractButton::clicked,
this, [this](){ m_eventType = Object::EventType::Destroy; accept(); });
}
AddEventDialog::~AddEventDialog() = default;
void AddEventDialog::accept()
{
if (!m_eventType)
{
QMessageBox::warning(this, tr("No Event selected!"), tr("No Event selected!"));
return;
}
QDialog::accept();
}
void AddEventDialog::reject()
{
m_eventType = std::nullopt;
QDialog::reject();
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <QDialog>
#include <optional>
#include "projectcontainer.h"
namespace Ui { class AddEventDialog; }
class AddEventDialog : public QDialog
{
Q_OBJECT
public:
explicit AddEventDialog(QWidget *parent = nullptr);
~AddEventDialog();
Object::EventType eventType() const { return *m_eventType; }
void accept() override;
void reject() override;
private:
const std::unique_ptr<Ui::AddEventDialog> m_ui;
std::optional<Object::EventType> m_eventType;
};
+166
View File
@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddEventDialog</class>
<widget class="QDialog" name="AddEventDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>265</width>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose the Event to Add</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QPushButton" name="pushButtonDraw">
<property name="text">
<string>Dra&amp;w</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButtonMouse">
<property name="text">
<string>&amp;Mouse</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="pushButtonKeyRelease">
<property name="text">
<string>Ke&amp;y Release</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButtonAlarm">
<property name="text">
<string>&amp;Alarm</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pushButtonStep">
<property name="text">
<string>&amp;Step</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/event-step.png</normaloff>:/qtgameengine/icons/event-step.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButtonCreate">
<property name="text">
<string>C&amp;reate</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/event-create.png</normaloff>:/qtgameengine/icons/event-create.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButtonOther">
<property name="text">
<string>O&amp;ther</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pushButtonCollision">
<property name="text">
<string>C&amp;ollision</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButtonDestroy">
<property name="text">
<string>&amp;Destroy</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/event-destroy.png</normaloff>:/qtgameengine/icons/event-destroy.png</iconset>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pushButtonKeyPress">
<property name="text">
<string>Key &amp;Press</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="pushButtonKeyboard">
<property name="text">
<string>&amp;Keyboard</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="pushButtonTrigger">
<property name="text">
<string>&amp;Trigger</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddEventDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>132</x>
<y>196</y>
</hint>
<hint type="destinationlabel">
<x>132</x>
<y>108</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddEventDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>132</x>
<y>196</y>
</hint>
<hint type="destinationlabel">
<x>132</x>
<y>108</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+1 -1
View File
@@ -25,7 +25,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
+1 -1
View File
@@ -23,7 +23,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
+15 -3
View File
@@ -7,17 +7,18 @@
#include <algorithm>
#include "projectcontainer.h"
#include "projecttreemodel.h"
#include "objecteventsmodel.h"
#include "objectactionsmodel.h"
#include "addeventdialog.h"
ObjectPropertiesDialog::ObjectPropertiesDialog(Object &object, ProjectTreeModel &projectModel, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::ObjectPropertiesDialog>()},
m_object{object},
m_projectModel{projectModel},
m_eventsModel{std::make_unique<ObjectEventsModel>()},
m_events{m_object.events},
m_eventsModel{std::make_unique<ObjectEventsModel>(m_events)},
m_actionsModel{std::make_unique<ObjectActionsModel>()},
m_spritesMenu{new QMenu{m_ui->toolButtonSprite}},
m_spriteName{object.spriteName}
@@ -106,6 +107,7 @@ void ObjectPropertiesDialog::accept()
m_object.solid = m_ui->checkBoxSolid->isChecked();
m_object.depth = m_ui->spinBoxDepth->value();
m_object.persistent = m_ui->checkBoxPersistent->isChecked();
m_object.events = std::move(m_events);
QDialog::accept();
}
@@ -157,7 +159,17 @@ void ObjectPropertiesDialog::showInformation()
void ObjectPropertiesDialog::addEvent()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
AddEventDialog dialog{this};
if (dialog.exec() == QDialog::Accepted)
{
if (!m_events.contains(dialog.eventType()))
{
m_eventsModel->beginResetModel();
m_events[dialog.eventType()];
m_eventsModel->endResetModel();
m_unsavedChanges = true;
}
}
}
void ObjectPropertiesDialog::deleteEvent()
+5 -2
View File
@@ -3,14 +3,15 @@
#include <QDialog>
#include <memory>
#include <map>
#include "projectcontainer.h"
class QMenu;
namespace Ui { class ObjectPropertiesDialog; }
struct Object;
class ProjectTreeModel;
class ObjectEventsModel;
class ObjectActionsModel;
class Sprite;
class ObjectPropertiesDialog : public QDialog
{
@@ -48,6 +49,8 @@ private:
Object &m_object;
ProjectTreeModel &m_projectModel;
std::map<Object::EventType, QString> m_events;
const std::unique_ptr<ObjectEventsModel> m_eventsModel;
const std::unique_ptr<ObjectActionsModel> m_actionsModel;
+1 -1
View File
@@ -25,7 +25,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
+13 -13
View File
@@ -114,18 +114,18 @@
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditName">
<property name="toolTip">
<string>The name of the path</string>
@@ -189,7 +189,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelX">
<property name="text">
<string>X:</string>
<string>&amp;X:</string>
</property>
<property name="buddy">
<cstring>spinBoxX</cstring>
@@ -209,7 +209,7 @@
<item row="1" column="0">
<widget class="QLabel" name="labelY">
<property name="text">
<string>Y:</string>
<string>&amp;Y:</string>
</property>
<property name="buddy">
<cstring>spinBoxY</cstring>
@@ -229,7 +229,7 @@
<item row="2" column="0">
<widget class="QLabel" name="labelSp">
<property name="text">
<string>sp:</string>
<string>s&amp;p:</string>
</property>
<property name="buddy">
<cstring>spinBoxSp</cstring>
@@ -269,7 +269,7 @@
<string>Add the point to the path</string>
</property>
<property name="text">
<string>Add</string>
<string>&amp;Add</string>
</property>
</widget>
</item>
@@ -279,7 +279,7 @@
<string>Insert the point before the current one</string>
</property>
<property name="text">
<string>Insert</string>
<string>&amp;Insert</string>
</property>
</widget>
</item>
@@ -289,7 +289,7 @@
<string>Delete the point from the path</string>
</property>
<property name="text">
<string>Delete</string>
<string>&amp;Delete</string>
</property>
</widget>
</item>
@@ -329,14 +329,14 @@
<item>
<widget class="QRadioButton" name="radioButtonStraight">
<property name="text">
<string>Straight lines</string>
<string>&amp;Straight lines</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSmooth">
<property name="text">
<string>Smooth curves</string>
<string>S&amp;mooth curves</string>
</property>
</widget>
</item>
@@ -348,7 +348,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelPrecision">
<property name="text">
<string>Precision:</string>
<string>P&amp;recision:</string>
</property>
<property name="buddy">
<cstring>spinBoxPrecision</cstring>
+1 -1
View File
@@ -16,7 +16,7 @@ ScriptPropertiesDialog::ScriptPropertiesDialog(Script &script, ProjectTreeModel
m_lineEditName{new QLineEdit{this}}
{
{
auto label = new QLabel{tr("Name:"), this};
auto label = new QLabel{tr("&Name:"), this};
label->setBuddy(m_lineEditName);
addToolbarWidget(label);
}
+1 -1
View File
@@ -23,7 +23,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
+3 -3
View File
@@ -25,7 +25,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
@@ -153,7 +153,7 @@
<item>
<widget class="QLabel" name="labelOriginX">
<property name="text">
<string>X:</string>
<string>&amp;X:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -173,7 +173,7 @@
<item>
<widget class="QLabel" name="labelOriginY">
<property name="text">
<string>Y:</string>
<string>&amp;Y:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+1 -1
View File
@@ -23,7 +23,7 @@
<item>
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>