Implemented create and add from file in sprite editor
This commit is contained in:
@@ -107,24 +107,10 @@ void BackgroundPropertiesDialog::reject()
|
||||
|
||||
void BackgroundPropertiesDialog::loadBackground()
|
||||
{
|
||||
const auto path = QFileDialog::getOpenFileName(this, tr("Open a Background Image..."), {},
|
||||
QStringLiteral("%0 (*.png);;%1 (*.bmp);;%2 (*.tiff);;%3 (*.jpg *.jpeg);;%4 (*)")
|
||||
.arg(tr("PNG Files"))
|
||||
.arg(tr("BMP Files"))
|
||||
.arg(tr("TIFF Files"))
|
||||
.arg(tr("JPEG Files"))
|
||||
.arg(tr("All Files"))
|
||||
);
|
||||
if (path.isEmpty())
|
||||
auto pixmap = loadPixmap(this);
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!pixmap.load(path))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not load sprite!"), tr("Could not load sprite!"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_pixmap = std::move(pixmap);
|
||||
changed();
|
||||
updateSpriteInfo();
|
||||
|
||||
@@ -43,8 +43,16 @@ EditSpriteDialog::EditSpriteDialog(const std::vector<QPixmap> &pixmaps, const QS
|
||||
|
||||
connect(m_ui->actionNew, &QAction::triggered,
|
||||
this, &EditSpriteDialog::newSprite);
|
||||
connect(m_ui->actionCreateFromFile, &QAction::triggered,
|
||||
this, &EditSpriteDialog::createFromFile);
|
||||
connect(m_ui->actionAddFromFile, &QAction::triggered,
|
||||
this, &EditSpriteDialog::addFromFile);
|
||||
connect(m_ui->actionSaveAsPngFile, &QAction::triggered,
|
||||
this, &EditSpriteDialog::saveAsPng);
|
||||
connect(m_ui->actionCreateFromStrip, &QAction::triggered,
|
||||
this, &EditSpriteDialog::createFromStrip);
|
||||
connect(m_ui->actionAddFromStrip, &QAction::triggered,
|
||||
this, &EditSpriteDialog::addFromStrip);
|
||||
connect(m_ui->actionSetTransparencyBackground, &QAction::triggered,
|
||||
this, &EditSpriteDialog::transparentBackgroundSettings);
|
||||
|
||||
@@ -116,6 +124,38 @@ void EditSpriteDialog::newSprite()
|
||||
}
|
||||
}
|
||||
|
||||
void EditSpriteDialog::createFromFile()
|
||||
{
|
||||
auto pixmap = loadPixmap(this);
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
m_model->beginResetModel();
|
||||
m_pixmaps = std::vector<QPixmap> { std::move(pixmap) };
|
||||
m_model->endResetModel();
|
||||
|
||||
changed();
|
||||
}
|
||||
|
||||
void EditSpriteDialog::addFromFile()
|
||||
{
|
||||
auto pixmap = loadPixmap(this);
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
if (!m_pixmaps.empty() && m_pixmaps.front().size() != pixmap.size())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_model->beginInsertRows({}, m_pixmaps.size(), m_pixmaps.size());
|
||||
m_pixmaps.emplace_back(std::move(pixmap));
|
||||
m_model->endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
void EditSpriteDialog::saveAsPng()
|
||||
{
|
||||
auto index = m_ui->listView->currentIndex();
|
||||
@@ -138,6 +178,16 @@ void EditSpriteDialog::saveAsPng()
|
||||
saveImage(this, pixmap.toImage());
|
||||
}
|
||||
|
||||
void EditSpriteDialog::createFromStrip()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void EditSpriteDialog::addFromStrip()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void EditSpriteDialog::transparentBackgroundSettings()
|
||||
{
|
||||
TransparentBackgroundSettingsDialog dialog{this};
|
||||
|
||||
@@ -25,7 +25,11 @@ public:
|
||||
|
||||
private slots:
|
||||
void newSprite();
|
||||
void createFromFile();
|
||||
void addFromFile();
|
||||
void saveAsPng();
|
||||
void createFromStrip();
|
||||
void addFromStrip();
|
||||
void transparentBackgroundSettings();
|
||||
|
||||
void activated(const QModelIndex &index);
|
||||
|
||||
@@ -125,24 +125,10 @@ void SpritePropertiesDialog::reject()
|
||||
|
||||
void SpritePropertiesDialog::loadSprite()
|
||||
{
|
||||
const auto path = QFileDialog::getOpenFileName(this, tr("Open a Sprite Image..."), {},
|
||||
QStringLiteral("%0 (*.png);;%1 (*.bmp);;%2 (*.tiff);;%3 (*.jpg *.jpeg);;%4 (*)")
|
||||
.arg(tr("PNG Files"))
|
||||
.arg(tr("BMP Files"))
|
||||
.arg(tr("TIFF Files"))
|
||||
.arg(tr("JPEG Files"))
|
||||
.arg(tr("All Files"))
|
||||
);
|
||||
if (path.isEmpty())
|
||||
auto pixmap = loadPixmap(this);
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!pixmap.load(path))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not load sprite!"), tr("Could not load sprite!"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_pixmaps = std::vector<QPixmap>{ std::move(pixmap) };
|
||||
changed();
|
||||
updateSpriteInfo();
|
||||
|
||||
@@ -11,6 +11,31 @@
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
|
||||
QPixmap loadPixmap(QWidget *parent)
|
||||
{
|
||||
const auto path = QFileDialog::getOpenFileName(parent, QCoreApplication::translate("imagehelpers", "Open a Sprite Image..."), {},
|
||||
QStringLiteral("%0 (*.png);;%1 (*.bmp);;%2 (*.tiff);;%3 (*.jpg *.jpeg);;%4 (*)")
|
||||
.arg(QCoreApplication::translate("imagehelpers", "PNG Files"))
|
||||
.arg(QCoreApplication::translate("imagehelpers", "BMP Files"))
|
||||
.arg(QCoreApplication::translate("imagehelpers", "TIFF Files"))
|
||||
.arg(QCoreApplication::translate("imagehelpers", "JPEG Files"))
|
||||
.arg(QCoreApplication::translate("imagehelpers", "All Files"))
|
||||
);
|
||||
if (path.isEmpty())
|
||||
return {};
|
||||
|
||||
QPixmap pixmap;
|
||||
if (!pixmap.load(path))
|
||||
{
|
||||
QMessageBox::warning(parent,
|
||||
QCoreApplication::translate("imagehelpers", "Could not load sprite!"),
|
||||
QCoreApplication::translate("imagehelpers", "Could not load sprite!"));
|
||||
return {};
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
void saveImage(QWidget *parent, const QImage &image)
|
||||
{
|
||||
QList<QByteArray> formats = QImageWriter::supportedImageFormats();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
class QWidget;
|
||||
class QPixmap;
|
||||
class QImage;
|
||||
|
||||
QPixmap loadPixmap(QWidget *parent);
|
||||
void saveImage(QWidget *parent, const QImage &image);
|
||||
|
||||
@@ -20,6 +20,9 @@ public:
|
||||
using QAbstractListModel::beginResetModel;
|
||||
using QAbstractListModel::endResetModel;
|
||||
|
||||
using QAbstractListModel::beginInsertRows;
|
||||
using QAbstractListModel::endInsertRows;
|
||||
|
||||
private:
|
||||
const std::vector<QPixmap> &m_pixmaps;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user