From 58df91fab61fe1200348d1e640e0be6ad4c935bd Mon Sep 17 00:00:00 2001 From: sh4shv4t Date: Fri, 6 Mar 2026 00:38:27 +0530 Subject: [PATCH] feat: Add --dark flag to iv for Dark Mode Add a --dark CLI argument that activates dark mode using Qt's Fusion style with a custom dark QPalette. The flag integrates with the existing darkPalette preference system in ImageViewer, so both the --dark CLI flag and the Preferences checkbox produce the same result. The dark palette is applied inside ImageViewer's constructor (rather than in main()) so it does not conflict with ImageViewer's own palette setup. The OpenGL background for transparent pixels (glClearColor) is unaffected since it is hardcoded separately from the QPalette. Signed-off-by: Shashvat Singh Signed-off-by: sh4shv4t --- src/iv/imageviewer.cpp | 29 ++++++++++++++++++++++++----- src/iv/imageviewer.h | 3 ++- src/iv/ivmain.cpp | 9 +++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/iv/imageviewer.cpp b/src/iv/imageviewer.cpp index f4a4924a5e..f3f00049c7 100644 --- a/src/iv/imageviewer.cpp +++ b/src/iv/imageviewer.cpp @@ -25,11 +25,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #if OIIO_QT_MAJOR < 6 @@ -99,7 +101,8 @@ static const char *s_file_filters = "" ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space, - const std::string& display, const std::string& view) + const std::string& display, const std::string& view, + bool dark) : infoWindow(NULL) , preferenceWindow(NULL) , darkPaletteBox(NULL) @@ -110,7 +113,7 @@ ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space, , m_zoom(1) , m_fullscreen(false) , m_default_gamma(1) - , m_darkPalette(false) + , m_darkPalette(dark) , m_useOCIO(use_ocio) , m_ocioColourSpace(image_color_space) , m_ocioDisplay(display) @@ -126,10 +129,26 @@ ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space, // Also, some time in the future we may want a real 3D LUT for // "film look", etc. - if (darkPalette()) - m_palette = QPalette(Qt::darkGray); // darkGray? - else + if (darkPalette()) { + QApplication::setStyle(QStyleFactory::create("Fusion")); + QPalette dp; + dp.setColor(QPalette::Window, QColor(53, 53, 53)); + dp.setColor(QPalette::WindowText, Qt::white); + dp.setColor(QPalette::Base, QColor(25, 25, 25)); + dp.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); + dp.setColor(QPalette::ToolTipBase, Qt::white); + dp.setColor(QPalette::ToolTipText, Qt::white); + dp.setColor(QPalette::Text, Qt::white); + dp.setColor(QPalette::Button, QColor(53, 53, 53)); + dp.setColor(QPalette::ButtonText, Qt::white); + dp.setColor(QPalette::BrightText, Qt::red); + dp.setColor(QPalette::Link, QColor(42, 130, 218)); + dp.setColor(QPalette::Highlight, QColor(42, 130, 218)); + dp.setColor(QPalette::HighlightedText, Qt::black); + m_palette = dp; + } else { m_palette = QPalette(); + } QApplication::setPalette(m_palette); // FIXME -- why not work? this->setPalette(m_palette); diff --git a/src/iv/imageviewer.h b/src/iv/imageviewer.h index 763aaf0dd7..d2f38e1e69 100644 --- a/src/iv/imageviewer.h +++ b/src/iv/imageviewer.h @@ -148,7 +148,8 @@ class ImageViewer final : public QMainWindow { public: ImageViewer(bool use_ocio, const std::string& image_color_space, - const std::string& display, const std::string& view); + const std::string& display, const std::string& view, + bool dark = false); ~ImageViewer(); enum COLOR_MODE { diff --git a/src/iv/ivmain.cpp b/src/iv/ivmain.cpp index 69509071dc..14abb48f48 100644 --- a/src/iv/ivmain.cpp +++ b/src/iv/ivmain.cpp @@ -58,6 +58,11 @@ getargs(int argc, char* argv[]) ap.arg("--rawcolor") .help("Do not automatically transform to RGB"); + ap.arg("--dark") + .help("Start in dark mode") + .dest("dark") + .store_true(); + ap.arg("--display") .help("OCIO display") .metavar("STRING") @@ -124,8 +129,8 @@ main(int argc, char* argv[]) #endif } - ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display, - view); + ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display, view, + ap["dark"].get()); mainWin->show();