1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwCssStyle.cpp
22 * @brief Typed cascading style property.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwCssStyle.h"
30 #include "KwCssUnprocessed.h"
32 KwCssUnprocessed KwCssStringify
<KwCssUnprocessed
>(const KwCssUnprocessed
& value
)
37 KwCssUnprocessed KwCssUnstringify
<KwCssUnprocessed
>(const KwCssUnprocessed
& value
, bool* success
)
45 KwCssUnprocessed KwCssStringify
<bool>(const bool& value
)
47 return KwCssUnprocessed(value
? "true" : "false");
50 bool KwCssUnstringify
<bool>(const KwCssUnprocessed
& value
, bool* success
)
57 else if (value
== "false")
70 KwCssUnprocessed KwCssStringify
<int>(const int& value
)
72 return KwCssUnprocessed::number(value
);
75 int KwCssUnstringify
<int>(const KwCssUnprocessed
& value
, bool* success
)
77 return value
.toInt(success
);
81 KwCssUnprocessed KwCssStringify
<float>(const float& value
)
83 return KwCssUnprocessed::number(value
);
86 float KwCssUnstringify
<float>(const KwCssUnprocessed
& value
, bool* success
)
88 return value
.toFloat(success
);
92 KwCssUnprocessed KwCssStringify
<double>(const double& value
)
94 return KwCssUnprocessed::number(value
);
97 double KwCssUnstringify
<double>(const KwCssUnprocessed
& value
, bool* success
)
99 return value
.toDouble(success
);
102 #include <KwResourceLink.h>
104 KwCssUnprocessed KwCssStringify
<KwResourceLink
>(const KwResourceLink
& value
)
106 switch (value
.type())
108 case KwResourceLink::Url
:
110 QString url
= value
.url().url();
111 url
.replace('\\', "\\\\")
112 .replace('"', "\\\"");
113 return QString("\"%1\"").arg(url
);
116 case KwResourceLink::FileRelative
:
118 QString url
= value
.path();
119 url
.replace('\\', "\\\\")
120 .replace('"', "\\\"");
121 return QString("frel \"%1\"").arg(url
);
124 case KwResourceLink::ArchiveRoot
:
126 QString url
= value
.path();
127 url
.replace('\\', "\\\\")
128 .replace('"', "\\\"");
129 return QString("aroot \"%1\"").arg(url
);
132 case KwResourceLink::ArchiveRelative
:
134 QString url
= value
.path();
135 url
.replace('\\', "\\\\")
136 .replace('"', "\\\"");
137 return QString("arel \"%1\"").arg(url
);
140 case KwResourceLink::Null
:
149 KwResourceLink KwCssUnstringify
<KwResourceLink
>(const KwCssUnprocessed
& value
, bool* success
)
153 static QRegExp
reFormat("((\\w*)\\s+)?\"((\\.|[^\\\"])*)\"");
154 static const QRegExp
reUnescape("\\(.)");
155 static const QString
unescapeReplace("\\1");
156 if (reFormat
.exactMatch(value
))
158 QString keyword
= reFormat
.cap(1);
159 QString file
= reFormat
.cap(3);
160 file
.replace(reUnescape
, unescapeReplace
);
162 if (keyword
.isEmpty())
164 return KwResourceLink(KUrl(file
));
166 else if ("frel" == keyword
)
168 return KwResourceLink(KwResourceLink::FileRelative
, file
);
170 else if ("aroot" == keyword
)
172 return KwResourceLink(KwResourceLink::ArchiveRoot
, file
);
174 else if ("arel" == keyword
)
176 return KwResourceLink(KwResourceLink::ArchiveRelative
, file
);
181 return KwResourceLink();
186 KwCssUnprocessed KwCssStringify
<QBrush
>(const QBrush
& value
)
191 QBrush KwCssUnstringify
<QBrush
>(const KwCssUnprocessed
& value
, bool* success
)
194 return QBrush(Qt::black
);
199 KwCssUnprocessed KwCssStringify
<QPen
>(const QPen
& value
)
204 QPen KwCssUnstringify
<QPen
>(const KwCssUnprocessed
& value
, bool* success
)
212 KwCssUnprocessed KwCssStringify
<QFont
>(const QFont
& value
)
217 QFont KwCssUnstringify
<QFont
>(const KwCssUnprocessed
& value
, bool* success
)