File indexing completed on 2024-05-12 16:36:44
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 "KPrPlaceholderShape.h" 0021 0022 #include <QPainter> 0023 #include <QTextOption> 0024 #include <KoShapeSavingContext.h> 0025 #include <KoViewConverter.h> 0026 #include <KoXmlWriter.h> 0027 #include <KoOdfWorkaround.h> 0028 0029 #include "KPrPlaceholderStrategy.h" 0030 0031 KPrPlaceholderShape::KPrPlaceholderShape() 0032 : m_strategy( 0 ) 0033 { 0034 } 0035 0036 KPrPlaceholderShape::KPrPlaceholderShape( const QString & presentationClass ) 0037 : m_strategy( 0 ) 0038 { 0039 m_strategy = KPrPlaceholderStrategy::create( presentationClass ); 0040 } 0041 0042 KPrPlaceholderShape::~KPrPlaceholderShape() 0043 { 0044 delete m_strategy; 0045 } 0046 0047 void KPrPlaceholderShape::paint( QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) 0048 { 0049 QRectF rect( QPointF( 0, 0 ), size() ); 0050 if ( m_strategy ) { 0051 m_strategy->paint( painter, converter, rect, paintcontext); 0052 } 0053 else { 0054 applyConversion( painter, converter ); 0055 QPen pen(Qt::gray, 0); 0056 pen.setStyle( Qt::DashLine ); 0057 painter.setPen( pen ); 0058 painter.drawRect( rect ); 0059 } 0060 } 0061 0062 bool KPrPlaceholderShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context ) 0063 { 0064 loadOdfAttributes(element, context, OdfAdditionalAttributes); 0065 0066 #ifndef NWORKAROUND_ODF_BUGS 0067 KoOdfWorkaround::fixPresentationPlaceholder(this); 0068 #endif 0069 delete m_strategy; 0070 0071 m_strategy = KPrPlaceholderStrategy::create( additionalAttribute( "presentation:class" ) ); 0072 if ( m_strategy == 0 ) { 0073 return false; 0074 } 0075 0076 // first check if we can create a placeholder before we load the attributes 0077 loadOdfAttributes(element, context, OdfMandatories | OdfTransformation | OdfGeometry | OdfCommonChildElements); 0078 m_strategy->loadOdf( element, context ); 0079 0080 return true; 0081 } 0082 0083 void KPrPlaceholderShape::saveOdf( KoShapeSavingContext & context ) const 0084 { 0085 KoXmlWriter & writer = context.xmlWriter(); 0086 writer.startElement( "draw:frame" ); 0087 saveOdfAttributes( context, OdfAllAttributes ); 0088 if ( m_strategy ) { 0089 m_strategy->saveOdf( context ); 0090 } 0091 saveOdfCommonChildElements( context ); 0092 writer.endElement(); // draw:frame 0093 } 0094 0095 KoShape *KPrPlaceholderShape::createShape(KoDocumentResourceManager *documentResources) 0096 { 0097 Q_ASSERT( m_strategy ); 0098 KoShape * shape = 0; 0099 if ( m_strategy ) { 0100 shape = m_strategy->createShape(documentResources); 0101 } 0102 return shape; 0103 } 0104 0105 void KPrPlaceholderShape::initStrategy(KoDocumentResourceManager *documentResources) 0106 { 0107 Q_ASSERT( m_strategy ); 0108 if ( m_strategy ) { 0109 m_strategy->init(documentResources); 0110 } 0111 } 0112 0113 KoShapeUserData * KPrPlaceholderShape::userData() const 0114 { 0115 Q_ASSERT( m_strategy ); 0116 return m_strategy ? m_strategy->userData() : 0; 0117 }