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 tagName( tag.tagName() );
00050     const bool textFoo = tagName.startsWith( "text:" );
00051     kdDebug() << "KWTextDocument::loadSpanTag: " << tagName << endl;
00052 
00053     if ( textFoo )
00054     {
00055         if ( tagName == "text: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 <text: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 text:span inside the text: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                 else {
00077                     // The save/restore of the stack is done by the caller (KoTextParag::loadOasisSpan)
00078                     // This allows to use the span's format for the variable.
00079                     //kdDebug(32500) << "filling stack with " << spanElem.attributeNS( KoXmlNS::text, "style-name", QString::null ) << endl;
00080                     context.fillStyleStack( spanElem, KoXmlNS::text, "style-name", "text" );
00081                     text = spanElem.text();
00082                 }
00083                 textData = '#'; // hyperlink placeholder
00084                 // unused tag.attributeNS( KoXmlNS::office, "name", QString::null )
00085                 KoVariableCollection& coll = context.variableCollection();
00086                 customItem = new KoLinkVariable( this, text, href,
00087                                                  coll.formatCollection()->format( "STRING" ),
00088                                                  &coll );
00089             }
00090             return true;
00091         }
00092     }
00093     else // non "text:" tags
00094         {
00095             kdDebug()<<"Extension found tagName : "<<tagName<<endl;
00096         }
00097     return false;
00098 }
00099 
00100 
00101 #include "KPrTextDocument.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys