782 lines
31 KiB
782 lines
31 KiB
/***************************************************************************
|
|
* Copyright (C) 2003 by Gulmini Luciano *
|
|
* gulmini.luciano@student.unife.it *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
***************************************************************************/
|
|
#include "shorthandformer.h"
|
|
#include <tqstringlist.h>
|
|
#include "cssshpropertyparser.h"
|
|
#include <kdebug.h>
|
|
#include "csseditor_globals.h"
|
|
|
|
TQRegExp globalPercentagePattern("\\d%"),
|
|
globalLengthPattern("\\d(ex|em|px|cm|pt|pc|in|mm)"),
|
|
globalColorPattern("#[\\w\\d]*"),
|
|
globalNumberPattern("\\d*");
|
|
|
|
static const TQString borderStyleValueString("none,hidden,dotted,dashed,solid,double,groove,ridge,inset,outset,inherit");
|
|
static const TQString widthValueString("thin,medium,thick,inherit");
|
|
static const TQString listTypeValueString("disc,circle,square,decimal,decimal-leading-zero,lower-roman,upper-roman,lower-greek,lower-alpha,lower-latin,upper-alpha,upper-latin,hebrew,armenian,georgian,cjk-ideographic,hiragana,katakana,hiragana-iroha,katakana-iroha,none,inherit");
|
|
static const TQString fontSizeValueString("smaller,larger,xx-large,x-large,large,medium,small,x-small,xx-small,inherit");
|
|
static const TQString fontWeightValueString("900,800,700,600,500,400,300,200,100,lighter,bolder,normal,bold,inherit");
|
|
static const TQString fontVariantValueString("normal,small-caps,inherit");
|
|
static const TQString fontStyleValueString("oblique,italic,normal,inherit");
|
|
static const TQString backgroundRepeatValueString("repeat,repeat-x,repeat-y,no-repeat,inherit");
|
|
|
|
|
|
static const TQStringList borderStyleValueList = TQStringList::split(",",borderStyleValueString);
|
|
static const TQStringList widthValueList = TQStringList::split(",",widthValueString);
|
|
static const TQStringList listTypeValueList = TQStringList::split(",",listTypeValueString);
|
|
static const TQStringList fontSizeValueList = TQStringList::split(",",fontSizeValueString);
|
|
static const TQStringList fontWeightValueList = TQStringList::split(",",fontWeightValueString);
|
|
static const TQStringList fontStyleValueList = TQStringList::split(",",fontStyleValueString);
|
|
static const TQStringList fontVariantValueList = TQStringList::split(",",fontVariantValueString);
|
|
static const TQStringList backgroundRepeatValueList = TQStringList::split(",",backgroundRepeatValueString);
|
|
|
|
|
|
|
|
ShorthandFormer::ShorthandFormer( TQMap<TQString,TQString> m){
|
|
|
|
m_properties = m;
|
|
if(m_properties.contains("cue-after")){
|
|
cue_after= m_properties["cue-after"];
|
|
m_properties.remove("cue-after");
|
|
}
|
|
if(m_properties.contains("cue-before")){
|
|
cue_before = m_properties["cue-before"];
|
|
m_properties.remove("cue-before");
|
|
}
|
|
if(m_properties.contains("pause-before")){
|
|
pause_before= m_properties["pause-before"];
|
|
m_properties.remove("pause-before");
|
|
}
|
|
if(m_properties.contains("pause-after")){
|
|
pause_after = m_properties["pause-after"];
|
|
m_properties.remove("pause-after");
|
|
}
|
|
if(m_properties.contains("background-color")){
|
|
background_color = m_properties["background-color"];
|
|
m_properties.remove("background-color");
|
|
}
|
|
if(m_properties.contains("background-image")){
|
|
background_image = m_properties["background-image"];
|
|
m_properties.remove("background-image");
|
|
}
|
|
if(m_properties.contains("background-repeat")){
|
|
background_repeat = m_properties["background-repeat"];
|
|
m_properties.remove("background-repeat");
|
|
}
|
|
if(m_properties.contains("background-attachment")){
|
|
background_attachment = m_properties["background-attachment"];
|
|
m_properties.remove("background-attachment");
|
|
}
|
|
if(m_properties.contains("background-position")){
|
|
background_position = m_properties["background-position"];
|
|
m_properties.remove("background-position");
|
|
}
|
|
if(m_properties.contains("border-top-style")){
|
|
border_top_style = m_properties["border-top-style"];
|
|
m_properties.remove("border-top-style");
|
|
}
|
|
if(m_properties.contains("border-top-color")){
|
|
border_top_color = m_properties["border-top-color"];
|
|
m_properties.remove("border-top-color");
|
|
}
|
|
if(m_properties.contains("border-top-width")){
|
|
border_top_width = m_properties["border-top-width"];
|
|
m_properties.remove("border-top-width");
|
|
}
|
|
if(m_properties.contains("border-left-style")){
|
|
border_left_style = m_properties["border-left-style"];
|
|
m_properties.remove("border-left-style");
|
|
}
|
|
if(m_properties.contains("border-left-color")){
|
|
border_left_color = m_properties["border-left-color"];
|
|
m_properties.remove("border-left-color");
|
|
}
|
|
if(m_properties.contains("border-left-width")){
|
|
border_left_width = m_properties["border-left-width"];
|
|
m_properties.remove("border-left-width");
|
|
}
|
|
if(m_properties.contains("border-right-style")){
|
|
border_right_style = m_properties["border-right-style"];
|
|
m_properties.remove("border-right-style");
|
|
}
|
|
if(m_properties.contains("border-right-color")){
|
|
border_right_color = m_properties["border-right-color"];
|
|
m_properties.remove("border-right-color");
|
|
}
|
|
if(m_properties.contains("border-right-width")){
|
|
border_right_width= m_properties["border-right-width"];
|
|
m_properties.remove("border-right-width");
|
|
}
|
|
if(m_properties.contains("border-bottom-style")){
|
|
border_bottom_style = m_properties["border-bottom-style"];
|
|
m_properties.remove("border-bottom-style");
|
|
}
|
|
if(m_properties.contains("border-bottom-color")){
|
|
border_bottom_color = m_properties["border-bottom-color"];
|
|
m_properties.remove("border-bottom-color");
|
|
}
|
|
if(m_properties.contains("border-bottom-width")){
|
|
border_bottom_width = m_properties["border-bottom-width"];
|
|
m_properties.remove("border-bottom-width");
|
|
}
|
|
if(m_properties.contains("outline-style")){
|
|
outline_style = m_properties["outline-style"];
|
|
m_properties.remove("outline-style");
|
|
}
|
|
if(m_properties.contains("outline-color")){
|
|
outline_color = m_properties["outline-color"];
|
|
m_properties.remove("outline-color");
|
|
}
|
|
if(m_properties.contains("outline-width")){
|
|
outline_width = m_properties["outline-width"];
|
|
m_properties.remove("outline-width");
|
|
}
|
|
if(m_properties.contains("list-style-type")){
|
|
list_style_type= m_properties["list-style-type"];
|
|
m_properties.remove("list-style-type");
|
|
}
|
|
if(m_properties.contains("list-style-image")){
|
|
list_style_image = m_properties["list-style-image"];
|
|
m_properties.remove("list-style-image");
|
|
}
|
|
if(m_properties.contains("list-style-position")){
|
|
list_style_position = m_properties["list-style-position"];
|
|
m_properties.remove("list-style-position");
|
|
}
|
|
if(m_properties.contains("font-style")){
|
|
font_style = m_properties["font-style"];
|
|
m_properties.remove("font-style");
|
|
}
|
|
if(m_properties.contains("font-variant")){
|
|
font_variant = m_properties["font-variant"];
|
|
m_properties.remove("font-variant");
|
|
}
|
|
if(m_properties.contains("font-weight")){
|
|
font_weight = m_properties["font-weight"];
|
|
m_properties.remove("font-weight");
|
|
}
|
|
if(m_properties.contains("font-size")){
|
|
font_size = m_properties["font-size"];
|
|
m_properties.remove("font-size");
|
|
}
|
|
if(m_properties.contains("line-height")){
|
|
line_height= m_properties["line-height"];
|
|
m_properties.remove("line-height");
|
|
}
|
|
if(m_properties.contains("font-family")){
|
|
font_family = m_properties["font-family"];
|
|
m_properties.remove("font-family");
|
|
}
|
|
if(m_properties.contains("margin-top")){
|
|
margin_top = m_properties["margin-top"];
|
|
m_properties.remove("margin-top");
|
|
}
|
|
if(m_properties.contains("margin-bottom")){
|
|
margin_bottom = m_properties["margin-bottom"];
|
|
m_properties.remove("margin-bottom");
|
|
}
|
|
if(m_properties.contains("margin-left")){
|
|
margin_left = m_properties["margin-left"];
|
|
m_properties.remove("margin-left");
|
|
}
|
|
if(m_properties.contains("margin-right")){
|
|
margin_right = m_properties["margin-right"];
|
|
m_properties.remove("margin-right");
|
|
}
|
|
if(m_properties.contains("padding-top")){
|
|
padding_top = m_properties["padding-top"];
|
|
m_properties.remove("padding-top");
|
|
}
|
|
if(m_properties.contains("padding-bottom")){
|
|
padding_bottom = m_properties["padding-bottom"];
|
|
m_properties.remove("padding-bottom");
|
|
}
|
|
if(m_properties.contains("padding-left")){
|
|
padding_left = m_properties["padding-left"];
|
|
m_properties.remove("padding-left");
|
|
}
|
|
if(m_properties.contains("padding-right")){
|
|
padding_right = m_properties["padding-right"];
|
|
m_properties.remove("padding-right");
|
|
}
|
|
}
|
|
|
|
TQString ShorthandFormer::compress(){
|
|
TQString props;
|
|
|
|
props += compressCueProp();
|
|
props += compressPauseProp();
|
|
props += compressBackgroundProp();
|
|
props += compressFontProp();
|
|
props += compressPaddingProp();
|
|
props += compressMarginProp();
|
|
props += compressOutlineProp();
|
|
props += compressListStyleProp();
|
|
props += compressBorderProp();
|
|
|
|
TQMap<TQString,TQString>::Iterator it;
|
|
for ( it = m_properties.begin(); it != m_properties.end(); ++it )
|
|
props += it.key() + " : " + it.data().stripWhiteSpace() + "; " ;
|
|
|
|
props.truncate(props.length()-1);//the last white space creates some problem: better remove it
|
|
//props.chop(1);
|
|
return props;
|
|
}
|
|
|
|
TQString ShorthandFormer::compressBorderProp(){
|
|
TQString props;
|
|
|
|
bool allColorSidesSet = false,
|
|
allStyleSidesSet = false,
|
|
allWidthSidesSet = false;
|
|
|
|
if(!border_left_color.isEmpty())
|
|
if( ( border_left_color == border_top_color ) && ( border_top_color == border_right_color ) && ( border_right_color == border_bottom_color ) )
|
|
allColorSidesSet = true;
|
|
|
|
if(!border_left_style.isEmpty())
|
|
if( ( border_left_style == border_top_style ) && ( border_top_style == border_right_style ) && ( border_right_style == border_bottom_style ) )
|
|
allStyleSidesSet = true;
|
|
|
|
if(!border_left_width.isEmpty())
|
|
if( ( border_left_width == border_top_width ) && ( border_top_width == border_right_width ) && ( border_right_width == border_bottom_width ) )
|
|
allWidthSidesSet = true;
|
|
|
|
if ( allColorSidesSet ) {
|
|
if ( allStyleSidesSet ) {
|
|
if ( allWidthSidesSet ) {
|
|
props += "border : " + border_left_color + " " + border_left_style + " " + border_left_width +"; ";
|
|
|
|
}
|
|
else {
|
|
props += "border : " + border_left_color + " " + border_left_style +"; ";
|
|
props += compressBorderWidthProp();
|
|
}
|
|
}
|
|
else {
|
|
if ( allWidthSidesSet ) {
|
|
props += "border : " + border_left_color + " " + border_left_width +"; ";
|
|
props += compressBorderStyleProp();
|
|
}
|
|
else {
|
|
props += "border : " + border_left_color +"; ";
|
|
props += compressBorderWidthProp();
|
|
props += compressBorderStyleProp();
|
|
}
|
|
|
|
}
|
|
}
|
|
else { // allColorSidesSet is false
|
|
if ( allStyleSidesSet ) {
|
|
if ( allWidthSidesSet ) {
|
|
props += "border : " + border_left_style + " " + border_left_width +"; ";
|
|
props += compressBorderColorProp();
|
|
}
|
|
else {
|
|
props += compressBorderStyleProp();
|
|
props += compressBorderWidthProp();
|
|
props += compressBorderColorProp();
|
|
}
|
|
}
|
|
else {
|
|
|
|
props += compressBorderStyleProp();
|
|
props += compressBorderWidthProp();
|
|
props += compressBorderColorProp();
|
|
}
|
|
}
|
|
|
|
return props;
|
|
}
|
|
|
|
TQString ShorthandFormer::compressBorderStyleProp(){
|
|
return compressImplementation( "border-style" ,border_top_style, border_bottom_style, border_right_style, border_left_style, "none");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressBorderWidthProp(){
|
|
return compressImplementation( "border-width" ,border_top_width, border_bottom_width, border_right_width, border_left_width, "medium");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressBorderColorProp(){
|
|
//because the default value of color property is browser dependant, this method doesn't compress the color value
|
|
TQString props;
|
|
if( !border_top_color.isEmpty() )
|
|
props += "border-top-color : " + border_top_color +"; ";
|
|
if( !border_right_color.isEmpty() )
|
|
props += "border-right-color : " + border_right_color +"; ";
|
|
if( !border_bottom_color.isEmpty() )
|
|
props += "border-bottom-color : " + border_bottom_color +"; ";
|
|
if( !border_left_color.isEmpty() )
|
|
props += "border-left-color : " + border_left_color +"; ";
|
|
return props;
|
|
}
|
|
|
|
TQString ShorthandFormer::compressFontProp(){
|
|
TQString fontProp,
|
|
props;
|
|
//bool appendLineHeight = false;
|
|
|
|
if( font_style.isEmpty() && font_variant.isEmpty() && font_weight.isEmpty() && font_size.isEmpty() && font_family.isEmpty() ) {
|
|
if( !line_height.isEmpty() )
|
|
props += "line-height : " + line_height + "; ";
|
|
}
|
|
else {
|
|
if( !font_style.isEmpty() )
|
|
fontProp += " " + font_style;
|
|
if( !font_variant.isEmpty() )
|
|
fontProp += " " + font_variant;
|
|
if( !font_weight.isEmpty() )
|
|
fontProp += " " + font_weight;
|
|
if( !font_size.isEmpty() ){
|
|
fontProp += " " + font_size;
|
|
if( !line_height.isEmpty() )
|
|
fontProp += "/" + line_height.stripWhiteSpace() ;
|
|
}
|
|
else {
|
|
fontProp += ( " medium");
|
|
/*if( !line_height.isEmpty() )
|
|
appendLineHeight = true; */
|
|
if( !line_height.isEmpty() )
|
|
fontProp += ( "/" + line_height.stripWhiteSpace() );
|
|
}
|
|
|
|
if( !font_family.isEmpty() )
|
|
fontProp += ( " " + font_family);
|
|
else fontProp += " serif";
|
|
if( !fontProp.isEmpty() )
|
|
props += ( "font :" + fontProp + "; ");
|
|
/* if(appendLineHeight)
|
|
props += ( "line-height : " + line_height + "; ");*/
|
|
}
|
|
return props;
|
|
}
|
|
|
|
TQString ShorthandFormer::compressCueProp(){
|
|
return compressImplementation2( "cue", cue_after, cue_before, "none");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressPauseProp(){
|
|
return compressImplementation2( "pause", pause_after, pause_before, "0");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressBackgroundProp(){
|
|
TQString backgroundProp;
|
|
if( !background_color.isEmpty() ) backgroundProp += (" " + background_color );
|
|
if( !background_image.isEmpty() ) backgroundProp += (" " + background_image );
|
|
if( !background_repeat.isEmpty() ) backgroundProp += (" " + background_repeat );
|
|
if( !background_attachment.isEmpty() ) backgroundProp += (" " + background_attachment );
|
|
if( !background_position.isEmpty() ) backgroundProp += (" " + background_position );
|
|
if( !backgroundProp.isEmpty() ) return ( "background :" + backgroundProp + "; ");
|
|
return TQString();
|
|
}
|
|
|
|
TQString ShorthandFormer::compressPaddingProp(){
|
|
return compressImplementation( "padding" ,padding_top, padding_bottom, padding_right, padding_left, "0");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressMarginProp(){
|
|
return compressImplementation( "margin" ,margin_top, margin_bottom, margin_right, margin_left, "0");
|
|
}
|
|
|
|
TQString ShorthandFormer::compressOutlineProp(){
|
|
return compressImplementation3("outline", outline_color, outline_style, outline_width);
|
|
}
|
|
TQString ShorthandFormer::compressListStyleProp(){
|
|
return compressImplementation3("list-style", list_style_type, list_style_image, list_style_position);
|
|
}
|
|
|
|
TQString ShorthandFormer::compressImplementation3( const TQString& prop, const TQString& p1, const TQString& p2, const TQString& p3){
|
|
TQString props;
|
|
if( !p1.isEmpty() ) props += (" " + p1 );
|
|
if( !p2.isEmpty() ) props += (" " + p2 );
|
|
if( !p3.isEmpty() ) props += (" " + p3 );
|
|
if( !props.isEmpty() ) return ( prop + " :" + props + "; ");
|
|
return TQString();
|
|
}
|
|
|
|
TQString ShorthandFormer::compressImplementation2( const TQString& prop, const TQString& after, const TQString& before, const TQString& defValue){
|
|
TQString props;
|
|
if(after == before){
|
|
if(!after.isEmpty()) props+=( prop + " : " + after + "; ");
|
|
}
|
|
else {
|
|
if(before.isEmpty()) props+=( prop + " : " + defValue + " " + after + "; ");
|
|
else
|
|
if(after.isEmpty()) props+=( prop + " : " + before + " " + defValue + "; ");
|
|
else props+=( prop + " : " + before + " " + after + "; ");
|
|
}
|
|
return props;
|
|
}
|
|
|
|
TQString ShorthandFormer::compressImplementation( const TQString& prop, const TQString& t, const TQString& b, const TQString& r, const TQString& l, const TQString& defValue){
|
|
|
|
TQString props,
|
|
top(t.stripWhiteSpace()),
|
|
bottom(b.stripWhiteSpace()),
|
|
left(l.stripWhiteSpace()),
|
|
right(r.stripWhiteSpace());
|
|
|
|
if( top.isEmpty() ) top = defValue;
|
|
if( bottom.isEmpty() ) bottom = defValue;
|
|
if( left.isEmpty() ) left = defValue;
|
|
if( right.isEmpty() ) right = defValue;
|
|
|
|
|
|
if( top == defValue && bottom == defValue && right == defValue && left == defValue)
|
|
return TQString();
|
|
|
|
if( top == bottom && bottom == right && right == left )
|
|
return ( prop +" : " + top + "; ");
|
|
|
|
if( right == left ) {
|
|
if( top == bottom ) return ( prop +" : " + top + " " + right + "; ");
|
|
else return ( prop +" : " + top + " " + right + " " + bottom + "; ");
|
|
}
|
|
else return (prop +" : " + top + " " + right + " " + bottom + " " + left + "; ");
|
|
}
|
|
|
|
|
|
//+++++++++++++++++++++EXPANDING METHODS+++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expand( const TQString& propertyName, const TQString& propertyValue ){
|
|
CSSSHPropertyParser parser(propertyValue);
|
|
TQStringList foundValues = parser.parse();
|
|
|
|
if( propertyName == "cue" ) return expandCueProp(foundValues);
|
|
if( propertyName == "pause") return expandPauseProp(foundValues);
|
|
if( propertyName == "background") return expandBackgroundProp(foundValues);
|
|
if( propertyName == "border-color") return expandBox("color", foundValues);
|
|
if( propertyName == "border-style") return expandBox("style", foundValues);
|
|
if( propertyName == "border-width") return expandBox("width", foundValues);
|
|
if( propertyName == "font") return expandFontProp(foundValues);
|
|
if( propertyName == "outline") return expandOutlineProp(foundValues);
|
|
if( propertyName == "list-style") return expandListstyleProp(foundValues);
|
|
if( propertyName == "border-bottom") return expandBoxSide("bottom",foundValues);
|
|
if( propertyName == "border-top") return expandBoxSide("top",foundValues);
|
|
if( propertyName == "border-left") return expandBoxSide("left",foundValues);
|
|
if( propertyName == "border-right") return expandBoxSide("right",foundValues);
|
|
if( propertyName == "border") return expandBorderProp(foundValues);
|
|
if( propertyName == "padding") return expandPaddingProp(foundValues);
|
|
if( propertyName == "margin") return expandMarginProp(foundValues);
|
|
return TQMap<TQString,TQString>();//dummy instruction avoiding a pedantic warning; can never be reached
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandCueProp(const TQStringList& l){
|
|
return expandImplementation("cue",l);
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandPauseProp(const TQStringList& l){
|
|
return expandImplementation("pause",l);
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandImplementation(const TQString& propertyName, const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
if( l.count()==1) {
|
|
expandedProps[propertyName + "-before"] = l[0] ;
|
|
expandedProps[propertyName + "-after"] = l[0] ;
|
|
return expandedProps;
|
|
}
|
|
else
|
|
{
|
|
expandedProps[propertyName + "-before"] = l[0] ;
|
|
expandedProps[propertyName + "-after"] = l[1] ;
|
|
return expandedProps;
|
|
}
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandBackgroundProp(const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
if(l.count()==1 && l[0] == "inherit"){ // it works also as protection against wrong single value inserted
|
|
expandedProps["background-color"] = l[0];
|
|
expandedProps["background-image"] = l[0];
|
|
expandedProps["background-repeat"] = l[0];
|
|
expandedProps["background-attachment"] =l[0];
|
|
expandedProps["background-position"] = l[0];
|
|
}
|
|
else {
|
|
|
|
TQStringList::ConstIterator it = l.begin();
|
|
|
|
while ( it != l.end() ) {
|
|
TQString temp((*it).stripWhiteSpace());
|
|
if( (*it).contains("url(") || temp == "none" || temp == "inherit" ){
|
|
expandedProps["background-image"] = (*it);
|
|
}
|
|
else
|
|
if( backgroundRepeatValueList.contains(temp)!=0 ) {
|
|
expandedProps["background-repeat"] = (*it);
|
|
}
|
|
else
|
|
if( temp == "scroll" || temp == "fixed" || temp == "inherit"){
|
|
expandedProps["background-attachment"] = (*it);
|
|
}
|
|
else
|
|
if( (*it).contains("rgb(") || (*it).contains(globalColorPattern) || CSSEditorGlobals::HTMLColors.contains((*it))!=0 || temp == "transparent" || temp == "inherit" ){
|
|
expandedProps["background-color"] = (*it);
|
|
}
|
|
else
|
|
if( temp == "top" || temp == "center" || temp == "bottom" || temp == "left" || temp == "right" || (*it).contains(globalPercentagePattern) || (*it).contains(globalLengthPattern) || temp == "inherit"){
|
|
if( expandedProps.contains("background-position") )
|
|
expandedProps["background-position"] = ( expandedProps["background-position"] + " " + (*it) );
|
|
else
|
|
expandedProps["background-position"] = (*it);
|
|
}
|
|
|
|
++it;
|
|
}
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandBox(const TQString& subPropName, const TQStringList& l){
|
|
|
|
TQMap<TQString,TQString> expandedProps;
|
|
expandedProps["border-top-" + subPropName] = l[0];
|
|
switch(l.count()){
|
|
case 1 :
|
|
expandedProps["border-right-" + subPropName] = l[0];
|
|
expandedProps["border-bottom-" + subPropName] = l[0];
|
|
expandedProps["border-left-" + subPropName] = l[0];
|
|
break;
|
|
case 2 :
|
|
expandedProps["border-right-" + subPropName] = l[1];
|
|
expandedProps["border-bottom-" + subPropName] = l[0];
|
|
expandedProps["border-left-" + subPropName] = l[1];
|
|
break;
|
|
case 3 :
|
|
expandedProps["border-right-" + subPropName] = l[1];
|
|
expandedProps["border-bottom-" + subPropName] = l[2];
|
|
expandedProps["border-left-" + subPropName] = l[1];
|
|
break;
|
|
case 4 :
|
|
expandedProps["border-right-" + subPropName] = l[1];
|
|
expandedProps["border-bottom-" + subPropName] = l[2];
|
|
expandedProps["border-left-" + subPropName] = l[3];
|
|
break;
|
|
default:break;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandFontProp(const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
|
|
TQRegExp percentagePattern("/"+globalPercentagePattern.pattern()),
|
|
lengthPattern("/"+globalLengthPattern.pattern()),
|
|
numberPattern("/"+globalNumberPattern.pattern());
|
|
|
|
TQStringList fontPseudoSHFormValues;
|
|
fontPseudoSHFormValues.append("caption");
|
|
fontPseudoSHFormValues.append("icon");
|
|
fontPseudoSHFormValues.append("menu");
|
|
fontPseudoSHFormValues.append("message-box");
|
|
fontPseudoSHFormValues.append("small-caption");
|
|
fontPseudoSHFormValues.append("status-bar");
|
|
if( l.count()==1 && fontPseudoSHFormValues.contains(l[0]) != 0) {
|
|
expandedProps["font"] = l[0];
|
|
return expandedProps;
|
|
}
|
|
else {
|
|
TQStringList::ConstIterator it = l.begin();
|
|
while ( it != l.end() ) {
|
|
TQString currentIt = (*it);
|
|
TQString temp(currentIt.stripWhiteSpace());
|
|
if( fontStyleValueList.contains(temp)!=0 ) expandedProps["font-style"] = (*it);
|
|
else
|
|
if( fontVariantValueList.contains(temp)!=0 ) expandedProps["font-variant"] = currentIt ;
|
|
else
|
|
if( fontWeightValueList.contains(temp)!=0) expandedProps["font-weight"] = currentIt;
|
|
else
|
|
if( (fontSizeValueList.contains(temp)!=0 || currentIt.contains(globalPercentagePattern)!=0 || currentIt.contains(globalLengthPattern)!=0) && expandedProps["font-size"].isEmpty() )
|
|
{
|
|
expandedProps["font-size"] = currentIt;
|
|
}
|
|
else
|
|
if( currentIt.contains(percentagePattern)!=0 || currentIt.contains(numberPattern)!=0 || currentIt.contains(lengthPattern)!=0 || temp == "/normal" || temp == "/inherit" )
|
|
{
|
|
expandedProps["line-height"] = (currentIt.remove('/'));
|
|
}
|
|
else expandedProps["font-family"] = currentIt;
|
|
++it;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandListstyleProp( const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
if( (l.count() == 1) && (l[0] == "inherit")){
|
|
expandedProps["list-style-image"] ="inherit";
|
|
expandedProps["list-style-type"] ="inherit";
|
|
expandedProps["list-style-position"] ="inherit";
|
|
return expandedProps;
|
|
}
|
|
|
|
if( (l.count() == 1) && (l[0] == "none")){
|
|
expandedProps["list-style-image"] ="none";
|
|
expandedProps["list-style-type"] ="none";
|
|
return expandedProps;
|
|
}
|
|
|
|
|
|
TQStringList::ConstIterator it = l.begin();
|
|
while ( it != l.end() ) {
|
|
TQString temp((*it).stripWhiteSpace());
|
|
if( listTypeValueList.contains(temp)!=0) {
|
|
expandedProps["list-style-type"] = (*it) ;
|
|
}
|
|
else
|
|
if( temp == "inside" || temp == "outside" || temp == "inherit") {
|
|
expandedProps["list-style-position"] = (*it);
|
|
}
|
|
else
|
|
if( (*it).contains("url(") || temp == "none" || temp == "inherit" )
|
|
expandedProps["list-style-image"] = (*it);
|
|
|
|
++it;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandOutlineProp( const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
TQStringList::ConstIterator it = l.begin();
|
|
while ( it != l.end() ) {
|
|
TQString temp((*it).stripWhiteSpace());
|
|
if( borderStyleValueList.contains(temp)!=0 ) expandedProps["outline-style"] = (*it);
|
|
else
|
|
if( (*it).contains(globalColorPattern) || CSSEditorGlobals::HTMLColors.contains((*it))!=0 || temp == "invert" || temp == "inherit")
|
|
expandedProps["outline-color"] = (*it) ;
|
|
else
|
|
if( (*it).contains(globalLengthPattern) || widthValueList.contains(temp)!=0)
|
|
expandedProps["outline-width"] = (*it);
|
|
++it;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandBoxSide(const TQString& subPropName, const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
|
|
TQStringList::ConstIterator it = l.begin();
|
|
while ( it != l.end() ) {
|
|
TQString temp((*it).stripWhiteSpace());
|
|
if( borderStyleValueList.contains(temp)!=0 ) expandedProps[subPropName + "-style"] = (*it);
|
|
else
|
|
if( (*it).contains(globalColorPattern) || CSSEditorGlobals::HTMLColors.contains((*it))!=0 || temp == "transparent" || temp == "inherit")
|
|
expandedProps[subPropName + "-color"] = (*it) ;
|
|
else
|
|
if( (*it).contains(globalLengthPattern) || widthValueList.contains(temp)!=0)
|
|
expandedProps[subPropName + "-width"] = (*it);
|
|
++it;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandBorderProp(const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
TQStringList::ConstIterator it = l.begin();
|
|
while ( it != l.end() ) {
|
|
TQString temp((*it).stripWhiteSpace());
|
|
if( borderStyleValueList.contains(temp)!=0 ){
|
|
expandedProps["border-top-style"] = (*it);
|
|
expandedProps["border-left-style"] = (*it);
|
|
expandedProps["border-right-style"] = (*it);
|
|
expandedProps["border-bottom-style"] = (*it);
|
|
}
|
|
else
|
|
if( (*it).contains(globalColorPattern) || CSSEditorGlobals::HTMLColors.contains((*it))!=0 || temp == "transparent" || temp == "inherit"){
|
|
expandedProps["border-top-color"] = (*it);
|
|
expandedProps["border-left-color"] = (*it);
|
|
expandedProps["border-right-color"] = (*it);
|
|
expandedProps["border-bottom-color"] = (*it);
|
|
}
|
|
else
|
|
if( (*it).contains(globalLengthPattern) || widthValueList.contains(temp)!=0){
|
|
expandedProps["border-top-width"] = (*it);
|
|
expandedProps["border-left-width"] = (*it);
|
|
expandedProps["border-right-width"] = (*it);
|
|
expandedProps["border-bottom-width"] = (*it);
|
|
}
|
|
++it;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandImplementation2(const TQString& propertyName, const TQStringList& l){
|
|
TQMap<TQString,TQString> expandedProps;
|
|
expandedProps[ propertyName + "-top" ] = l[0];
|
|
switch(l.count()){
|
|
case 1 :
|
|
expandedProps[ propertyName + "-right" ] = l[0];
|
|
expandedProps[ propertyName + "-bottom" ] = l[0];
|
|
expandedProps[ propertyName + "-left" ] = l[0];
|
|
break;
|
|
case 2 :
|
|
expandedProps[ propertyName + "-right" ] = l[1];
|
|
expandedProps[ propertyName + "-bottom" ] = l[0];
|
|
expandedProps[ propertyName + "-left" ] = l[1];
|
|
break;
|
|
case 3 :
|
|
expandedProps[ propertyName + "-right" ] = l[1];
|
|
expandedProps[ propertyName + "-bottom" ] = l[2];
|
|
expandedProps[ propertyName + "-left" ] = l[1];
|
|
break;
|
|
case 4 :
|
|
expandedProps[ propertyName + "-right" ] = l[1];
|
|
expandedProps[ propertyName + "-bottom" ] = l[2];
|
|
expandedProps[ propertyName + "-left" ] = l[3];
|
|
break;
|
|
default:break;
|
|
}
|
|
return expandedProps;
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandPaddingProp(const TQStringList& l){
|
|
return expandImplementation2("padding", l);
|
|
}
|
|
|
|
TQMap<TQString,TQString> ShorthandFormer::expandMarginProp(const TQStringList& l){
|
|
return expandImplementation2("margin", l);
|
|
}
|
|
|
|
TQStringList ShorthandFormer::SHFormList() {
|
|
TQStringList l;
|
|
l.append("cue");
|
|
l.append("pause");
|
|
l.append("font");
|
|
l.append("background");
|
|
l.append("border");
|
|
l.append("border-top");
|
|
l.append("border-bottom");
|
|
l.append("border-left");
|
|
l.append("border-right");
|
|
l.append("border-color");
|
|
l.append("border-style");
|
|
l.append("border-width");
|
|
l.append("outline");
|
|
l.append("list-style");
|
|
l.append("padding");
|
|
l.append("margin");
|
|
return l;
|
|
}
|
|
|