Skip to content

Commit

Permalink
MainWindow/PaletteWidget: Move palette/translation handling to Palett…
Browse files Browse the repository at this point in the history
…eWidget

Currently we are splitting the palette/translation handling between
`MainWindow` class and `PaletteWidget`, so this patch changes that
- it moves the whole logic that was contained in MainWindow to
PaletteWidget and unifies it, so all of the handling happens here.
  • Loading branch information
tetektoza committed Dec 31, 2024
1 parent 6c57fd8 commit 1ce4125
Show file tree
Hide file tree
Showing 8 changed files with 497 additions and 738 deletions.
14 changes: 12 additions & 2 deletions source/d1formats/d1trn.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "d1trn.h"

D1Trn::D1Trn(D1Pal *pal)
: palette(QPointer<D1Pal>(pal))
: palette(pal)
{
}

bool D1Trn::load(QString filePath)
{
if (this->palette.isNull())
if (this->palette == nullptr)
return false;

QFile file = QFile(filePath);
Expand Down Expand Up @@ -73,6 +73,16 @@ QString D1Trn::getFilePath()
return this->trnFilePath;
}

QString D1Trn::getDefaultPath() const
{
return IDENTITY_PATH;
}

QString D1Trn::getDefaultName() const
{
return IDENTITY_NAME;
}

quint8 D1Trn::getTranslation(quint8 index)
{
return this->translations[index];
Expand Down
16 changes: 10 additions & 6 deletions source/d1formats/d1trn.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define D1TRN_TRANSLATIONS 256

class D1Trn : public QObject {
class D1Trn final : public D1Pal {
Q_OBJECT

public:
Expand All @@ -17,15 +17,19 @@ class D1Trn : public QObject {
D1Trn(D1Pal *pal);
~D1Trn() = default;

bool load(QString);
bool save(QString);
bool load(QString filepath) override;
bool save(QString filepath) override;

bool isModified() const;
[[nodiscard]] bool isModified() const override;

void refreshResultingPalette();
QColor getResultingColor(quint8);

QString getFilePath();
QString getFilePath() override;

[[nodiscard]] QString getDefaultPath() const override;
[[nodiscard]] QString getDefaultName() const override;

quint8 getTranslation(quint8);
void setTranslation(quint8, quint8);
void setPalette(D1Pal *pal);
Expand All @@ -35,6 +39,6 @@ class D1Trn : public QObject {
QString trnFilePath;
bool modified;
quint8 translations[D1TRN_TRANSLATIONS];
QPointer<D1Pal> palette;
D1Pal* palette = nullptr;
D1Pal resultingPalette;
};
Loading

0 comments on commit 1ce4125

Please sign in to comment.