Skip to content

Commit

Permalink
MW/PaletteWidget: Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tetektoza committed Jan 1, 2025
1 parent 948e64a commit 3b50c6c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
2 changes: 1 addition & 1 deletion source/d1formats/d1trn.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class D1Trn final : public D1Pal {
QString trnFilePath;
bool modified;
quint8 translations[D1TRN_TRANSLATIONS];
D1Pal* palette = nullptr;
D1Pal *palette = nullptr;
D1Pal resultingPalette;
};
16 changes: 8 additions & 8 deletions source/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@ MainWindow::~MainWindow()
delete this->redoAction;
}

void MainWindow::setPal(const QString& path)
void MainWindow::setPal(const QString &path)
{
this->m_palWidget->setPal(path);
this->m_trnUniqueWidget->setTrnPalette(m_palWidget->pal());
this->m_trnWidget->refresh();
}

void MainWindow::setTrnUnique(const QString& path)
void MainWindow::setTrnUnique(const QString &path)
{
this->m_trnUniqueWidget->setTrn(path);
this->m_trnUniqueWidget->setTrnPalette(m_palWidget->pal());
this->m_trnWidget->setTrnPalette(this->m_trnUniqueWidget->trn()->getResultingPalette());
this->m_trnWidget->refresh();
}

void MainWindow::setTrn(const QString& path)
void MainWindow::setTrn(const QString &path)
{
this->m_trnWidget->setTrn(path);
this->m_trnWidget->setTrnPalette(this->m_trnUniqueWidget->trn()->getResultingPalette());
Expand Down Expand Up @@ -192,13 +192,13 @@ void MainWindow::paletteWidget_callback(PaletteWidget *widget, PWIDGET_CALLBACK_

void MainWindow::resetPaletteCycle()
{
//this->pal->resetColors();
// this->pal->resetColors();
this->m_palWidget->modify();
}

void MainWindow::nextPaletteCycle(D1PAL_CYCLE_TYPE type)
{
//this->pal->cycleColors(type);
// this->pal->cycleColors(type);
this->m_palWidget->modify();
}

Expand Down Expand Up @@ -631,14 +631,14 @@ void MainWindow::openImageFiles(IMAGE_FILE_MODE mode, QStringList filePaths, boo
this->ui->statusBar->clearMessage();
}

void MainWindow::openPalFiles(const QStringList& filePaths, PaletteWidget *widget) const
void MainWindow::openPalFiles(const QStringList &filePaths, PaletteWidget *widget) const
{
QString firstFound;

this->ui->statusBar->showMessage("Reading...");
this->ui->statusBar->repaint();

for (const QString& path : filePaths) {
for (const QString &path : filePaths) {
if (widget->loadPalette(path) && firstFound.isEmpty()) {
firstFound = path;
}
Expand Down Expand Up @@ -933,7 +933,7 @@ void MainWindow::closeAllElements()
this->m_trnWidget = nullptr;

delete this->gfx;

delete this->min;
delete this->til;
delete this->sol;
Expand Down
31 changes: 20 additions & 11 deletions source/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainWindow;
}

namespace mw {
bool QuestionDiscardChanges(bool isModified, QString filePath);
bool QuestionDiscardChanges(bool isModified, QString filePath);
} // namespace mw

class MainWindow : public QMainWindow {
Expand All @@ -55,13 +55,13 @@ class MainWindow : public QMainWindow {
explicit MainWindow();
~MainWindow();

void setPal(const QString&);
void setTrn(const QString&);
void setTrnUnique(const QString&);
void setPal(const QString &);
void setTrn(const QString &);
void setTrnUnique(const QString &);

void openFile(const OpenAsParam &params);
void openImageFiles(IMAGE_FILE_MODE mode, QStringList filePaths, bool append);
void openPalFiles(const QStringList& filePaths, PaletteWidget *widget) const;
void openPalFiles(const QStringList &filePaths, PaletteWidget *widget) const;
void openFontFile(QString filePath, QColor renderColor, int pointSize, uint symbolPrefix);
void saveFile(const QString &gfxPath);

Expand All @@ -74,9 +74,18 @@ class MainWindow : public QMainWindow {
QString getLastFilePath();
QString fileDialog(FILE_DIALOG_MODE mode, const char *title, const char *filter);
QStringList filesDialog(const char *title, const char *filter);
PaletteWidget *trnWidget() { return m_trnWidget; }
PaletteWidget *uniqTrnWidget() { return m_trnUniqueWidget; }
PaletteWidget *paletteWidget() { return m_palWidget; }
PaletteWidget *trnWidget()
{
return m_trnWidget;
}
PaletteWidget *uniqTrnWidget()
{
return m_trnUniqueWidget;
}
PaletteWidget *paletteWidget()
{
return m_palWidget;
}

static bool hasImageUrl(const QMimeData *mimeData);

Expand Down Expand Up @@ -170,9 +179,9 @@ private slots:
QPointer<CelView> celView;
QPointer<LevelCelView> levelCelView;

PaletteWidget* m_palWidget = nullptr;
PaletteWidget* m_trnWidget = nullptr;
PaletteWidget* m_trnUniqueWidget = nullptr;
PaletteWidget *m_palWidget = nullptr;
PaletteWidget *m_trnWidget = nullptr;
PaletteWidget *m_trnUniqueWidget = nullptr;

OpenAsDialog openAsDialog = OpenAsDialog(this);
SettingsDialog settingsDialog = SettingsDialog(this);
Expand Down
47 changes: 21 additions & 26 deletions source/widgets/palettewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,21 @@ PaletteWidget::~PaletteWidget()
delete ui;
delete scene;

for (auto& pair : m_palettes_map) {
for (auto &pair : m_palettes_map) {
delete pair.second.second;
}
}

void PaletteWidget::setPal(const QString& path)
void PaletteWidget::setPal(const QString &path)
{
m_pal = m_palettes_map[path].second;

emit this->modified();
}

void PaletteWidget::setTrn(const QString& path)
void PaletteWidget::setTrn(const QString &path)
{
this->m_trn = dynamic_cast<D1Trn*>(m_palettes_map[path].second);
this->m_trn = dynamic_cast<D1Trn *>(m_palettes_map[path].second);

emit this->modified();
}
Expand Down Expand Up @@ -368,8 +368,7 @@ void PaletteWidget::initialize(D1Pal *p, D1Trn *t, LevelCelView *lc, D1PalHits *

void PaletteWidget::initializeUi()
{
bool trnMode = this->m_paletteType == PaletteType::Translation ||
this->m_paletteType == PaletteType::UniqTranslation;
bool trnMode = this->m_paletteType == PaletteType::Translation || this->m_paletteType == PaletteType::UniqTranslation;

this->ui->monsterTrnPushButton->setVisible(trnMode);
this->ui->translationClearPushButton->setVisible(trnMode);
Expand Down Expand Up @@ -466,18 +465,18 @@ void PaletteWidget::checkTranslationsSelection(QList<quint8> indexes)
emit this->clearRootBorder();
}

void PaletteWidget::addPath(const QString& path, const QString& name, D1Pal *pal)
void PaletteWidget::addPath(const QString &path, const QString &name, D1Pal *pal)
{
this->m_palettes_map[path] = std::make_pair(name, pal);
}

void PaletteWidget::removePath(const QString& path)
void PaletteWidget::removePath(const QString &path)
{
if (this->m_palettes_map.contains(path))
this->m_palettes_map.erase(path);
}

void PaletteWidget::selectPath(const QString& path)
void PaletteWidget::selectPath(const QString &path)
{
this->ui->pathComboBox->setCurrentIndex(this->ui->pathComboBox->findData(path));
this->ui->pathComboBox->setToolTip(path);
Expand All @@ -498,7 +497,7 @@ QString PaletteWidget::getWidgetsDefaultPath() const
QString PaletteWidget::getSelectedPath() const
{
QString path = this->ui->pathComboBox->currentText();
for (const auto& [key, valuePair] : m_palettes_map) {
for (const auto &[key, valuePair] : m_palettes_map) {
if (valuePair.first == this->ui->pathComboBox->currentText())
return key;
}
Expand Down Expand Up @@ -577,7 +576,7 @@ void PaletteWidget::finishColorSelection()
this->refresh();
}

void PaletteWidget::setTrnPalette(D1Pal* pal)
void PaletteWidget::setTrnPalette(D1Pal *pal)
{
this->m_trn->setPalette(pal);
refresh();
Expand Down Expand Up @@ -606,13 +605,12 @@ PaletteFileInfo PaletteWidget::paletteFileInfo() const
return { "palette", "pal" };
}

void PaletteWidget::performSave(const QString& palFilePath, const PaletteFileInfo& fileInfo)
void PaletteWidget::performSave(const QString &palFilePath, const PaletteFileInfo &fileInfo)
{
bool opResult = false;
if (m_paletteType == PaletteType::Palette) {
opResult = this->m_pal->save(palFilePath);
}
else {
} else {
opResult = this->m_trn->save(palFilePath);
}

Expand All @@ -628,13 +626,11 @@ void PaletteWidget::newOrSaveAsFile(const PWIDGET_CALLBACK_TYPE action)
QString actionStr;
if (action == PWIDGET_CALLBACK_TYPE::PWIDGET_CALLBACK_SAVEAS) {
actionStr = QString("Save %1 File as...").arg(fileInfo.name);
}
else {
} else {
actionStr = QString("New %1 File").arg(fileInfo.name);
}


auto *mw = dynamic_cast<MainWindow*>(this->window());
auto *mw = dynamic_cast<MainWindow *>(this->window());
QString palFilePath = mw->fileDialog(FILE_DIALOG_MODE::SAVE_CONF,
actionStr.toStdString().c_str(),
(QString("%2 Files (*.%1 *.%2)").arg(fileInfo.suffix, fileInfo.suffix.toUpper())).toStdString().c_str());
Expand Down Expand Up @@ -678,8 +674,7 @@ void PaletteWidget::newOrSaveAsFile(const PWIDGET_CALLBACK_TYPE action)
QString loadedFilePath;
if (action == PWIDGET_CALLBACK_TYPE::PWIDGET_CALLBACK_NEW) {
loadedFilePath = newPal->getDefaultPath();
}
else {
} else {
loadedFilePath = path;
}

Expand All @@ -701,11 +696,11 @@ void PaletteWidget::newOrSaveAsFile(const PWIDGET_CALLBACK_TYPE action)
selectPath(path);
}

bool PaletteWidget::loadPalette(const QString& filepath)
bool PaletteWidget::loadPalette(const QString &filepath)
{
PaletteFileInfo fileInfo = paletteFileInfo();

auto *mw = dynamic_cast<MainWindow*>(this->window());
auto *mw = dynamic_cast<MainWindow *>(this->window());
QFileInfo palFileInfo(filepath);
// QString path = trnFileInfo.absoluteFilePath();
const QString &path = filepath;
Expand Down Expand Up @@ -740,10 +735,10 @@ void PaletteWidget::openPalette()
{
PaletteFileInfo fileInfo = paletteFileInfo();

auto *mw = dynamic_cast<MainWindow*>(this->window());
auto *mw = dynamic_cast<MainWindow *>(this->window());
QString paletteFilePath = mw->fileDialog(FILE_DIALOG_MODE::OPEN,
QString("Load %1 File").arg(fileInfo.name).toStdString().c_str(),
QString("%2 Files (*.%1 *.%2)").arg(fileInfo.suffix, fileInfo.suffix.toUpper()).toStdString().c_str());
QString("%2 Files (*.%1 *.%2)").arg(fileInfo.suffix, fileInfo.suffix.toUpper()).toStdString().c_str());

if (!paletteFilePath.isEmpty() && loadPalette(paletteFilePath)) {
selectPath(paletteFilePath);
Expand All @@ -752,8 +747,8 @@ void PaletteWidget::openPalette()

bool PaletteWidget::isOkToQuit()
{
for (const auto& pair : m_palettes_map) {
D1Pal* pal = pair.second.second;
for (const auto &pair : m_palettes_map) {
D1Pal *pal = pair.second.second;
if (!mw::QuestionDiscardChanges(pal->isModified(), pal->getFilePath())) {
return false;
}
Expand Down
32 changes: 19 additions & 13 deletions source/widgets/palettewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class PaletteWidget : public QWidget {
explicit PaletteWidget(std::shared_ptr<UndoStack> undoStack, QString title);
~PaletteWidget();

void setPal(const QString& path);
void setTrn(const QString& path);
void setPal(const QString &path);
void setTrn(const QString &path);
bool isTrnWidget();

void initialize(D1Pal *p, CelView *c, D1PalHits *ph, PaletteType palType);
Expand All @@ -156,9 +156,9 @@ class PaletteWidget : public QWidget {
void selectColor(quint8);
void checkTranslationsSelection(QList<quint8>);

void addPath(const QString&, const QString&, D1Pal* pal);
void removePath(const QString&);
void selectPath(const QString&);
void addPath(const QString &, const QString &, D1Pal *pal);
void removePath(const QString &);
void selectPath(const QString &);

QString getWidgetsDefaultPath() const;
QString getSelectedPath() const;
Expand All @@ -167,20 +167,26 @@ class PaletteWidget : public QWidget {
void startColorSelection(int colorIndex);
void changeColorSelection(int colorIndex);
void finishColorSelection();
[[nodiscard]] D1Pal* pal() const { return m_pal; };
[[nodiscard]] D1Trn* trn() const { return m_trn; };
[[nodiscard]] D1Pal *pal() const
{
return m_pal;
};
[[nodiscard]] D1Trn *trn() const
{
return m_trn;
};

void save();
void newOrSaveAsFile(PWIDGET_CALLBACK_TYPE action);

bool loadPalette(const QString& filepath);
bool loadPalette(const QString &filepath);
void openPalette();

bool isOkToQuit();

void closePalette();

void setTrnPalette(D1Pal* pal);
void setTrnPalette(D1Pal *pal);
// Display functions
bool displayColor(int index);
void displayColors();
Expand Down Expand Up @@ -214,7 +220,7 @@ class PaletteWidget : public QWidget {

private:
[[nodiscard]] PaletteFileInfo paletteFileInfo() const;
void performSave(const QString& palFilePath, const PaletteFileInfo& fileInfo);
void performSave(const QString &palFilePath, const PaletteFileInfo &fileInfo);
QPushButton *addButton(QStyle::StandardPixmap type, QString tooltip, void (PaletteWidget::*callback)(void));

public slots:
Expand Down Expand Up @@ -260,12 +266,12 @@ private slots:
bool pickingTranslationColor = false;
bool temporarilyDisplayingAllColors = false;

D1Pal* m_pal;
D1Trn* m_trn;
D1Pal *m_pal;
D1Trn *m_trn;

PaletteType m_paletteType;

D1PalHits *palHits;

std::map<QString, std::pair<QString, D1Pal*>> m_palettes_map;
std::map<QString, std::pair<QString, D1Pal *>> m_palettes_map;
};

0 comments on commit 3b50c6c

Please sign in to comment.