Basic stringification of KwCssStyle and KwCssUnprocessed placeholder
[kworship.git] / kworship / css / KwCssStyle.h
blob95dc37eb57ee6d54dfb1d585a52e4ed8575f80bd
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 #ifndef _KwCssStyle_h_
21 #define _KwCssStyle_h_
23 /**
24 * @file KwCssStyle.h
25 * @brief Typed cascading style property.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssAbstractStyle.h"
30 #include "KwCssUnprocessed.h"
32 /// Stringify a type.
33 template <typename T>
34 KwCssUnprocessed KwCssStringify(const T& value);
36 /// Unstringify a type.
37 template <typename T>
38 T KwCssUnstringify(const KwCssUnprocessed& value, bool* success);
40 /// Typed cascading style property.
41 /**
42 * @param T The type of the property.
44 template <typename T>
45 class KwCssStyle : public KwCssAbstractStyle
47 public:
50 * Types
53 /// Operation types.
54 enum Operation
56 none,
57 override,
58 revert,
59 clear
63 * Constructors + destructors
66 /// Default constructor.
67 KwCssStyle()
68 : KwCssAbstractStyle()
69 , m_operation(none)
70 , m_value()
74 /// Copy constructor.
75 KwCssStyle(const KwCssStyle& copy)
76 : KwCssAbstractStyle(copy)
77 , m_operation(copy.m_operation)
78 , m_value(copy.m_value)
82 /// Primary constructor.
83 KwCssStyle(const T& value, Operation op = override)
84 : KwCssAbstractStyle()
85 , m_operation(op)
86 , m_value(value)
90 /// Primary constructor.
91 KwCssStyle(Operation op)
92 : KwCssAbstractStyle()
93 , m_operation(op)
94 , m_value()
98 /// Destructor.
99 virtual ~KwCssStyle()
104 * Main interface
107 // Reimplemented
108 virtual KwCssAbstractStyleState* getNewState() const;
110 // Reimplemented
111 virtual KwCssAbstractStyle* duplicate() const
113 return new KwCssStyle<T>(*this);
116 // Reimplemented
117 virtual QString toString() const
119 switch (m_operation)
121 case revert:
123 return "revert";
126 case override:
128 return KwCssStringify(m_value);
131 case clear:
133 return "clear";
136 case none:
137 default:
139 return "inherit";
146 * Accessors
149 /// Get the operation type.
150 Operation getOperation() const
152 return m_operation;
155 /// Get the value.
156 T getValue() const
158 return m_value;
161 private:
164 * Variables
167 /// Type of operation.
168 Operation m_operation;
170 /// Initial or overrided value.
171 T m_value;
174 #include "KwCssStyleState.h"
176 /// Get a new state.
177 template <typename T>
178 KwCssAbstractStyleState* KwCssStyle<T>::getNewState() const
180 return new KwCssStyleState<T>();
183 #endif // _KwCssStyle_h_