From 4b886a903378d31b47b14e8be2069ae184c92ec3 Mon Sep 17 00:00:00 2001 From: Luca D'Amico Date: Sat, 10 Aug 2024 15:12:50 +0200 Subject: [PATCH] Implemented theme selector and fixed FatTools UI --- CMakeLists.txt | 4 +++ main.cpp | 18 +++++++--- ndsfactory/crctable.h | 5 +-- ndsfactory/fatstruct.h | 5 +-- ndsfactory/ndsfactory.h | 4 +-- ndsfactory/ndsheader.h | 5 +-- ui/dialogs/about/aboutdialog.h | 5 +-- ui/dialogs/about/revision.h | 2 +- ui/mainwindow.cpp | 16 +++++++++ ui/mainwindow.h | 8 ++--- ui/mainwindow.ui | 62 ++++++++++++++++++++++++---------- ui/models/ndsheadermodel.h | 5 +-- ui/tabs/commons/headernames.h | 5 +-- ui/utils/theme.h | 60 ++++++++++++++++++++++++++++++++ 14 files changed, 151 insertions(+), 53 deletions(-) create mode 100644 ui/utils/theme.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ec6ba6..bb900e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ file(GLOB_RECURSE TABS_SOURCES ui/tabs/*.cpp) file(GLOB_RECURSE MODELS_HEADERS ui/models/*.h) file(GLOB_RECURSE MODELS_SOURCES ui/models/*.cpp) +## Utils +file(GLOB_RECURSE UTILS_HEADERS ui/utils/*.h) + ## NDSFactory file(GLOB_RECURSE NDSFACTORY_SOURCES ndsfactory/*.cpp) file(GLOB_RECURSE NDSFACTORY_HEADERS ndsfactory/*.h) @@ -59,6 +62,7 @@ SET(HEADERS ${TABS_HEADERS} ${MODELS_HEADERS} ${DIALOGS_HEADERS} + ${UTILS_HEADERS} ) set(FORMS diff --git a/main.cpp b/main.cpp index 2eae0c2..0ff1ac4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,23 @@ #include "ui/mainwindow.h" #include #include +#include "ui/utils/theme.h" int main(int argc, char *argv[]) { QApplication::setStyle(QStyleFactory::create("Fusion")); - QApplication a(argc, argv); - MainWindow w; - w.show(); + QApplication app(argc, argv); + app.setApplicationName("NDSFactory"); + app.setOrganizationName("NDSFactory"); - return a.exec(); + QString theme = getCurrentTheme(); + if(theme == "dark") + setDarkTheme(app); + else if(theme == "light") + setLightTheme(app); + + MainWindow mainWindow; + mainWindow.show(); + + return app.exec(); } diff --git a/ndsfactory/crctable.h b/ndsfactory/crctable.h index 8c8c29a..0ebb2c0 100644 --- a/ndsfactory/crctable.h +++ b/ndsfactory/crctable.h @@ -1,5 +1,4 @@ -#ifndef CRCTABLE_H -#define CRCTABLE_H +#pragma once #include @@ -39,5 +38,3 @@ static const uint16_t lCRCTable[] = 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; - -#endif // CRCTABLE_H diff --git a/ndsfactory/fatstruct.h b/ndsfactory/fatstruct.h index 39c6a87..70eb1a8 100644 --- a/ndsfactory/fatstruct.h +++ b/ndsfactory/fatstruct.h @@ -1,5 +1,4 @@ -#ifndef FATSTRUCT_H -#define FATSTRUCT_H +#pragma once #include @@ -7,5 +6,3 @@ struct FatRange { uint32_t startAddr; uint32_t endAddr; }; - -#endif // FATSTRUCT_H diff --git a/ndsfactory/ndsfactory.h b/ndsfactory/ndsfactory.h index 25aea53..d3810a9 100644 --- a/ndsfactory/ndsfactory.h +++ b/ndsfactory/ndsfactory.h @@ -1,5 +1,4 @@ -#ifndef NDSFACTORY_H -#define NDSFACTORY_H +#pragma once #include #include @@ -29,4 +28,3 @@ private: }; -#endif // NDSFACTORY_H diff --git a/ndsfactory/ndsheader.h b/ndsfactory/ndsheader.h index afda3db..461493c 100644 --- a/ndsfactory/ndsheader.h +++ b/ndsfactory/ndsheader.h @@ -1,5 +1,4 @@ -#ifndef NDSHEADER_H -#define NDSHEADER_H +#pragma once #include @@ -69,5 +68,3 @@ struct NDSHeader unsigned char Reserved4[0x90]; }; #pragma pack(pop) - -#endif // NDSHEADER_H diff --git a/ui/dialogs/about/aboutdialog.h b/ui/dialogs/about/aboutdialog.h index 5681bc2..9857081 100644 --- a/ui/dialogs/about/aboutdialog.h +++ b/ui/dialogs/about/aboutdialog.h @@ -1,5 +1,4 @@ -#ifndef ABOUTDIALOG_H -#define ABOUTDIALOG_H +#pragma once #include @@ -18,5 +17,3 @@ class AboutDialog : public QDialog Ui::AboutDialog *ui; }; - -#endif // ABOUTDIALOG_H diff --git a/ui/dialogs/about/revision.h b/ui/dialogs/about/revision.h index 128590b..5172a59 100644 --- a/ui/dialogs/about/revision.h +++ b/ui/dialogs/about/revision.h @@ -1,6 +1,6 @@ #ifndef REVISION_H #define REVISION_H -#define GIT_COMMIT_HASH "c7eaa8e" +#define GIT_COMMIT_HASH "aa2ed50" #endif diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 462c472..e947fbe 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -2,6 +2,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "dialogs/about/aboutdialog.h" +#include "utils/theme.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -26,3 +27,18 @@ void MainWindow::on_actionAbout_triggered() AboutDialog aboutDialog; aboutDialog.exec(); } + +void MainWindow::on_actionDark_triggered() +{ + setTheme("dark"); +} + +void MainWindow::on_actionLight_triggered() +{ + setTheme("light"); +} + +void MainWindow::on_actionDefault_triggered() +{ + setTheme("default"); +} diff --git a/ui/mainwindow.h b/ui/mainwindow.h index f1f16d5..8eb5fe1 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -1,5 +1,4 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#pragma once #include #include @@ -35,6 +34,9 @@ private slots: void on_unpackerDecodeFatFilesBtn_clicked(); void notifyExtractionResult(bool result); + void on_actionDark_triggered(); + void on_actionLight_triggered(); + void on_actionDefault_triggered(); void on_actionExit_triggered(); void on_actionAbout_triggered(); @@ -113,5 +115,3 @@ private: bool patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath); }; - -#endif // MAINWINDOW_H diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 42272cf..e3fab5a 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -617,23 +617,27 @@ - - - - 0 - 0 - - - - If the address of the fat_data.bin file is different from the original location in ROM, you need to patch the fat.bin file... - - - false - - - Qt::AlignmentFlag::AlignCenter - - + + + + + + 0 + 0 + + + + If the address of the fat_data.bin file is different from the original location in ROM, you need to patch the fat.bin file... + + + false + + + Qt::AlignmentFlag::AlignCenter + + + + @@ -760,6 +764,15 @@ File + + + Theme + + + + + + @@ -786,6 +799,21 @@ Exit + + + Dark + + + + + Light + + + + + Default + + diff --git a/ui/models/ndsheadermodel.h b/ui/models/ndsheadermodel.h index 04b08f8..47e3d10 100644 --- a/ui/models/ndsheadermodel.h +++ b/ui/models/ndsheadermodel.h @@ -1,5 +1,4 @@ -#ifndef NDSHEADERMODEL_H -#define NDSHEADERMODEL_H +#pragma once #include @@ -21,5 +20,3 @@ private: NDSHeader *ndsHeader; bool isValueRowEditable = false; }; - -#endif // NDSHEADERMODEL_H diff --git a/ui/tabs/commons/headernames.h b/ui/tabs/commons/headernames.h index 10df5e4..64dcc93 100644 --- a/ui/tabs/commons/headernames.h +++ b/ui/tabs/commons/headernames.h @@ -1,5 +1,4 @@ -#ifndef HEADERNAMES_H -#define HEADERNAMES_H +#pragma once #include #include @@ -52,5 +51,3 @@ namespace NDSHeaderNames { FATFilesAddress }; } - -#endif // HEADERNAMES_H diff --git a/ui/utils/theme.h b/ui/utils/theme.h new file mode 100644 index 0000000..d5f0a10 --- /dev/null +++ b/ui/utils/theme.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include + +inline void setDarkTheme(QApplication& app) +{ + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, QColor(35, 35, 35)); + darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::ToolTipBase, Qt::white); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::BrightText, Qt::red); + darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); + + app.setPalette(darkPalette); +} + +inline void setLightTheme(QApplication& app) +{ + QPalette lightPalette; + lightPalette.setColor(QPalette::Window, QColor(240, 240, 240)); + lightPalette.setColor(QPalette::WindowText, Qt::black); + lightPalette.setColor(QPalette::Base, QColor(255, 255, 255)); + lightPalette.setColor(QPalette::AlternateBase, QColor(233, 233, 233)); + lightPalette.setColor(QPalette::ToolTipBase, Qt::black); + lightPalette.setColor(QPalette::ToolTipText, Qt::white); + lightPalette.setColor(QPalette::Text, Qt::black); + lightPalette.setColor(QPalette::Button, QColor(240, 240, 240)); + lightPalette.setColor(QPalette::ButtonText, Qt::black); + lightPalette.setColor(QPalette::BrightText, Qt::red); + lightPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + lightPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + lightPalette.setColor(QPalette::HighlightedText, Qt::white); + + app.setPalette(lightPalette); +} + +inline void setTheme(QString themeValue) +{ + QSettings settings; + settings.setValue("theme", themeValue); + QMessageBox::information(nullptr, "NDS Factory", "Restart NDSFactory to change theme!"); + +} + +inline QString getCurrentTheme() +{ + QSettings settings; + return settings.value("theme", "default").toString(); +} \ No newline at end of file