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