Qt 4.8
qstylesheetstyle_default.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
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 
148 {
149  StyleSheet sheet;
150  StyleRule styleRule;
151  BasicSelector bSelector;
152  Selector selector;
153  Declaration decl;
154  QCss::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"));
173  ADD_SELECTOR;
174 
175  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
178 
179  SET_PROPERTY(QLatin1String("border"), Border);
182 
183  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
184  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
186 
188  }
189 
190  /*QLineEdit:no-frame {
191  border: none;
192  }*/
193  {
194  SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
197  ADD_SELECTOR;
198 
199  SET_PROPERTY(QLatin1String("border"), Border);
202 
204  }
205 
206  /*QFrame {
207  border: native;
208  }*/
209  {
210  SET_ELEMENT_NAME(QLatin1String("QFrame"));
212  ADD_SELECTOR;
213 
214  SET_PROPERTY(QLatin1String("border"), Border);
217 
219  }
220 
221  /*QLabel, QToolBox {
222  background: none;
223  border-image: none;
224  }*/
225  {
226  SET_ELEMENT_NAME(QLatin1String("QLabel"));
228  ADD_SELECTOR;
229 
230  SET_ELEMENT_NAME(QLatin1String("QToolBox"));
232  ADD_SELECTOR;
233 
234  SET_PROPERTY(QLatin1String("background"), Background);
237 
238  SET_PROPERTY(QLatin1String("border-image"), BorderImage);
241 
243  }
244 
245  /*QGroupBox {
246  border: native;
247  }*/
248  {
249  SET_ELEMENT_NAME(QLatin1String("QGroupBox"));
251  ADD_SELECTOR;
252 
253  SET_PROPERTY(QLatin1String("border"), Border);
256 
258  }
259 
260 
261  /*QToolTip {
262  -qt-background-role: window;
263  border: native;
264  }*/
265  {
266  SET_ELEMENT_NAME(QLatin1String("QToolTip"));
268  ADD_SELECTOR;
269 
270  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
273 
274  SET_PROPERTY(QLatin1String("border"), Border);
277 
279  }
280 
281  /*QPushButton, QToolButton {
282  border-style: native;
283  -qt-style-features: background-color; //only for not pixmap based styles
284  }*/
285  {
286  SET_ELEMENT_NAME(QLatin1String("QPushButton"));
288  ADD_SELECTOR;
289 
290  SET_ELEMENT_NAME(QLatin1String("QToolButton"));
292  ADD_SELECTOR;
293 
294  SET_PROPERTY(QLatin1String("border-style"), BorderStyles);
297 
298  if (!styleIsPixmapBased) {
299  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
300  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
302  }
303 
304 
306  }
307 
308 
309  /*QComboBox {
310  border: native;
311  -qt-style-features: background-color background-gradient; //only for not pixmap based styles
312  -qt-background-role: base;
313  }*/
314 
315  {
316  SET_ELEMENT_NAME(QLatin1String("QComboBox"));
318  ADD_SELECTOR;
319 
320  SET_PROPERTY(QLatin1String("border"), Border);
323 
324  if (!styleIsPixmapBased) {
325  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
326  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
327  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-gradient"));
329  }
330 
331  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
334 
336  }
337 
338  /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
339  QComboBox[style="QCleanlooksStyle"][readOnly="true"]
340  {
341  -qt-background-role: button;
342  }*/
343  if (baseStyle()->inherits("QPlastiqueStyle") || baseStyle()->inherits("QCleanlooksStyle"))
344  {
345  SET_ELEMENT_NAME(QLatin1String("QComboBox"));
348  ADD_SELECTOR;
349 
350  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
353 
355  }
356 
357  /*QAbstractSpinBox {
358  border: native;
359  -qt-style-features: background-color;
360  -qt-background-role: base;
361  }*/
362  {
363  SET_ELEMENT_NAME(QLatin1String("QAbstractSpinBox"));
365  ADD_SELECTOR;
366 
367  SET_PROPERTY(QLatin1String("border"), Border);
370 
371  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
372  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
374 
375  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
378 
380  }
381 
382  /*QMenu {
383  -qt-background-role: window;
384  }*/
385  {
388  ADD_SELECTOR;
389 
390  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
393 
395  }
396  /*QMenu::item {
397  -qt-style-features: background-color;
398  }*/
399  if (!styleIsPixmapBased) {
403  ADD_SELECTOR;
404 
405  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
406  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
408 
410  }
411 
412  /*QHeaderView {
413  -qt-background-role: window;
414  }*/
415  {
416  SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
418  ADD_SELECTOR;
419 
420  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
423 
425  }
426 
427  /*QTableCornerButton::section, QHeaderView::section {
428  -qt-background-role: button;
429  -qt-style-features: background-color; //if style is not pixmap based
430  border: native;
431  }*/
432  {
433  SET_ELEMENT_NAME(QLatin1String("QTableCornerButton"));
436  ADD_SELECTOR;
437 
438  SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
441  ADD_SELECTOR;
442 
443  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
446 
447  if (!styleIsPixmapBased) {
448  SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
449  ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
451  }
452 
453  SET_PROPERTY(QLatin1String("border"), Border);
456 
458  }
459 
460  /*QProgressBar {
461  -qt-background-role: base;
462  }*/
463  {
464  SET_ELEMENT_NAME(QLatin1String("QProgressBar"));
466  ADD_SELECTOR;
467 
468  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
471 
473  }
474 
475  /*QScrollBar {
476  -qt-background-role: window;
477  }*/
478  {
479  SET_ELEMENT_NAME(QLatin1String("QScrollBar"));
481  ADD_SELECTOR;
482 
483  SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
486 
488  }
489 
490  /*QDockWidget {
491  border: native;
492  }*/
493  {
494  SET_ELEMENT_NAME(QLatin1String("QDockWidget"));
496  ADD_SELECTOR;
497 
498  SET_PROPERTY(QLatin1String("border"), Border);
501 
503  }
504 
506  sheet.buildIndexes();
507  return sheet;
508 }
509 
510 #endif // #ifndef QT_NO_STYLE_STYLESHEET
511 
QCss::StyleSheet getDefaultStyleSheet() const
void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define ADD_BASIC_SELECTOR
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
StyleSheetOrigin origin
Definition: qcssparser_p.h:643
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define SET_PROPERTY(x, y)
const quint64 PseudoClass_Unknown
Definition: qcssparser_p.h:461
#define ADD_STYLE_RULE
#define SET_ELEMENT_NAME(x)
#define ADD_DECLARATION
The BorderImage element provides an image that can be used as a border.
const quint64 PseudoClass_Frameless
Definition: qcssparser_p.h:491
#define ADD_SELECTOR
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define ADD_VALUE(x, y)
#define ADD_PSEUDO(x, y)
#define ADD_ATTRIBUTE_SELECTOR(x, y, z)