diff --git a/QtGameMaker.pro b/QtGameMaker.pro index b7ff665..2ee6515 100644 --- a/QtGameMaker.pro +++ b/QtGameMaker.pro @@ -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 \ diff --git a/src/editor/dialogs/backgroundpropertiesdialog.cpp b/src/editor/dialogs/backgroundpropertiesdialog.cpp index 0ae3c8a..97fac2d 100644 --- a/src/editor/dialogs/backgroundpropertiesdialog.cpp +++ b/src/editor/dialogs/backgroundpropertiesdialog.cpp @@ -17,6 +17,7 @@ BackgroundPropertiesDialog::BackgroundPropertiesDialog(Background &background, P m_ui{std::make_unique()}, 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(); diff --git a/src/editor/dialogs/backgroundpropertiesdialog.h b/src/editor/dialogs/backgroundpropertiesdialog.h index 6dd8b1f..c8bb7ca 100644 --- a/src/editor/dialogs/backgroundpropertiesdialog.h +++ b/src/editor/dialogs/backgroundpropertiesdialog.h @@ -38,6 +38,7 @@ private: Background &m_background; ProjectTreeModel &m_projectModel; + MainWindow &m_mainWindow; bool m_unsavedChanges{}; diff --git a/src/editor/dialogs/editspritedialog.cpp b/src/editor/dialogs/editspritedialog.cpp index 9ce1dde..726548e 100644 --- a/src/editor/dialogs/editspritedialog.cpp +++ b/src/editor/dialogs/editspritedialog.cpp @@ -4,19 +4,19 @@ #include #include -#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 &pixmaps, const QString &spriteName, QWidget *parent) : +EditSpriteDialog::EditSpriteDialog(const std::vector &pixmaps, const QString &spriteName, + EditorSettings &settings, QWidget *parent) : QDialog{parent}, m_ui{std::make_unique()}, - m_pixmaps{pixmaps}, + m_settings{settings}, m_spriteName{spriteName}, - m_model{std::make_unique(m_pixmaps, this)} + m_model{std::make_unique(pixmaps, this)} { m_ui->setupUi(this); @@ -138,6 +138,11 @@ void EditSpriteDialog::reject() } } +const std::vector &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 { 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 { 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() diff --git a/src/editor/dialogs/editspritedialog.h b/src/editor/dialogs/editspritedialog.h index d339188..c3e60fb 100644 --- a/src/editor/dialogs/editspritedialog.h +++ b/src/editor/dialogs/editspritedialog.h @@ -7,6 +7,7 @@ #include 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 &pixmaps, const QString &spriteName, QWidget *parent = nullptr); + explicit EditSpriteDialog(const std::vector &pixmaps, const QString &spriteName, + EditorSettings &settings, QWidget *parent = nullptr); ~EditSpriteDialog(); void accept() override; void reject() override; - const std::vector &pixmaps() const { return m_pixmaps; } + const std::vector &pixmaps() const; private slots: void newSprite(); @@ -54,7 +56,8 @@ private: const std::unique_ptr m_ui; - std::vector m_pixmaps; + EditorSettings &m_settings; + const QString m_spriteName; bool m_unsavedChanges{}; diff --git a/src/editor/dialogs/imageeditordialog.cpp b/src/editor/dialogs/imageeditordialog.cpp index af206fa..2f774e4 100644 --- a/src/editor/dialogs/imageeditordialog.cpp +++ b/src/editor/dialogs/imageeditordialog.cpp @@ -5,15 +5,17 @@ #include #include #include -#include #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()}, 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; diff --git a/src/editor/dialogs/imageeditordialog.h b/src/editor/dialogs/imageeditordialog.h index 797f12f..c832766 100644 --- a/src/editor/dialogs/imageeditordialog.h +++ b/src/editor/dialogs/imageeditordialog.h @@ -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 m_ui; const QString m_title; + EditorSettings &m_settings; QLabel &m_posLabel; QLabel &m_zoomLabel; diff --git a/src/editor/dialogs/imageeditordialog.ui b/src/editor/dialogs/imageeditordialog.ui index 5a50542..806f29c 100644 --- a/src/editor/dialogs/imageeditordialog.ui +++ b/src/editor/dialogs/imageeditordialog.ui @@ -746,7 +746,7 @@ - + 0 @@ -772,7 +772,7 @@ - + 0 @@ -1163,6 +1163,11 @@
widgets/zoomablescrollarea.h
1 + + ColorButton + QPushButton +
widgets/colorbutton.h
+
diff --git a/src/editor/dialogs/preferencesdialog.cpp b/src/editor/dialogs/preferencesdialog.cpp index f17fe5b..7c50a7f 100644 --- a/src/editor/dialogs/preferencesdialog.cpp +++ b/src/editor/dialogs/preferencesdialog.cpp @@ -1,11 +1,12 @@ #include "preferencesdialog.h" #include "ui_preferencesdialog.h" -#include +#include #include "editorguiutils.h" +#include "editorsettings.h" -PreferencesDialog::PreferencesDialog(QWidget *parent) : +PreferencesDialog::PreferencesDialog(const EditorSettings &settings, QWidget *parent) : QDialog{parent}, m_ui{std::make_unique()} { @@ -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")); +} diff --git a/src/editor/dialogs/preferencesdialog.h b/src/editor/dialogs/preferencesdialog.h index e76862c..77633bb 100644 --- a/src/editor/dialogs/preferencesdialog.h +++ b/src/editor/dialogs/preferencesdialog.h @@ -5,15 +5,21 @@ #include 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 m_ui; }; diff --git a/src/editor/dialogs/preferencesdialog.ui b/src/editor/dialogs/preferencesdialog.ui index 2b6291a..b16cb81 100644 --- a/src/editor/dialogs/preferencesdialog.ui +++ b/src/editor/dialogs/preferencesdialog.ui @@ -6,8 +6,8 @@ 0 0 - 634 - 614 + 747 + 463
@@ -29,21 +29,21 @@ - CheckBox + &Show recently edited games in the file menu - CheckBox + &Load last openend file on startup - Qt::Vertical + Qt::Orientation::Vertical @@ -56,7 +56,7 @@ - CheckBox + &Keep backup copies of files (with extension .qb1, .qb2) @@ -65,7 +65,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -78,7 +78,7 @@ - TextLabel + Ma&ximum number of backups: @@ -88,7 +88,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -103,7 +103,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -116,28 +116,28 @@ - CheckBox + Show progress while loading and saving files - CheckBox + At start&up, check for, and remove old temporary files - CheckBox + Don't show the &website image in the main menu - Qt::Vertical + Qt::Orientation::Vertical @@ -150,21 +150,21 @@ - CheckBox + &Hide the designer and wait while the game is running - CheckBox + &Run games in secure mode, not executing any programs - Qt::Vertical + Qt::Orientation::Vertical @@ -179,33 +179,40 @@ - QFrame::HLine + QFrame::Shape::HLine - QFrame::Sunken + QFrame::Shadow::Sunken - + - CheckBox + Show &news on startup - CheckBox + Show news in default &browser + + + + + + + Show Minimap in Room editor - Qt::Vertical + Qt::Orientation::Vertical @@ -218,7 +225,7 @@ - TextLabel + Location of the GameMaker TV style logo on screen @@ -228,7 +235,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -241,14 +248,14 @@ - CheckBox + Show Trace.log after &Debug - Qt::Vertical + Qt::Orientation::Vertical @@ -270,13 +277,13 @@ - GroupBox + Sprite Form - CheckBox + S&how the origin in the sprite image @@ -286,7 +293,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -299,13 +306,13 @@ - GroupBox + Object Form - CheckBox + &In object properties, show hints for the actions @@ -314,7 +321,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -327,7 +334,7 @@ - TextLabel + Default TAB to select: @@ -337,7 +344,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -355,7 +362,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -368,27 +375,27 @@ - GroupBox + Room Form - CheckBox + &When closing, remove instances outside the room - CheckBox + R&emember room settings when closing the form - CheckBox + Room Grid ON by default @@ -397,21 +404,17 @@ - CheckBox + Fill room with color when no background color selected. (Editor only) - - - ... - - + - Qt::Horizontal + Qt::Orientation::Horizontal @@ -429,7 +432,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -456,12 +459,19 @@ - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + ColorButton + QPushButton +
widgets/colorbutton.h
+
+
diff --git a/src/editor/dialogs/spritepropertiesdialog.cpp b/src/editor/dialogs/spritepropertiesdialog.cpp index b1889e5..5694ad4 100644 --- a/src/editor/dialogs/spritepropertiesdialog.cpp +++ b/src/editor/dialogs/spritepropertiesdialog.cpp @@ -19,6 +19,7 @@ SpritePropertiesDialog::SpritePropertiesDialog(Sprite &sprite, ProjectTreeModel m_ui{std::make_unique()}, 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() diff --git a/src/editor/dialogs/spritepropertiesdialog.h b/src/editor/dialogs/spritepropertiesdialog.h index a655d7e..9e6e70d 100644 --- a/src/editor/dialogs/spritepropertiesdialog.h +++ b/src/editor/dialogs/spritepropertiesdialog.h @@ -40,6 +40,7 @@ private: Sprite &m_sprite; ProjectTreeModel &m_projectModel; + MainWindow &m_mainWindow; bool m_unsavedChanges{}; diff --git a/src/editor/dialogs/transparentbackgroundsettingsdialog.cpp b/src/editor/dialogs/transparentbackgroundsettingsdialog.cpp index 7436230..87bd2df 100644 --- a/src/editor/dialogs/transparentbackgroundsettingsdialog.cpp +++ b/src/editor/dialogs/transparentbackgroundsettingsdialog.cpp @@ -1,15 +1,69 @@ #include "transparentbackgroundsettingsdialog.h" #include "ui_transparentbackgroundsettingsdialog.h" -#include "editorguiutils.h" +#include -TransparentBackgroundSettingsDialog::TransparentBackgroundSettingsDialog(QWidget *parent) : +#include "editorguiutils.h" +#include "editorsettings.h" + +TransparentBackgroundSettingsDialog::TransparentBackgroundSettingsDialog(const EditorSettings &settings, QWidget *parent) : QDialog{parent}, m_ui{std::make_unique()} { 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(); +} diff --git a/src/editor/dialogs/transparentbackgroundsettingsdialog.h b/src/editor/dialogs/transparentbackgroundsettingsdialog.h index 3d6fbe7..7c34306 100644 --- a/src/editor/dialogs/transparentbackgroundsettingsdialog.h +++ b/src/editor/dialogs/transparentbackgroundsettingsdialog.h @@ -5,15 +5,21 @@ #include 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 m_ui; }; diff --git a/src/editor/dialogs/transparentbackgroundsettingsdialog.ui b/src/editor/dialogs/transparentbackgroundsettingsdialog.ui index 24fd2d7..dc05dba 100644 --- a/src/editor/dialogs/transparentbackgroundsettingsdialog.ui +++ b/src/editor/dialogs/transparentbackgroundsettingsdialog.ui @@ -6,30 +6,137 @@ 0 0 - 400 - 300 + 301 + 221
Transparent Background Settings - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + + + + + + Block pattern + + + + + + + 1 + + + 65535 + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Color: + + + + + + + + + + Single color + + + + + + + Color 1: + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Color 2: + + + + + + + Block size: + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + +
+ + + ColorButton + QPushButton +
widgets/colorbutton.h
+
+
diff --git a/src/editor/editorguiutils.cpp b/src/editor/editorguiutils.cpp index d07e564..71aca0d 100644 --- a/src/editor/editorguiutils.cpp +++ b/src/editor/editorguiutils.cpp @@ -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 {}; +} diff --git a/src/editor/editorguiutils.h b/src/editor/editorguiutils.h index d5eac40..a842ee3 100644 --- a/src/editor/editorguiutils.h +++ b/src/editor/editorguiutils.h @@ -1,11 +1,36 @@ #pragma once +#include +#include + 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); diff --git a/src/editor/editorsettings.cpp b/src/editor/editorsettings.cpp new file mode 100644 index 0000000..1e086fc --- /dev/null +++ b/src/editor/editorsettings.cpp @@ -0,0 +1,84 @@ +#include "editorsettings.h" + +#include + +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(); +} + +void EditorSettings::setTransparentBackgroundPatternType(TransparentBackgroundPattern::Type transparentBackgroundPatternType) +{ + setValue("transparentBackgroundPatternType", QVariant::fromValue(transparentBackgroundPatternType)); +} + +QColor EditorSettings::transparentBackgroundBlockPatternColor1() const +{ + return value("transparentBackgroundBlockPatternColor1", QColor{Qt::gray}).value(); +} + +void EditorSettings::setTransparentBackgroundBlockPatternColor1(QColor transparentBackgroundBlockPatternColor1) +{ + setValue("transparentBackgroundBlockPatternColor1", transparentBackgroundBlockPatternColor1); +} + +QColor EditorSettings::transparentBackgroundBlockPatternColor2() const +{ + return value("transparentBackgroundBlockPatternColor2", QColor{Qt::white}).value(); +} + +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(); +} + +void EditorSettings::setTransparentBackgroundSingleColor(QColor transparentBackgroundSingleColor) +{ + setValue("transparentBackgroundSingleColor", transparentBackgroundSingleColor); +} + +TransparentBackgroundPattern EditorSettings::transparentBackgroundPattern() const +{ + return TransparentBackgroundPattern { + transparentBackgroundPatternType(), + transparentBackgroundBlockPatternColor1(), + transparentBackgroundBlockPatternColor2(), + transparentBackgroundBlockPatternBlockSize(), + transparentBackgroundSingleColor() + }; +} diff --git a/src/editor/editorsettings.h b/src/editor/editorsettings.h new file mode 100644 index 0000000..0b0cf63 --- /dev/null +++ b/src/editor/editorsettings.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#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; +}; diff --git a/src/editor/mainwindow.cpp b/src/editor/mainwindow.cpp index 5b01cc7..788c156 100644 --- a/src/editor/mainwindow.cpp +++ b/src/editor/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include +#include "editorsettings.h" #include "projectserialization.h" #include "models/projecttreemodel.h" #include "dialogs/preferencesdialog.h" @@ -47,9 +48,10 @@ template<> struct PropertiesDialogForDetail { using Type = RoomPropertiesD template using PropertiesDialogFor = typename PropertiesDialogForDetail::Type; } -MainWindow::MainWindow(const QString &filePath, QWidget *parent) : +MainWindow::MainWindow(const QString &filePath, EditorSettings &settings, QWidget *parent) : QMainWindow{parent}, m_ui{std::make_unique()}, + m_settings{settings}, m_filePath{filePath}, m_projectTreeModel{std::make_unique(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 diff --git a/src/editor/mainwindow.h b/src/editor/mainwindow.h index b9a7d21..8f3c564 100644 --- a/src/editor/mainwindow.h +++ b/src/editor/mainwindow.h @@ -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 std::map &propertyWindowsFor(); @@ -96,6 +100,8 @@ private: const std::unique_ptr m_ui; + EditorSettings &m_settings; + ProjectContainer m_project; QString m_filePath; diff --git a/src/editor/models/spritesmodel.cpp b/src/editor/models/spritesmodel.cpp index a1c4a21..6a78924 100644 --- a/src/editor/models/spritesmodel.cpp +++ b/src/editor/models/spritesmodel.cpp @@ -9,6 +9,12 @@ SpritesModel::SpritesModel(const std::vector &pixmaps, QObject *parent) { } +SpritesModel::SpritesModel(std::vector &&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 &pixmaps) +{ + beginResetModel(); + m_pixmaps = pixmaps; + endResetModel(); +} + +void SpritesModel::setPixmaps(std::vector &&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(); } diff --git a/src/editor/models/spritesmodel.h b/src/editor/models/spritesmodel.h index ae4609f..7a36a55 100644 --- a/src/editor/models/spritesmodel.h +++ b/src/editor/models/spritesmodel.h @@ -11,24 +11,31 @@ class SpritesModel : public QAbstractListModel public: explicit SpritesModel(const std::vector &pixmaps, QObject *parent = nullptr); + explicit SpritesModel(std::vector &&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 &pixmaps() const { return m_pixmaps; } + void setPixmaps(const std::vector &pixmaps); + void setPixmaps(std::vector &&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 &m_pixmaps; + std::vector m_pixmaps; }; diff --git a/src/editor/widgets/colorbutton.cpp b/src/editor/widgets/colorbutton.cpp new file mode 100644 index 0000000..087768e --- /dev/null +++ b/src/editor/widgets/colorbutton.cpp @@ -0,0 +1,43 @@ +#include "colorbutton.h" + +#include + +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()); +} diff --git a/src/editor/widgets/colorbutton.h b/src/editor/widgets/colorbutton.h new file mode 100644 index 0000000..a3709b9 --- /dev/null +++ b/src/editor/widgets/colorbutton.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +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; +}; diff --git a/src/editor/widgets/drawingcanvaswidget.cpp b/src/editor/widgets/drawingcanvaswidget.cpp index 5f84ca9..2e36e42 100644 --- a/src/editor/widgets/drawingcanvaswidget.cpp +++ b/src/editor/widgets/drawingcanvaswidget.cpp @@ -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; }; diff --git a/src/editor/widgets/drawingcanvaswidget.h b/src/editor/widgets/drawingcanvaswidget.h index 689a5d6..33d94f7 100644 --- a/src/editor/widgets/drawingcanvaswidget.h +++ b/src/editor/widgets/drawingcanvaswidget.h @@ -2,6 +2,8 @@ #include +#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 m_currentlyDrawing; }; diff --git a/src/main.cpp b/src/main.cpp index 7093d93..c8c4cd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include +#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(); diff --git a/src/projectcontainer.h b/src/projectcontainer.h index 0df972d..a722825 100644 --- a/src/projectcontainer.h +++ b/src/projectcontainer.h @@ -21,7 +21,7 @@ struct GlobalGameSettings }; struct FullScale { }; - std::variant scaling{ + std::variant scaling { KeepAspectRatio{} }; bool interpolateBetweenColors{};