| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2025 g10 Code GmbH |
| 4 | SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #include "highcontrasthelper_p.h" |
| 10 | |
| 11 | #include <QGuiApplication> |
| 12 | #include <QStyleHints> |
| 13 | #if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) |
| 14 | #include <QAccessibilityHints> |
| 15 | #else |
| 16 | #ifdef Q_OS_WIN |
| 17 | #include <windows.h> |
| 18 | #endif |
| 19 | #endif |
| 20 | |
| 21 | static bool isHighContrastModeActive() |
| 22 | { |
| 23 | #if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) |
| 24 | return QGuiApplication::styleHints()->accessibility()->contrastPreference() == Qt::ContrastPreference::HighContrast; |
| 25 | #else |
| 26 | #ifdef Q_OS_WIN |
| 27 | HIGHCONTRAST result; |
| 28 | result.cbSize = sizeof(HIGHCONTRAST); |
| 29 | if (SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0)) { |
| 30 | return (result.dwFlags & HCF_HIGHCONTRASTON); |
| 31 | } |
| 32 | #endif |
| 33 | return false; |
| 34 | #endif |
| 35 | } |
| 36 | |
| 37 | static bool isDefaultColorSchemeInUse() |
| 38 | { |
| 39 | const QVariant colorSchemePathProperty = qApp->property(name: "KDE_COLOR_SCHEME_PATH" ); |
| 40 | return !colorSchemePathProperty.isValid() || colorSchemePathProperty.toString().isEmpty(); |
| 41 | } |
| 42 | |
| 43 | bool isHighContrastColorSchemeInUse() |
| 44 | { |
| 45 | return isHighContrastModeActive() && isDefaultColorSchemeInUse(); |
| 46 | } |
| 47 | |