1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 /* This is the default Qt style sheet.
41 
42    IMPORTANT: This style sheet is primarily meant for defining feature
43    capablities of styles. Do NOT add default styling rules here. When in
44    doubt ask the stylesheet maintainer.
45 
46    The stylesheet in here used to be in a CSS file, but was moved here to
47    avoid parsing overhead.
48 */
49 
50 #include "private/qcssparser_p.h"
51 #include "qstylesheetstyle_p.h"
52 
53 #ifndef QT_NO_STYLE_STYLESHEET
54 
55 QT_BEGIN_NAMESPACE
56 
57 using namespace QCss;
58 
59 // This is the class name of the selector.
60 // Use an empty string where you would use '*' in CSS.
61 // Ex. QHeaderView
62 
63 #define SET_ELEMENT_NAME(x) \
64     bSelector.elementName = (x)
65 
66 // This acts as both pseudo state and sub control. The first parameter is the
67 // string name, and the second is the PseudoClass_* constant.
68 // The sub control specifier is always the first, and has the type
69 // PseudoClass_Unknown.
70 // If there is no PseudoClass_Unknown as the first pseudo, it is assumed to be
71 // a pseudo state.
72 // Ex. QComboBox::drop-down:enabled
73 //                   ^         ^
74 
75 #define ADD_PSEUDO(x, y) \
76     pseudo.type = (y); \
77     pseudo.name = (x); \
78     bSelector.pseudos << pseudo
79 
80 // This is attributes. The third parameter is AttributeSelector::*
81 // Ex. QComboBox[style="QWindowsVistaStyle"]
82 //                 ^           ^
83 
84 #define ADD_ATTRIBUTE_SELECTOR(x, y, z) \
85     attr.name = (x); \
86     attr.value = (y); \
87     attr.valueMatchCriterium = (z); \
88     bSelector.attributeSelectors << attr
89 
90 // Adds the current basic selector to the rule.
91 // Several basic selectors behave as AND (space in CSS).
92 
93 #define ADD_BASIC_SELECTOR \
94     selector.basicSelectors << bSelector; \
95     bSelector.ids.clear(); \
96     bSelector.pseudos.clear(); \
97     bSelector.attributeSelectors.clear()
98 
99 // Adds the current selector to the rule.
100 // Several selectors behave as OR (comma in CSS).
101 
102 #define ADD_SELECTOR \
103     styleRule.selectors << selector; \
104     selector.basicSelectors.clear()
105 
106 // Sets the name of a property.
107 // Ex. background: red;
108 //         ^
109 
110 #define SET_PROPERTY(x, y) \
111     decl.d->property = (x); \
112     decl.d->propertyId = (y)
113 
114 // Adds a value to the current property.
115 // The first parameter should be Value::KnownIdentifier if the value can be
116 // found among the Value_* constants, in which case the second should be that
117 // constant. Otherwise the first parameter is Value::Identifier and the second
118 // is a string.
119 // Adding more values is the same as seperating by spaces in CSS.
120 // Ex. border: 2px solid black;
121 //              ^    ^     ^
122 
123 #define ADD_VALUE(x, y) \
124     value.type = (x); \
125     value.variant = (y); \
126     decl.d->values << value
127 
128 // Adds the current declaration to the rule.
129 // Ex. border: 2px solid black;
130 //     \----------------------/
131 
132 #define ADD_DECLARATION \
133     styleRule.declarations << decl; \
134     decl.d.detach(); \
135     decl.d->values.clear()
136 
137 // Adds the rule to the stylesheet.
138 // Use at the end of every CSS block.
139 
140 #define ADD_STYLE_RULE \
141     sheet.styleRules << styleRule; \
142     styleRule.selectors.clear(); \
143     styleRule.declarations.clear()
144 
getDefaultStyleSheet() const145 StyleSheet QStyleSheetStyle::getDefaultStyleSheet() const
146 {
147     StyleSheet sheet;
148     StyleRule styleRule;
149     BasicSelector bSelector;
150     Selector selector;
151     Declaration decl;
152     QCss::Value value;
153     Pseudo pseudo;
154     AttributeSelector attr;
155 
156     // pixmap based style doesn't support any features
157     bool styleIsPixmapBased = baseStyle()->inherits("QMacStyle")
158                            || baseStyle()->inherits("QWindowsVistaStyle");
159 
160 
161     /*QLineEdit {
162         -qt-background-role: base;
163         border: native;
164         -qt-style-features: background-color;
165     }*/
166     {
167         SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
168         ADD_BASIC_SELECTOR;
169         ADD_SELECTOR;
170 
171         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
172         ADD_VALUE(Value::KnownIdentifier, Value_Base);
173         ADD_DECLARATION;
174 
175         SET_PROPERTY(QLatin1String("border"), Border);
176         ADD_VALUE(Value::KnownIdentifier, Value_Native);
177         ADD_DECLARATION;
178 
179         SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
180         ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
181         ADD_DECLARATION;
182 
183         ADD_STYLE_RULE;
184     }
185 
186     /*QLineEdit:no-frame {
187         border: none;
188     }*/
189     {
190         SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
191         ADD_PSEUDO(QLatin1String("no-frame"), PseudoClass_Frameless);
192         ADD_BASIC_SELECTOR;
193         ADD_SELECTOR;
194 
195         SET_PROPERTY(QLatin1String("border"), Border);
196         ADD_VALUE(Value::KnownIdentifier, Value_None);
197         ADD_DECLARATION;
198 
199         ADD_STYLE_RULE;
200     }
201 
202     /*QFrame {
203         border: native;
204     }*/
205     {
206         SET_ELEMENT_NAME(QLatin1String("QFrame"));
207         ADD_BASIC_SELECTOR;
208         ADD_SELECTOR;
209 
210         SET_PROPERTY(QLatin1String("border"), Border);
211         ADD_VALUE(Value::KnownIdentifier, Value_Native);
212         ADD_DECLARATION;
213 
214         ADD_STYLE_RULE;
215     }
216 
217     /*QLabel, QToolBox {
218         background: none;
219         border-image: none;
220     }*/
221     {
222         SET_ELEMENT_NAME(QLatin1String("QLabel"));
223         ADD_BASIC_SELECTOR;
224         ADD_SELECTOR;
225 
226         SET_ELEMENT_NAME(QLatin1String("QToolBox"));
227         ADD_BASIC_SELECTOR;
228         ADD_SELECTOR;
229 
230         SET_PROPERTY(QLatin1String("background"), Background);
231         ADD_VALUE(Value::KnownIdentifier, Value_None);
232         ADD_DECLARATION;
233 
234         SET_PROPERTY(QLatin1String("border-image"), BorderImage);
235         ADD_VALUE(Value::KnownIdentifier, Value_None);
236         ADD_DECLARATION;
237 
238         ADD_STYLE_RULE;
239     }
240 
241     /*QGroupBox {
242         border: native;
243     }*/
244     {
245         SET_ELEMENT_NAME(QLatin1String("QGroupBox"));
246         ADD_BASIC_SELECTOR;
247         ADD_SELECTOR;
248 
249         SET_PROPERTY(QLatin1String("border"), Border);
250         ADD_VALUE(Value::KnownIdentifier, Value_Native);
251         ADD_DECLARATION;
252 
253         ADD_STYLE_RULE;
254     }
255 
256 
257     /*QToolTip {
258         -qt-background-role: window;
259         border: native;
260     }*/
261     {
262         SET_ELEMENT_NAME(QLatin1String("QToolTip"));
263         ADD_BASIC_SELECTOR;
264         ADD_SELECTOR;
265 
266         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
267         ADD_VALUE(Value::KnownIdentifier, Value_Window);
268         ADD_DECLARATION;
269 
270         SET_PROPERTY(QLatin1String("border"), Border);
271         ADD_VALUE(Value::KnownIdentifier, Value_Native);
272         ADD_DECLARATION;
273 
274         ADD_STYLE_RULE;
275     }
276 
277     /*QPushButton, QToolButton {
278         border-style: native;
279         -qt-style-features: background-color;  //only for not pixmap based styles
280     }*/
281     {
282         SET_ELEMENT_NAME(QLatin1String("QPushButton"));
283         ADD_BASIC_SELECTOR;
284         ADD_SELECTOR;
285 
286         SET_ELEMENT_NAME(QLatin1String("QToolButton"));
287         ADD_BASIC_SELECTOR;
288         ADD_SELECTOR;
289 
290         SET_PROPERTY(QLatin1String("border-style"), BorderStyles);
291         ADD_VALUE(Value::KnownIdentifier, Value_Native);
292         ADD_DECLARATION;
293 
294         if (!styleIsPixmapBased) {
295             SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
296             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
297             ADD_DECLARATION;
298         }
299 
300 
301         ADD_STYLE_RULE;
302     }
303 
304 
305     /*QComboBox {
306         border: native;
307         -qt-style-features: background-color background-gradient;   //only for not pixmap based styles
308         -qt-background-role: base;
309     }*/
310 
311     {
312         SET_ELEMENT_NAME(QLatin1String("QComboBox"));
313         ADD_BASIC_SELECTOR;
314         ADD_SELECTOR;
315 
316         SET_PROPERTY(QLatin1String("border"), Border);
317         ADD_VALUE(Value::KnownIdentifier, Value_Native);
318         ADD_DECLARATION;
319 
320         if (!styleIsPixmapBased) {
321             SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
322             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
323             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-gradient"));
324             ADD_DECLARATION;
325         }
326 
327         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
328         ADD_VALUE(Value::KnownIdentifier, Value_Base);
329         ADD_DECLARATION;
330 
331         ADD_STYLE_RULE;
332     }
333 
334     /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
335     QComboBox[style="QFusionStyle"][readOnly="true"],
336     QComboBox[style="QCleanlooksStyle"][readOnly="true"]
337     {
338         -qt-background-role: button;
339     }*/
340     if (baseStyle()->inherits("QPlastiqueStyle")  || baseStyle()->inherits("QCleanlooksStyle") || baseStyle()->inherits("QFusionStyle"))
341     {
342         SET_ELEMENT_NAME(QLatin1String("QComboBox"));
343         ADD_ATTRIBUTE_SELECTOR(QLatin1String("readOnly"), QLatin1String("true"), AttributeSelector::MatchEqual);
344         ADD_BASIC_SELECTOR;
345         ADD_SELECTOR;
346 
347         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
348         ADD_VALUE(Value::KnownIdentifier, Value_Button);
349         ADD_DECLARATION;
350 
351         ADD_STYLE_RULE;
352     }
353 
354     /*QAbstractSpinBox {
355         border: native;
356         -qt-style-features: background-color;
357         -qt-background-role: base;
358     }*/
359     {
360         SET_ELEMENT_NAME(QLatin1String("QAbstractSpinBox"));
361         ADD_BASIC_SELECTOR;
362         ADD_SELECTOR;
363 
364         SET_PROPERTY(QLatin1String("border"), Border);
365         ADD_VALUE(Value::KnownIdentifier, Value_Native);
366         ADD_DECLARATION;
367 
368         SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
369         ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
370         ADD_DECLARATION;
371 
372         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
373         ADD_VALUE(Value::KnownIdentifier, Value_Base);
374         ADD_DECLARATION;
375 
376         ADD_STYLE_RULE;
377     }
378 
379     /*QMenu {
380         -qt-background-role: window;
381     }*/
382     {
383         SET_ELEMENT_NAME(QLatin1String("QMenu"));
384         ADD_BASIC_SELECTOR;
385         ADD_SELECTOR;
386 
387         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
388         ADD_VALUE(Value::KnownIdentifier, Value_Window);
389         ADD_DECLARATION;
390 
391         ADD_STYLE_RULE;
392     }
393     /*QMenu::item {
394         -qt-style-features: background-color;
395     }*/
396     if (!styleIsPixmapBased) {
397         SET_ELEMENT_NAME(QLatin1String("QMenu"));
398         ADD_PSEUDO(QLatin1String("item"), PseudoClass_Unknown);
399         ADD_BASIC_SELECTOR;
400         ADD_SELECTOR;
401 
402         SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
403         ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
404         ADD_DECLARATION;
405 
406         ADD_STYLE_RULE;
407     }
408 
409     /*QHeaderView {
410         -qt-background-role: window;
411     }*/
412     {
413         SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
414         ADD_BASIC_SELECTOR;
415         ADD_SELECTOR;
416 
417         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
418         ADD_VALUE(Value::KnownIdentifier, Value_Window);
419         ADD_DECLARATION;
420 
421         ADD_STYLE_RULE;
422     }
423 
424     /*QTableCornerButton::section, QHeaderView::section {
425         -qt-background-role: button;
426         -qt-style-features: background-color; //if style is not pixmap based
427         border: native;
428     }*/
429     {
430         SET_ELEMENT_NAME(QLatin1String("QTableCornerButton"));
431         ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
432         ADD_BASIC_SELECTOR;
433         ADD_SELECTOR;
434 
435         SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
436         ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
437         ADD_BASIC_SELECTOR;
438         ADD_SELECTOR;
439 
440         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
441         ADD_VALUE(Value::KnownIdentifier, Value_Button);
442         ADD_DECLARATION;
443 
444         if (!styleIsPixmapBased) {
445             SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
446             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
447             ADD_DECLARATION;
448         }
449 
450         SET_PROPERTY(QLatin1String("border"), Border);
451         ADD_VALUE(Value::KnownIdentifier, Value_Native);
452         ADD_DECLARATION;
453 
454         ADD_STYLE_RULE;
455     }
456 
457     /*QProgressBar {
458         -qt-background-role: base;
459     }*/
460     {
461         SET_ELEMENT_NAME(QLatin1String("QProgressBar"));
462         ADD_BASIC_SELECTOR;
463         ADD_SELECTOR;
464 
465         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
466         ADD_VALUE(Value::KnownIdentifier, Value_Base);
467         ADD_DECLARATION;
468 
469         ADD_STYLE_RULE;
470     }
471 
472     /*QScrollBar {
473         -qt-background-role: window;
474     }*/
475     {
476         SET_ELEMENT_NAME(QLatin1String("QScrollBar"));
477         ADD_BASIC_SELECTOR;
478         ADD_SELECTOR;
479 
480         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
481         ADD_VALUE(Value::KnownIdentifier, Value_Window);
482         ADD_DECLARATION;
483 
484         ADD_STYLE_RULE;
485     }
486 
487     /*QDockWidget {
488         border: native;
489     }*/
490     {
491         SET_ELEMENT_NAME(QLatin1String("QDockWidget"));
492         ADD_BASIC_SELECTOR;
493         ADD_SELECTOR;
494 
495         SET_PROPERTY(QLatin1String("border"), Border);
496         ADD_VALUE(Value::KnownIdentifier, Value_Native);
497         ADD_DECLARATION;
498 
499         ADD_STYLE_RULE;
500     }
501 
502     sheet.origin = StyleSheetOrigin_UserAgent;
503     sheet.buildIndexes();
504     return sheet;
505 }
506 
507 #endif // #ifndef QT_NO_STYLE_STYLESHEET
508 
509 QT_END_NAMESPACE
510