File indexing completed on 2024-05-12 16:36:46
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Fredy Yanardi <fyanardi@gmail.com> 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 "KPrPresenterViewInterface.h" 0021 0022 #include <QBoxLayout> 0023 #include <QFrame> 0024 #include <QLabel> 0025 #include <QKeyEvent> 0026 #include <QPainter> 0027 #include <QTextEdit> 0028 #include <QToolButton> 0029 0030 #include <klocalizedstring.h> 0031 0032 #include <KoPACanvas.h> 0033 #include <KoPAPageBase.h> 0034 #include <KoShape.h> 0035 #include <KoTextShapeData.h> 0036 0037 #include "StageDebug.h" 0038 #include "KPrEndOfSlideShowPage.h" 0039 #include "KPrNotes.h" 0040 #include "KPrPage.h" 0041 0042 KPrPresenterViewInterface::KPrPresenterViewInterface( const QList<KoPAPageBase *> &pages, KoPACanvas *canvas, QWidget *parent ) 0043 : KPrPresenterViewBaseInterface( pages, parent ) 0044 , m_canvas( canvas ) 0045 { 0046 QVBoxLayout *vLayout = new QVBoxLayout; 0047 QHBoxLayout *hLayout = new QHBoxLayout; 0048 0049 QFrame *frame = new QFrame; 0050 QVBoxLayout *frameLayout = new QVBoxLayout; 0051 m_currentSlideLabel = new QLabel; 0052 frameLayout->addWidget( m_currentSlideLabel, 0, Qt::AlignHCenter ); 0053 frameLayout->addWidget( m_canvas ); 0054 frameLayout->addStretch(); 0055 frame->setLayout( frameLayout ); 0056 0057 hLayout->addWidget( frame ); 0058 hLayout->addStretch(); 0059 0060 frame = new QFrame; 0061 frameLayout = new QVBoxLayout; 0062 m_nextSlideLabel = new QLabel( i18n( "Next Slide" ) ); 0063 m_nextSlidePreview = new QLabel; 0064 frameLayout->addWidget( m_nextSlideLabel, 0, Qt::AlignHCenter ); 0065 frameLayout->addWidget( m_nextSlidePreview ); 0066 frameLayout->addStretch(); 0067 frame->setLayout( frameLayout ); 0068 hLayout->addWidget( frame ); 0069 0070 vLayout->addLayout( hLayout ); 0071 0072 vLayout->addWidget( new QLabel( i18n( "Speaker Notes") ) ); 0073 m_notesTextEdit = new QTextEdit; 0074 m_notesTextEdit->setReadOnly( true ); 0075 vLayout->addWidget( m_notesTextEdit ); 0076 0077 setLayout( vLayout ); 0078 } 0079 0080 void KPrPresenterViewInterface::setActivePage( int pageIndex ) 0081 { 0082 KPrPresenterViewBaseInterface::setActivePage( pageIndex ); 0083 0084 Q_ASSERT(pageIndex >= 0 && pageIndex < m_pages.size()); 0085 KoPAPageBase *page = m_pages.at( pageIndex ); 0086 int pageCount = dynamic_cast<KPrEndOfSlideShowPage *>( m_pages.last() ) ? 0087 m_pages.count() - 1 : m_pages.count(); 0088 0089 // set the thumbnail for next page preview 0090 KoPAPageBase *nextPage = 0; 0091 if ( pageIndex != pageCount ) { 0092 nextPage = m_pages.at( pageIndex + 1 ); 0093 m_nextSlidePreview->setPixmap( nextPage->thumbnail( m_previewSize ) ); 0094 } 0095 else { // End of presentation, just a black pixmap for the next slide preview 0096 QPixmap pixmap( m_previewSize ); 0097 pixmap.fill( Qt::black ); 0098 m_nextSlidePreview->setPixmap( pixmap ); 0099 } 0100 0101 // update the label 0102 m_currentSlideLabel->setText( pageIndex != pageCount ? 0103 i18n( "Current Slide %1 of %2", pageIndex + 1, pageCount ) : 0104 i18n( "End of Slide Show" ) ); 0105 0106 // set the presentation notes 0107 KPrPage *prPage = dynamic_cast<KPrPage *>( page ); 0108 Q_ASSERT( prPage ); 0109 KPrNotes *pageNotes = prPage->pageNotes(); 0110 KoShape *textShape = pageNotes->textShape(); 0111 KoTextShapeData *textShapeData = qobject_cast<KoTextShapeData *>( textShape->userData() ); 0112 Q_ASSERT( textShapeData ); 0113 QTextDocument *document = textShapeData->document()->clone( m_notesTextEdit ); 0114 m_notesTextEdit->setDocument( document ); 0115 } 0116 0117 void KPrPresenterViewInterface::setPreviewSize( const QSize &size ) 0118 { 0119 m_previewSize = size; 0120 m_canvas->setFixedSize( size ); 0121 0122 // set the thumbnail for next page preview 0123 Q_ASSERT( m_activePage != -1 ); 0124 KoPAPageBase *nextPage = 0; 0125 if ( m_activePage != m_pages.count() - 1 ) { 0126 nextPage = m_pages.at( m_activePage + 1 ); 0127 } 0128 else { 0129 nextPage = m_pages.at( m_activePage ); 0130 } 0131 m_nextSlidePreview->setPixmap( nextPage->thumbnail( m_previewSize ) ); 0132 }