GrantleeTheme

palette.cpp
1 /*
2  * SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 
7 #include "palette.h"
8 
9 #include <grantlee/metatype.h>
10 
11 #include <QPalette>
12 
13 #define ROLE(R) \
14  { \
15 #R, QPalette::R \
16  }
17 
18 static 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 };
26 
27 GRANTLEE_BEGIN_LOOKUP(QPalette)
28 auto group = QPalette::Inactive;
29 auto roleName = property;
30 
31 if (property.startsWith(QLatin1String("active"))) {
32  roleName = property.mid(6);
33  group = QPalette::Active;
34 } else if (property.startsWith(QLatin1String("disabled"))) {
35  roleName = property.mid(8);
36  group = QPalette::Disabled;
37 } else if (property.startsWith(QLatin1String("inactive"))) {
38  roleName = property.mid(8);
39  group = QPalette::Inactive;
40 }
41 
42 for (const auto &role : color_roles) {
43  if (roleName.compare(QLatin1String(role.name), Qt::CaseInsensitive) == 0) {
44  return object.color(group, role.role);
45  }
46 }
47 return {};
48 GRANTLEE_END_LOOKUP
49 
50 void Palette::registerMetaType()
51 {
52  Grantlee::registerMetaType<QPalette>();
53 }
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu May 13 2021 23:17:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.