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

Last change on this file since 497 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