-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2023 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qml/thememanager.h> | ||
|
||
ThemeManager::ThemeManager(QObject* parent) | ||
: QObject(parent) | ||
{ | ||
} | ||
|
||
void ThemeManager::setSystemBaseColor(QColor base_color) | ||
{ | ||
// Convert QColor's 8-bit RGB values to linear RGB values | ||
double linearR = base_color.redF(); | ||
double linearG = base_color.greenF(); | ||
double linearB = base_color.blueF(); | ||
|
||
// Constants for the luminance formula | ||
const double RED_FACTOR = 0.2126; | ||
const double GREEN_FACTOR = 0.7152; | ||
const double BLUE_FACTOR = 0.0722; | ||
|
||
// Calculate luminance using the formula | ||
double luminance = RED_FACTOR * linearR + GREEN_FACTOR * linearG + BLUE_FACTOR * linearB; | ||
|
||
if (luminance <= 0.5) { | ||
m_dark_mode = true; | ||
} else { | ||
m_dark_mode = false; | ||
} | ||
|
||
m_system_base_color = base_color; | ||
|
||
#ifdef Q_OS_MAC | ||
setSystemThemeAvailable(true); | ||
#endif | ||
|
||
Q_EMIT darkModeChanged(); | ||
} | ||
|
||
void ThemeManager::setSystemThemeAvailable(bool available) | ||
{ | ||
if (m_system_theme_available != available) { | ||
m_system_theme_available = available; | ||
Q_EMIT systemThemeAvailableChanged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2023 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QML_THEMEMANAGER_H | ||
#define BITCOIN_QML_THEMEMANAGER_H | ||
|
||
#include <QObject> | ||
#include <QColor> | ||
#include <QProcess> | ||
|
||
|
||
class ThemeManager : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(bool darkMode READ darkMode NOTIFY darkModeChanged) | ||
Q_PROPERTY(QColor systemBaseColor READ systemBaseColor WRITE setSystemBaseColor) | ||
Q_PROPERTY(bool systemThemeAvailable READ systemThemeAvailable WRITE setSystemThemeAvailable NOTIFY systemThemeAvailableChanged) | ||
|
||
public: | ||
explicit ThemeManager(QObject* parent = nullptr); | ||
|
||
bool darkMode() const { return m_dark_mode; }; | ||
QColor systemBaseColor() const { return m_system_base_color; }; | ||
bool systemThemeAvailable() const { return m_system_theme_available; }; | ||
|
||
public Q_SLOTS: | ||
void setSystemBaseColor(QColor base_color); | ||
void setSystemThemeAvailable(bool available); | ||
|
||
Q_SIGNALS: | ||
void darkModeChanged(); | ||
void systemThemeAvailableChanged(); | ||
|
||
private: | ||
bool m_dark_mode{ true }; | ||
QColor m_system_base_color; | ||
bool m_system_theme_available{ false }; | ||
}; | ||
|
||
#endif // BITCOIN_QML_THEMEMANAGER_H |