Back to index

scribus-ng  1.3.4.dfsg+svn20071115
sctext_shared.cpp
Go to the documentation of this file.
00001 //FIXME: this include must go to sctextstruct.h !
00002 #include <qvaluelist.h>
00003 #include <cassert>  //added to make Fedora-5 happy
00004 #include "fpoint.h"
00005 #include "scfonts.h"
00006 #include "scribusdoc.h"
00007 #include "sctext_shared.h"
00008 // #include "storytext.moc"
00009 #include "scribus.h"
00010 #include "util.h"
00011 
00012 ScText_Shared::ScText_Shared(const StyleContext* pstyles) : QPtrList<ScText>(), 
00013        defaultStyle(), 
00014        pstyleContext(NULL),
00015        refs(1), len(0), trailingStyle()
00016 {
00017        pstyleContext.setDefaultStyle( & defaultStyle );
00018        setAutoDelete(true);
00019        defaultStyle.setContext( pstyles );
00020        trailingStyle.setContext( &pstyleContext );
00021 //            defaultStyle.charStyle().setContext( cstyles );
00022 //            qDebug(QString("ScText_Shared() %1 %2 %3 %4").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&defaultStyle)).arg(reinterpret_cast<uint>(pstyles)).arg(reinterpret_cast<uint>(cstyles)));
00023 }
00024               
00025 
00026 ScText_Shared::ScText_Shared(const ScText_Shared& other) : QPtrList<ScText>(), 
00027        defaultStyle(other.defaultStyle), 
00028        pstyleContext(other.pstyleContext),
00029        refs(1), len(0), trailingStyle(other.trailingStyle)
00030 {
00031        pstyleContext.setDefaultStyle( &defaultStyle );
00032        trailingStyle.setContext( &pstyleContext );
00033        setAutoDelete(true); 
00034        QPtrListIterator<ScText> it( other );
00035        ScText* elem;
00036        while ( (elem = it.current()) != NULL ) {
00037               ++it;
00038               ScText* elem2 = new ScText(*elem);
00039               append(elem2);
00040               if (elem2->parstyle) {
00041                      elem2->parstyle->setContext( & pstyleContext);
00042 //                          elem2->parstyle->charStyle().setContext( defaultStyle.charStyleContext() );
00043                      replaceCharStyleContextInParagraph(count()-1, elem2->parstyle->charStyleContext());
00044               }
00045        }
00046        len = count();
00047        replaceCharStyleContextInParagraph(len,  trailingStyle.charStyleContext() );
00048 //            qDebug(QString("ScText_Shared(%2) %1").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&other)));
00049 }
00050 
00051 ScText_Shared& ScText_Shared::operator= (const ScText_Shared& other) 
00052 {
00053        if (this != &other) 
00054        {
00055               defaultStyle = other.defaultStyle;
00056               trailingStyle = other.trailingStyle;
00057               pstyleContext = other.pstyleContext;
00058               pstyleContext.setDefaultStyle( &defaultStyle );
00059               defaultStyle.setContext( other.defaultStyle.context() );
00060               trailingStyle.setContext( &pstyleContext );
00061               clear();
00062               QPtrListIterator<ScText> it( other );
00063               ScText* elem;
00064               while ( (elem = it.current()) != NULL ) {
00065                      ++it;
00066                      ScText* elem2 = new ScText(*elem);
00067                      append(elem2);
00068                      if (elem2->parstyle) {
00069                             elem2->parstyle->setContext( & pstyleContext );
00070 //                                 qDebug(QString("StoryText::copy: * %1 align=%2").arg(elem2->parstyle->parent())
00071 //                                           .arg(elem2->parstyle->alignment())
00072 //                                           .arg((uint)elem2->parstyle->context()));
00073                                    //                          elem2->parstyle->charStyle().setContext( defaultStyle.charStyleContext() );
00074                             replaceCharStyleContextInParagraph(count()-1, elem2->parstyle->charStyleContext());
00075                      }
00076               }
00077               len = count();
00078               pstyleContext.invalidate();
00079 //                   qDebug(QString("StoryText::copy: %1 align=%2 %3").arg(trailingStyle.parentStyle()->name())
00080 //                             .arg(trailingStyle.alignment()).arg((uint)trailingStyle.context()));
00081               replaceCharStyleContextInParagraph(len,  trailingStyle.charStyleContext());
00082        }
00083 //                   qDebug(QString("ScText_Shared: %1 = %2").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(&other)));
00084        return *this;
00085 }
00086 
00087 ScText_Shared::~ScText_Shared() {
00088 //            qDebug(QString("~ScText_Shared() %1").arg(reinterpret_cast<uint>(this)));
00089 }
00090 
00096 void ScText_Shared::replaceCharStyleContextInParagraph(int pos, const StyleContext* newContext)
00097 {
00098        QPtrListIterator<ScText> it( *this );
00099        it += pos;    
00100        ScText* elem = it.current();
00101        if (elem)
00102               elem->setContext(newContext);
00103        --it;
00104        while ( (elem = it.current()) != NULL ) {
00105               if (elem->ch[0] == SpecialChars::PARSEP)
00106                      break;
00107               elem->setContext(newContext);
00108               --it;
00109        }
00110        // assert that all chars point to the following parstyle
00111        QPtrListIterator<ScText> test( *this );
00112        const StyleContext* lastContext = NULL;
00113        while ( (elem = it.current()) != NULL ) {
00114               if ( elem->ch.isEmpty() ) 
00115               {
00116                      // nothing, see code in removeParSep
00117               }
00118               else if (elem->ch[0] == SpecialChars::PARSEP)
00119               {
00120                      assert( elem->parstyle );
00121                      if ( lastContext )
00122                             assert( lastContext == elem->parstyle->charStyleContext() );
00123                      lastContext = NULL;
00124               }
00125               else if (lastContext == NULL)
00126               {
00127                      lastContext = elem->context();
00128               }
00129               else 
00130               {
00131                      assert( lastContext == elem->context() );
00132               }
00133               ++it;
00134        }
00135        if ( lastContext )
00136               assert( lastContext == trailingStyle.charStyleContext() );
00137 }
00138