00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kostyle.h"
00021
#include <kdebug.h>
00022
#include <klocale.h>
00023
#include <qdom.h>
00024
#include <koparagcounter.h>
00025
00026
00027
int KoStyleCollection::styleNumber = 0;
00028
00029 KoStyleCollection::KoStyleCollection()
00030 {
00031 m_styleList.setAutoDelete(
false );
00032 m_deletedStyles.setAutoDelete(
true );
00033 m_lastStyle = 0L;
00034 }
00035
00036 KoStyleCollection::~KoStyleCollection()
00037 {
00038 m_styleList.setAutoDelete(
true );
00039 m_styleList.clear();
00040 m_deletedStyles.clear();
00041 }
00042
00043
KoStyle* KoStyleCollection::findStyle(
const QString & _name )
00044 {
00045
00046
if ( m_lastStyle && m_lastStyle->name() == _name )
00047
return m_lastStyle;
00048
00049
QPtrListIterator<KoStyle> styleIt( m_styleList );
00050
for ( ; styleIt.current(); ++styleIt )
00051 {
00052
if ( styleIt.current()->name() == _name ) {
00053 m_lastStyle = styleIt.current();
00054
return m_lastStyle;
00055 }
00056 }
00057
00058
if(_name ==
"Standard")
return m_styleList.at(0);
00059
00060
return 0L;
00061 }
00062
00063
00064
KoStyle* KoStyleCollection::findStyleShortCut(
const QString & _shortCut )
00065 {
00066
00067
if ( m_lastStyle && m_lastStyle->shortCutName() == _shortCut )
00068
return m_lastStyle;
00069
00070
QPtrListIterator<KoStyle> styleIt( m_styleList );
00071
for ( ; styleIt.current(); ++styleIt )
00072 {
00073
if ( styleIt.current()->shortCutName() == _shortCut ) {
00074 m_lastStyle = styleIt.current();
00075
return m_lastStyle;
00076 }
00077 }
00078
return 0L;
00079 }
00080
00081
KoStyle* KoStyleCollection::addStyleTemplate(
KoStyle * sty )
00082 {
00083
00084
for (
KoStyle* p = m_styleList.first(); p != 0L; p = m_styleList.next() )
00085 {
00086
if ( p->name() == sty->name() ) {
00087
00088
if ( sty != p )
00089 {
00090 *p = *sty;
00091
delete sty;
00092 }
00093
return p;
00094 }
00095 }
00096 m_styleList.append( sty );
00097
00098 sty->setShortCutName(
QString(
"shortcut_style_%1").arg(styleNumber).latin1());
00099 styleNumber++;
00100
return sty;
00101 }
00102
00103
void KoStyleCollection::removeStyleTemplate (
KoStyle *style ) {
00104
if( m_styleList.removeRef(style)) {
00105
if ( m_lastStyle == style )
00106 m_lastStyle = 0L;
00107
00108 m_deletedStyles.append(style);
00109 }
00110 }
00111
00112
void KoStyleCollection::updateStyleListOrder(
const QStringList &list )
00113 {
00114
QPtrList<KoStyle> orderStyle;
00115
QStringList lst( list );
00116
for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
00117 {
00118
00119
QPtrListIterator<KoStyle> style( m_styleList );
00120
for ( ; style.current() ; ++style )
00121 {
00122
if ( style.current()->name() == *it)
00123 {
00124 orderStyle.append( style.current() );
00125
00126
break;
00127 }
00128 }
00129 }
00130 m_styleList.setAutoDelete(
false );
00131 m_styleList.clear();
00132 m_styleList = orderStyle;
00133
#if 0
00134
QPtrListIterator<KoStyle> style( m_styleList );
00135
for ( ; style.current() ; ++style )
00136 {
00137 kdDebug()<<
" style.current()->name() :"<<style.current()->name()<<endl;
00138 }
00139
#endif
00140
}
00141
00143
00144 KoCharStyle::KoCharStyle(
const QString & name )
00145 {
00146 m_name = name;
00147 m_shortCut_name = QString::null;
00148 }
00149
00150
void KoCharStyle::operator=(
const KoCharStyle &rhs )
00151 {
00152 m_name = rhs.m_name;
00153 m_shortCut_name = rhs.m_shortCut_name;
00154 m_format = rhs.m_format;
00155 }
00156
00157
QString KoCharStyle::translatedName()
const
00158
{
00159
return i18n(
"Style name", name().utf8() );
00160 }
00161
00162
const KoTextFormat & KoCharStyle::format()
const
00163
{
00164
return m_format;
00165 }
00166
00167
KoTextFormat & KoCharStyle::format()
00168 {
00169
return m_format;
00170 }
00171
00173
00174 KoStyle::KoStyle(
const QString & name )
00175 : KoCharStyle( name )
00176 {
00177 m_name = name;
00178 m_shortCut_name = QString::null;
00179 m_followingStyle =
this;
00180
00181
00182 m_paragLayout.
style =
this;
00183 m_parentStyle = 0L;
00184 m_inheritedParagLayoutFlag = 0;
00185 m_inheritedFormatFlag = 0;
00186 m_bOutline =
false;
00187 }
00188
00189 KoStyle::KoStyle(
const KoStyle & rhs )
00190 : KoCharStyle( rhs)
00191 {
00192 *
this = rhs;
00193 }
00194
00195
void KoStyle::operator=(
const KoStyle &rhs )
00196 {
00197 KoCharStyle::operator=( rhs );
00198 m_paragLayout = rhs.
m_paragLayout;
00199 m_name = rhs.m_name;
00200 m_shortCut_name = rhs.m_shortCut_name;
00201 m_followingStyle = rhs.
m_followingStyle;
00202 m_paragLayout.
style =
this;
00203 m_parentStyle = rhs.
m_parentStyle;
00204 m_inheritedParagLayoutFlag = rhs.
m_inheritedParagLayoutFlag;
00205 m_inheritedFormatFlag = rhs.
m_inheritedFormatFlag;
00206 m_bOutline = rhs.
m_bOutline;
00207 }
00208
00209
void KoStyle::saveStyle(
QDomElement & parentElem )
00210 {
00211 m_paragLayout.
saveParagLayout( parentElem, m_paragLayout.
alignment );
00212
00213
if ( followingStyle() )
00214 {
00215
QDomElement element = parentElem.ownerDocument().createElement(
"FOLLOWING" );
00216 parentElem.appendChild( element );
00217 element.setAttribute(
"name", followingStyle()->name() );
00218 }
00219
00220
00221 parentElem.setAttribute(
"outline", m_bOutline ?
"true" :
"false" );
00222 }
00223
00224
void KoStyle::loadStyle(
QDomElement & parentElem,
int docVersion )
00225 {
00226
KoParagLayout layout;
00227
KoParagLayout::loadParagLayout( layout, parentElem, docVersion );
00228
00229
00230 layout.
style =
this;
00231 m_paragLayout = layout;
00232
00233
00234
QDomElement nameElem = parentElem.namedItem(
"NAME").toElement();
00235
if ( !nameElem.isNull() )
00236 m_name = nameElem.attribute(
"value");
00237
else
00238 kdWarning() <<
"No NAME tag in LAYOUT -> no name for this style!" << endl;
00239
00240
00241
00242 m_bOutline = parentElem.attribute(
"outline" ) ==
"true";
00243 }
00244
00245
00246
00247
const KoParagLayout & KoStyle::paragLayout()
const
00248
{
00249
return m_paragLayout;
00250 }
00251
00252
KoParagLayout & KoStyle::paragLayout()
00253 {
00254
return m_paragLayout;
00255 }
00256
00257
void KoStyle::propagateChanges(
int paragLayoutFlag,
int )
00258 {
00259
if ( !m_parentStyle )
00260
return;
00261
if ( !(paragLayoutFlag & KoParagLayout::Alignment) )
00262 m_paragLayout.
alignment = m_parentStyle->
paragLayout().
alignment;
00263
if ( !(paragLayoutFlag & KoParagLayout::Margins) )
00264
for (
int i = 0 ; i < 5 ; ++i )
00265 m_paragLayout.
margins[i] = m_parentStyle->
paragLayout().
margins[i];
00266
if ( !(paragLayoutFlag & KoParagLayout::LineSpacing) )
00267 {
00268 m_paragLayout.
setLineSpacingValue(m_parentStyle->
paragLayout().
lineSpacingValue());
00269 m_paragLayout.
lineSpacingType = m_parentStyle->
paragLayout().
lineSpacingType;
00270 }
00271
if ( !(paragLayoutFlag & KoParagLayout::Borders) )
00272 {
00273 m_paragLayout.
leftBorder = m_parentStyle->
paragLayout().
leftBorder;
00274 m_paragLayout.
rightBorder = m_parentStyle->
paragLayout().
rightBorder;
00275 m_paragLayout.
topBorder = m_parentStyle->
paragLayout().
topBorder;
00276 m_paragLayout.
bottomBorder = m_parentStyle->
paragLayout().
bottomBorder;
00277 }
00278
if ( !(paragLayoutFlag & KoParagLayout::BulletNumber) )
00279 m_paragLayout.
counter = m_parentStyle->
paragLayout().
counter;
00280
if ( !(paragLayoutFlag & KoParagLayout::Tabulator) )
00281 m_paragLayout.
setTabList(m_parentStyle->
paragLayout().
tabList());
00282
#if 0
00283
if ( paragLayoutFlag == KoParagLayout::All )
00284 {
00285 setDirection( static_cast<QChar::Direction>(layout.direction) );
00286
00287 setStyle( layout.style );
00288 }
00289
#endif
00290
00291
00292 }
00293
00294
void KoStyle::setOutline(
bool b )
00295 {
00296 m_bOutline = b;
00297 }