File indexing completed on 2024-05-12 16:36:45

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (  at your option ) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KPrPlaceholderShapeFactory.h"
0021 
0022 #include <klocalizedstring.h>
0023 
0024 #include <KoXmlNS.h>
0025 #include <KoOdfWorkaround.h>
0026 #include <KoShapeLoadingContext.h>
0027 
0028 #include "KPrPlaceholderShape.h"
0029 #include "StageDebug.h"
0030 
0031 KPrPlaceholderShapeFactory::KPrPlaceholderShapeFactory()
0032 : KoShapeFactoryBase(KPrPlaceholderShapeId, i18n( "Placeholder shape" ) )
0033 {
0034     QStringList elementNames;
0035     elementNames << "text-box" << "object" << "image";
0036     setXmlElementNames( KoXmlNS::draw, elementNames );
0037     // use a really high number as we want to be used before the normal shapes try to load it
0038     setLoadingPriority( 1000 );
0039     setHidden(true);
0040 }
0041 
0042 KPrPlaceholderShapeFactory::~KPrPlaceholderShapeFactory()
0043 {
0044 }
0045 
0046 KoShape *KPrPlaceholderShapeFactory::createDefaultShape(KoDocumentResourceManager *) const
0047 {
0048     return new KPrPlaceholderShape();
0049 }
0050 
0051 bool KPrPlaceholderShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const
0052 {
0053     Q_UNUSED(context);
0054     // check parent if placeholder is set to true
0055     KoXmlNode parent = e.parentNode();
0056     if ( !parent.isNull() ) {
0057         KoXmlElement element = parent.toElement();
0058         if ( !element.isNull() ) {
0059             bool supported =  element.attributeNS( KoXmlNS::presentation, "placeholder", "false" ) == "true";
0060             debugStage << "placeholder:" << supported;
0061 #ifndef NWORKAROUND_ODF_BUGS
0062             if (!supported && KoOdfWorkaround::fixPresentationPlaceholder() && element.hasAttributeNS(KoXmlNS::presentation, "class")) {
0063                 supported = true;
0064                 debugStage << "workaround OO placeholder bug" << supported;
0065             }
0066 #endif
0067             return supported;
0068         }
0069     }
0070     return false;
0071 }