Deskflow 1.26.0.314
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 Synergy App 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 <QFontDatabase>
12#include <QIcon>
13#include <QPalette>
14#include <QStyleHints>
15
16#include "common/Constants.h"
17
18namespace deskflow::gui {
19
26inline bool isDarkMode()
27{
28 const QPalette defaultPalette;
29 const auto text = defaultPalette.color(QPalette::WindowText);
30 const auto window = defaultPalette.color(QPalette::Window);
31 return text.lightness() > window.lightness();
32}
33
37inline QString iconMode()
38{
39 return isDarkMode() ? QStringLiteral("dark") : QStringLiteral("light");
40}
41
42inline void updateIconTheme()
43{
44 // Sets the fallback icon path and fallback theme
45 const auto themeName = QStringLiteral("%1-%2").arg(kAppId, iconMode());
46 if (QIcon::themeName().isEmpty() || QIcon::themeName().startsWith(kAppId))
47 QIcon::setThemeName(themeName);
48 else
49 QIcon::setFallbackThemeName(themeName);
50 QIcon::setFallbackSearchPaths({QStringLiteral(":/icons/%1").arg(themeName)});
51}
52} // namespace deskflow::gui
53
54inline QFont fixedFont()
55{
56#if defined(Q_OS_WIN)
57 QFont f({"Hack", "Liberation Mono", "Monospace", "Andale Mono"});
58 f.setStyleHint(QFont::Monospace);
59#else
60 QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont);
61#endif
62
63#if defined(Q_OS_MAC)
64 f.setPointSize(12);
65#endif
66 return f;
67}
QFont fixedFont()
Definition StyleUtils.h:54
Definition CoreProcess.cpp:30
QString iconMode()
get a string for the iconMode
Definition StyleUtils.h:37
void updateIconTheme()
Definition StyleUtils.h:42
bool isDarkMode()
Detects dark mode in a universal manner (all Qt versions). Until better platform support is added,...
Definition StyleUtils.h:26