Fixed rename errors in dialogs, implemented lots more
This commit is contained in:
@@ -6,22 +6,32 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
#include "imageeditordialog.h"
|
||||
|
||||
BackgroundPropertiesDialog::BackgroundPropertiesDialog(Background &background, QWidget *parent) :
|
||||
BackgroundPropertiesDialog::BackgroundPropertiesDialog(Background &background, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::BackgroundPropertiesDialog>()},
|
||||
m_background{background}
|
||||
m_background{background},
|
||||
m_projectModel{projectModel}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Background Properties: %0").arg(m_background.name));
|
||||
updateTitle();
|
||||
|
||||
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"});
|
||||
|
||||
m_ui->lineEditName->setText(m_background.name);
|
||||
m_ui->labelWidth->setText(tr("Width: %0").arg(m_background.pixmap.width()));
|
||||
m_ui->labelHeight->setText(tr("Height: %0").arg(m_background.pixmap.height()));
|
||||
updateSpriteInfo();
|
||||
m_ui->checkBoxTileset->setChecked(m_background.tileset);
|
||||
m_ui->labelPreview->setPixmap(m_background.pixmap);
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::backgroundNameChanged,
|
||||
this, &BackgroundPropertiesDialog::backgroundNameChanged);
|
||||
|
||||
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
|
||||
this, &BackgroundPropertiesDialog::loadBackground);
|
||||
connect(m_ui->pushButtonSave, &QAbstractButton::pressed,
|
||||
@@ -41,11 +51,16 @@ void BackgroundPropertiesDialog::accept()
|
||||
{
|
||||
if (m_background.name != m_ui->lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renameBackground(m_background, m_ui->lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Background failed!"), tr("Renaming Background failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
if (m_newPixmap)
|
||||
m_background.pixmap = std::move(*m_newPixmap);
|
||||
m_background.tileset = m_ui->checkBoxTileset->isChecked();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -82,12 +97,45 @@ void BackgroundPropertiesDialog::reject()
|
||||
|
||||
void BackgroundPropertiesDialog::loadBackground()
|
||||
{
|
||||
QFileDialog::getOpenFileName(this, tr("Open a Background Image..."));
|
||||
const auto path = QFileDialog::getOpenFileName(this, tr("Open a Background Image..."), {}, tr("BMP Files (*.bmp), PNG Files (*png)"));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!pixmap.load(path))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not load sprite!"), tr("Could not load sprite!"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->labelPreview->setPixmap(pixmap);
|
||||
|
||||
m_newPixmap = std::move(pixmap);
|
||||
m_unsavedChanges = true;
|
||||
|
||||
updateTitle();
|
||||
updateSpriteInfo();
|
||||
}
|
||||
|
||||
void BackgroundPropertiesDialog::saveBackground()
|
||||
{
|
||||
QFileDialog::getSaveFileName(this, tr("Save a Background Image..."), m_background.name + ".png", tr("PNG Files (*.png)"));
|
||||
const auto &pixmap = m_newPixmap ? *m_newPixmap : m_background.pixmap;
|
||||
|
||||
if (pixmap.isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("No background available to save!"), tr("No background available to save!"));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto path = QFileDialog::getSaveFileName(this, tr("Save a Background Image..."), m_background.name + ".png", tr("PNG Files (*.png)"));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
if (!pixmap.save(path))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not save Background!"), tr("Could not save Background!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundPropertiesDialog::editBackground()
|
||||
@@ -99,7 +147,35 @@ void BackgroundPropertiesDialog::changed()
|
||||
{
|
||||
if (!m_unsavedChanges)
|
||||
{
|
||||
setWindowTitle(tr("Background Properties: %0*").arg(m_background.name));
|
||||
m_unsavedChanges = true;
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundPropertiesDialog::backgroundNameChanged(const Background &background)
|
||||
{
|
||||
if (&background != &m_background)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_ui->lineEditName};
|
||||
m_ui->lineEditName->setText(background.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void BackgroundPropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Background Properties: %0%1")
|
||||
.arg(m_background.name)
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
||||
void BackgroundPropertiesDialog::updateSpriteInfo()
|
||||
{
|
||||
const auto &pixmap = m_newPixmap ? *m_newPixmap : m_background.pixmap;
|
||||
m_ui->labelWidth->setText(tr("Width: %0").arg(pixmap.width()));
|
||||
m_ui->labelHeight->setText(tr("Height: %0").arg(pixmap.height()));
|
||||
}
|
||||
|
@@ -4,16 +4,18 @@
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace Ui { class BackgroundPropertiesDialog; }
|
||||
struct Background;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class BackgroundPropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BackgroundPropertiesDialog(Background &background, QWidget *parent = nullptr);
|
||||
explicit BackgroundPropertiesDialog(Background &background, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~BackgroundPropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
@@ -26,10 +28,18 @@ private slots:
|
||||
|
||||
void changed();
|
||||
|
||||
void backgroundNameChanged(const Background &background);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
void updateSpriteInfo();
|
||||
|
||||
const std::unique_ptr<Ui::BackgroundPropertiesDialog> m_ui;
|
||||
|
||||
Background &m_background;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
std::optional<QPixmap> m_newPixmap;
|
||||
};
|
||||
|
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>573</width>
|
||||
<height>221</height>
|
||||
<width>597</width>
|
||||
<height>295</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -44,6 +44,19 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonLoad">
|
||||
<property name="text">
|
||||
@@ -95,6 +108,19 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxTileset">
|
||||
<property name="text">
|
||||
@@ -103,51 +129,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Minimum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonOk">
|
||||
<property name="text">
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/qtgameengine/icons/ok.png</normaloff>:/qtgameengine/icons/ok.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Minimum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@@ -161,8 +150,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>371</width>
|
||||
<height>201</height>
|
||||
<width>396</width>
|
||||
<height>275</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
@@ -178,18 +167,34 @@
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButtonOk</sender>
|
||||
<signal>pressed()</signal>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>BackgroundPropertiesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>124</x>
|
||||
<y>197</y>
|
||||
<x>96</x>
|
||||
<y>272</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>110</y>
|
||||
<x>298</x>
|
||||
<y>147</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>BackgroundPropertiesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>96</x>
|
||||
<y>272</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>298</x>
|
||||
<y>147</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include "createspritedialog.h"
|
||||
#include "ui_createspritedialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
CreateSpriteDialog::CreateSpriteDialog(QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::CreateSpriteDialog>()}
|
||||
@@ -8,9 +10,14 @@ CreateSpriteDialog::CreateSpriteDialog(QWidget *parent) :
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowFlags(windowFlags()
|
||||
& ~Qt::Dialog
|
||||
& ~Qt::Dialog
|
||||
| Qt::Window
|
||||
| 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"});
|
||||
}
|
||||
|
||||
CreateSpriteDialog::CreateSpriteDialog(const QSize &size, QWidget *parent) :
|
||||
|
@@ -6,12 +6,20 @@ ExtensionPackagesDialog::ExtensionPackagesDialog(QWidget *parent) :
|
||||
m_ui{std::make_unique<Ui::ExtensionPackagesDialog>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowFlags(windowFlags()
|
||||
& ~Qt::Dialog
|
||||
| Qt::Window
|
||||
| Qt::WindowMinimizeButtonHint
|
||||
| Qt::WindowMaximizeButtonHint
|
||||
| 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"});
|
||||
m_ui->buttonBox->addButton(tr("Install"), QDialogButtonBox::ActionRole)
|
||||
->setIcon(QIcon{":/qtgameengine/icons/extension-packages-file.png"});
|
||||
}
|
||||
|
||||
ExtensionPackagesDialog::~ExtensionPackagesDialog() = default;
|
||||
|
@@ -168,7 +168,7 @@
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@@ -5,15 +5,22 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
|
||||
FontPropertiesDialog::FontPropertiesDialog(Font &font, QWidget *parent) :
|
||||
FontPropertiesDialog::FontPropertiesDialog(Font &font, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::FontPropertiesDialog>()},
|
||||
m_font{font}
|
||||
m_font{font},
|
||||
m_projectModel{projectModel}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Font Properties: %0").arg(m_font.name));
|
||||
updateTitle();
|
||||
|
||||
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"});
|
||||
|
||||
m_ui->lineEditName->setText(m_font.name);
|
||||
m_ui->fontComboBox->setCurrentFont(m_font.font);
|
||||
@@ -25,6 +32,9 @@ FontPropertiesDialog::FontPropertiesDialog(Font &font, QWidget *parent) :
|
||||
|
||||
m_ui->labelPreview->setFont(currentFont());
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::fontNameChanged,
|
||||
this, &FontPropertiesDialog::fontNameChanged);
|
||||
|
||||
connect(m_ui->pushButtonNormal, &QAbstractButton::pressed,
|
||||
this, &FontPropertiesDialog::normalRange);
|
||||
connect(m_ui->pushButtonDigits, &QAbstractButton::pressed,
|
||||
@@ -56,8 +66,11 @@ void FontPropertiesDialog::accept()
|
||||
{
|
||||
if (m_font.name != m_ui->lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renameFont(m_font, m_ui->lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Font failed!"), tr("Renaming Font failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_font.font = currentFont();
|
||||
@@ -128,11 +141,32 @@ void FontPropertiesDialog::changed()
|
||||
m_ui->labelPreview->setFont(currentFont());
|
||||
if (!m_unsavedChanges)
|
||||
{
|
||||
setWindowTitle(tr("Font Properties: %0*").arg(m_font.name));
|
||||
m_unsavedChanges = true;
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void FontPropertiesDialog::fontNameChanged(const Font &font)
|
||||
{
|
||||
if (&font != &m_font)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_ui->lineEditName};
|
||||
m_ui->lineEditName->setText(font.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void FontPropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Font Properties: %0%1")
|
||||
.arg(m_font.name)
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
||||
QFont FontPropertiesDialog::currentFont() const
|
||||
{
|
||||
QFont font;
|
||||
|
@@ -6,13 +6,14 @@
|
||||
|
||||
namespace Ui { class FontPropertiesDialog; }
|
||||
struct Font;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class FontPropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FontPropertiesDialog(Font &font, QWidget *parent = nullptr);
|
||||
explicit FontPropertiesDialog(Font &font, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~FontPropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
@@ -26,12 +27,16 @@ private slots:
|
||||
|
||||
void changed();
|
||||
|
||||
void fontNameChanged(const Font &font);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
QFont currentFont() const;
|
||||
|
||||
const std::unique_ptr<Ui::FontPropertiesDialog> m_ui;
|
||||
|
||||
Font &m_font;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>266</width>
|
||||
<width>338</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -54,8 +54,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QFontComboBox" name="fontComboBox">
|
||||
</widget>
|
||||
<widget class="QFontComboBox" name="fontComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spinBoxSize"/>
|
||||
@@ -193,45 +192,14 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonOk">
|
||||
<property name="text">
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/qtgameengine/icons/ok.png</normaloff>:/qtgameengine/icons/ok.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -240,14 +208,30 @@
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButtonOk</sender>
|
||||
<signal>pressed()</signal>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>FontPropertiesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>168</x>
|
||||
<y>428</y>
|
||||
<y>429</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>168</x>
|
||||
<y>225</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>FontPropertiesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>168</x>
|
||||
<y>429</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>168</x>
|
||||
|
@@ -1,17 +1,25 @@
|
||||
#include "globalgamesettingsdialog.h"
|
||||
#include "ui_globalgamesettingsdialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
GlobalGameSettingsDialog::GlobalGameSettingsDialog(QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::GlobalGameSettingsDialog>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowFlags(windowFlags()
|
||||
& ~Qt::Dialog
|
||||
| Qt::Window
|
||||
| Qt::WindowMinimizeButtonHint
|
||||
| Qt::WindowMaximizeButtonHint
|
||||
| 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"});
|
||||
}
|
||||
|
||||
GlobalGameSettingsDialog::~GlobalGameSettingsDialog() = default;
|
||||
|
@@ -5,18 +5,20 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
|
||||
PathPropertiesDialog::PathPropertiesDialog(Path &path, QWidget *parent) :
|
||||
PathPropertiesDialog::PathPropertiesDialog(Path &path, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::PathPropertiesDialog>()},
|
||||
m_path{path},
|
||||
m_projectModel{projectModel},
|
||||
m_labelX{new QLabel{tr("x: %0").arg(0)}},
|
||||
m_labelY{new QLabel{tr("y: %0").arg(0)}},
|
||||
m_labelArea{new QLabel{tr("Area: (%0,%1)->(%2,%3)").arg(0).arg(0).arg(0).arg(0)}}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Path Properties: %0").arg(m_path.name));
|
||||
updateTitle();
|
||||
|
||||
m_labelX->setFrameStyle(QFrame::Sunken);
|
||||
m_ui->statusbar->addWidget(m_labelX, 1);
|
||||
@@ -33,6 +35,16 @@ PathPropertiesDialog::PathPropertiesDialog(Path &path, QWidget *parent) :
|
||||
|
||||
m_ui->lineEditName->setText(m_path.name);
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::pathNameChanged,
|
||||
this, &PathPropertiesDialog::pathNameChanged);
|
||||
|
||||
connect(m_ui->pushButtonAdd, &QAbstractButton::pressed,
|
||||
this, &PathPropertiesDialog::add);
|
||||
connect(m_ui->pushButtonInsert, &QAbstractButton::pressed,
|
||||
this, &PathPropertiesDialog::insert);
|
||||
connect(m_ui->pushButtonDelete, &QAbstractButton::pressed,
|
||||
this, &PathPropertiesDialog::delete_);
|
||||
|
||||
connect(m_ui->lineEditName, &QLineEdit::textChanged,
|
||||
this, &PathPropertiesDialog::changed);
|
||||
}
|
||||
@@ -43,8 +55,11 @@ void PathPropertiesDialog::accept()
|
||||
{
|
||||
if (m_path.name != m_ui->lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renamePath(m_path, m_ui->lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Path failed!"), tr("Renaming Path failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
@@ -82,11 +97,47 @@ void PathPropertiesDialog::reject()
|
||||
}
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::add()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::insert()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::delete_()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::changed()
|
||||
{
|
||||
if (!m_unsavedChanges)
|
||||
{
|
||||
setWindowTitle(tr("Path Properties: %0*").arg(m_path.name));
|
||||
m_unsavedChanges = true;
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::pathNameChanged(const Path &path)
|
||||
{
|
||||
if (&path != &m_path)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_ui->lineEditName};
|
||||
m_ui->lineEditName->setText(path.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void PathPropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Path Properties: %0%1")
|
||||
.arg(m_path.name)
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
@@ -7,29 +7,39 @@
|
||||
class QLabel;
|
||||
namespace Ui { class PathPropertiesDialog; }
|
||||
struct Path;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class PathPropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PathPropertiesDialog(Path &path, QWidget *parent = nullptr);
|
||||
explicit PathPropertiesDialog(Path &path, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~PathPropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
void add();
|
||||
void insert();
|
||||
void delete_();
|
||||
|
||||
void changed();
|
||||
|
||||
void pathNameChanged(const Path &path);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
|
||||
const std::unique_ptr<Ui::PathPropertiesDialog> m_ui;
|
||||
|
||||
Path &m_path;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
QLabel * const m_labelX;
|
||||
QLabel * const m_labelY;
|
||||
QLabel * const m_labelArea;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
};
|
||||
|
@@ -87,6 +87,18 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
@@ -104,6 +116,22 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="sizePolicy">
|
||||
@@ -114,6 +142,22 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
@@ -190,6 +234,22 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
|
@@ -9,18 +9,20 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
#include "jshighlighter.h"
|
||||
|
||||
ScriptPropertiesDialog::ScriptPropertiesDialog(Script &script, QWidget *parent) :
|
||||
ScriptPropertiesDialog::ScriptPropertiesDialog(Script &script, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::ScriptPropertiesDialog>()},
|
||||
m_script{script},
|
||||
m_projectModel{projectModel},
|
||||
m_lineEditName{new QLineEdit{this}},
|
||||
m_labelPosition{new QLabel{this}}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Script Properties: %0").arg(m_script.name));
|
||||
updateTitle();
|
||||
|
||||
{
|
||||
auto label = new QLabel{tr("Name:"), this};
|
||||
@@ -48,6 +50,9 @@ ScriptPropertiesDialog::ScriptPropertiesDialog(Script &script, QWidget *parent)
|
||||
|
||||
updatePosition();
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::scriptNameChanged,
|
||||
this, &ScriptPropertiesDialog::scriptNameChanged);
|
||||
|
||||
connect(m_ui->actionLoad, &QAction::triggered,
|
||||
this, &ScriptPropertiesDialog::load);
|
||||
connect(m_ui->actionSave, &QAction::triggered,
|
||||
@@ -71,8 +76,11 @@ void ScriptPropertiesDialog::accept()
|
||||
{
|
||||
if (m_script.name != m_lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renameScript(m_script, m_lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Script failed!"), tr("Renaming Script failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_script.script = m_ui->codeEdit->toPlainText();
|
||||
@@ -114,8 +122,8 @@ void ScriptPropertiesDialog::changed()
|
||||
{
|
||||
if (!m_unsavedChanges)
|
||||
{
|
||||
setWindowTitle(tr("Script Properties: %0*").arg(m_script.name));
|
||||
m_unsavedChanges = true;
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +164,24 @@ void ScriptPropertiesDialog::updatePosition()
|
||||
|
||||
m_labelPosition->setText(tr("%0/%1: %2").arg(lines).arg(m_ui->codeEdit->blockCount()).arg(position));
|
||||
}
|
||||
|
||||
void ScriptPropertiesDialog::scriptNameChanged(const Script &script)
|
||||
{
|
||||
if (&script != &m_script)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_lineEditName};
|
||||
m_lineEditName->setText(script.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void ScriptPropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Script Properties: %0%1")
|
||||
.arg(m_script.name)
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
@@ -8,13 +8,14 @@ class QLineEdit;
|
||||
class QLabel;
|
||||
namespace Ui { class ScriptPropertiesDialog; }
|
||||
struct Script;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class ScriptPropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScriptPropertiesDialog(Script &script, QWidget *parent = nullptr);
|
||||
explicit ScriptPropertiesDialog(Script &script, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~ScriptPropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
@@ -29,14 +30,19 @@ private slots:
|
||||
|
||||
void updatePosition();
|
||||
|
||||
void scriptNameChanged(const Script &script);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
|
||||
const std::unique_ptr<Ui::ScriptPropertiesDialog> m_ui;
|
||||
|
||||
Script &m_script;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
QLineEdit * const m_lineEditName;
|
||||
|
||||
QLabel * const m_labelPosition;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
};
|
||||
|
@@ -8,15 +8,22 @@
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
|
||||
SoundPropertiesDialog::SoundPropertiesDialog(Sound &sound, QWidget *parent) :
|
||||
SoundPropertiesDialog::SoundPropertiesDialog(Sound &sound, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::SoundPropertiesDialog>()},
|
||||
m_sound{sound}
|
||||
m_sound{sound},
|
||||
m_projectModel{projectModel}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Sound Properties: %0").arg(m_sound.name));
|
||||
updateTitle();
|
||||
|
||||
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"});
|
||||
|
||||
m_ui->lineEditName->setText(m_sound.name);
|
||||
if (!m_sound.path.isEmpty())
|
||||
@@ -35,6 +42,9 @@ SoundPropertiesDialog::SoundPropertiesDialog(Sound &sound, QWidget *parent) :
|
||||
m_ui->horizontalSliderPan->setValue(m_sound.pan);
|
||||
m_ui->checkBoxPreload->setChecked(m_sound.preload);
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::soundNameChanged,
|
||||
this, &SoundPropertiesDialog::soundNameChanged);
|
||||
|
||||
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
|
||||
this, &SoundPropertiesDialog::loadSound);
|
||||
connect(m_ui->pushButtonPlay, &QAbstractButton::pressed,
|
||||
@@ -80,12 +90,15 @@ void SoundPropertiesDialog::accept()
|
||||
{
|
||||
if (m_sound.name != m_ui->lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renameSound(m_sound, m_ui->lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Sound failed!"), tr("Renaming Sound failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_newPath)
|
||||
m_sound.path = *m_newPath;
|
||||
m_sound.path = std::move(*m_newPath);
|
||||
|
||||
if (m_ui->radioButtonNormal->isChecked())
|
||||
m_sound.type = Sound::Type::Sound;
|
||||
@@ -195,7 +208,28 @@ void SoundPropertiesDialog::changed()
|
||||
{
|
||||
if (!m_unsavedChanges)
|
||||
{
|
||||
setWindowTitle(tr("Sound Properties: %0*").arg(m_sound.name));
|
||||
m_unsavedChanges = true;
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void SoundPropertiesDialog::soundNameChanged(const Sound &sound)
|
||||
{
|
||||
if (&sound != &m_sound)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_ui->lineEditName};
|
||||
m_ui->lineEditName->setText(sound.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void SoundPropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Sound Properties: %0%1")
|
||||
.arg(m_sound.name)
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
@@ -9,13 +9,14 @@
|
||||
|
||||
namespace Ui { class SoundPropertiesDialog; }
|
||||
struct Sound;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class SoundPropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SoundPropertiesDialog(Sound &sound, QWidget *parent = nullptr);
|
||||
explicit SoundPropertiesDialog(Sound &sound, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~SoundPropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
@@ -30,10 +31,15 @@ private slots:
|
||||
|
||||
void changed();
|
||||
|
||||
void soundNameChanged(const Sound &sound);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
|
||||
const std::unique_ptr<Ui::SoundPropertiesDialog> m_ui;
|
||||
|
||||
Sound &m_sound;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
|
@@ -288,45 +288,14 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonOk">
|
||||
<property name="text">
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/qtgameengine/icons/ok.png</normaloff>:/qtgameengine/icons/ok.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -335,18 +304,34 @@
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButtonOk</sender>
|
||||
<signal>pressed()</signal>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SoundPropertiesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>119</x>
|
||||
<y>534</y>
|
||||
<y>480</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>119</x>
|
||||
<y>279</y>
|
||||
<y>266</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SoundPropertiesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>119</x>
|
||||
<y>512</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>119</x>
|
||||
<y>266</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
@@ -4,29 +4,38 @@
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QSignalBlocker>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "projecttreemodel.h"
|
||||
#include "editspritedialog.h"
|
||||
|
||||
SpritePropertiesDialog::SpritePropertiesDialog(Sprite &sprite, QWidget *parent) :
|
||||
SpritePropertiesDialog::SpritePropertiesDialog(Sprite &sprite, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::SpritePropertiesDialog>()},
|
||||
m_sprite{sprite}
|
||||
m_sprite{sprite},
|
||||
m_projectModel{projectModel}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setWindowTitle(tr("Sprite Properties: %0").arg(m_sprite.name));
|
||||
updateTitle();
|
||||
|
||||
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"});
|
||||
|
||||
m_ui->lineEditName->setText(m_sprite.name);
|
||||
m_ui->labelWidth->setText(tr("Width: %0").arg(m_sprite.pixmaps.empty() ? tr("n/a") : QString::number(m_sprite.pixmaps.front().width())));
|
||||
m_ui->labelHeight->setText(tr("Height: %0").arg(m_sprite.pixmaps.empty() ? tr("n/a") : QString::number(m_sprite.pixmaps.front().height())));
|
||||
m_ui->labelSubimages->setText(tr("Number of subimages: %0").arg(m_sprite.pixmaps.size()));
|
||||
updateSpriteInfo();
|
||||
m_ui->spinBoxOriginX->setValue(m_sprite.origin.x);
|
||||
m_ui->spinBoxOriginY->setValue(m_sprite.origin.y);
|
||||
m_ui->checkBoxPreciseCollisionChecking->setChecked(m_sprite.preciseCollisionChecking);
|
||||
m_ui->checkBoxSeparateCollisionMasks->setChecked(m_sprite.separateCollisionMasks);
|
||||
m_ui->labelPreview->setPixmap(m_sprite.pixmaps.empty() ? QPixmap{} : m_sprite.pixmaps.front());
|
||||
|
||||
connect(&m_projectModel, &ProjectTreeModel::spriteNameChanged,
|
||||
this, &SpritePropertiesDialog::spriteNameChanged);
|
||||
|
||||
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
|
||||
this, &SpritePropertiesDialog::loadSprite);
|
||||
connect(m_ui->pushButtonSave, &QAbstractButton::pressed,
|
||||
@@ -54,12 +63,15 @@ void SpritePropertiesDialog::accept()
|
||||
{
|
||||
if (m_sprite.name != m_ui->lineEditName->text())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
|
||||
return;
|
||||
if (!m_projectModel.renameSprite(m_sprite, m_ui->lineEditName->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Renaming Sprite failed!"), tr("Renaming Sprite failed!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_newPixmaps)
|
||||
m_sprite.pixmaps = *m_newPixmaps;
|
||||
m_sprite.pixmaps = std::move(*m_newPixmaps);
|
||||
m_sprite.origin.x = m_ui->spinBoxOriginX->value();
|
||||
m_sprite.origin.y = m_ui->spinBoxOriginY->value();
|
||||
m_sprite.preciseCollisionChecking = m_ui->checkBoxPreciseCollisionChecking->isChecked();
|
||||
@@ -117,13 +129,14 @@ void SpritePropertiesDialog::loadSprite()
|
||||
m_unsavedChanges = true;
|
||||
|
||||
updateTitle();
|
||||
updateSpriteInfo();
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::saveSprite()
|
||||
{
|
||||
const auto &pixmaps = m_newPixmaps ? *m_newPixmaps : m_sprite.pixmaps;
|
||||
|
||||
if (pixmaps.empty())
|
||||
if (pixmaps.empty() || pixmaps.front().isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("No sprites available to save!"), tr("No sprites available to save!"));
|
||||
return;
|
||||
@@ -135,7 +148,7 @@ void SpritePropertiesDialog::saveSprite()
|
||||
|
||||
if (!pixmaps.front().save(path))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not save sprite!"), tr("Could not save sprite!"));
|
||||
QMessageBox::warning(this, tr("Could not save Sprite!"), tr("Could not save Sprite!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -147,14 +160,15 @@ void SpritePropertiesDialog::editSprite()
|
||||
|
||||
void SpritePropertiesDialog::centerOrigin()
|
||||
{
|
||||
if (m_sprite.pixmaps.empty())
|
||||
const auto &pixmaps = m_newPixmaps ? *m_newPixmaps : m_sprite.pixmaps;
|
||||
if (pixmaps.empty() || pixmaps.front().isNull())
|
||||
{
|
||||
qDebug() << "unexpected empty pixmaps";
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->spinBoxOriginX->setValue(m_sprite.pixmaps.front().width() / 2);
|
||||
m_ui->spinBoxOriginY->setValue(m_sprite.pixmaps.front().height() / 2);
|
||||
m_ui->spinBoxOriginX->setValue(pixmaps.front().width() / 2);
|
||||
m_ui->spinBoxOriginY->setValue(pixmaps.front().height() / 2);
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::changed()
|
||||
@@ -166,6 +180,19 @@ void SpritePropertiesDialog::changed()
|
||||
}
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::spriteNameChanged(const Sprite &sprite)
|
||||
{
|
||||
if (&sprite != &m_sprite)
|
||||
return;
|
||||
|
||||
{
|
||||
QSignalBlocker blocker{m_ui->lineEditName};
|
||||
m_ui->lineEditName->setText(sprite.name);
|
||||
}
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::updateTitle()
|
||||
{
|
||||
setWindowTitle(tr("Sprite Properties: %0%1")
|
||||
@@ -173,3 +200,11 @@ void SpritePropertiesDialog::updateTitle()
|
||||
.arg(m_unsavedChanges ? tr("*") : QString{})
|
||||
);
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::updateSpriteInfo()
|
||||
{
|
||||
const auto &pixmaps = m_newPixmaps ? *m_newPixmaps : m_sprite.pixmaps;
|
||||
m_ui->labelWidth->setText(tr("Width: %0").arg(pixmaps.empty() ? tr("n/a") : QString::number(pixmaps.front().width())));
|
||||
m_ui->labelHeight->setText(tr("Height: %0").arg(pixmaps.empty() ? tr("n/a") : QString::number(pixmaps.front().height())));
|
||||
m_ui->labelSubimages->setText(tr("Number of subimages: %0").arg(pixmaps.size()));
|
||||
}
|
||||
|
@@ -8,13 +8,14 @@
|
||||
|
||||
namespace Ui { class SpritePropertiesDialog; }
|
||||
struct Sprite;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class SpritePropertiesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SpritePropertiesDialog(Sprite &sprite, QWidget *parent = nullptr);
|
||||
explicit SpritePropertiesDialog(Sprite &sprite, ProjectTreeModel &projectModel, QWidget *parent = nullptr);
|
||||
~SpritePropertiesDialog();
|
||||
|
||||
void accept() override;
|
||||
@@ -28,12 +29,16 @@ private slots:
|
||||
|
||||
void changed();
|
||||
|
||||
void spriteNameChanged(const Sprite &sprite);
|
||||
|
||||
private:
|
||||
void updateTitle();
|
||||
void updateSpriteInfo();
|
||||
|
||||
const std::unique_ptr<Ui::SpritePropertiesDialog> m_ui;
|
||||
|
||||
Sprite &m_sprite;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
|
@@ -225,45 +225,14 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonOk">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/qtgameengine/icons/ok.png</normaloff>:/qtgameengine/icons/ok.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@@ -341,14 +310,30 @@
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButtonOk</sender>
|
||||
<signal>pressed()</signal>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SpritePropertiesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>106</x>
|
||||
<y>320</y>
|
||||
<x>108</x>
|
||||
<y>321</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>279</x>
|
||||
<y>171</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SpritePropertiesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>108</x>
|
||||
<y>321</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>279</x>
|
||||
|
@@ -202,7 +202,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new SpritePropertiesDialog{*sprite};
|
||||
auto dialog = new SpritePropertiesDialog{*sprite, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
@@ -247,7 +247,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new SoundPropertiesDialog{*sound};
|
||||
auto dialog = new SoundPropertiesDialog{*sound, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
@@ -292,7 +292,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new BackgroundPropertiesDialog{*background};
|
||||
auto dialog = new BackgroundPropertiesDialog{*background, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
@@ -337,7 +337,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new PathPropertiesDialog{*path};
|
||||
auto dialog = new PathPropertiesDialog{*path, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
@@ -382,7 +382,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new ScriptPropertiesDialog{*script};
|
||||
auto dialog = new ScriptPropertiesDialog{*script, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
@@ -427,7 +427,7 @@ void MainWindow::doubleClicked(const QModelIndex &index)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dialog = new FontPropertiesDialog{*font};
|
||||
auto dialog = new FontPropertiesDialog{*font, *m_projectTreeModel};
|
||||
auto subwindow = m_ui->mdiArea->addSubWindow(dialog);
|
||||
auto action = m_ui->menuWindow->addAction(dialog->windowTitle());
|
||||
action->setCheckable(true);
|
||||
|
@@ -73,6 +73,7 @@ QDataStream &operator<<(QDataStream &ds, const Background &background)
|
||||
{
|
||||
ds << background.name;
|
||||
ds << background.pixmap;
|
||||
ds << background.tileset;
|
||||
return ds;
|
||||
}
|
||||
|
||||
@@ -80,6 +81,7 @@ QDataStream &operator>>(QDataStream &ds, Background &background)
|
||||
{
|
||||
ds >> background.name;
|
||||
ds >> background.pixmap;
|
||||
ds >> background.tileset;
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
@@ -43,6 +43,7 @@ struct Background
|
||||
{
|
||||
QString name;
|
||||
QPixmap pixmap;
|
||||
bool tileset{};
|
||||
};
|
||||
|
||||
struct Path
|
||||
|
@@ -465,6 +465,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit spriteNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -501,6 +502,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit soundNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -537,6 +539,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit backgroundNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -573,6 +576,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit pathNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -609,6 +613,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit scriptNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -645,6 +650,7 @@ bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
iter->name = std::move(name);
|
||||
emit fontNameChanged(*iter);
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
}
|
||||
return true;
|
||||
@@ -1458,3 +1464,177 @@ const Font *ProjectTreeModel::getFont(const QModelIndex &index) const
|
||||
|
||||
return &*std::next(std::cbegin(m_project->fonts), index.row());
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renameSprite(const Sprite &sprite, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->sprites), std::end(m_project->sprites),
|
||||
[&sprite](const auto &entry){ return &entry == &sprite; });
|
||||
if (iter == std::cend(m_project->sprites))
|
||||
{
|
||||
qWarning() << "sprite not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->sprites), std::cend(m_project->sprites),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate sprite name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit spriteNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->sprites), iter), 0, spritesRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renameSound(const Sound &sound, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->sounds), std::end(m_project->sounds),
|
||||
[&sound](const auto &entry){ return &entry == &sound; });
|
||||
if (iter == std::cend(m_project->sounds))
|
||||
{
|
||||
qWarning() << "sound not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->sounds), std::cend(m_project->sounds),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate sound name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit soundNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->sounds), iter), 0, soundsRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renameBackground(const Background &background, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->backgrounds), std::end(m_project->backgrounds),
|
||||
[&background](const auto &entry){ return &entry == &background; });
|
||||
if (iter == std::cend(m_project->backgrounds))
|
||||
{
|
||||
qWarning() << "background not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->backgrounds), std::cend(m_project->backgrounds),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate background name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit backgroundNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->backgrounds), iter), 0, backgroundsRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renamePath(const Path &path, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->paths), std::end(m_project->paths),
|
||||
[&path](const auto &entry){ return &entry == &path; });
|
||||
if (iter == std::cend(m_project->paths))
|
||||
{
|
||||
qWarning() << "path not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->paths), std::cend(m_project->paths),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate path name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit pathNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->paths), iter), 0, pathsRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renameScript(const Script &script, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->scripts), std::end(m_project->scripts),
|
||||
[&script](const auto &entry){ return &entry == &script; });
|
||||
if (iter == std::cend(m_project->scripts))
|
||||
{
|
||||
qWarning() << "script not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->scripts), std::cend(m_project->scripts),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate script name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit scriptNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->scripts), iter), 0, scriptsRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectTreeModel::renameFont(const Font &font, const QString &newName)
|
||||
{
|
||||
const auto iter = std::find_if(std::begin(m_project->fonts), std::end(m_project->fonts),
|
||||
[&font](const auto &entry){ return &entry == &font; });
|
||||
if (iter == std::cend(m_project->fonts))
|
||||
{
|
||||
qWarning() << "font not from this project!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->name == newName)
|
||||
return true;
|
||||
|
||||
if (std::any_of(std::cbegin(m_project->fonts), std::cend(m_project->fonts),
|
||||
[&newName](const auto &entry){ return entry.name == newName; }))
|
||||
{
|
||||
qWarning() << "duplicate font name" << newName;
|
||||
return false;
|
||||
}
|
||||
|
||||
iter->name = newName;
|
||||
|
||||
emit fontNameChanged(*iter);
|
||||
const auto index = this->index(std::distance(std::begin(m_project->fonts), iter), 0, fontsRoot());
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -75,9 +75,23 @@ public:
|
||||
Font *getFont(const QModelIndex &index);
|
||||
const Font *getFont(const QModelIndex &index) const;
|
||||
|
||||
bool renameSprite(const Sprite &sprite, const QString &newName);
|
||||
bool renameSound(const Sound &sound, const QString &newName);
|
||||
bool renameBackground(const Background &background, const QString &newName);
|
||||
bool renamePath(const Path &path, const QString &newName);
|
||||
bool renameScript(const Script &script, const QString &newName);
|
||||
bool renameFont(const Font &font, const QString &newName);
|
||||
|
||||
signals:
|
||||
void errorOccured(const QString &message);
|
||||
|
||||
void spriteNameChanged(const Sprite &sprite);
|
||||
void soundNameChanged(const Sound &sound);
|
||||
void backgroundNameChanged(const Background &background);
|
||||
void pathNameChanged(const Path &path);
|
||||
void scriptNameChanged(const Script &script);
|
||||
void fontNameChanged(const Font &font);
|
||||
|
||||
private:
|
||||
ProjectContainer *m_project{};
|
||||
};
|
||||
|
Reference in New Issue
Block a user