Warning, file /office/calligra/libs/pageapp/KoPAMasterPage.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006-2009 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 "KoPAMasterPage.h"
0021 
0022 #include <QBuffer>
0023 #include <QPainter>
0024 
0025 #include <KoShapePainter.h>
0026 #include <KoGenStyle.h>
0027 #include <KoGenStyles.h>
0028 #include <KoXmlWriter.h>
0029 #include <KoXmlNS.h>
0030 #include <KoOdfStylesReader.h>
0031 #include <KoOdfLoadingContext.h>
0032 #include <KoZoomHandler.h>
0033 #include <KoShapePaintingContext.h>
0034 
0035 #include "KoPASavingContext.h"
0036 #include "KoPALoadingContext.h"
0037 #include "KoPAPixmapCache.h"
0038 
0039 KoPAMasterPage::KoPAMasterPage()
0040 : KoPAPageBase()
0041 {
0042     setName( "Standard" );
0043 }
0044 
0045 KoPAMasterPage::~KoPAMasterPage()
0046 {
0047 }
0048 
0049 void KoPAMasterPage::saveOdf( KoShapeSavingContext & context ) const
0050 {
0051     KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );
0052 
0053     KoGenStyle pageLayoutStyle = pageLayout().saveOdf();
0054     pageLayoutStyle.setAutoStyleInStylesDotXml( true );
0055     pageLayoutStyle.addAttribute( "style:page-usage", "all" );
0056     QString pageLayoutName( paContext.mainStyles().insert( pageLayoutStyle, "pm" ) );
0057 
0058     KoGenStyle pageMaster( KoGenStyle::MasterPageStyle );
0059     pageMaster.addAttribute( "style:page-layout-name", pageLayoutName );
0060     pageMaster.addAttribute( "style:display-name", name() );
0061     pageMaster.addAttribute( "draw:style-name", saveOdfPageStyle( paContext ) );
0062 
0063     KoXmlWriter &savedWriter = paContext.xmlWriter();
0064 
0065     QBuffer buffer;
0066     buffer.open( QIODevice::WriteOnly );
0067     KoXmlWriter xmlWriter( &buffer );
0068 
0069     paContext.setXmlWriter( xmlWriter );
0070 
0071     saveOdfPageContent( paContext );
0072 
0073     paContext.setXmlWriter( savedWriter );
0074 
0075     QString contentElement = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
0076     pageMaster.addChildElement( paContext.masterPageElementName(), contentElement );
0077     paContext.addMasterPage( this, paContext.mainStyles().insert( pageMaster, "Default" ) );
0078 }
0079 
0080 void KoPAMasterPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
0081 {
0082     KoPAPageBase::loadOdfPageTag( element, loadingContext );
0083     if ( element.hasAttributeNS( KoXmlNS::style, "display-name" ) ) {
0084         setName( element.attributeNS( KoXmlNS::style, "display-name" ) );
0085     }
0086     else {
0087         setName( element.attributeNS( KoXmlNS::style, "name" ) );
0088     }
0089     QString pageLayoutName = element.attributeNS( KoXmlNS::style, "page-layout-name" );
0090     const KoOdfStylesReader& styles = loadingContext.odfLoadingContext().stylesReader();
0091     const KoXmlElement* masterPageStyle = styles.findStyle( pageLayoutName );
0092     KoPageLayout pageLayout;
0093 
0094     if ( masterPageStyle ) {
0095         pageLayout.loadOdf( *masterPageStyle );
0096     }
0097 
0098     setPageLayout( pageLayout );
0099 }
0100 
0101 bool KoPAMasterPage::displayMasterShapes()
0102 {
0103     return false;
0104 }
0105 
0106 void KoPAMasterPage::setDisplayMasterShapes( bool display )
0107 {
0108     Q_UNUSED( display );
0109 }
0110 
0111 bool KoPAMasterPage::displayMasterBackground()
0112 {
0113     return false;
0114 }
0115 
0116 void KoPAMasterPage::setDisplayMasterBackground( bool display )
0117 {
0118     Q_UNUSED( display );
0119 }
0120 
0121 bool KoPAMasterPage::displayShape(KoShape *shape) const
0122 {
0123     Q_UNUSED(shape);
0124     return true;
0125 }
0126 
0127 void KoPAMasterPage::pageUpdated()
0128 {
0129     KoPAPageBase::pageUpdated();
0130     // TODO that is not the best way as it removes to much from the cache
0131     KoPAPixmapCache::instance()->clear( false );
0132 }
0133 
0134 void KoPAMasterPage::paintPage( QPainter & painter, KoZoomHandler & zoomHandler )
0135 {
0136     KoShapePaintingContext context;
0137     paintBackground( painter, zoomHandler, context );
0138 
0139     KoShapePainter shapePainter;
0140     shapePainter.setShapes( shapes() );
0141     shapePainter.paint(painter, zoomHandler);
0142 }