Deskflow 1.24.0.365
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
StyleUtils.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
4 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
5 */
6
7#pragma once
8
9#include <QDir>
10#include <QFileInfoList>
11#include <QIcon>
12#include <QPalette>
13#include <QStyleHints>
14
15#include "common/Constants.h"
16
17namespace deskflow::gui {
18
25inline bool isDarkMode()
26{
27 const QPalette defaultPalette;
28 const auto text = defaultPalette.color(QPalette::WindowText);
29 const auto window = defaultPalette.color(QPalette::Window);
30 return text.lightness() > window.lightness();
31}
32
36inline QString iconMode()
37{
38 return isDarkMode() ? QStringLiteral("dark") : QStringLiteral("light");
39}
40
41inline void updateIconTheme()
42{
43 // Sets the fallback icon path and fallback theme
44 const auto themeName = QStringLiteral("%1-%2").arg(kAppId, iconMode());
45 if (QIcon::themeName().isEmpty() || QIcon::themeName().startsWith(kAppId))
46 QIcon::setThemeName(themeName);
47 else
48 QIcon::setFallbackThemeName(themeName);
49 QIcon::setFallbackSearchPaths({QStringLiteral(":/icons/%1").arg(themeName)});
50}
51} // namespace deskflow::gui
Definition IServerConfig.h:14
QString iconMode()
get a string for the iconMode
Definition StyleUtils.h:36
void updateIconTheme()
Definition StyleUtils.h:41
bool isDarkMode()
Detects dark mode in a universal manner (all Qt versions). Until better platform support is added,...
Definition StyleUtils.h:25