1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.gui.palette;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.global;
17 import qt.core.metamacros;
18 import qt.core.namespace;
19 import qt.core.typeinfo;
20 import qt.core.variant;
21 import qt.gui.brush;
22 import qt.gui.color;
23 import qt.helpers;
24 
25 extern(C++, class) struct QPalettePrivate;
26 
27 /// Binding for C++ class [QPalette](https://doc.qt.io/qt-6/qpalette.html).
28 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QPalette
29 {
30     mixin(Q_GADGET);
31 public:
32     @disable this();
33     pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this))))
34     ref typeof(this) rawConstructor();
35     static typeof(this) create()
36     {
37         typeof(this) r = typeof(this).init;
38         r.rawConstructor();
39         return r;
40     }
41 
42     this(ref const(QColor) button);
43     this(/+ Qt:: +/qt.core.namespace.GlobalColor button);
44     this(ref const(QColor) button, ref const(QColor) window);
45     this(ref const(QBrush) windowText, ref const(QBrush) button, ref const(QBrush) light,
46                  ref const(QBrush) dark, ref const(QBrush) mid, ref const(QBrush) text,
47                  ref const(QBrush) bright_text, ref const(QBrush) base, ref const(QBrush) window);
48     this(ref const(QColor) windowText, ref const(QColor) window, ref const(QColor) light,
49                  ref const(QColor) dark, ref const(QColor) mid, ref const(QColor) text, ref const(QColor) base);
50     @disable this(this);
51     this(ref const(QPalette) palette);
52     ~this();
53     /+ref QPalette operator =(ref const(QPalette) palette);+/
54     /+ QPalette(QPalette &&other) noexcept
55         : d(qExchange(other.d, nullptr)), currentGroup(other.currentGroup)
56     {} +/
57     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPalette) +/
58 
59     /+ void swap(QPalette &other) noexcept
60     {
61         qSwap(currentGroup, other.currentGroup);
62         qSwap(d, other.d);
63     } +/
64 
65     /+auto opCast(T : QVariant)() const;+/
66 
67     // Do not change the order, the serialization format depends on it
68     enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = ColorGroup.Active }
69     /+ Q_ENUM(ColorGroup) +/
70     enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
71                      Text, BrightText, ButtonText, Base, Window, Shadow,
72                      Highlight, HighlightedText,
73                      Link, LinkVisited,
74                      AlternateBase,
75                      NoRole,
76                      ToolTipBase, ToolTipText,
77                      PlaceholderText,
78                      NColorRoles = ColorRole.PlaceholderText + 1,
79                    }
80     /+ Q_ENUM(ColorRole) +/
81 
82     pragma(inline, true) ColorGroup currentColorGroup() const { return currentGroup; }
83     pragma(inline, true) void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; }
84 
85     pragma(inline, true) ref const(QColor) color(ColorGroup cg, ColorRole cr) const
86     { return brush(cg, cr).color(); }
87     ref const(QBrush) brush(ColorGroup cg, ColorRole cr) const;
88     pragma(inline, true) void setColor(ColorGroup acg, ColorRole acr, ref const(QColor) acolor)
89     { auto tmp = QBrush(acolor); setBrush(acg, acr, tmp); }
90     pragma(inline, true) void setColor(ColorRole acr, ref const(QColor) acolor)
91     { setColor(ColorGroup.All, acr, acolor); }
92     pragma(inline, true) void setBrush(ColorRole acr, ref const(QBrush) abrush)
93     { setBrush(ColorGroup.All, acr, abrush); }
94     bool isBrushSet(ColorGroup cg, ColorRole cr) const;
95     void setBrush(ColorGroup cg, ColorRole cr, ref const(QBrush) brush);
96     void setColorGroup(ColorGroup cr, ref const(QBrush) windowText, ref const(QBrush) button,
97                            ref const(QBrush) light, ref const(QBrush) dark, ref const(QBrush) mid,
98                            ref const(QBrush) text, ref const(QBrush) bright_text, ref const(QBrush) base,
99                            ref const(QBrush) window);
100     bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
101 
102     pragma(inline, true) ref const(QColor) color(ColorRole cr) const { return color(ColorGroup.Current, cr); }
103     pragma(inline, true) ref const(QBrush) brush(ColorRole cr) const { return brush(ColorGroup.Current, cr); }
104     pragma(inline, true) ref const(QBrush) windowText() const { return brush(ColorRole.WindowText); }
105     pragma(inline, true) ref const(QBrush) button() const { return brush(ColorRole.Button); }
106     pragma(inline, true) ref const(QBrush) light() const { return brush(ColorRole.Light); }
107     pragma(inline, true) ref const(QBrush) dark() const { return brush(ColorRole.Dark); }
108     pragma(inline, true) ref const(QBrush) mid() const { return brush(ColorRole.Mid); }
109     pragma(inline, true) ref const(QBrush) text() const { return brush(ColorRole.Text); }
110     pragma(inline, true) ref const(QBrush) base() const { return brush(ColorRole.Base); }
111     pragma(inline, true) ref const(QBrush) alternateBase() const { return brush(ColorRole.AlternateBase); }
112     pragma(inline, true) ref const(QBrush) toolTipBase() const { return brush(ColorRole.ToolTipBase); }
113     pragma(inline, true) ref const(QBrush) toolTipText() const { return brush(ColorRole.ToolTipText); }
114     pragma(inline, true) ref const(QBrush) window() const { return brush(ColorRole.Window); }
115     pragma(inline, true) ref const(QBrush) midlight() const { return brush(ColorRole.Midlight); }
116     pragma(inline, true) ref const(QBrush) brightText() const { return brush(ColorRole.BrightText); }
117     pragma(inline, true) ref const(QBrush) buttonText() const { return brush(ColorRole.ButtonText); }
118     pragma(inline, true) ref const(QBrush) shadow() const { return brush(ColorRole.Shadow); }
119     pragma(inline, true) ref const(QBrush) highlight() const { return brush(ColorRole.Highlight); }
120     pragma(inline, true) ref const(QBrush) highlightedText() const { return brush(ColorRole.HighlightedText); }
121     pragma(inline, true) ref const(QBrush) link() const { return brush(ColorRole.Link); }
122     pragma(inline, true) ref const(QBrush) linkVisited() const { return brush(ColorRole.LinkVisited); }
123     pragma(inline, true) ref const(QBrush) placeholderText() const { return brush(ColorRole.PlaceholderText); }
124 
125     /+bool operator ==(ref const(QPalette) p) const;+/
126     /+pragma(inline, true) bool operator !=(ref const(QPalette) p) const { return !(operator==(p)); }+/
127     bool isCopyOf(ref const(QPalette) p) const;
128 
129     qint64 cacheKey() const;
130 
131     QPalette resolve(ref const(QPalette) other) const;
132 
133     alias ResolveMask = quint64;
134     ResolveMask resolveMask() const;
135     void setResolveMask(ResolveMask mask);
136 
137 private:
138     void setColorGroup(ColorGroup cr, ref const(QBrush) windowText, ref const(QBrush) button,
139                            ref const(QBrush) light, ref const(QBrush) dark, ref const(QBrush) mid,
140                            ref const(QBrush) text, ref const(QBrush) bright_text,
141                            ref const(QBrush) base, ref const(QBrush) alternate_base,
142                            ref const(QBrush) window, ref const(QBrush) midlight,
143                            ref const(QBrush) button_text, ref const(QBrush) shadow,
144                            ref const(QBrush) highlight, ref const(QBrush) highlighted_text,
145                            ref const(QBrush) link, ref const(QBrush) link_visited);
146     void setColorGroup(ColorGroup cr, ref const(QBrush) windowText, ref const(QBrush) button,
147                            ref const(QBrush) light, ref const(QBrush) dark, ref const(QBrush) mid,
148                            ref const(QBrush) text, ref const(QBrush) bright_text,
149                            ref const(QBrush) base, ref const(QBrush) alternate_base,
150                            ref const(QBrush) window, ref const(QBrush) midlight,
151                            ref const(QBrush) button_text, ref const(QBrush) shadow,
152                            ref const(QBrush) highlight, ref const(QBrush) highlighted_text,
153                            ref const(QBrush) link, ref const(QBrush) link_visited,
154                            ref const(QBrush) toolTipBase, ref const(QBrush) toolTipText);
155     //void init_();
156     void detach();
157 
158     QPalettePrivate* d;
159     ColorGroup currentGroup = ColorGroup(ColorGroup.Active);
160 
161     /+ friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p); +/
162     mixin(CREATE_CONVENIENCE_WRAPPERS);
163 }
164 
165 /+ Q_DECLARE_SHARED(QPalette)
166 
167 /*****************************************************************************
168   QPalette stream functions
169  *****************************************************************************/
170 #ifndef QT_NO_DATASTREAM
171 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
172 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
173 #endif // QT_NO_DATASTREAM
174 
175 #ifndef QT_NO_DEBUG_STREAM
176 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
177 #endif +/
178