Implemented transparent background settings
This commit is contained in:
@@ -36,9 +36,11 @@ HEADERS += \
|
||||
src/editor/dialogs/includedfilepropertiesdialog.h \
|
||||
src/editor/dialogs/transparentbackgroundsettingsdialog.h \
|
||||
src/editor/editorguiutils.h \
|
||||
src/editor/editorsettings.h \
|
||||
src/editor/roomscene.h \
|
||||
src/editor/widgets/actiondragwidget.h \
|
||||
src/editor/widgets/coarsecolorwidget.h \
|
||||
src/editor/widgets/colorbutton.h \
|
||||
src/editor/widgets/colorwidget.h \
|
||||
src/editor/widgets/draggabletreeview.h \
|
||||
src/editor/widgets/finecolorwidget.h \
|
||||
@@ -111,9 +113,11 @@ SOURCES += \
|
||||
src/editor/dialogs/includedfilepropertiesdialog.cpp \
|
||||
src/editor/dialogs/transparentbackgroundsettingsdialog.cpp \
|
||||
src/editor/editorguiutils.cpp \
|
||||
src/editor/editorsettings.cpp \
|
||||
src/editor/roomscene.cpp \
|
||||
src/editor/widgets/actiondragwidget.cpp \
|
||||
src/editor/widgets/coarsecolorwidget.cpp \
|
||||
src/editor/widgets/colorbutton.cpp \
|
||||
src/editor/widgets/colorwidget.cpp \
|
||||
src/editor/widgets/draggabletreeview.cpp \
|
||||
src/editor/widgets/finecolorwidget.cpp \
|
||||
|
||||
@@ -17,6 +17,7 @@ BackgroundPropertiesDialog::BackgroundPropertiesDialog(Background &background, P
|
||||
m_ui{std::make_unique<Ui::BackgroundPropertiesDialog>()},
|
||||
m_background{background},
|
||||
m_projectModel{projectModel},
|
||||
m_mainWindow{mainWindow},
|
||||
m_pixmap{m_background.pixmap}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
@@ -129,7 +130,12 @@ void BackgroundPropertiesDialog::saveBackground()
|
||||
|
||||
void BackgroundPropertiesDialog::editBackground()
|
||||
{
|
||||
ImageEditorDialog dialog{m_pixmap, tr("Image Editor: %0").arg(m_background.name), this};
|
||||
ImageEditorDialog dialog {
|
||||
m_pixmap,
|
||||
tr("Image Editor: %0").arg(m_background.name),
|
||||
m_mainWindow.settings(),
|
||||
this
|
||||
};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
m_pixmap = dialog.pixmap();
|
||||
|
||||
@@ -38,6 +38,7 @@ private:
|
||||
|
||||
Background &m_background;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
MainWindow &m_mainWindow;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
#include "projectcontainer.h"
|
||||
#include "models/spritesmodel.h"
|
||||
#include "dialogs/transparentbackgroundsettingsdialog.h"
|
||||
#include "createspritedialog.h"
|
||||
#include "imageeditordialog.h"
|
||||
#include "imagehelpers.h"
|
||||
|
||||
EditSpriteDialog::EditSpriteDialog(const std::vector<QPixmap> &pixmaps, const QString &spriteName, QWidget *parent) :
|
||||
EditSpriteDialog::EditSpriteDialog(const std::vector<QPixmap> &pixmaps, const QString &spriteName,
|
||||
EditorSettings &settings, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::EditSpriteDialog>()},
|
||||
m_pixmaps{pixmaps},
|
||||
m_settings{settings},
|
||||
m_spriteName{spriteName},
|
||||
m_model{std::make_unique<SpritesModel>(m_pixmaps, this)}
|
||||
m_model{std::make_unique<SpritesModel>(pixmaps, this)}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@@ -138,6 +138,11 @@ void EditSpriteDialog::reject()
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<QPixmap> &EditSpriteDialog::pixmaps() const
|
||||
{
|
||||
return m_model->pixmaps();
|
||||
}
|
||||
|
||||
void EditSpriteDialog::newSprite()
|
||||
{
|
||||
CreateSpriteDialog dialog{this};
|
||||
@@ -146,9 +151,7 @@ void EditSpriteDialog::newSprite()
|
||||
QPixmap pixmap{dialog.spriteSize()};
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
m_model->beginResetModel();
|
||||
m_pixmaps = std::vector<QPixmap> { std::move(pixmap) };
|
||||
m_model->endResetModel();
|
||||
m_model->setPixmaps({ std::move(pixmap) });
|
||||
|
||||
changed();
|
||||
}
|
||||
@@ -160,9 +163,7 @@ void EditSpriteDialog::createFromFile()
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
m_model->beginResetModel();
|
||||
m_pixmaps = std::vector<QPixmap> { std::move(pixmap) };
|
||||
m_model->endResetModel();
|
||||
m_model->setPixmaps({ std::move(pixmap) });
|
||||
|
||||
changed();
|
||||
}
|
||||
@@ -173,16 +174,14 @@ void EditSpriteDialog::addFromFile()
|
||||
if (pixmap.isNull())
|
||||
return;
|
||||
|
||||
if (!m_pixmaps.empty() && m_pixmaps.front().size() != pixmap.size())
|
||||
if (!m_model->empty() && m_model->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();
|
||||
m_model->insertPixmap(std::move(pixmap), m_model->size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,13 +192,13 @@ void EditSpriteDialog::saveAsPng()
|
||||
return;
|
||||
|
||||
const int row = index.row();
|
||||
if (row < 0 || size_t(row) >= m_pixmaps.size())
|
||||
if (row < 0 || size_t(row) >= m_model->size())
|
||||
{
|
||||
qWarning() << "invalid row" << row;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &pixmap = m_pixmaps[row];
|
||||
const auto &pixmap = m_model->pixmap(row);
|
||||
if (pixmap.isNull())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Invalid sprite!"), tr("The sprite you tried to save is invalid!"));
|
||||
@@ -256,17 +255,14 @@ void EditSpriteDialog::delete_()
|
||||
return;
|
||||
|
||||
const int row = index.row();
|
||||
if (row < 0 || size_t(row) >= m_pixmaps.size())
|
||||
if (row < 0 || size_t(row) >= m_model->size())
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
return;
|
||||
}
|
||||
|
||||
m_model->beginRemoveRows({}, row, row);
|
||||
m_pixmaps.erase(std::begin(m_pixmaps) + row);
|
||||
m_model->endRemoveRows();
|
||||
|
||||
changed();
|
||||
if (m_model->removeRow(row))
|
||||
changed();
|
||||
}
|
||||
|
||||
void EditSpriteDialog::moveLeft()
|
||||
@@ -276,17 +272,14 @@ void EditSpriteDialog::moveLeft()
|
||||
return;
|
||||
|
||||
const size_t row = index.row();
|
||||
if (row < 1 || row >= m_pixmaps.size())
|
||||
if (row < 1 || row >= m_model->size())
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
return;
|
||||
}
|
||||
|
||||
m_model->beginMoveRows({}, row, row, {}, row-1);
|
||||
std::swap(m_pixmaps[row-1], m_pixmaps[row]);
|
||||
m_model->endMoveRows();
|
||||
|
||||
changed();
|
||||
if (m_model->moveRow({}, row, {}, row-1))
|
||||
changed();
|
||||
}
|
||||
|
||||
void EditSpriteDialog::moveRight()
|
||||
@@ -296,24 +289,21 @@ void EditSpriteDialog::moveRight()
|
||||
return;
|
||||
|
||||
const int row = index.row();
|
||||
if (row < 0 || size_t(row) >= m_pixmaps.size() - 1)
|
||||
if (row < 0 || size_t(row) >= m_model->size() - 1)
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
return;
|
||||
}
|
||||
|
||||
m_model->beginMoveRows({}, row, row, {}, row+2);
|
||||
std::swap(m_pixmaps[row+1], m_pixmaps[row]);
|
||||
m_model->endMoveRows();
|
||||
|
||||
changed();
|
||||
if (m_model->moveRow({}, row, {}, row+2))
|
||||
changed();
|
||||
}
|
||||
|
||||
void EditSpriteDialog::addEmpty()
|
||||
{
|
||||
QSize size;
|
||||
if (!m_pixmaps.empty())
|
||||
size = m_pixmaps.front().size();
|
||||
if (!m_model->empty())
|
||||
size = m_model->front().size();
|
||||
|
||||
if (size.isEmpty())
|
||||
{
|
||||
@@ -327,9 +317,7 @@ void EditSpriteDialog::addEmpty()
|
||||
QPixmap pixmap{size};
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
m_model->beginInsertRows({}, m_pixmaps.size(), m_pixmaps.size());
|
||||
m_pixmaps.emplace_back(std::move(pixmap));
|
||||
m_model->endInsertRows();
|
||||
m_model->insertPixmap(std::move(pixmap), m_model->size());
|
||||
|
||||
changed();
|
||||
}
|
||||
@@ -342,7 +330,7 @@ void EditSpriteDialog::insertEmpty()
|
||||
if (index.isValid())
|
||||
{
|
||||
row = index.row();
|
||||
if (row < 0 || size_t(row) >= m_pixmaps.size())
|
||||
if (row < 0 || size_t(row) >= m_model->size())
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
row = 0;
|
||||
@@ -350,8 +338,8 @@ void EditSpriteDialog::insertEmpty()
|
||||
}
|
||||
|
||||
QSize size;
|
||||
if (!m_pixmaps.empty())
|
||||
size = m_pixmaps.front().size();
|
||||
if (!m_model->empty())
|
||||
size = m_model->front().size();
|
||||
|
||||
if (size.isEmpty())
|
||||
{
|
||||
@@ -365,9 +353,7 @@ void EditSpriteDialog::insertEmpty()
|
||||
QPixmap pixmap{size};
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
m_model->beginInsertRows({}, row, row);
|
||||
m_pixmaps.emplace(std::begin(m_pixmaps) + row, std::move(pixmap));
|
||||
m_model->endInsertRows();
|
||||
m_model->insertPixmap(std::move(pixmap), row);
|
||||
}
|
||||
|
||||
void EditSpriteDialog::edit()
|
||||
@@ -381,11 +367,9 @@ void EditSpriteDialog::edit()
|
||||
|
||||
void EditSpriteDialog::transparentBackgroundSettings()
|
||||
{
|
||||
TransparentBackgroundSettingsDialog dialog{this};
|
||||
TransparentBackgroundSettingsDialog dialog{m_settings, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
// TODO apply
|
||||
}
|
||||
dialog.save(m_settings);
|
||||
}
|
||||
|
||||
void EditSpriteDialog::activated(const QModelIndex &index)
|
||||
@@ -396,12 +380,10 @@ void EditSpriteDialog::activated(const QModelIndex &index)
|
||||
return;
|
||||
}
|
||||
|
||||
ImageEditorDialog dialog{m_model->pixmap(index), tr("Image Editor: %0").arg(m_spriteName), this};
|
||||
ImageEditorDialog dialog{m_model->pixmap(index), tr("Image Editor: %0").arg(m_spriteName), m_settings, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
m_pixmaps[index.row()] = dialog.pixmap();
|
||||
emit m_model->dataChanged(index, index, {Qt::DecorationRole});
|
||||
|
||||
m_model->setPixmap(dialog.pixmap(), index);
|
||||
changed();
|
||||
}
|
||||
}
|
||||
@@ -414,7 +396,7 @@ void EditSpriteDialog::currentChanged()
|
||||
m_ui->actionCopy->setEnabled(index.isValid());
|
||||
m_ui->actionDelete->setEnabled(index.isValid());
|
||||
m_ui->actionMoveLeft->setEnabled(index.isValid() && index.row() > 0);
|
||||
m_ui->actionMoveRight->setEnabled(index.isValid() && size_t(index.row()) < m_pixmaps.size() - 1);
|
||||
m_ui->actionMoveRight->setEnabled(index.isValid() && size_t(index.row()) < m_model->size() - 1);
|
||||
}
|
||||
|
||||
void EditSpriteDialog::changed()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Ui { class EditSpriteDialog; }
|
||||
class EditorSettings;
|
||||
struct Sprite;
|
||||
class SpritesModel;
|
||||
|
||||
@@ -15,13 +16,14 @@ class EditSpriteDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditSpriteDialog(const std::vector<QPixmap> &pixmaps, const QString &spriteName, QWidget *parent = nullptr);
|
||||
explicit EditSpriteDialog(const std::vector<QPixmap> &pixmaps, const QString &spriteName,
|
||||
EditorSettings &settings, QWidget *parent = nullptr);
|
||||
~EditSpriteDialog();
|
||||
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
const std::vector<QPixmap> &pixmaps() const { return m_pixmaps; }
|
||||
const std::vector<QPixmap> &pixmaps() const;
|
||||
|
||||
private slots:
|
||||
void newSprite();
|
||||
@@ -54,7 +56,8 @@ private:
|
||||
|
||||
const std::unique_ptr<Ui::EditSpriteDialog> m_ui;
|
||||
|
||||
std::vector<QPixmap> m_pixmaps;
|
||||
EditorSettings &m_settings;
|
||||
|
||||
const QString m_spriteName;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
@@ -5,15 +5,17 @@
|
||||
#include <QDebug>
|
||||
#include <QButtonGroup>
|
||||
#include <QFontDialog>
|
||||
#include <QColorDialog>
|
||||
|
||||
#include "dialogs/transparentbackgroundsettingsdialog.h"
|
||||
#include "imagehelpers.h"
|
||||
#include "editorsettings.h"
|
||||
|
||||
ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title, QWidget *parent) :
|
||||
ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title,
|
||||
EditorSettings &settings, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::ImageEditorDialog>()},
|
||||
m_title{title},
|
||||
m_settings{settings},
|
||||
m_posLabel{*new QLabel(tr("(%0,%1)").arg(0).arg(0))},
|
||||
m_zoomLabel{*new QLabel},
|
||||
m_sizeLabel{*new QLabel},
|
||||
@@ -50,11 +52,6 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
|
||||
connect(m_ui->pushButtonSelectFont, &QAbstractButton::pressed,
|
||||
this, &ImageEditorDialog::selectFont);
|
||||
|
||||
connect(m_ui->pushButtonLeftButtonColor, &QAbstractButton::pressed,
|
||||
this, &ImageEditorDialog::selectLeftButtonColor);
|
||||
connect(m_ui->pushButtonRightButtonColor, &QAbstractButton::pressed,
|
||||
this, &ImageEditorDialog::selectRightButtonColor);
|
||||
|
||||
connect(m_ui->frameColorCoarse, &ColorWidget::colorLeftClicked,
|
||||
m_ui->canvas, &DrawingCanvasWidget::setLeftButtonColor);
|
||||
connect(m_ui->frameColorCoarse, &ColorWidget::colorRightClicked,
|
||||
@@ -67,10 +64,16 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
|
||||
|
||||
connect(m_ui->canvas, &DrawingCanvasWidget::changed,
|
||||
this, &ImageEditorDialog::changed);
|
||||
|
||||
connect(m_ui->canvas, &DrawingCanvasWidget::leftButtonColorChanged,
|
||||
this, &ImageEditorDialog::updateLeftButtonColor);
|
||||
m_ui->pushButtonLeftButtonColor, &ColorButton::setColor);
|
||||
connect(m_ui->pushButtonLeftButtonColor, &ColorButton::colorChanged,
|
||||
m_ui->canvas, &DrawingCanvasWidget::setLeftButtonColor);
|
||||
|
||||
connect(m_ui->canvas, &DrawingCanvasWidget::rightButtonColorChanged,
|
||||
this, &ImageEditorDialog::updateRightButtonColor);
|
||||
m_ui->pushButtonRightButtonColor, &ColorButton::setColor);
|
||||
connect(m_ui->pushButtonRightButtonColor, &ColorButton::colorChanged,
|
||||
m_ui->canvas, &DrawingCanvasWidget::rightButtonColor);
|
||||
|
||||
{
|
||||
auto group = new QButtonGroup{this};
|
||||
@@ -96,6 +99,17 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
|
||||
m_ui->canvas, [canvas=m_ui->canvas](int id){ canvas->setMode(DrawingCanvasWidget::Mode(id)); });
|
||||
}
|
||||
|
||||
{
|
||||
auto group = new QButtonGroup{this};
|
||||
group->setExclusive(true);
|
||||
group->addButton(m_ui->toolButtonSize1);
|
||||
group->addButton(m_ui->toolButtonSize2);
|
||||
group->addButton(m_ui->toolButtonSize3);
|
||||
group->addButton(m_ui->toolButtonSize4);
|
||||
group->addButton(m_ui->toolButtonSize5);
|
||||
group->addButton(m_ui->toolButtonSize6);
|
||||
}
|
||||
|
||||
{
|
||||
auto group = new QButtonGroup{this};
|
||||
group->setExclusive(true);
|
||||
@@ -121,10 +135,11 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
|
||||
group->addButton(m_ui->toolButtonAlignRight);
|
||||
}
|
||||
|
||||
updateLeftButtonColor(m_ui->canvas->leftButtonColor());
|
||||
updateRightButtonColor(m_ui->canvas->rightButtonColor());
|
||||
m_ui->pushButtonLeftButtonColor->setColor(m_ui->canvas->leftButtonColor());
|
||||
m_ui->pushButtonRightButtonColor->setColor(m_ui->canvas->rightButtonColor());
|
||||
|
||||
m_ui->canvas->setPixmap(pixmap);
|
||||
m_ui->canvas->setTransparentBackgroundPattern(settings.transparentBackgroundPattern());
|
||||
|
||||
connect(m_ui->canvas, &DrawingCanvasWidget::cursorMoved,
|
||||
this, &ImageEditorDialog::cursorMoved);
|
||||
@@ -159,13 +174,6 @@ const QImage &ImageEditorDialog::image() const
|
||||
return m_ui->canvas->image();
|
||||
}
|
||||
|
||||
void ImageEditorDialog::accept()
|
||||
{
|
||||
// TODO
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void ImageEditorDialog::reject()
|
||||
{
|
||||
if (!m_unsavedChanges)
|
||||
@@ -210,10 +218,11 @@ void ImageEditorDialog::saveAsPng()
|
||||
|
||||
void ImageEditorDialog::transparentBackgroundSettings()
|
||||
{
|
||||
TransparentBackgroundSettingsDialog dialog{this};
|
||||
TransparentBackgroundSettingsDialog dialog{m_settings, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
// TODO apply
|
||||
dialog.save(m_settings);
|
||||
m_ui->canvas->setTransparentBackgroundPattern(m_settings.transparentBackgroundPattern());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,38 +242,6 @@ void ImageEditorDialog::selectFont()
|
||||
m_ui->pushButtonSelectFont->setFont(dialog.selectedFont());
|
||||
}
|
||||
|
||||
void ImageEditorDialog::selectLeftButtonColor()
|
||||
{
|
||||
QColorDialog dialog{m_ui->canvas->leftButtonColor(), this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
m_ui->canvas->setLeftButtonColor(dialog.selectedColor());
|
||||
}
|
||||
|
||||
void ImageEditorDialog::selectRightButtonColor()
|
||||
{
|
||||
QColorDialog dialog{m_ui->canvas->rightButtonColor(), this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
m_ui->canvas->setRightButtonColor(dialog.selectedColor());
|
||||
}
|
||||
|
||||
void ImageEditorDialog::updateLeftButtonColor(const QColor &leftButtonColor)
|
||||
{
|
||||
auto frame = m_ui->pushButtonLeftButtonColor;
|
||||
auto palette = frame->palette();
|
||||
auto role = frame->backgroundRole();
|
||||
palette.setBrush(role, leftButtonColor);
|
||||
frame->setPalette(palette);
|
||||
}
|
||||
|
||||
void ImageEditorDialog::updateRightButtonColor(const QColor &rightButtonColor)
|
||||
{
|
||||
auto frame = m_ui->pushButtonRightButtonColor;
|
||||
auto palette = frame->palette();
|
||||
auto role = frame->backgroundRole();
|
||||
palette.setBrush(role, rightButtonColor);
|
||||
frame->setPalette(palette);
|
||||
}
|
||||
|
||||
void ImageEditorDialog::modeChanged(DrawingCanvasWidget::Mode mode)
|
||||
{
|
||||
QString msg;
|
||||
|
||||
@@ -11,19 +11,20 @@ class QLabel;
|
||||
class QPixmap;
|
||||
class QImage;
|
||||
namespace Ui { class ImageEditorDialog; }
|
||||
class EditorSettings;
|
||||
|
||||
class ImageEditorDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImageEditorDialog(const QPixmap &pixmap, const QString &title, QWidget *parent = nullptr);
|
||||
explicit ImageEditorDialog(const QPixmap &pixmap, const QString &title,
|
||||
EditorSettings &settings, QWidget *parent = nullptr);
|
||||
~ImageEditorDialog();
|
||||
|
||||
QPixmap pixmap() const;
|
||||
const QImage &image() const;
|
||||
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
@@ -32,10 +33,6 @@ private slots:
|
||||
|
||||
void changed();
|
||||
void selectFont();
|
||||
void selectLeftButtonColor();
|
||||
void selectRightButtonColor();
|
||||
void updateLeftButtonColor(const QColor &leftButtonColor);
|
||||
void updateRightButtonColor(const QColor &rightButtonColor);
|
||||
void modeChanged(DrawingCanvasWidget::Mode mode);
|
||||
void cursorMoved(const QPoint &pos);
|
||||
void zoomChanged(float zoom);
|
||||
@@ -47,6 +44,7 @@ private:
|
||||
const std::unique_ptr<Ui::ImageEditorDialog> m_ui;
|
||||
|
||||
const QString m_title;
|
||||
EditorSettings &m_settings;
|
||||
|
||||
QLabel &m_posLabel;
|
||||
QLabel &m_zoomLabel;
|
||||
|
||||
@@ -746,7 +746,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonLeftButtonColor">
|
||||
<widget class="ColorButton" name="pushButtonLeftButtonColor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@@ -772,7 +772,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonRightButtonColor">
|
||||
<widget class="ColorButton" name="pushButtonRightButtonColor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@@ -1163,6 +1163,11 @@
|
||||
<header>widgets/zoomablescrollarea.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>widgets/colorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../resources_editor.qrc"/>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "preferencesdialog.h"
|
||||
#include "ui_preferencesdialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include "editorsettings.h"
|
||||
|
||||
PreferencesDialog::PreferencesDialog(QWidget *parent) :
|
||||
PreferencesDialog::PreferencesDialog(const EditorSettings &settings, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::PreferencesDialog>()}
|
||||
{
|
||||
@@ -17,6 +18,20 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
|
||||
setWindowFlag(Qt::WindowCloseButtonHint);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
|
||||
Q_UNUSED(settings);
|
||||
// TODO copy from settings to m_ui->*
|
||||
}
|
||||
|
||||
PreferencesDialog::~PreferencesDialog() = default;
|
||||
|
||||
void PreferencesDialog::save(EditorSettings &settings)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
// TODO copy from m_ui->* to settings
|
||||
}
|
||||
|
||||
void PreferencesDialog::accept()
|
||||
{
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
@@ -5,15 +5,21 @@
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class PreferencesDialog; }
|
||||
class EditorSettings;
|
||||
|
||||
class PreferencesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PreferencesDialog(QWidget *parent = nullptr);
|
||||
explicit PreferencesDialog(const EditorSettings &settings, QWidget *parent = nullptr);
|
||||
~PreferencesDialog();
|
||||
|
||||
void save(EditorSettings &settings);
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::PreferencesDialog> m_ui;
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>634</width>
|
||||
<height>614</height>
|
||||
<width>747</width>
|
||||
<height>463</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -29,21 +29,21 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_2">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&Show recently edited games in the file menu</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&Load last openend file on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -56,7 +56,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_3">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&Keep backup copies of files (with extension .qb1, .qb2)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -65,7 +65,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -78,7 +78,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Ma&ximum number of backups:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -88,7 +88,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -103,7 +103,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -116,28 +116,28 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_4">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Show progress while loading and saving files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_5">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>At start&up, check for, and remove old temporary files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_6">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Don't show the &website image in the main menu</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -150,21 +150,21 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_7">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&Hide the designer and wait while the game is running</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_8">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&Run games in secure mode, not executing any programs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -179,33 +179,40 @@
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::HLine</enum>
|
||||
<enum>QFrame::Shape::HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
<enum>QFrame::Shadow::Sunken</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0,0,0,0,0,1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0,0,0,0,0,0,1">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_9">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Show &news on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_10">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Show news in default &browser</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_18">
|
||||
<property name="text">
|
||||
<string>Show Minimap in Room editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -218,7 +225,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Location of the GameMaker TV style logo on screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -228,7 +235,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -241,14 +248,14 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_11">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Show Trace.log after &Debug</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -270,13 +277,13 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
<string>Sprite Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_12">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>S&how the origin in the sprite image</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -286,7 +293,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -299,13 +306,13 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
<string>Object Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_13">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&In object properties, show hints for the actions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -314,7 +321,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -327,7 +334,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Default TAB to select:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -337,7 +344,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -355,7 +362,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_9">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -368,27 +375,27 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
<string>Room Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_14">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>&When closing, remove instances outside the room</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_15">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>R&emember room settings when closing the form</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_16">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Room Grid ON by default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -397,21 +404,17 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_17">
|
||||
<property name="text">
|
||||
<string>CheckBox</string>
|
||||
<string>Fill room with color when no background color selected. (Editor only)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="ColorButton" name="pushButton"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -429,7 +432,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -456,12 +459,19 @@
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>widgets/colorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -19,6 +19,7 @@ SpritePropertiesDialog::SpritePropertiesDialog(Sprite &sprite, ProjectTreeModel
|
||||
m_ui{std::make_unique<Ui::SpritePropertiesDialog>()},
|
||||
m_sprite{sprite},
|
||||
m_projectModel{projectModel},
|
||||
m_mainWindow{mainWindow},
|
||||
m_pixmaps{m_sprite.pixmaps}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
@@ -147,7 +148,12 @@ void SpritePropertiesDialog::saveSprite()
|
||||
|
||||
void SpritePropertiesDialog::editSprite()
|
||||
{
|
||||
EditSpriteDialog dialog{m_pixmaps, m_sprite.name, this};
|
||||
EditSpriteDialog dialog {
|
||||
m_pixmaps,
|
||||
m_sprite.name,
|
||||
m_mainWindow.settings(),
|
||||
this
|
||||
};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
m_pixmaps = dialog.pixmaps();
|
||||
@@ -158,16 +164,17 @@ void SpritePropertiesDialog::editSprite()
|
||||
|
||||
void SpritePropertiesDialog::centerOrigin()
|
||||
{
|
||||
QPoint center;
|
||||
if (m_pixmaps.empty() || m_pixmaps.front().isNull())
|
||||
{
|
||||
qDebug() << "unexpected empty pixmaps";
|
||||
m_ui->spinBoxOriginX->setValue(0);
|
||||
m_ui->spinBoxOriginY->setValue(0);
|
||||
return;
|
||||
}
|
||||
else
|
||||
center = {
|
||||
m_pixmaps.front().width() / 2,
|
||||
m_pixmaps.front().height() / 2
|
||||
};
|
||||
|
||||
m_ui->spinBoxOriginX->setValue(m_pixmaps.front().width() / 2);
|
||||
m_ui->spinBoxOriginY->setValue(m_pixmaps.front().height() / 2);
|
||||
m_ui->spinBoxOriginX->setValue(center.x());
|
||||
m_ui->spinBoxOriginY->setValue(center.y());
|
||||
}
|
||||
|
||||
void SpritePropertiesDialog::modifyMask()
|
||||
|
||||
@@ -40,6 +40,7 @@ private:
|
||||
|
||||
Sprite &m_sprite;
|
||||
ProjectTreeModel &m_projectModel;
|
||||
MainWindow &m_mainWindow;
|
||||
|
||||
bool m_unsavedChanges{};
|
||||
|
||||
|
||||
@@ -1,15 +1,69 @@
|
||||
#include "transparentbackgroundsettingsdialog.h"
|
||||
#include "ui_transparentbackgroundsettingsdialog.h"
|
||||
|
||||
#include "editorguiutils.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
TransparentBackgroundSettingsDialog::TransparentBackgroundSettingsDialog(QWidget *parent) :
|
||||
#include "editorguiutils.h"
|
||||
#include "editorsettings.h"
|
||||
|
||||
TransparentBackgroundSettingsDialog::TransparentBackgroundSettingsDialog(const EditorSettings &settings, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_ui{std::make_unique<Ui::TransparentBackgroundSettingsDialog>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
improveButtonBox(m_ui->buttonBox);
|
||||
|
||||
const auto type = settings.transparentBackgroundPatternType();
|
||||
switch (type)
|
||||
{
|
||||
case TransparentBackgroundPattern::Type::BlockPattern:
|
||||
m_ui->radioButtonBlockPattern->setChecked(true);
|
||||
goto after;
|
||||
case TransparentBackgroundPattern::Type::SingleColor:
|
||||
m_ui->radioButtonSingleColor->setChecked(true);
|
||||
goto after;
|
||||
}
|
||||
qWarning() << "unknown TransparentBackgroundPattern::Type" << std::to_underlying(type);
|
||||
after:
|
||||
|
||||
m_ui->pushButtonColor1->setColor(settings.transparentBackgroundBlockPatternColor1());
|
||||
m_ui->pushButtonColor2->setColor(settings.transparentBackgroundBlockPatternColor2());
|
||||
m_ui->spinBoxBlockSize->setValue(settings.transparentBackgroundBlockPatternBlockSize());
|
||||
m_ui->pushButtonColor->setColor(settings.transparentBackgroundSingleColor());
|
||||
}
|
||||
|
||||
TransparentBackgroundSettingsDialog::~TransparentBackgroundSettingsDialog() = default;
|
||||
|
||||
void TransparentBackgroundSettingsDialog::save(EditorSettings &settings)
|
||||
{
|
||||
if (m_ui->radioButtonBlockPattern->isChecked())
|
||||
settings.setTransparentBackgroundPatternType(TransparentBackgroundPattern::Type::BlockPattern);
|
||||
else if (m_ui->radioButtonSingleColor->isChecked())
|
||||
settings.setTransparentBackgroundPatternType(TransparentBackgroundPattern::Type::SingleColor);
|
||||
else
|
||||
qWarning() << "no type is selected?!";
|
||||
|
||||
settings.setTransparentBackgroundBlockPatternColor1(m_ui->pushButtonColor1->color());
|
||||
settings.setTransparentBackgroundBlockPatternColor2(m_ui->pushButtonColor2->color());
|
||||
settings.setTransparentBackgroundBlockPatternBlockSize(m_ui->spinBoxBlockSize->value());
|
||||
settings.setTransparentBackgroundSingleColor(m_ui->pushButtonColor->color());
|
||||
}
|
||||
|
||||
void TransparentBackgroundSettingsDialog::accept()
|
||||
{
|
||||
if (!m_ui->radioButtonBlockPattern->isChecked() &&
|
||||
!m_ui->radioButtonSingleColor->isChecked())
|
||||
{
|
||||
QMessageBox::warning(this, tr("No pattern type selected!"), tr("No pattern type selected!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ui->spinBoxBlockSize->value() < 1)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Invalid block size selected!"), tr("Invalid block size selected!"));
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@@ -5,15 +5,21 @@
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class TransparentBackgroundSettingsDialog; }
|
||||
class EditorSettings;
|
||||
|
||||
class TransparentBackgroundSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TransparentBackgroundSettingsDialog(QWidget *parent = nullptr);
|
||||
explicit TransparentBackgroundSettingsDialog(const EditorSettings &settings, QWidget *parent = nullptr);
|
||||
~TransparentBackgroundSettingsDialog() override;
|
||||
|
||||
void save(EditorSettings &settings);
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::TransparentBackgroundSettingsDialog> m_ui;
|
||||
};
|
||||
|
||||
@@ -6,30 +6,137 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>301</width>
|
||||
<height>221</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Transparent Background Settings</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="2">
|
||||
<widget class="ColorButton" name="pushButtonColor"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="radioButtonBlockPattern">
|
||||
<property name="text">
|
||||
<string>Block pattern</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QSpinBox" name="spinBoxBlockSize">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="labelColor">
|
||||
<property name="text">
|
||||
<string>Color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="ColorButton" name="pushButtonColor1"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QRadioButton" name="radioButtonSingleColor">
|
||||
<property name="text">
|
||||
<string>Single color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="labelColor1">
|
||||
<property name="text">
|
||||
<string>Color 1:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="ColorButton" name="pushButtonColor2"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="labelColor2">
|
||||
<property name="text">
|
||||
<string>Color 2:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="labelBlockSize">
|
||||
<property name="text">
|
||||
<string>Block size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>widgets/colorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -45,3 +45,35 @@ void improveButtonBox(QDialogButtonBox *buttonBox)
|
||||
if (auto button = buttonBox->button(QDialogButtonBox::Cancel))
|
||||
button->setIcon(QIcon{":/qtgameengine/icons/delete.png"});
|
||||
}
|
||||
|
||||
static QBrush makeBlockPatternBrush(QColor color1, QColor color2, int blockSize)
|
||||
{
|
||||
QBrush brush;
|
||||
QPixmap pixmap{blockSize * 2, blockSize * 2};
|
||||
QPainter painter{&pixmap};
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(color1);
|
||||
painter.drawRect(0, 0, blockSize, blockSize);
|
||||
painter.drawRect(blockSize, blockSize, blockSize, blockSize);
|
||||
painter.setBrush(color2);
|
||||
painter.drawRect(0, blockSize, blockSize, blockSize);
|
||||
painter.drawRect(blockSize, 0, blockSize, blockSize);
|
||||
brush.setTexture(std::move(pixmap));
|
||||
return brush;
|
||||
}
|
||||
|
||||
QBrush makeTransparentBackgroundPatternBrush(const TransparentBackgroundPattern &transparentBackgroundPattern)
|
||||
{
|
||||
switch (transparentBackgroundPattern.type)
|
||||
{
|
||||
case TransparentBackgroundPattern::Type::BlockPattern:
|
||||
return makeBlockPatternBrush(
|
||||
transparentBackgroundPattern.color1,
|
||||
transparentBackgroundPattern.color2,
|
||||
transparentBackgroundPattern.blockSize);
|
||||
case TransparentBackgroundPattern::Type::SingleColor:
|
||||
return transparentBackgroundPattern.singleColor;
|
||||
}
|
||||
qWarning() << "unknown TransparentBackgroundPattern::Type" << transparentBackgroundPattern.type;
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
|
||||
class QBrush;
|
||||
class QPen;
|
||||
class QColor;
|
||||
class QDialogButtonBox;
|
||||
|
||||
QBrush makeGridBrush(int snapX, int snapY, const QPen &gridPen, const QColor &backgroundColor);
|
||||
QBrush makeGridBrush(int snapX, int snapY, const QColor &gridColor, const QColor &backgroundColor);
|
||||
|
||||
struct TransparentBackgroundPattern
|
||||
{
|
||||
Q_GADGET
|
||||
public:
|
||||
|
||||
enum class Type {
|
||||
BlockPattern,
|
||||
SingleColor
|
||||
};
|
||||
Q_ENUM(Type)
|
||||
|
||||
Type type{Type::BlockPattern};
|
||||
QColor color1{Qt::gray};
|
||||
QColor color2{Qt::white};
|
||||
int blockSize{16};
|
||||
|
||||
QColor singleColor{Qt::darkGray};
|
||||
|
||||
constexpr bool operator==(const TransparentBackgroundPattern &other) const = default;
|
||||
};
|
||||
|
||||
QBrush makeTransparentBackgroundPatternBrush(const TransparentBackgroundPattern &transparentBackgroundPattern);
|
||||
|
||||
void improveButtonBox(QDialogButtonBox *buttonBox);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "editorsettings.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
QByteArray EditorSettings::mainWindowGeometry() const
|
||||
{
|
||||
return value("mainWindowGeometry").toByteArray();
|
||||
}
|
||||
|
||||
void EditorSettings::setMainWindowGeometry(const QByteArray &mainWindowGeometry)
|
||||
{
|
||||
setValue("mainWindowGeometry", mainWindowGeometry);
|
||||
}
|
||||
|
||||
QByteArray EditorSettings::mainWindowState() const
|
||||
{
|
||||
return value("mainWindowState").toByteArray();
|
||||
}
|
||||
|
||||
void EditorSettings::setMainWindowState(const QByteArray &mainWindowState)
|
||||
{
|
||||
setValue("mainWindowState", mainWindowState);
|
||||
}
|
||||
|
||||
TransparentBackgroundPattern::Type EditorSettings::transparentBackgroundPatternType() const
|
||||
{
|
||||
return value("transparentBackgroundPatternType", QVariant::fromValue(TransparentBackgroundPattern::Type::BlockPattern)).value<TransparentBackgroundPattern::Type>();
|
||||
}
|
||||
|
||||
void EditorSettings::setTransparentBackgroundPatternType(TransparentBackgroundPattern::Type transparentBackgroundPatternType)
|
||||
{
|
||||
setValue("transparentBackgroundPatternType", QVariant::fromValue(transparentBackgroundPatternType));
|
||||
}
|
||||
|
||||
QColor EditorSettings::transparentBackgroundBlockPatternColor1() const
|
||||
{
|
||||
return value("transparentBackgroundBlockPatternColor1", QColor{Qt::gray}).value<QColor>();
|
||||
}
|
||||
|
||||
void EditorSettings::setTransparentBackgroundBlockPatternColor1(QColor transparentBackgroundBlockPatternColor1)
|
||||
{
|
||||
setValue("transparentBackgroundBlockPatternColor1", transparentBackgroundBlockPatternColor1);
|
||||
}
|
||||
|
||||
QColor EditorSettings::transparentBackgroundBlockPatternColor2() const
|
||||
{
|
||||
return value("transparentBackgroundBlockPatternColor2", QColor{Qt::white}).value<QColor>();
|
||||
}
|
||||
|
||||
void EditorSettings::setTransparentBackgroundBlockPatternColor2(QColor transparentBackgroundBlockPatternColor2)
|
||||
{
|
||||
setValue("transparentBackgroundBlockPatternColor2", transparentBackgroundBlockPatternColor2);
|
||||
}
|
||||
|
||||
int EditorSettings::transparentBackgroundBlockPatternBlockSize() const
|
||||
{
|
||||
return value("transparentBackgroundBlockPatternBlockSize", 16).toInt();
|
||||
}
|
||||
|
||||
void EditorSettings::setTransparentBackgroundBlockPatternBlockSize(int transparentBackgroundBlockPatternBlockSize)
|
||||
{
|
||||
setValue("transparentBackgroundBlockPatternBlockSize", transparentBackgroundBlockPatternBlockSize);
|
||||
}
|
||||
|
||||
QColor EditorSettings::transparentBackgroundSingleColor() const
|
||||
{
|
||||
return value("transparentBackgroundSingleColor", QColor{Qt::darkGray}).value<QColor>();
|
||||
}
|
||||
|
||||
void EditorSettings::setTransparentBackgroundSingleColor(QColor transparentBackgroundSingleColor)
|
||||
{
|
||||
setValue("transparentBackgroundSingleColor", transparentBackgroundSingleColor);
|
||||
}
|
||||
|
||||
TransparentBackgroundPattern EditorSettings::transparentBackgroundPattern() const
|
||||
{
|
||||
return TransparentBackgroundPattern {
|
||||
transparentBackgroundPatternType(),
|
||||
transparentBackgroundBlockPatternColor1(),
|
||||
transparentBackgroundBlockPatternColor2(),
|
||||
transparentBackgroundBlockPatternBlockSize(),
|
||||
transparentBackgroundSingleColor()
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
|
||||
class EditorSettings : public QSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using QSettings::QSettings;
|
||||
|
||||
QByteArray mainWindowGeometry() const;
|
||||
void setMainWindowGeometry(const QByteArray &mainWindowGeometry);
|
||||
|
||||
QByteArray mainWindowState() const;
|
||||
void setMainWindowState(const QByteArray &mainWindowState);
|
||||
|
||||
TransparentBackgroundPattern::Type transparentBackgroundPatternType() const;
|
||||
void setTransparentBackgroundPatternType(TransparentBackgroundPattern::Type transparentBackgroundPatternType);
|
||||
|
||||
QColor transparentBackgroundBlockPatternColor1() const;
|
||||
void setTransparentBackgroundBlockPatternColor1(QColor transparentBackgroundBlockPatternColor1);
|
||||
|
||||
QColor transparentBackgroundBlockPatternColor2() const;
|
||||
void setTransparentBackgroundBlockPatternColor2(QColor transparentBackgroundBlockPatternColor2);
|
||||
|
||||
int transparentBackgroundBlockPatternBlockSize() const;
|
||||
void setTransparentBackgroundBlockPatternBlockSize(int transparentBackgroundBlockPatternBlockSize);
|
||||
|
||||
QColor transparentBackgroundSingleColor() const;
|
||||
void setTransparentBackgroundSingleColor(QColor transparentBackgroundSingleColor);
|
||||
|
||||
TransparentBackgroundPattern transparentBackgroundPattern() const;
|
||||
};
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QInputDialog>
|
||||
#include <QDebug>
|
||||
|
||||
#include "editorsettings.h"
|
||||
#include "projectserialization.h"
|
||||
#include "models/projecttreemodel.h"
|
||||
#include "dialogs/preferencesdialog.h"
|
||||
@@ -47,9 +48,10 @@ template<> struct PropertiesDialogForDetail<Room> { using Type = RoomPropertiesD
|
||||
template<typename T> using PropertiesDialogFor = typename PropertiesDialogForDetail<T>::Type;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(const QString &filePath, QWidget *parent) :
|
||||
MainWindow::MainWindow(const QString &filePath, EditorSettings &settings, QWidget *parent) :
|
||||
QMainWindow{parent},
|
||||
m_ui{std::make_unique<Ui::MainWindow>()},
|
||||
m_settings{settings},
|
||||
m_filePath{filePath},
|
||||
m_projectTreeModel{std::make_unique<ProjectTreeModel>(m_project, this)}
|
||||
{
|
||||
@@ -166,6 +168,9 @@ MainWindow::MainWindow(const QString &filePath, QWidget *parent) :
|
||||
|
||||
if (!m_filePath.isEmpty())
|
||||
loadFile(m_filePath);
|
||||
|
||||
restoreGeometry(m_settings.mainWindowGeometry());
|
||||
restoreState(m_settings.mainWindowState());
|
||||
}
|
||||
|
||||
template<>
|
||||
@@ -319,6 +324,9 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.setMainWindowGeometry(saveGeometry());
|
||||
m_settings.setMainWindowState(saveState());
|
||||
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
@@ -594,8 +602,9 @@ void MainWindow::exportResources()
|
||||
|
||||
void MainWindow::preferences()
|
||||
{
|
||||
PreferencesDialog dialog{this};
|
||||
dialog.exec();
|
||||
PreferencesDialog dialog{m_settings, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
dialog.save(m_settings);
|
||||
}
|
||||
|
||||
void MainWindow::create()
|
||||
@@ -718,11 +727,9 @@ void MainWindow::showObjectInformation()
|
||||
|
||||
void MainWindow::transparentBackgroundSettings()
|
||||
{
|
||||
TransparentBackgroundSettingsDialog dialog{this};
|
||||
TransparentBackgroundSettingsDialog dialog{m_settings, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
// TODO apply
|
||||
}
|
||||
dialog.save(m_settings);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
class QMdiSubWindow;
|
||||
class QActionGroup;
|
||||
namespace Ui { class MainWindow; }
|
||||
class EditorSettings;
|
||||
class ProjectTreeModel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
@@ -17,9 +18,12 @@ class MainWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(const QString &filePath, QWidget *parent = nullptr);
|
||||
explicit MainWindow(const QString &filePath, EditorSettings &settings, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
EditorSettings &settings() { return m_settings; }
|
||||
const EditorSettings &settings() const { return m_settings; }
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
std::map<T*, QMdiSubWindow*> &propertyWindowsFor();
|
||||
@@ -96,6 +100,8 @@ private:
|
||||
|
||||
const std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
|
||||
EditorSettings &m_settings;
|
||||
|
||||
ProjectContainer m_project;
|
||||
|
||||
QString m_filePath;
|
||||
|
||||
@@ -9,6 +9,12 @@ SpritesModel::SpritesModel(const std::vector<QPixmap> &pixmaps, QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
SpritesModel::SpritesModel(std::vector<QPixmap> &&pixmaps, QObject *parent) :
|
||||
QAbstractListModel{parent},
|
||||
m_pixmaps{std::move(pixmaps)}
|
||||
{
|
||||
}
|
||||
|
||||
int SpritesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
@@ -45,10 +51,124 @@ QVariant SpritesModel::data(const QModelIndex &index, int role) const
|
||||
return {};
|
||||
}
|
||||
|
||||
bool SpritesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
||||
if (row < 0 || std::size_t(row) >= m_pixmaps.size())
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count < 0 || std::size_t(count) > m_pixmaps.size() - row)
|
||||
{
|
||||
qWarning() << "unexpected row+count" << count << row;
|
||||
return false;
|
||||
}
|
||||
|
||||
beginRemoveRows({}, row, row + count - 1);
|
||||
auto begin = std::next(std::begin(m_pixmaps), row);
|
||||
auto end = std::next(begin, count);
|
||||
m_pixmaps.erase(begin, end);
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpritesModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
|
||||
{
|
||||
if (sourceParent.isValid())
|
||||
return false;
|
||||
if (destinationParent.isValid())
|
||||
return false;
|
||||
if (count != 1)
|
||||
return false;
|
||||
|
||||
beginMoveRows({}, sourceRow, sourceRow, {}, destinationChild);
|
||||
auto first = m_pixmaps.begin();
|
||||
auto src = first + sourceRow;
|
||||
auto dst = first + destinationChild;
|
||||
|
||||
if (src < dst)
|
||||
std::rotate(src, src + 1, dst);
|
||||
else if (dst < src)
|
||||
std::rotate(dst, src, src + 1);
|
||||
endMoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmaps(const std::vector<QPixmap> &pixmaps)
|
||||
{
|
||||
beginResetModel();
|
||||
m_pixmaps = pixmaps;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmaps(std::vector<QPixmap> &&pixmaps)
|
||||
{
|
||||
beginResetModel();
|
||||
m_pixmaps = std::move(pixmaps);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
const QPixmap &SpritesModel::pixmap(const QModelIndex &index) const
|
||||
{
|
||||
if (index.row() < 0 || std::size_t(index.row()) >= m_pixmaps.size())
|
||||
if (!index.isValid())
|
||||
qFatal("invalid index");
|
||||
return pixmap(index.row());
|
||||
}
|
||||
|
||||
const QPixmap &SpritesModel::pixmap(int row) const
|
||||
{
|
||||
if (row < 0 || std::size_t(row) >= m_pixmaps.size())
|
||||
qFatal("row %i out of range", row);
|
||||
return m_pixmaps.at(row);
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(const QPixmap &pixmap, const QModelIndex &index)
|
||||
{
|
||||
m_pixmaps[index.row()] = pixmap;
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(QPixmap &&pixmap, const QModelIndex &index)
|
||||
{
|
||||
m_pixmaps[index.row()] = std::move(pixmap);
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(const QPixmap &pixmap, int row)
|
||||
{
|
||||
const auto index = createIndex(row, 0);
|
||||
m_pixmaps[index.row()] = pixmap;
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(QPixmap &&pixmap, int row)
|
||||
{
|
||||
const auto index = createIndex(row, 0);
|
||||
m_pixmaps[index.row()] = std::move(pixmap);
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::insertPixmap(const QPixmap &pixmap, std::size_t index)
|
||||
{
|
||||
if (index > m_pixmaps.size())
|
||||
qFatal("index out of range");
|
||||
|
||||
return m_pixmaps.at(index.row());
|
||||
beginInsertRows({}, index, index);
|
||||
m_pixmaps.emplace(std::begin(m_pixmaps) + index, pixmap);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void SpritesModel::insertPixmap(QPixmap &&pixmap, std::size_t index)
|
||||
{
|
||||
if (index > m_pixmaps.size())
|
||||
qFatal("index out of range");
|
||||
|
||||
beginInsertRows({}, index, index);
|
||||
m_pixmaps.emplace(std::begin(m_pixmaps) + index, std::move(pixmap));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@@ -11,24 +11,31 @@ class SpritesModel : public QAbstractListModel
|
||||
|
||||
public:
|
||||
explicit SpritesModel(const std::vector<QPixmap> &pixmaps, QObject *parent = nullptr);
|
||||
explicit SpritesModel(std::vector<QPixmap> &&pixmaps, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
||||
|
||||
const std::vector<QPixmap> &pixmaps() const { return m_pixmaps; }
|
||||
void setPixmaps(const std::vector<QPixmap> &pixmaps);
|
||||
void setPixmaps(std::vector<QPixmap> &&pixmaps);
|
||||
|
||||
auto size() const { return m_pixmaps.size(); }
|
||||
auto empty() const { return m_pixmaps.empty(); }
|
||||
const auto &front() const { return m_pixmaps.front(); }
|
||||
|
||||
const QPixmap &pixmap(const QModelIndex &index) const;
|
||||
const QPixmap &pixmap(int row) const;
|
||||
void setPixmap(const QPixmap &pixmap, const QModelIndex &index);
|
||||
void setPixmap(QPixmap &&pixmap, const QModelIndex &index);
|
||||
void setPixmap(const QPixmap &pixmap, int row);
|
||||
void setPixmap(QPixmap &&pixmap, int row);
|
||||
|
||||
using QAbstractListModel::beginResetModel;
|
||||
using QAbstractListModel::endResetModel;
|
||||
|
||||
using QAbstractListModel::beginInsertRows;
|
||||
using QAbstractListModel::endInsertRows;
|
||||
|
||||
using QAbstractListModel::beginRemoveRows;
|
||||
using QAbstractListModel::endRemoveRows;
|
||||
|
||||
using QAbstractListModel::beginMoveRows;
|
||||
using QAbstractListModel::endMoveRows;
|
||||
void insertPixmap(const QPixmap &pixmap, std::size_t index);
|
||||
void insertPixmap(QPixmap &&pixmap, std::size_t index);
|
||||
|
||||
private:
|
||||
const std::vector<QPixmap> &m_pixmaps;
|
||||
std::vector<QPixmap> m_pixmaps;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "colorbutton.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
|
||||
ColorButton::ColorButton(QWidget *parent) :
|
||||
QPushButton{parent}
|
||||
{
|
||||
connect(this, &QAbstractButton::pressed,
|
||||
this, &ColorButton::selectColor);
|
||||
}
|
||||
|
||||
ColorButton::ColorButton(const QString &text, QWidget *parent) :
|
||||
QPushButton{text, parent}
|
||||
{
|
||||
connect(this, &QAbstractButton::pressed,
|
||||
this, &ColorButton::selectColor);
|
||||
}
|
||||
|
||||
ColorButton::ColorButton(const QIcon &icon, const QString &text, QWidget *parent) :
|
||||
QPushButton{icon, text, parent}
|
||||
{
|
||||
connect(this, &QAbstractButton::pressed,
|
||||
this, &ColorButton::selectColor);
|
||||
}
|
||||
|
||||
void ColorButton::setColor(const QColor &color)
|
||||
{
|
||||
if (m_color == color)
|
||||
return;
|
||||
|
||||
auto pal = palette();
|
||||
pal.setBrush(backgroundRole(), color);
|
||||
setPalette(pal);
|
||||
|
||||
emit colorChanged(m_color = color);
|
||||
}
|
||||
|
||||
void ColorButton::selectColor()
|
||||
{
|
||||
QColorDialog dialog{m_color, this};
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
setColor(dialog.selectedColor());
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class ColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true FINAL)
|
||||
|
||||
public:
|
||||
explicit ColorButton(QWidget *parent = nullptr);
|
||||
explicit ColorButton(const QString &text, QWidget *parent = nullptr);
|
||||
ColorButton(const QIcon& icon, const QString &text, QWidget *parent = nullptr);
|
||||
|
||||
QColor color() const { return m_color; }
|
||||
|
||||
public slots:
|
||||
void setColor(const QColor &color);
|
||||
|
||||
signals:
|
||||
void colorChanged(const QColor &color);
|
||||
|
||||
private slots:
|
||||
void selectColor();
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
};
|
||||
@@ -55,25 +55,20 @@ void DrawingCanvasWidget::setRightButtonColor(const QColor &rightButtonColor)
|
||||
emit rightButtonColorChanged(m_rightButtonColor = rightButtonColor);
|
||||
}
|
||||
|
||||
void DrawingCanvasWidget::setTransparentBackgroundPattern(const TransparentBackgroundPattern &transparentBackgroundPattern)
|
||||
{
|
||||
if (m_transparentBackgroundPattern == transparentBackgroundPattern)
|
||||
return;
|
||||
|
||||
emit transparentBackgroundPatternChanged(m_transparentBackgroundPattern = transparentBackgroundPattern);
|
||||
update();
|
||||
}
|
||||
|
||||
void DrawingCanvasWidget::paintEvent(QPaintEvent *ev)
|
||||
{
|
||||
QWidget::paintEvent(ev);
|
||||
|
||||
QBrush brush;
|
||||
{
|
||||
QPixmap pixmap{32, 32};
|
||||
{
|
||||
QPainter painter{&pixmap};
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(Qt::gray);
|
||||
painter.drawRect(0, 0, 16, 16);
|
||||
painter.drawRect(16, 16, 16, 16);
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawRect(0, 16, 16, 16);
|
||||
painter.drawRect(16, 0, 16, 16);
|
||||
}
|
||||
brush.setTexture(std::move(pixmap));
|
||||
}
|
||||
const auto brush = makeTransparentBackgroundPatternBrush(m_transparentBackgroundPattern);
|
||||
|
||||
QPainter painter{this};
|
||||
|
||||
@@ -106,33 +101,46 @@ void DrawingCanvasWidget::mousePressEvent(QMouseEvent *event)
|
||||
setPixel(zoomdPos, left);
|
||||
break;
|
||||
case Mode::Spray:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Erase:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Pick:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Line:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Polygon:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Rectangle:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Ellipse:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::RoundedRectangle:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::SelectRegion:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::SelectWand:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::SelectSpray:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Text:
|
||||
//TODO
|
||||
break;
|
||||
case Mode::Fill:
|
||||
floodFill(zoomdPos, left);
|
||||
break;
|
||||
case Mode::Replace:
|
||||
//TODO
|
||||
break;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "editorguiutils.h"
|
||||
|
||||
class QPixmap;
|
||||
|
||||
class DrawingCanvasWidget : public QWidget
|
||||
@@ -11,6 +13,7 @@ class DrawingCanvasWidget : public QWidget
|
||||
Q_PROPERTY(float zoom READ zoom WRITE setScale NOTIFY zoomChanged FINAL)
|
||||
Q_PROPERTY(QColor leftButtonColor READ leftButtonColor WRITE setLeftButtonColor NOTIFY leftButtonColorChanged FINAL)
|
||||
Q_PROPERTY(QColor rightButtonColor READ rightButtonColor WRITE setRightButtonColor NOTIFY rightButtonColorChanged FINAL)
|
||||
Q_PROPERTY(TransparentBackgroundPattern transparentBackgroundPattern READ transparentBackgroundPattern WRITE setTransparentBackgroundPattern NOTIFY transparentBackgroundPatternChanged FINAL)
|
||||
|
||||
public:
|
||||
explicit DrawingCanvasWidget(QWidget *parent = nullptr);
|
||||
@@ -50,6 +53,9 @@ public:
|
||||
QColor rightButtonColor() const { return m_rightButtonColor; }
|
||||
void setRightButtonColor(const QColor &rightButtonColor);
|
||||
|
||||
const TransparentBackgroundPattern &transparentBackgroundPattern() const { return m_transparentBackgroundPattern; };
|
||||
void setTransparentBackgroundPattern(const TransparentBackgroundPattern &transparentBackgroundPattern);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
@@ -59,6 +65,7 @@ signals:
|
||||
void zoomChanged(float zoom);
|
||||
void leftButtonColorChanged(const QColor &LeftButtonColor);
|
||||
void rightButtonColorChanged(const QColor &rightButtonColor);
|
||||
void transparentBackgroundPatternChanged(const TransparentBackgroundPattern &transparentBackgroundPattern);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *ev) override;
|
||||
@@ -79,5 +86,7 @@ private:
|
||||
QColor m_leftButtonColor{Qt::white};
|
||||
QColor m_rightButtonColor{Qt::black};
|
||||
|
||||
TransparentBackgroundPattern m_transparentBackgroundPattern;
|
||||
|
||||
std::optional<bool> m_currentlyDrawing;
|
||||
};
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@
|
||||
#include <QCommandLineParser>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include "editorsettings.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(lcVk, "qt.vulkan")
|
||||
@@ -38,7 +39,9 @@ int main(int argc, char *argv[])
|
||||
parser.addPositionalArgument("project", "The project to open.");
|
||||
parser.process(app);
|
||||
|
||||
MainWindow mainWindow{parser.positionalArguments().value(0)};
|
||||
EditorSettings settings;
|
||||
|
||||
MainWindow mainWindow{parser.positionalArguments().value(0), settings};
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
|
||||
@@ -21,7 +21,7 @@ struct GlobalGameSettings
|
||||
};
|
||||
struct FullScale {
|
||||
};
|
||||
std::variant<FixedScale, KeepAspectRatio, FullScale> scaling{
|
||||
std::variant<FixedScale, KeepAspectRatio, FullScale> scaling {
|
||||
KeepAspectRatio{}
|
||||
};
|
||||
bool interpolateBetweenColors{};
|
||||
|
||||
Reference in New Issue
Block a user