source: trunk/src/gui/styles/qstylesheetstyle_default.cpp@ 139

Last change on this file since 139 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 16.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
57QT_BEGIN_NAMESPACE
58
59using 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
147StyleSheet 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
163
164 /*QLineEdit {
165 -qt-background-role: base;
166 border: native;
167 -qt-style-features: background-color;
168 }*/
169 {
170 SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
171 ADD_BASIC_SELECTOR;
172 ADD_SELECTOR;
173
174 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
175 ADD_VALUE(Value::KnownIdentifier, Value_Base);
176 ADD_DECLARATION;
177
178 SET_PROPERTY(QLatin1String("border"), Border);
179 ADD_VALUE(Value::KnownIdentifier, Value_Native);
180 ADD_DECLARATION;
181
182 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
183 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
184 ADD_DECLARATION;
185
186 ADD_STYLE_RULE;
187 }
188
189 /*QLineEdit:no-frame {
190 border: none;
191 }*/
192 {
193 SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
194 ADD_PSEUDO(QLatin1String("no-frame"), PseudoClass_Frameless);
195 ADD_BASIC_SELECTOR;
196 ADD_SELECTOR;
197
198 SET_PROPERTY(QLatin1String("border"), Border);
199 ADD_VALUE(Value::KnownIdentifier, Value_None);
200 ADD_DECLARATION;
201
202 ADD_STYLE_RULE;
203 }
204
205 /*QLineEdit[style="QCleanlooksStyle"] {
206 padding-top: 2px;
207 padding-bottom: 2px;
208 }*/
209 if (baseStyle()->inherits("QCleanlooksStyle"))
210 {
211 SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
212 ADD_BASIC_SELECTOR;
213 ADD_SELECTOR;
214
215
216 SET_PROPERTY(QLatin1String("padding-top"), PaddingTop);
217 ADD_VALUE(Value::Identifier, QString::fromLatin1("2px"));
218 ADD_DECLARATION;
219
220 SET_PROPERTY(QLatin1String("padding-bottom"), PaddingBottom);
221 ADD_VALUE(Value::Identifier, QString::fromLatin1("2px"));
222 ADD_DECLARATION;
223
224 ADD_STYLE_RULE;
225 }
226
227 /*QLineEdit[style="QWindowsXPStyle"],
228 QLineEdit[style="QWindowsVistaStyle"],
229 QLineEdit[style="QGtkStyle"] {
230 padding-top: 1px;
231 padding-bottom: 1px;
232 }*/
233 if (baseStyle()->inherits("QWindowsXPStyle") || baseStyle()->inherits("QGtkStyle"))
234 {
235 SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
236
237 SET_PROPERTY(QLatin1String("padding-top"), PaddingTop);
238 ADD_VALUE(Value::Identifier, QString::fromLatin1("1px"));
239 ADD_DECLARATION;
240
241 SET_PROPERTY(QLatin1String("padding-bottom"), PaddingBottom);
242 ADD_VALUE(Value::Identifier, QString::fromLatin1("1px"));
243 ADD_DECLARATION;
244
245 ADD_STYLE_RULE;
246 }
247
248 /*QFrame {
249 border: native;
250 }*/
251 {
252 SET_ELEMENT_NAME(QLatin1String("QFrame"));
253 ADD_BASIC_SELECTOR;
254 ADD_SELECTOR;
255
256 SET_PROPERTY(QLatin1String("border"), Border);
257 ADD_VALUE(Value::KnownIdentifier, Value_Native);
258 ADD_DECLARATION;
259
260 ADD_STYLE_RULE;
261 }
262
263 /*QLabel, QToolBox {
264 background: none;
265 border-image: none;
266 }*/
267 {
268 SET_ELEMENT_NAME(QLatin1String("QLabel"));
269 ADD_BASIC_SELECTOR;
270 ADD_SELECTOR;
271
272 SET_ELEMENT_NAME(QLatin1String("QToolBox"));
273 ADD_BASIC_SELECTOR;
274 ADD_SELECTOR;
275
276 SET_PROPERTY(QLatin1String("background"), Background);
277 ADD_VALUE(Value::KnownIdentifier, Value_None);
278 ADD_DECLARATION;
279
280 SET_PROPERTY(QLatin1String("border-image"), BorderImage);
281 ADD_VALUE(Value::KnownIdentifier, Value_None);
282 ADD_DECLARATION;
283
284 ADD_STYLE_RULE;
285 }
286
287 /*QGroupBox {
288 border: native;
289 }*/
290 {
291 SET_ELEMENT_NAME(QLatin1String("QGroupBox"));
292 ADD_BASIC_SELECTOR;
293 ADD_SELECTOR;
294
295 SET_PROPERTY(QLatin1String("border"), Border);
296 ADD_VALUE(Value::KnownIdentifier, Value_Native);
297 ADD_DECLARATION;
298
299 ADD_STYLE_RULE;
300 }
301
302
303 /*QToolTip {
304 -qt-background-role: window;
305 border: native;
306 }*/
307 {
308 SET_ELEMENT_NAME(QLatin1String("QToolTip"));
309 ADD_BASIC_SELECTOR;
310 ADD_SELECTOR;
311
312 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
313 ADD_VALUE(Value::KnownIdentifier, Value_Window);
314 ADD_DECLARATION;
315
316 SET_PROPERTY(QLatin1String("border"), Border);
317 ADD_VALUE(Value::KnownIdentifier, Value_Native);
318 ADD_DECLARATION;
319
320 ADD_STYLE_RULE;
321 }
322
323 /*QPushButton, QToolButton {
324 border-style: native;
325 -qt-style-features: background-color; //only for not pixmap based styles
326 }*/
327 {
328 SET_ELEMENT_NAME(QLatin1String("QPushButton"));
329 ADD_BASIC_SELECTOR;
330 ADD_SELECTOR;
331
332 SET_ELEMENT_NAME(QLatin1String("QToolButton"));
333 ADD_BASIC_SELECTOR;
334 ADD_SELECTOR;
335
336 SET_PROPERTY(QLatin1String("border-style"), BorderStyles);
337 ADD_VALUE(Value::KnownIdentifier, Value_Native);
338 ADD_DECLARATION;
339
340 if (!styleIsPixmapBased) {
341 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
342 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
343 ADD_DECLARATION;
344 }
345
346
347 ADD_STYLE_RULE;
348 }
349
350
351 /*QComboBox {
352 border: native;
353 -qt-style-features: background-color background-gradient; //only for not pixmap based styles
354 -qt-background-role: base;
355 }*/
356
357 {
358 SET_ELEMENT_NAME(QLatin1String("QComboBox"));
359 ADD_BASIC_SELECTOR;
360 ADD_SELECTOR;
361
362 SET_PROPERTY(QLatin1String("border"), Border);
363 ADD_VALUE(Value::KnownIdentifier, Value_Native);
364 ADD_DECLARATION;
365
366 if (!styleIsPixmapBased) {
367 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
368 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
369 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-gradient"));
370 ADD_DECLARATION;
371 }
372
373 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
374 ADD_VALUE(Value::KnownIdentifier, Value_Base);
375 ADD_DECLARATION;
376
377 ADD_STYLE_RULE;
378 }
379
380 /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
381 QComboBox[style="QCleanlooksStyle"][readOnly="true"]
382 {
383 -qt-background-role: button;
384 }*/
385 if (baseStyle()->inherits("QPlastiqueStyle") || baseStyle()->inherits("QCleanlooksStyle"))
386 {
387 SET_ELEMENT_NAME(QLatin1String("QComboBox"));
388 ADD_ATTRIBUTE_SELECTOR(QLatin1String("readOnly"), QLatin1String("true"), AttributeSelector::MatchEqual);
389 ADD_BASIC_SELECTOR;
390 ADD_SELECTOR;
391
392 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
393 ADD_VALUE(Value::KnownIdentifier, Value_Button);
394 ADD_DECLARATION;
395
396 ADD_STYLE_RULE;
397 }
398
399 /*QAbstractSpinBox {
400 border: native;
401 -qt-style-features: background-color;
402 -qt-background-role: base;
403 }*/
404 {
405 SET_ELEMENT_NAME(QLatin1String("QAbstractSpinBox"));
406 ADD_BASIC_SELECTOR;
407 ADD_SELECTOR;
408
409 SET_PROPERTY(QLatin1String("border"), Border);
410 ADD_VALUE(Value::KnownIdentifier, Value_Native);
411 ADD_DECLARATION;
412
413 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
414 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
415 ADD_DECLARATION;
416
417 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
418 ADD_VALUE(Value::KnownIdentifier, Value_Base);
419 ADD_DECLARATION;
420
421 ADD_STYLE_RULE;
422 }
423
424 /*QMenu {
425 -qt-background-role: window;
426 }*/
427 {
428 SET_ELEMENT_NAME(QLatin1String("QMenu"));
429 ADD_BASIC_SELECTOR;
430 ADD_SELECTOR;
431
432 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
433 ADD_VALUE(Value::KnownIdentifier, Value_Window);
434 ADD_DECLARATION;
435
436 ADD_STYLE_RULE;
437 }
438 /*QMenu::item {
439 -qt-style-features: background-color;
440 }*/
441 if (!styleIsPixmapBased) {
442 SET_ELEMENT_NAME(QLatin1String("QMenu"));
443 ADD_PSEUDO(QLatin1String("item"), PseudoClass_Unknown);
444 ADD_BASIC_SELECTOR;
445 ADD_SELECTOR;
446
447 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
448 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
449 ADD_DECLARATION;
450
451 ADD_STYLE_RULE;
452 }
453
454 /*QHeaderView {
455 -qt-background-role: window;
456 }*/
457 {
458 SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
459 ADD_BASIC_SELECTOR;
460 ADD_SELECTOR;
461
462 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
463 ADD_VALUE(Value::KnownIdentifier, Value_Window);
464 ADD_DECLARATION;
465
466 ADD_STYLE_RULE;
467 }
468
469 /*QTableCornerButton::section, QHeaderView::section {
470 -qt-background-role: button;
471 -qt-style-features: background-color; //if style is not pixmap based
472 border: native;
473 }*/
474 {
475 SET_ELEMENT_NAME(QLatin1String("QTableCornerButton"));
476 ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
477 ADD_BASIC_SELECTOR;
478 ADD_SELECTOR;
479
480 SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
481 ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
482 ADD_BASIC_SELECTOR;
483 ADD_SELECTOR;
484
485 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
486 ADD_VALUE(Value::KnownIdentifier, Value_Button);
487 ADD_DECLARATION;
488
489 if (!styleIsPixmapBased) {
490 SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
491 ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
492 ADD_DECLARATION;
493 }
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 /*QProgressBar {
503 -qt-background-role: base;
504 }*/
505 {
506 SET_ELEMENT_NAME(QLatin1String("QProgressBar"));
507 ADD_BASIC_SELECTOR;
508 ADD_SELECTOR;
509
510 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
511 ADD_VALUE(Value::KnownIdentifier, Value_Base);
512 ADD_DECLARATION;
513
514 ADD_STYLE_RULE;
515 }
516
517 /*QScrollBar {
518 -qt-background-role: window;
519 }*/
520 {
521 SET_ELEMENT_NAME(QLatin1String("QScrollBar"));
522 ADD_BASIC_SELECTOR;
523 ADD_SELECTOR;
524
525 SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
526 ADD_VALUE(Value::KnownIdentifier, Value_Window);
527 ADD_DECLARATION;
528
529 ADD_STYLE_RULE;
530 }
531
532 /*QDockWidget {
533 border: native;
534 }*/
535 {
536 SET_ELEMENT_NAME(QLatin1String("QDockWidget"));
537 ADD_BASIC_SELECTOR;
538 ADD_SELECTOR;
539
540 SET_PROPERTY(QLatin1String("border"), Border);
541 ADD_VALUE(Value::KnownIdentifier, Value_Native);
542 ADD_DECLARATION;
543
544 ADD_STYLE_RULE;