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