New css schema object for constructing property values from strings
[kworship.git] / kworship / css / KwCssStyle.cpp
blob9573ee709120e76541b80f913f9294be0f707e10
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 /**
21 * @file KwCssStyle.cpp
22 * @brief Typed cascading style property.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwCssStyle.h"
28 #include "KwCssUnprocessed.h"
29 template <>
30 KwCssUnprocessed KwCssStringify<KwCssUnprocessed>(const KwCssUnprocessed& value)
32 return value;
34 template <>
35 KwCssUnprocessed KwCssUnstringify<KwCssUnprocessed>(const KwCssUnprocessed& value, bool* success)
37 *success = true;
38 return value;
41 #include <KwResourceLink.h>
42 template <>
43 KwCssUnprocessed KwCssStringify<KwResourceLink>(const KwResourceLink& value)
45 switch (value.type())
47 case KwResourceLink::Url:
49 QString url = value.url().url();
50 url.replace('\\', "\\\\")
51 .replace('"', "\\\"");
52 return QString("\"%1\"").arg(url);
55 case KwResourceLink::FileRelative:
57 QString url = value.path();
58 url.replace('\\', "\\\\")
59 .replace('"', "\\\"");
60 return QString("frel \"%1\"").arg(url);
63 case KwResourceLink::ArchiveRoot:
65 QString url = value.path();
66 url.replace('\\', "\\\\")
67 .replace('"', "\\\"");
68 return QString("aroot \"%1\"").arg(url);
71 case KwResourceLink::ArchiveRelative:
73 QString url = value.path();
74 url.replace('\\', "\\\\")
75 .replace('"', "\\\"");
76 return QString("arel \"%1\"").arg(url);
79 case KwResourceLink::Null:
80 default:
82 return "null";
87 template <>
88 KwResourceLink KwCssUnstringify<KwResourceLink>(const KwCssUnprocessed& value, bool* success)
90 *success = false;
91 return KwResourceLink();
94 #include <QBrush>
95 template <>
96 KwCssUnprocessed KwCssStringify<QBrush>(const QBrush& value)
98 return "Brush()";
100 template <>
101 QBrush KwCssUnstringify<QBrush>(const KwCssUnprocessed& value, bool* success)
103 *success = true;
104 return QBrush(Qt::black);
107 #include <QPixmap>
108 template <>
109 KwCssUnprocessed KwCssStringify<QPixmap>(const QPixmap& value)
111 return "Pixmap()";
113 template <>
114 QPixmap KwCssUnstringify<QPixmap>(const KwCssUnprocessed& value, bool* success)
116 *success = true;
117 return QPixmap();