GrantleeTheme

palette.cpp
1/*
2 * SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "palette.h"
8
9#include <KTextTemplate/MetaType>
10#include <QObject>
11
12#include <QPalette>
13using namespace Qt::Literals::StringLiterals;
14
15#define ROLE(R) {#R, QPalette::R}
16
17static const struct {
18 const char *name;
20} color_roles[] = {
21 ROLE(AlternateBase), ROLE(Base), ROLE(BrightText), ROLE(Button), ROLE(ButtonText), ROLE(Dark), ROLE(Highlight),
22 ROLE(HighlightedText), ROLE(Light), ROLE(Link), ROLE(LinkVisited), ROLE(Mid), ROLE(Midlight), ROLE(PlaceholderText),
23 ROLE(Shadow), ROLE(Text), ROLE(ToolTipBase), ROLE(ToolTipText), ROLE(Window), ROLE(WindowText),
24};
26auto group = QPalette::Inactive;
27auto roleName = property;
28
29if (property.startsWith("active"_L1)) {
30 roleName = property.mid(6);
31 group = QPalette::Active;
32} else if (property.startsWith("disabled"_L1)) {
33 roleName = property.mid(8);
34 group = QPalette::Disabled;
35} else if (property.startsWith("inactive"_L1)) {
36 roleName = property.mid(8);
37 group = QPalette::Inactive;
38}
39
40for (const auto &role : color_roles) {
41 if (roleName.compare(QLatin1StringView(role.name), Qt::CaseInsensitive) == 0) {
42 return object.color(group, role.role);
43 }
44}
45return {};
47
48void Palette::registerMetaType()
49{
51}
#define KTEXTTEMPLATE_END_LOOKUP
#define KTEXTTEMPLATE_BEGIN_LOOKUP(Type)
int registerMetaType()
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.