From 3b50c6c3c192ba4f9f9023e910bd1645277c14db Mon Sep 17 00:00:00 2001 From: tetektoza Date: Wed, 1 Jan 2025 18:24:11 +0100 Subject: [PATCH] MW/PaletteWidget: Fix formatting --- source/d1formats/d1trn.h | 2 +- source/mainwindow.cpp | 16 +++++------ source/mainwindow.h | 31 +++++++++++++-------- source/widgets/palettewidget.cpp | 47 ++++++++++++++------------------ source/widgets/palettewidget.h | 32 +++++++++++++--------- 5 files changed, 69 insertions(+), 59 deletions(-) diff --git a/source/d1formats/d1trn.h b/source/d1formats/d1trn.h index 0b6c788a..0da14416 100644 --- a/source/d1formats/d1trn.h +++ b/source/d1formats/d1trn.h @@ -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; }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index e4dd590d..0dc13f94 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -117,14 +117,14 @@ 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()); @@ -132,7 +132,7 @@ void MainWindow::setTrnUnique(const QString& path) 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()); @@ -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(); } @@ -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; } @@ -933,7 +933,7 @@ void MainWindow::closeAllElements() this->m_trnWidget = nullptr; delete this->gfx; - + delete this->min; delete this->til; delete this->sol; diff --git a/source/mainwindow.h b/source/mainwindow.h index 61dcd01c..9f29dd46 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -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 { @@ -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 ¶ms); 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); @@ -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); @@ -170,9 +179,9 @@ private slots: QPointer celView; QPointer 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); diff --git a/source/widgets/palettewidget.cpp b/source/widgets/palettewidget.cpp index d3ebb22c..923e6b3d 100644 --- a/source/widgets/palettewidget.cpp +++ b/source/widgets/palettewidget.cpp @@ -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(m_palettes_map[path].second); + this->m_trn = dynamic_cast(m_palettes_map[path].second); emit this->modified(); } @@ -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); @@ -466,18 +465,18 @@ void PaletteWidget::checkTranslationsSelection(QList 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); @@ -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; } @@ -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(); @@ -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); } @@ -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(this->window()); + auto *mw = dynamic_cast(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()); @@ -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; } @@ -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(this->window()); + auto *mw = dynamic_cast(this->window()); QFileInfo palFileInfo(filepath); // QString path = trnFileInfo.absoluteFilePath(); const QString &path = filepath; @@ -740,10 +735,10 @@ void PaletteWidget::openPalette() { PaletteFileInfo fileInfo = paletteFileInfo(); - auto *mw = dynamic_cast(this->window()); + auto *mw = dynamic_cast(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); @@ -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; } diff --git a/source/widgets/palettewidget.h b/source/widgets/palettewidget.h index fdc49fc7..e572b4ef 100644 --- a/source/widgets/palettewidget.h +++ b/source/widgets/palettewidget.h @@ -138,8 +138,8 @@ class PaletteWidget : public QWidget { explicit PaletteWidget(std::shared_ptr 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); @@ -156,9 +156,9 @@ class PaletteWidget : public QWidget { void selectColor(quint8); void checkTranslationsSelection(QList); - 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; @@ -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(); @@ -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: @@ -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> m_palettes_map; + std::map> m_palettes_map; };