20#include "KWTableStyle.h"
21#include "KWDocument.h"
24#include <KoGenStyles.h>
25#include <KoOasisStyles.h>
26#include <KoOasisContext.h>
33KWTableStyleCollection::KWTableStyleCollection()
34 : KoUserStyleCollection( TQString::fromLatin1(
"table" ) )
38void KWTableStyleCollection::saveOasis( KoGenStyles& mainStyles, KoSavingContext& savingContext )
const
41 for ( TQValueList<KoUserStyle *>::const_iterator styleIt = m_styleList.begin(), styleEnd = m_styleList.end() ; styleIt != styleEnd ; ++styleIt )
44 style->
saveOasis( mainStyles, savingContext );
49int KWTableStyleCollection::loadOasisStyles( KoOasisContext& context,
const KoStyleCollection& paragraphStyles,
const KWFrameStyleCollection& frameStyles )
51 TQValueVector<TQDomElement> userStyles = context.oasisStyles().userStyles();
52 bool defaultStyleDeleted =
false;
54 for (
unsigned int item = 0; item < userStyles.count(); item++) {
55 TQDomElement styleElem = userStyles[item];
56 Q_ASSERT( !styleElem.isNull() );
58 if ( styleElem.attributeNS( KoXmlNS::style,
"family", TQString() ) !=
"table-cell" )
61 if ( !defaultStyleDeleted ) {
66 defaultStyleDeleted =
true;
71 sty->
loadOasis( styleElem, context, paragraphStyles, frameStyles );
75 kdDebug() <<
" Loaded table cell style " << sty->name() <<
" - now " << count() <<
" styles" << endl;
88 m_paragStyle = _paragStyle;
89 m_frameStyle = _frameStyle;
93 : KoUserStyle( TQString() )
95 TQDomElement element = parentElem.namedItem(
"NAME" ).toElement();
96 if ( ( !element.isNull() ) && ( element.hasAttribute(
"value") ) ) {
97 m_name = element.attribute(
"value" );
98 m_displayName = i18n(
"Style name", m_name.utf8() );
100 kdWarning() <<
"No NAME tag in table style!" << endl;
102 element = parentElem.namedItem(
"PFRAMESTYLE" ).toElement();
104 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") ) )
105 m_frameStyle = _doc->frameStyleCollection()->findStyleByDisplayName( element.attribute(
"name" ) );
107 if ( !m_frameStyle ) {
108 if ( !_doc->frameStyleCollection()->isEmpty() )
109 m_frameStyle = _doc->frameStyleCollection()->frameStyleAt( 0 );
112 standardFrameStyle->setBackgroundColor(TQColor(
"white"));
113 standardFrameStyle->setTopBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
114 standardFrameStyle->setRightBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
115 standardFrameStyle->setLeftBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
116 standardFrameStyle->setBottomBorder(KoBorder(TQColor(
"black"),KoBorder::SOLID,0));
117 _doc->frameStyleCollection()->addStyle( standardFrameStyle );
118 m_frameStyle = _doc->frameStyleCollection()->frameStyleAt( 0 );
122 element = parentElem.namedItem(
"PSTYLE" ).toElement();
124 if ( ( !element.isNull() ) && ( element.hasAttribute(
"name") ) )
125 m_paragStyle = _doc->styleCollection()->findStyleByDisplayName( element.attribute(
"name" ) );
127 if ( !m_paragStyle ) {
128 if ( _doc->styleCollection()->styleList().count()>0 )
129 m_paragStyle = _doc->styleCollection()->styleAt( 0 );
131 KoParagStyle * standardStyle =
new KoParagStyle(
"Standard" );
132 standardStyle->format().setFont( _doc->defaultFont() );
133 _doc->styleCollection()->addStyle( standardStyle );
134 m_paragStyle = _doc->styleCollection()->styleAt( 0 );
141 KoUserStyle::operator=( rhs );
142 m_paragStyle = rhs.paragraphStyle();
143 m_frameStyle = rhs.frameStyle();
148 TQDomDocument doc = parentElem.ownerDocument();
149 TQDomElement element = doc.createElement(
"NAME" );
150 parentElem.appendChild( element );
151 element.setAttribute(
"value", displayName() );
155 element = doc.createElement(
"PFRAMESTYLE" );
156 parentElem.appendChild( element );
157 element.setAttribute(
"name", m_frameStyle->displayName() );
161 element = doc.createElement(
"PSTYLE" );
162 parentElem.appendChild( element );
163 element.setAttribute(
"name", m_paragStyle->displayName() );
170 return new KWTableStyle( parentElem, _doc, docVersion );
175 KoGenStyle tableCellStyle( KWDocument::STYLE_TABLE_CELL_USER,
"table-cell" );
176 tableCellStyle.addAttribute(
"style:display-name", displayName() );
178 tableCellStyle.addProperty(
"koffice:frame-style-name", m_frameStyle->name() );
180 tableCellStyle.addProperty(
"koffice:paragraph-style-name", m_paragStyle->name() );
184 const bool nameIsConform = !m_name.isEmpty() && m_name.find(
' ' ) == -1;
187 newName = mainStyles.lookup( tableCellStyle, m_name, KoGenStyles::DontForceNumbering );
189 newName = mainStyles.lookup( tableCellStyle,
"tc" );
196 m_name = styleElem.attributeNS( KoXmlNS::style,
"name", TQString() );
197 m_displayName = styleElem.attributeNS( KoXmlNS::style,
"display-name", TQString() );
198 if ( m_displayName.isEmpty() )
199 m_displayName = m_name;
200 kdDebug() << k_funcinfo << m_name <<
" " << m_displayName << endl;
202 KoStyleStack& styleStack = context.styleStack();
203 styleStack.setTypeProperties(
"table-cell" );
206 context.addStyles( &styleElem,
"table-cell" );
208 const TQString frameStyleName = styleStack.attributeNS( KoXmlNS::koffice,
"frame-style-name" );
209 m_frameStyle = frameStyles.
findStyle( frameStyleName );
211 kdWarning(32001) <<
"Frame style " << frameStyleName <<
" not found!" << endl;
213 const TQString paragraphStyleName = styleStack.attributeNS( KoXmlNS::koffice,
"paragraph-style-name" );
214 m_paragStyle = paragraphStyles.findStyle( paragraphStyleName );
216 kdWarning(32001) <<
"Paragraph style " << paragraphStyleName <<
" not found!" << endl;
218 styleStack.restore();
Collection of frame styles.
KWFrameStyle * findStyle(const TQString &name) const
Find style based on the untranslated name name.
The user-visible style for frames (borders and background)
KWTableStyle * findStyle(const TQString &name) const
Find style based on the untranslated name name.
KWTableStyle * addStyle(KWTableStyle *sty)
See KoUserStyleCollection::addStyle.
Table style (can created/modified/deleted by the user) A table style is simply a paragraph style and ...
static KWTableStyle * loadStyle(TQDomElement &parentElem, KWDocument *_doc, int docVersion=2)
load (old xml format)
void loadOasis(TQDomElement &styleElem, KoOasisContext &context, const KoStyleCollection ¶graphStyles, const KWFrameStyleCollection &frameStyles)
load (new oasis xml format)
KWTableStyle(const TQString &name, KoParagStyle *_style, KWFrameStyle *_frameStyle)
Create a blank framestyle (with default attributes)
void saveOasis(KoGenStyles &mainStyles, KoSavingContext &savingContext) const
save (new oasis xml format)
void saveTableStyle(TQDomElement &parentElem)
save (old xml format)