20#include "KWTableTemplate.h"
22#include "KWDocument.h"
23#include "KWFrameStyle.h"
24#include "KoParagStyle.h"
35KWTableTemplateCollection::KWTableTemplateCollection()
37 m_templateList.setAutoDelete(
false );
38 m_deletedTemplates.setAutoDelete(
true );
42KWTableTemplateCollection::~KWTableTemplateCollection()
48void KWTableTemplateCollection::clear()
50 m_templateList.setAutoDelete(
true );
51 m_templateList.clear();
52 m_deletedTemplates.clear();
56KWTableTemplate* KWTableTemplateCollection::findTableTemplate(
const TQString & _name )
59 if ( m_lastTemplate && m_lastTemplate->name() == _name )
60 return m_lastTemplate;
62 TQPtrListIterator<KWTableTemplate> templateIt( m_templateList );
63 for ( ; templateIt.current(); ++templateIt )
65 if ( templateIt.current()->name() == _name ) {
66 m_lastTemplate = templateIt.current();
67 return m_lastTemplate;
77KWTableTemplate* KWTableTemplateCollection::addTableTemplate( KWTableTemplate * tt )
80 for ( KWTableTemplate* p = m_templateList.first(); p != 0L; p = m_templateList.next() )
82 if ( p->name() == tt->name() ) {
92 m_templateList.append( tt );
96void KWTableTemplateCollection::removeTableTemplate ( KWTableTemplate *tt )
98 if( m_templateList.removeRef( tt )) {
99 if ( m_lastTemplate == tt )
102 m_deletedTemplates.append( tt );
116 m_firstRow = _firstRow;
117 m_firstCol = _firstCol;
118 m_lastRow = _lastRow;
119 m_lastCol = _lastCol;
120 m_bodyCell = _bodyCell;
121 m_topLeftCorner = _topLeftCorner;
122 m_topRightCorner = _topRightCorner;
123 m_bottomRightCorner = _bottomRightCorner;
124 m_bottomLeftCorner = _bottomLeftCorner;
127KWTableTemplate::KWTableTemplate( TQDomElement & parentElem, KWDocument *_doc,
int )
129 m_topRightCorner = 0L;
130 m_topLeftCorner = 0L;
131 m_bottomRightCorner = 0L;
132 m_bottomLeftCorner = 0L;
134 TQDomElement element = parentElem.namedItem(
"NAME" ).toElement();
135 if ( ( !element.isNull() ) && ( element.hasAttribute(
"value") ) )
136 m_name = element.attribute(
"value" );
138 element = parentElem.namedItem(
"BODYCELL" ).toElement();
139 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") )
140 && ( _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) ) ) )
141 m_bodyCell = _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) );
143 KWTableStyle *ts = _doc->tableStyleCollection()->
findStyle(
"Plain" );
148 ts =
new KWTableStyle(
"Plain", 0L, 0L );
149 KWFrameStyle *fs = _doc->frameStyleCollection()->
findStyle(
"Plain" );
150 KoParagStyle *s = _doc->styleCollection()->findStyle(
"Standard" );
152 ts->setFrameStyle( fs );
154 KWFrameStyle * standardFrameStyle =
new KWFrameStyle(
"Plain" );
155 standardFrameStyle->setBackgroundColor(TQColor(
"white"));
156 standardFrameStyle->setTopBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
157 standardFrameStyle->setRightBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
158 standardFrameStyle->setLeftBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
159 standardFrameStyle->setBottomBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
160 _doc->frameStyleCollection()->
addStyle( standardFrameStyle );
161 ts->setFrameStyle( fs );
165 ts->setParagraphStyle( s );
167 KoParagStyle * standardStyle =
new KoParagStyle(
"Standard" );
168 standardStyle->format().setFont( _doc->defaultFont() );
169 _doc->styleCollection()->addStyle( standardStyle );
170 ts->setParagraphStyle( s );
175 element = parentElem.namedItem(
"FIRSTROW" ).toElement();
176 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") )
177 && ( _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) ) ) )
179 m_firstRow = _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) );
181 if ( element.hasAttribute(
"topleftcorner") )
182 m_topLeftCorner = m_firstRow;
183 if ( element.hasAttribute(
"toprightcorner") )
184 m_topRightCorner = m_firstRow;
187 m_firstRow = m_bodyCell;
189 element = parentElem.namedItem(
"FIRSTCOL" ).toElement();
190 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") )
191 && ( _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) ) ) )
193 m_firstCol = _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) );
195 if ( element.hasAttribute(
"topleftcorner") )
196 m_topLeftCorner = m_firstCol;
197 if ( element.hasAttribute(
"bottomleftcorner") )
198 m_bottomLeftCorner = m_firstCol;
201 m_firstCol = m_bodyCell;
203 element = parentElem.namedItem(
"LASTROW" ).toElement();
204 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") )
205 && ( _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) ) ) )
207 m_lastRow = _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) );
209 if ( ( !element.isNull() ) && ( element.hasAttribute(
"bottomrightcorner") ) )
210 m_bottomRightCorner = m_lastRow;
211 if ( ( !element.isNull() ) && ( element.hasAttribute(
"bottomleftcorner") ) )
212 m_bottomLeftCorner = m_lastRow;
215 m_lastRow = m_bodyCell;
217 element = parentElem.namedItem(
"LASTCOL" ).toElement();
218 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") )
219 && ( _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) ) ) )
221 m_lastCol = _doc->tableStyleCollection()->
findStyle( element.attribute(
"name" ) );
223 if ( element.hasAttribute(
"toprightcorner") )
224 m_topRightCorner = m_lastCol;
225 if ( element.hasAttribute(
"bottomrightcorner") )
226 m_bottomRightCorner = m_lastCol;
229 m_lastCol = m_bodyCell;
231 if (!m_topRightCorner) m_topRightCorner = m_bodyCell;
232 if (!m_topLeftCorner) m_topLeftCorner = m_bodyCell;
233 if (!m_bottomRightCorner) m_bottomRightCorner = m_bodyCell;
234 if (!m_bottomLeftCorner) m_bottomLeftCorner = m_bodyCell;
237void KWTableTemplate::operator=(
const KWTableTemplate &rhs )
240 m_firstRow = rhs.pFirstRow();
241 m_firstCol = rhs.pFirstCol();
242 m_lastRow = rhs.pLastRow();
243 m_lastCol = rhs.pLastCol();
244 m_bodyCell = rhs.pBodyCell();
245 m_topLeftCorner = rhs.pTopLeftCorner();
246 m_topRightCorner = rhs.pTopRightCorner();
247 m_bottomRightCorner = rhs.pBottomRightCorner();
248 m_bottomLeftCorner = rhs.pBottomLeftCorner();
251TQString KWTableTemplate::displayName()
const
253 return i18n(
"Style name", name().utf8() );
257void KWTableTemplate::saveTableTemplate( TQDomElement & parentElem )
259 TQDomDocument doc = parentElem.ownerDocument();
260 TQDomElement element = doc.createElement(
"NAME" );
261 parentElem.appendChild( element );
262 element.setAttribute(
"value", name() );
266 element = doc.createElement(
"BODYCELL" );
267 parentElem.appendChild( element );
268 element.setAttribute(
"name", m_bodyCell->name() );
272 element = doc.createElement(
"FIRSTROW" );
273 parentElem.appendChild( element );
274 element.setAttribute(
"name", m_firstRow->name() );
278 element = doc.createElement(
"FIRSTCOL" );
279 parentElem.appendChild( element );
280 element.setAttribute(
"name", m_firstCol->name() );
284 element = doc.createElement(
"LASTROW" );
285 parentElem.appendChild( element );
286 element.setAttribute(
"name", m_lastRow->name() );
290 element = doc.createElement(
"LASTCOL" );
291 parentElem.appendChild( element );
292 element.setAttribute(
"name", m_lastCol->name() );
296KWTableTemplate *KWTableTemplate::loadTemplate( TQDomElement & parentElem, KWDocument *_doc,
int docVersion )
298 return new KWTableTemplate(parentElem, _doc, docVersion);
KWFrameStyle * findStyle(const TQString &name) const
Find style based on the untranslated name name.
KWFrameStyle * addStyle(KWFrameStyle *sty)
See KoUserStyleCollection::addStyle.
KWTableStyle * findStyle(const TQString &name) const
Find style based on the untranslated name name.
Table style (can created/modified/deleted by the user) A table style is simply a paragraph style and ...