kpresenter

KPrTextDocument.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2001 Laurent Montel <lmontel@mandrakesoft.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrTextDocument.h"
00022 
00023 #include "KPrDocument.h"
00024 #include "KPrTextObject.h"
00025 #include <KoTextParag.h>
00026 #include <kdebug.h>
00027 
00028 #include "KPrVariableCollection.h"
00029 
00030 #include <KoOasisContext.h>
00031 #include <KoDom.h>
00032 #include <KoXmlNS.h>
00033 
00034 KPrTextDocument::KPrTextDocument( KPrTextObject * textobj, KoTextFormatCollection *fc, KoTextFormatter *formatter )
00035     : KoTextDocument( textobj->kPresenterDocument()->zoomHandler(), fc, formatter, true ), m_textobj( textobj )
00036 {
00037     //kdDebug(33001) << "KPrTextDocument constructed " << this << "  KPrTextObject:" << textobj << endl;
00038 }
00039 
00040 KPrTextDocument::~KPrTextDocument()
00041 {
00042 }
00043 
00044 
00045 bool KPrTextDocument::loadSpanTag( const QDomElement& tag, KoOasisContext& context,
00046                                   KoTextParag* parag, uint pos,
00047                                   QString& textData, KoTextCustomItem* & customItem )
00048 {
00049     const QString localName( tag.localName() );
00050     const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
00051     kdDebug( 32500 ) << "KPrTextDocument::loadSpanTag: " << localName << endl;
00052 
00053     if ( isTextNS )
00054     {
00055         if ( localName == "a" )
00056         {
00057             QString href( tag.attributeNS( KoXmlNS::xlink, "href", QString::null ) );
00058             if ( href.startsWith( "#" ) )
00059             {
00060                 context.styleStack().save();
00061                 // We have a reference to a bookmark (### TODO)
00062                 // As we do not support it now, treat it as a <span> without formatting
00063                 parag->loadOasisSpan( tag, context, pos ); // recurse
00064                 context.styleStack().restore();
00065             }
00066             else
00067             {
00068                 // The text is contained in a <span> inside the <a> element. In theory
00069                 // we could have multiple spans there, but OO ensures that there is always only one,
00070                 // splitting the hyperlink if necessary (at format changes).
00071                 // Note that we ignore the formatting of the span.
00072                 QDomElement spanElem = KoDom::namedItemNS( tag, KoXmlNS::text, "span" );
00073                 QString text;
00074                 if ( spanElem.isNull() )
00075                     text = tag.text();
00076                 if ( spanElem.isNull() )
00077                     text = tag.text();
00078                 else {
00079                     // The save/restore of the stack is done by the caller (KoTextParag::loadOasisSpan)
00080                     // This allows to use the span's format for the variable.
00081                     //kdDebug(32500) << "filling stack with " << spanElem.attributeNS( KoXmlNS::text, "style-name", QString::null ) << endl;
00082                     context.fillStyleStack( spanElem, KoXmlNS::text, "style-name", "text" );
00083                     text = spanElem.text();
00084                 }
00085                 textData = KoTextObject::customItemChar(); // hyperlink placeholder
00086                 // unused tag.attributeNS( KoXmlNS::office, "name", QString::null )
00087                 KoVariableCollection& coll = context.variableCollection();
00088                 customItem = new KoLinkVariable( this, text, href,
00089                         coll.formatCollection()->format( "STRING" ),
00090                         &coll );
00091             }
00092             return true;
00093         }
00094     }
00095     else // non "text:" tags
00096     {
00097         kdDebug()<<"Extension found tagName : "<< localName <<endl;
00098     }
00099     return false;
00100 }
00101 
00102 
00103 #include "KPrTextDocument.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys