Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
globals.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"globals.h"
5
6
#
include
<
QApplication
>
7
#
include
<
QColor
>
8
#
include
<
QPalette
>
9
#
include
<
QStyleHints
>
10
11
namespace
{
12
// Check for "Dark Mode", either system-wide or usage of a dark style
13
static
bool
isLight(
const
QColor &textColor)
14
{
15
constexpr
int
DarkThreshold = 200;
16
return
textColor.red() > DarkThreshold && textColor.green() > DarkThreshold
17
&& textColor.blue() > DarkThreshold;
18
}
19
}
// namespace
20
21
using
namespace
Qt::Literals::StringLiterals;
22
23
QT_BEGIN_NAMESPACE
24
25
const
QString &settingsPrefix()
26
{
27
28
static
QString prefix =
29
QString::number(QT_VERSION_MAJOR) + u'.' + QString::number(QT_VERSION_MINOR) + u'/';
30
return
prefix;
31
}
32
33
QString
settingPath
(
const
char
*path)
34
{
35
return
settingsPrefix() + QLatin1String(path);
36
}
37
38
bool
isDarkMode
()
39
{
40
return
QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark
41
|| isLight(QGuiApplication::palette().color(QPalette::WindowText));
42
}
43
44
QPixmap
createMarkIcon
(TranslationMarks mark,
bool
darkMode)
45
{
46
const
QString prefix = darkMode ?
":/images/darkmarks"_L1
:
":/images/lightmarks"_L1
;
47
switch
(mark) {
48
case
TranslationMarks::OnMark:
49
return
QPixmap(prefix +
"/on-mark"_L1
)
50
.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
51
case
TranslationMarks::OffMark:
52
return
QPixmap(prefix +
"/off-mark"_L1
)
53
.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
54
case
TranslationMarks::ObsoleteMark:
55
return
QPixmap(prefix +
"/obsolete-mark"_L1
)
56
.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
57
case
TranslationMarks::DangerMark:
58
return
QPixmap(prefix +
"/danger-mark"_L1
)
59
.scaled(24, 24, Qt::KeepAspectRatio, Qt::SmoothTransformation);
60
case
TranslationMarks::WarningMark:
61
return
QPixmap(prefix +
"/warning-mark"_L1
)
62
.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
63
case
TranslationMarks::EmptyMark:
64
return
QPixmap(prefix +
"/empty-mark"_L1
)
65
.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
66
};
67
Q_UNREACHABLE_RETURN({});
68
}
69
70
QT_END_NAMESPACE
settingPath
QString settingPath(const char *path)
Definition
globals.cpp:33
isDarkMode
bool isDarkMode()
Definition
globals.cpp:38
createMarkIcon
QPixmap createMarkIcon(TranslationMarks mark, bool darkMode)
Definition
globals.cpp:44
qttools
src
linguist
linguist
globals.cpp
Generated on
for Qt by
1.18.0