mirror of https://github.com/JakubMelka/PDF4QT.git
Issue #181: where is the dark mode?
This commit is contained in:
parent
625a4307d0
commit
3a57bc6de5
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <optional>
|
||||
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
@ -30,6 +31,7 @@
|
|||
#include <QGroupBox>
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QStyleHints>
|
||||
|
||||
#include "pdfdbgheap.h"
|
||||
|
||||
|
@ -44,6 +46,8 @@ int qt_default_dpi_y() { return 96; }
|
|||
namespace pdf
|
||||
{
|
||||
|
||||
std::optional<bool> s_isDarkThemeOverride;
|
||||
|
||||
static constexpr bool isScalingNeeded()
|
||||
{
|
||||
return QT_VERSION_MAJOR < 6;
|
||||
|
@ -172,13 +176,20 @@ void PDFWidgetUtils::style(QWidget* widget)
|
|||
}
|
||||
}
|
||||
|
||||
void PDFWidgetUtils::overrideDarkTheme(bool isDarkTheme)
|
||||
{
|
||||
s_isDarkThemeOverride = isDarkTheme;
|
||||
}
|
||||
|
||||
bool PDFWidgetUtils::isDarkTheme()
|
||||
{
|
||||
QPalette palette = QApplication::palette();
|
||||
QColor backgroundColor = palette.color(QPalette::Window);
|
||||
QColor textColor = palette.color(QPalette::WindowText);
|
||||
if (s_isDarkThemeOverride.has_value())
|
||||
{
|
||||
return s_isDarkThemeOverride.value();
|
||||
}
|
||||
|
||||
return backgroundColor.lightness() < textColor.lightness();
|
||||
Qt::ColorScheme colorScheme = QApplication::styleHints()->colorScheme();
|
||||
return colorScheme == Qt::ColorScheme::Dark;
|
||||
}
|
||||
|
||||
void PDFWidgetUtils::convertActionForDarkTheme(QAction* action, QSize iconSize, qreal devicePixelRatioF)
|
||||
|
|
|
@ -60,8 +60,10 @@ public:
|
|||
/// Apply style to the widget
|
||||
static void style(QWidget* widget);
|
||||
|
||||
/// Vrátí true, pokud je aktuálně nastavená dark theme
|
||||
/// pro aplikaci.
|
||||
/// Overrides automatically detected dark theme / light theme settings
|
||||
static void overrideDarkTheme(bool isDarkTheme);
|
||||
|
||||
/// Returns true if the dark theme is currently set for the application.
|
||||
static bool isDarkTheme();
|
||||
|
||||
/// Converts an action's icon for use in a dark theme.
|
||||
|
|
Loading…
Reference in New Issue