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

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 "KPrEndOfSlideShowPage.h"
0021 
0022 #include <klocalizedstring.h>
0023 
0024 #include <KoShapeLayer.h>
0025 #include <KoShapeFactoryBase.h>
0026 #include <KoShapeRegistry.h>
0027 #include <KoColorBackground.h>
0028 #include <KoTextShapeData.h>
0029 
0030 #include <QTextCursor>
0031 #include <QTextDocument>
0032 
0033 #include "KPrDocument.h"
0034 #include "KPrMasterPage.h"
0035 #include "StageDebug.h"
0036 
0037 KPrEndOfSlideShowPage::KPrEndOfSlideShowPage( const QRectF & screenRect, KPrDocument * document )
0038 : KPrPage(new KPrMasterPage(document), document)
0039 {
0040     qreal ratio = screenRect.width() / screenRect.height();
0041     KoPageLayout pageLayout;
0042     pageLayout.height = 510;
0043 
0044     pageLayout.width = 510 * ratio;
0045     pageLayout.leftMargin = 0;
0046     pageLayout.rightMargin = 0;
0047     pageLayout.topMargin = 0;
0048     pageLayout.bottomMargin = 0;
0049     pageLayout.orientation = screenRect.width() > screenRect.height() ? KoPageFormat::Landscape : KoPageFormat::Portrait;
0050     pageLayout.bindingSide = 0;
0051     pageLayout.pageEdge = 0;
0052     pageLayout.format = KoPageFormat::IsoA3Size; 
0053 
0054     masterPage()->setPageLayout( pageLayout );
0055     masterPage()->setBackground( QSharedPointer<KoColorBackground>( new KoColorBackground( Qt::black ) ) );
0056 
0057     KoShapeLayer* layer = new KoShapeLayer;
0058     addShape( layer );
0059 
0060     KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value( "TextShapeID" );
0061     Q_ASSERT( factory );
0062     if ( factory ) {
0063         KoShape * textShape = factory->createDefaultShape();
0064         QTextDocument * document = qobject_cast<KoTextShapeData*>( textShape->userData() )->document();
0065         QTextCursor cursor( document );
0066         QTextCharFormat format;
0067         format.setForeground( QBrush( Qt::white ) );
0068         cursor.mergeCharFormat( format );
0069         cursor.insertText( i18n("End of presentation. Click to exit." ) );
0070         textShape->setPosition( QPointF( 10.0, 10.0 ) );
0071         textShape->setSize( QSizeF( pageLayout.width - 20.0, pageLayout.height - 20.0 ) );
0072         layer->addShape( textShape );
0073     } else {
0074         warnStage << "text shape factory not found";
0075     }
0076 }
0077 
0078 KPrEndOfSlideShowPage::~KPrEndOfSlideShowPage()
0079 {
0080     delete masterPage();
0081 }
0082