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#include <KTextTemplate/MetaType>
9#include <QObject>
10
11#include <QPalette>
12
13#define ROLE(R) \
14 { \
15#R, QPalette::R \
16 }
17
18static const struct {
19 const char *name;
21} color_roles[] = {
22 ROLE(AlternateBase), ROLE(Base), ROLE(BrightText), ROLE(Button), ROLE(ButtonText), ROLE(Dark), ROLE(Highlight),
23 ROLE(HighlightedText), ROLE(Light), ROLE(Link), ROLE(LinkVisited), ROLE(Mid), ROLE(Midlight), ROLE(PlaceholderText),
24 ROLE(Shadow), ROLE(Text), ROLE(ToolTipBase), ROLE(ToolTipText), ROLE(Window), ROLE(WindowText),
25};
27auto group = QPalette::Inactive;
28auto roleName = property;
29
30if (property.startsWith(QLatin1StringView("active"))) {
31 roleName = property.mid(6);
32 group = QPalette::Active;
33} else if (property.startsWith(QLatin1StringView("disabled"))) {
34 roleName = property.mid(8);
35 group = QPalette::Disabled;
36} else if (property.startsWith(QLatin1StringView("inactive"))) {
37 roleName = property.mid(8);
38 group = QPalette::Inactive;
39}
40
41for (const auto &role : color_roles) {
42 if (roleName.compare(QLatin1StringView(role.name), Qt::CaseInsensitive) == 0) {
43 return object.color(group, role.role);
44 }
45}
46return {};
48
49void Palette::registerMetaType()
50{
51 KTextTemplate::registerMetaType<QPalette>();
52}
#define KTEXTTEMPLATE_END_LOOKUP
#define KTEXTTEMPLATE_BEGIN_LOOKUP(Type)
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.