util/src/gui/styles/qstylesheetstyle_default.cpp
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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     /*QFrame {
       
   207         border: native;
       
   208     }*/
       
   209     {
       
   210         SET_ELEMENT_NAME(QLatin1String("QFrame"));
       
   211         ADD_BASIC_SELECTOR;
       
   212         ADD_SELECTOR;
       
   213 
       
   214         SET_PROPERTY(QLatin1String("border"), Border);
       
   215         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   216         ADD_DECLARATION;
       
   217 
       
   218         ADD_STYLE_RULE;
       
   219     }
       
   220 
       
   221     /*QLabel, QToolBox {
       
   222         background: none;
       
   223         border-image: none;
       
   224     }*/
       
   225     {
       
   226         SET_ELEMENT_NAME(QLatin1String("QLabel"));
       
   227         ADD_BASIC_SELECTOR;
       
   228         ADD_SELECTOR;
       
   229 
       
   230         SET_ELEMENT_NAME(QLatin1String("QToolBox"));
       
   231         ADD_BASIC_SELECTOR;
       
   232         ADD_SELECTOR;
       
   233 
       
   234         SET_PROPERTY(QLatin1String("background"), Background);
       
   235         ADD_VALUE(Value::KnownIdentifier, Value_None);
       
   236         ADD_DECLARATION;
       
   237 
       
   238         SET_PROPERTY(QLatin1String("border-image"), BorderImage);
       
   239         ADD_VALUE(Value::KnownIdentifier, Value_None);
       
   240         ADD_DECLARATION;
       
   241 
       
   242         ADD_STYLE_RULE;
       
   243     }
       
   244 
       
   245     /*QGroupBox {
       
   246         border: native;
       
   247     }*/
       
   248     {
       
   249         SET_ELEMENT_NAME(QLatin1String("QGroupBox"));
       
   250         ADD_BASIC_SELECTOR;
       
   251         ADD_SELECTOR;
       
   252 
       
   253         SET_PROPERTY(QLatin1String("border"), Border);
       
   254         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   255         ADD_DECLARATION;
       
   256 
       
   257         ADD_STYLE_RULE;
       
   258     }
       
   259 
       
   260 
       
   261     /*QToolTip {
       
   262         -qt-background-role: window;
       
   263         border: native;
       
   264     }*/
       
   265     {
       
   266         SET_ELEMENT_NAME(QLatin1String("QToolTip"));
       
   267         ADD_BASIC_SELECTOR;
       
   268         ADD_SELECTOR;
       
   269 
       
   270         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   271         ADD_VALUE(Value::KnownIdentifier, Value_Window);
       
   272         ADD_DECLARATION;
       
   273 
       
   274         SET_PROPERTY(QLatin1String("border"), Border);
       
   275         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   276         ADD_DECLARATION;
       
   277 
       
   278         ADD_STYLE_RULE;
       
   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"));
       
   287         ADD_BASIC_SELECTOR;
       
   288         ADD_SELECTOR;
       
   289 
       
   290         SET_ELEMENT_NAME(QLatin1String("QToolButton"));
       
   291         ADD_BASIC_SELECTOR;
       
   292         ADD_SELECTOR;
       
   293 
       
   294         SET_PROPERTY(QLatin1String("border-style"), BorderStyles);
       
   295         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   296         ADD_DECLARATION;
       
   297 
       
   298         if (!styleIsPixmapBased) {
       
   299             SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
       
   300             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
       
   301             ADD_DECLARATION;
       
   302         }
       
   303 
       
   304 
       
   305         ADD_STYLE_RULE;
       
   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"));
       
   317         ADD_BASIC_SELECTOR;
       
   318         ADD_SELECTOR;
       
   319 
       
   320         SET_PROPERTY(QLatin1String("border"), Border);
       
   321         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   322         ADD_DECLARATION;
       
   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"));
       
   328             ADD_DECLARATION;
       
   329         }
       
   330 
       
   331         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   332         ADD_VALUE(Value::KnownIdentifier, Value_Base);
       
   333         ADD_DECLARATION;
       
   334 
       
   335         ADD_STYLE_RULE;
       
   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"));
       
   346         ADD_ATTRIBUTE_SELECTOR(QLatin1String("readOnly"), QLatin1String("true"), AttributeSelector::MatchEqual);
       
   347         ADD_BASIC_SELECTOR;
       
   348         ADD_SELECTOR;
       
   349 
       
   350         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   351         ADD_VALUE(Value::KnownIdentifier, Value_Button);
       
   352         ADD_DECLARATION;
       
   353 
       
   354         ADD_STYLE_RULE;
       
   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"));
       
   364         ADD_BASIC_SELECTOR;
       
   365         ADD_SELECTOR;
       
   366 
       
   367         SET_PROPERTY(QLatin1String("border"), Border);
       
   368         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   369         ADD_DECLARATION;
       
   370 
       
   371         SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
       
   372         ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
       
   373         ADD_DECLARATION;
       
   374 
       
   375         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   376         ADD_VALUE(Value::KnownIdentifier, Value_Base);
       
   377         ADD_DECLARATION;
       
   378 
       
   379         ADD_STYLE_RULE;
       
   380     }
       
   381 
       
   382     /*QMenu {
       
   383         -qt-background-role: window;
       
   384     }*/
       
   385     {
       
   386         SET_ELEMENT_NAME(QLatin1String("QMenu"));
       
   387         ADD_BASIC_SELECTOR;
       
   388         ADD_SELECTOR;
       
   389 
       
   390         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   391         ADD_VALUE(Value::KnownIdentifier, Value_Window);
       
   392         ADD_DECLARATION;
       
   393 
       
   394         ADD_STYLE_RULE;
       
   395     }
       
   396     /*QMenu::item {
       
   397         -qt-style-features: background-color;
       
   398     }*/
       
   399     if (!styleIsPixmapBased) {
       
   400         SET_ELEMENT_NAME(QLatin1String("QMenu"));
       
   401         ADD_PSEUDO(QLatin1String("item"), PseudoClass_Unknown);
       
   402         ADD_BASIC_SELECTOR;
       
   403         ADD_SELECTOR;
       
   404 
       
   405         SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
       
   406         ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
       
   407         ADD_DECLARATION;
       
   408 
       
   409         ADD_STYLE_RULE;
       
   410     }
       
   411 
       
   412     /*QHeaderView {
       
   413         -qt-background-role: window;
       
   414     }*/
       
   415     {
       
   416         SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
       
   417         ADD_BASIC_SELECTOR;
       
   418         ADD_SELECTOR;
       
   419 
       
   420         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   421         ADD_VALUE(Value::KnownIdentifier, Value_Window);
       
   422         ADD_DECLARATION;
       
   423 
       
   424         ADD_STYLE_RULE;
       
   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"));
       
   434         ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
       
   435         ADD_BASIC_SELECTOR;
       
   436         ADD_SELECTOR;
       
   437 
       
   438         SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
       
   439         ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
       
   440         ADD_BASIC_SELECTOR;
       
   441         ADD_SELECTOR;
       
   442 
       
   443         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   444         ADD_VALUE(Value::KnownIdentifier, Value_Button);
       
   445         ADD_DECLARATION;
       
   446 
       
   447         if (!styleIsPixmapBased) {
       
   448             SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
       
   449             ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
       
   450             ADD_DECLARATION;
       
   451         }
       
   452 
       
   453         SET_PROPERTY(QLatin1String("border"), Border);
       
   454         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   455         ADD_DECLARATION;
       
   456 
       
   457         ADD_STYLE_RULE;
       
   458     }
       
   459 
       
   460     /*QProgressBar {
       
   461         -qt-background-role: base;
       
   462     }*/
       
   463     {
       
   464         SET_ELEMENT_NAME(QLatin1String("QProgressBar"));
       
   465         ADD_BASIC_SELECTOR;
       
   466         ADD_SELECTOR;
       
   467 
       
   468         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   469         ADD_VALUE(Value::KnownIdentifier, Value_Base);
       
   470         ADD_DECLARATION;
       
   471 
       
   472         ADD_STYLE_RULE;
       
   473     }
       
   474 
       
   475     /*QScrollBar {
       
   476         -qt-background-role: window;
       
   477     }*/
       
   478     {
       
   479         SET_ELEMENT_NAME(QLatin1String("QScrollBar"));
       
   480         ADD_BASIC_SELECTOR;
       
   481         ADD_SELECTOR;
       
   482 
       
   483         SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
       
   484         ADD_VALUE(Value::KnownIdentifier, Value_Window);
       
   485         ADD_DECLARATION;
       
   486 
       
   487         ADD_STYLE_RULE;
       
   488     }
       
   489 
       
   490     /*QDockWidget {
       
   491         border: native;
       
   492     }*/
       
   493     {
       
   494         SET_ELEMENT_NAME(QLatin1String("QDockWidget"));
       
   495         ADD_BASIC_SELECTOR;
       
   496         ADD_SELECTOR;
       
   497 
       
   498         SET_PROPERTY(QLatin1String("border"), Border);
       
   499         ADD_VALUE(Value::KnownIdentifier, Value_Native);
       
   500         ADD_DECLARATION;
       
   501 
       
   502         ADD_STYLE_RULE;
       
   503     }
       
   504 
       
   505     sheet.origin = StyleSheetOrigin_UserAgent;
       
   506     sheet.buildIndexes();
       
   507     return sheet;
       
   508 }
       
   509 
       
   510 #endif // #ifndef QT_NO_STYLE_STYLESHEET
       
   511 
       
   512 QT_END_NAMESPACE