GrantleeTheme

palette.cpp
1 /*
2  * Copyright (C) 2019 Volker Krause <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "palette.h"
20 
21 #include <grantlee/metatype.h>
22 
23 #include <QPalette>
24 
25 #define ROLE(R) { #R, QPalette::R }
26 
27 static const struct {
28  const char *name;
30 } color_roles[] = {
31  ROLE(AlternateBase),
32  ROLE(Base),
33  ROLE(BrightText),
34  ROLE(Button),
35  ROLE(ButtonText),
36  ROLE(Dark),
37  ROLE(Highlight),
38  ROLE(HighlightedText),
39  ROLE(Light),
40  ROLE(Link),
41  ROLE(LinkVisited),
42  ROLE(Mid),
43  ROLE(Midlight),
44  ROLE(PlaceholderText),
45  ROLE(Shadow),
46  ROLE(Text),
47  ROLE(ToolTipBase),
48  ROLE(ToolTipText),
49  ROLE(Window),
50  ROLE(WindowText),
51 };
52 
53 GRANTLEE_BEGIN_LOOKUP(QPalette)
54 auto group = QPalette::Inactive;
55 auto roleName = property;
56 
57 if (property.startsWith(QLatin1String("active"))) {
58  roleName = property.mid(6);
59  group = QPalette::Active;
60 } else if (property.startsWith(QLatin1String("disabled"))) {
61  roleName = property.mid(8);
62  group = QPalette::Disabled;
63 } else if (property.startsWith(QLatin1String("inactive"))) {
64  roleName = property.mid(8);
65  group = QPalette::Inactive;
66 }
67 
68 for (const auto &role : color_roles) {
69  if (roleName.compare(QLatin1String(role.name), Qt::CaseInsensitive) == 0) {
70  return object.color(group, role.role);
71  }
72 }
73 return {};
74 GRANTLEE_END_LOOKUP
75 
76 void Palette::registerMetaType()
77 {
78  Grantlee::registerMetaType<QPalette>();
79 }
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 23:21:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.