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

source code of qtbase/src/widgets/styles/qstylesheetstyle_default.cpp