Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/qwindowkit_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ namespace QWK {
reinterpret_cast<unsigned char *>(&value), &size) == ERROR_SUCCESS;
return qMakePair(value, ok);
}
#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
WindowsRegistryKey::WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions, REGSAM access)
: QWinRegistryKey(parentHandle, subKey, permissions, access)
{
}
#endif

}
30 changes: 30 additions & 0 deletions src/core/qwindowkit_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ namespace QWK {
QString stringValue(QStringView subKey) const;
QPair<DWORD, bool> dwordValue(QStringView subKey) const;

template<typename T>
std::optional<T> value(QStringView subKey) const;

private:
HKEY m_key;

Expand All @@ -134,6 +137,33 @@ namespace QWK {
inline bool WindowsRegistryKey::isValid() const {
return m_key != nullptr;
}

template<>
inline std::optional<DWORD> WindowsRegistryKey::value(QStringView subKey) const {
const auto dv = dwordValue(subKey);
if (!dv.second) {
return {};
}
return dv.first;
}
#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
class WindowsRegistryKey : public QWinRegistryKey {
public:

explicit WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions = KEY_READ, REGSAM access = 0);

template<typename T>
inline std::optional<T> value(QStringView subKey) const;
};

template<>
inline std::optional<DWORD> WindowsRegistryKey::value(QStringView subKey) const {
const auto dv = dwordValue(subKey);
if (!dv.second) {
return {};
}
return dv.first;
}
#else
using WindowsRegistryKey = QWinRegistryKey;
#endif
Expand Down
20 changes: 7 additions & 13 deletions src/core/shared/qwkwindowsextra_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,8 @@ namespace QWK {
if (!registry.isValid()) {
return false;
}
auto value = registry.dwordValue(L"ColorPrevalence");
if (!value.second) {
return false;
}
return value.first;
auto value = registry.value<DWORD>(L"ColorPrevalence");
return value.value_or(false);
}

static inline bool isHighContrastModeEnabled() {
Expand All @@ -368,11 +365,8 @@ namespace QWK {
if (!registry.isValid()) {
return false;
}
auto value = registry.dwordValue(L"AppsUseLightTheme");
if (!value.second) {
return false;
}
return !value.first;
auto value = registry.value<DWORD>(L"AppsUseLightTheme");
return value.value_or(false);
#endif
}

Expand All @@ -398,13 +392,13 @@ namespace QWK {
if (!registry.isValid()) {
return {};
}
auto value = registry.dwordValue(L"AccentColor");
if (!value.second) {
auto value = registry.value<DWORD>(L"AccentColor");
if (!value) {
return {};
}
// The retrieved value is in the #AABBGGRR format, we need to
// convert it to the #AARRGGBB format which Qt expects.
QColor color = QColor::fromRgba(value.first);
QColor color = QColor::fromRgba(*value);
if (!color.isValid()) {
return {};
}
Expand Down