Skip to content

Commit 58df91f

Browse files
committed
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 <shashvat.kk@gmail.com> Signed-off-by: sh4shv4t <shashvat.k.singh.16@gmail.com>
1 parent 8a39d36 commit 58df91f

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/iv/imageviewer.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <QMenu>
2626
#include <QMenuBar>
2727
#include <QMessageBox>
28+
#include <QPalette>
2829
#include <QProgressBar>
2930
#include <QResizeEvent>
3031
#include <QSettings>
3132
#include <QSpinBox>
3233
#include <QStatusBar>
34+
#include <QStyleFactory>
3335
#include <QTimer>
3436

3537
#if OIIO_QT_MAJOR < 6
@@ -99,7 +101,8 @@ static const char *s_file_filters = ""
99101

100102

101103
ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space,
102-
const std::string& display, const std::string& view)
104+
const std::string& display, const std::string& view,
105+
bool dark)
103106
: infoWindow(NULL)
104107
, preferenceWindow(NULL)
105108
, darkPaletteBox(NULL)
@@ -110,7 +113,7 @@ ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space,
110113
, m_zoom(1)
111114
, m_fullscreen(false)
112115
, m_default_gamma(1)
113-
, m_darkPalette(false)
116+
, m_darkPalette(dark)
114117
, m_useOCIO(use_ocio)
115118
, m_ocioColourSpace(image_color_space)
116119
, m_ocioDisplay(display)
@@ -126,10 +129,26 @@ ImageViewer::ImageViewer(bool use_ocio, const std::string& image_color_space,
126129
// Also, some time in the future we may want a real 3D LUT for
127130
// "film look", etc.
128131

129-
if (darkPalette())
130-
m_palette = QPalette(Qt::darkGray); // darkGray?
131-
else
132+
if (darkPalette()) {
133+
QApplication::setStyle(QStyleFactory::create("Fusion"));
134+
QPalette dp;
135+
dp.setColor(QPalette::Window, QColor(53, 53, 53));
136+
dp.setColor(QPalette::WindowText, Qt::white);
137+
dp.setColor(QPalette::Base, QColor(25, 25, 25));
138+
dp.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
139+
dp.setColor(QPalette::ToolTipBase, Qt::white);
140+
dp.setColor(QPalette::ToolTipText, Qt::white);
141+
dp.setColor(QPalette::Text, Qt::white);
142+
dp.setColor(QPalette::Button, QColor(53, 53, 53));
143+
dp.setColor(QPalette::ButtonText, Qt::white);
144+
dp.setColor(QPalette::BrightText, Qt::red);
145+
dp.setColor(QPalette::Link, QColor(42, 130, 218));
146+
dp.setColor(QPalette::Highlight, QColor(42, 130, 218));
147+
dp.setColor(QPalette::HighlightedText, Qt::black);
148+
m_palette = dp;
149+
} else {
132150
m_palette = QPalette();
151+
}
133152
QApplication::setPalette(m_palette); // FIXME -- why not work?
134153
this->setPalette(m_palette);
135154

src/iv/imageviewer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class ImageViewer final : public QMainWindow {
148148

149149
public:
150150
ImageViewer(bool use_ocio, const std::string& image_color_space,
151-
const std::string& display, const std::string& view);
151+
const std::string& display, const std::string& view,
152+
bool dark = false);
152153
~ImageViewer();
153154

154155
enum COLOR_MODE {

src/iv/ivmain.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ getargs(int argc, char* argv[])
5858
ap.arg("--rawcolor")
5959
.help("Do not automatically transform to RGB");
6060

61+
ap.arg("--dark")
62+
.help("Start in dark mode")
63+
.dest("dark")
64+
.store_true();
65+
6166
ap.arg("--display")
6267
.help("OCIO display")
6368
.metavar("STRING")
@@ -124,8 +129,8 @@ main(int argc, char* argv[])
124129
#endif
125130
}
126131

127-
ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display,
128-
view);
132+
ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display, view,
133+
ap["dark"].get<int>());
129134

130135
mainWin->show();
131136

0 commit comments

Comments
 (0)