Implemented first drawing capabilities in image editor

This commit is contained in:
feedc0de committed 2025-11-23 18:53:22 +01:00
1 parent c2fb13325b
commit b6a6084ba8
10 files changed
+282 -29

No files matched your search

+5 -2
View File
@@ -89,7 +89,7 @@ void EditSpriteDialog::newSprite()
if (dialog.exec() == QDialog::Accepted)
{
QPixmap pixmap{dialog.spriteSize()};
pixmap.fill(Qt::white);
pixmap.fill(Qt::transparent);
m_model->beginResetModel();
m_pixmaps = std::vector<QPixmap> { std::move(pixmap) };
@@ -110,8 +110,11 @@ void EditSpriteDialog::doubleClicked(const QModelIndex &index)
ImageEditorDialog dialog{m_model->pixmap(index), tr("Image Editor: %0").arg(m_spriteName), this};
if (dialog.exec() == QDialog::Accepted)
{
qDebug() << "apply pixmap?!";
emit m_model->beginResetModel();
m_pixmaps[index.row()] = dialog.pixmap();
emit m_model->dataChanged(index, index, {Qt::DecorationRole});
emit m_model->endResetModel();
//emit m_model->dataChanged(index, index, {Qt::DecorationRole});
changed();
}
}
+59 -6
View File
@@ -4,6 +4,8 @@
#include <QMessageBox>
#include <QDebug>
#include <QButtonGroup>
#include <QFontDialog>
#include <QColorDialog>
ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title, QWidget *parent) :
QDialog{parent},
@@ -24,6 +26,21 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
m_ui->scrollArea->setBackgroundRole(QPalette::Dark);
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->canvas, &DrawingCanvasWidget::changed,
this, &ImageEditorDialog::changed);
connect(m_ui->canvas, &DrawingCanvasWidget::leftButtonColorChanged,
this, &ImageEditorDialog::updateLeftButtonColor);
connect(m_ui->canvas, &DrawingCanvasWidget::rightButtonColorChanged,
this, &ImageEditorDialog::updateRightButtonColor);
{
auto group = new QButtonGroup{this};
group->setExclusive(true);
@@ -71,6 +88,9 @@ ImageEditorDialog::ImageEditorDialog(const QPixmap &pixmap, const QString &title
m_ui->toolButtonDraw->click();
updateLeftButtonColor(m_ui->canvas->leftButtonColor());
updateRightButtonColor(m_ui->canvas->rightButtonColor());
m_ui->canvas->setPixmap(m_pixmap);
}
@@ -78,12 +98,6 @@ ImageEditorDialog::~ImageEditorDialog() = default;
void ImageEditorDialog::accept()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
// TODO
QDialog::accept();
@@ -128,6 +142,45 @@ void ImageEditorDialog::changed()
}
}
void ImageEditorDialog::selectFont()
{
QFontDialog dialog{m_ui->pushButtonSelectFont->font(), this};
if (dialog.exec() == QDialog::Accepted)
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::updateTitle()
{
setWindowTitle(tr("%0%1")
+5
View File
@@ -23,6 +23,11 @@ public:
private slots:
void changed();
void selectFont();
void selectLeftButtonColor();
void selectRightButtonColor();
void updateLeftButtonColor(const QColor &leftButtonColor);
void updateRightButtonColor(const QColor &rightButtonColor);
private:
void updateTitle();
+22 -19
View File
@@ -631,6 +631,12 @@
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QPushButton" name="pushButtonSelectFont">
<property name="minimumSize">
<size>
<width>0</width>
<height>64</height>
</size>
</property>
<property name="text">
<string>Aa</string>
</property>
@@ -704,7 +710,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>759</width>
<width>741</width>
<height>1042</height>
</rect>
</property>
@@ -731,19 +737,13 @@
</widget>
</item>
<item>
<widget class="QFrame" name="frameLeft">
<widget class="QPushButton" name="pushButtonLeftButtonColor">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
</widget>
</item>
</layout>
@@ -758,19 +758,13 @@
</widget>
</item>
<item>
<widget class="QFrame" name="frameHeight">
<widget class="QPushButton" name="pushButtonRightButtonColor">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
</widget>
</item>
</layout>
@@ -778,10 +772,10 @@
</layout>
</item>
<item>
<widget class="QFrame" name="frame_4">
<widget class="ColorWidget" name="frameColorCoarse">
<property name="minimumSize">
<size>
<width>0</width>
<width>75</width>
<height>100</height>
</size>
</property>
@@ -794,10 +788,10 @@
</widget>
</item>
<item>
<widget class="QFrame" name="frame_5">
<widget class="ColorWidget" name="frameColorFine">
<property name="minimumSize">
<size>
<width>0</width>
<width>75</width>
<height>100</height>
</size>
</property>
@@ -878,6 +872,9 @@
</item>
<item>
<widget class="QGroupBox" name="groupBoxPreview">
<property name="visible">
<bool>false</bool>
</property>
<property name="title">
<string>Preview</string>
</property>
@@ -1114,6 +1111,12 @@
<extends>QWidget</extends>
<header>widgets/drawingcanvaswidget.h</header>
</customwidget>
<customwidget>
<class>ColorWidget</class>
<extends>QFrame</extends>
<header>widgets/colorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../resources_editor.qrc"/>