kpresenter

KPrNoteBar.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 
00022 #include <qlayout.h>
00023 #include <qpainter.h>
00024 #include <qpaintdevicemetrics.h>
00025 #include <qsimplerichtext.h>
00026 #include <qlabel.h>
00027 
00028 #include <kglobalsettings.h>
00029 #include <kprinter.h>
00030 #include <kdebug.h>
00031 #include <ktextedit.h>
00032 #include <klocale.h>
00033 
00034 #include "KPrNoteBar.h"
00035 #include "KPrView.h"
00036 #include "KPrDocument.h"
00037 #include "KPrPage.h"
00038 
00039 
00040 KPrNoteBar::KPrNoteBar( QWidget *_parent, KPrView *_view )
00041     : QWidget( _parent ),
00042       view( _view ),
00043       initialize( true )
00044 {
00045     QBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
00046 
00047     label = new QLabel(i18n("Note"), this);
00048 
00049     textEdit = new KTextEdit( this );
00050 
00051     QFont font = KoGlobal::defaultFont();
00052     textEdit->setCurrentFont( font );
00053 
00054     int currentPageNum = view->getCurrentPresPage(); // 1 base.
00055     QString text=QString::null;
00056     if (currentPageNum!=-1)
00057         text = view->kPresenterDoc()->pageList().at(currentPageNum - 1)->noteText( );
00058     textEdit->setText( text );
00059 
00060     connect( textEdit, SIGNAL( textChanged() ),
00061              this, SLOT( slotTextChanged() ) );
00062 
00063     connect( textEdit, SIGNAL( selectionChanged() ),
00064              this, SLOT( slotSelectionChanged() ) );
00065 
00066     connect( textEdit, SIGNAL( copyAvailable( bool ) ),
00067              this, SLOT( slotSelectionChanged() ) );
00068 
00069     connect( textEdit, SIGNAL( undoAvailable( bool ) ),
00070              this, SLOT( slotUndoAvailable( bool ) ) );
00071 
00072     connect( textEdit, SIGNAL( redoAvailable( bool ) ),
00073              this, SLOT( slotRedoAvailable( bool ) ) );
00074 
00075     topLayout->addWidget( label );
00076     topLayout->addWidget( textEdit );
00077 }
00078 
00079 KPrNoteBar::~KPrNoteBar()
00080 {
00081     delete textEdit;
00082 }
00083 
00084 void KPrNoteBar::setCurrentNoteText( const QString &_text )
00085 {
00086     initialize = true;
00087     textEdit->setText( _text );
00088     initialize = false;
00089 }
00090 
00091 void KPrNoteBar::slotTextChanged()
00092 {
00093     int currentPageNum = view->getCurrPgNum(); // 1 base.
00094     if ( currentPageNum > 0 && !initialize ) {
00095         if ( view->editMaster() )
00096             view->kPresenterDoc()->refreshAllNoteBarMasterPage(textEdit->text() , view);
00097         else
00098             view->kPresenterDoc()->refreshAllNoteBar(currentPageNum -1,textEdit->text() , view);
00099         textEdit->setModified( true );
00100     }
00101 }
00102 
00103 void KPrNoteBar::slotSelectionChanged()
00104 {
00105     kdDebug(33001) << "slotSelectionChanged(): " << textEdit->hasSelectedText() << endl;
00106 }
00107 
00108 void KPrNoteBar::slotCopyAvailable( bool yes )
00109 {
00110     kdDebug(33001) << "slotCopyAvailable( " << yes << " )" << endl;
00111 }
00112 
00113 void KPrNoteBar::slotUndoAvailable( bool /*yes*/ )
00114 {
00115     //kdDebug(33001) << "slotUndoAvailable( " << yes << " )" << endl;
00116 }
00117 
00118 void KPrNoteBar::slotRedoAvailable( bool /*yes*/ )
00119 {
00120     //kdDebug(33001) << "slotRedoAvailable( " << yes << " )" << endl;
00121 }
00122 
00123 void KPrNoteBar::printNotes( QPainter *_painter, KPrinter *_printer, QValueList<int> _list )
00124 {
00125     // base code from $QTDIR/example/textedit/textedit.cpp
00126     _painter->save();
00127 
00128     QPaintDeviceMetrics metrics( _painter->device() );
00129     int dpix = metrics.logicalDpiX();
00130     int dpiy = metrics.logicalDpiY();
00131 
00132     const int margin = 72; // pt
00133     QRect body( margin * dpix / 72, margin * dpiy / 72,
00134                 metrics.width() - margin * dpix / 72 * 2,
00135                 metrics.height() - margin * dpiy / 72 * 2 );
00136 
00137     QFont font = KoGlobal::defaultFont();
00138     QString allText = getNotesTextForPrinting(_list);
00139     QString str = QStyleSheet::convertFromPlainText( allText );
00140 
00141     QSimpleRichText richText( str, font, QString::null, QStyleSheet::defaultSheet(),
00142                               QMimeSourceFactory::defaultFactory(), body.height() );
00143 
00144     richText.setWidth( _painter, body.width() );
00145 
00146     QRect viewRect( body );
00147     do {
00148         richText.draw( _painter, body.left(), body.top(), viewRect, colorGroup() );
00149         viewRect.moveBy( 0, body.height() );
00150         _painter->translate( 0, -body.height() );
00151         _painter->setFont( font );
00152 
00153         if ( viewRect.top() >= richText.height() )
00154             break;
00155 
00156         _printer->newPage();
00157     } while ( true );
00158 
00159     _painter->restore();
00160 }
00161 
00162 QString KPrNoteBar::getNotesTextForPrinting(QValueList<int> _list) const
00163 {
00164     QString allText = QString::null;
00165     bool firstText = true;
00166     bool noteIsEmpty = true;
00167     int pageCount = 1;
00168     KPrDocument *doc=view->kPresenterDoc();
00169     for ( int i = 0; i < static_cast<int>( doc->pageList().count() ); i++, ++pageCount )
00170     {
00171         if (_list.contains(i+1)==0) // that slide isn't printed, don't print its note either
00172             continue;
00173 
00174         if ( !firstText )
00175             allText += QString("\n\n");
00176 
00177         allText += i18n( "Slide Note %1:\n" ).arg( pageCount );
00178         if(noteIsEmpty && !doc->pageList().at(i)->noteText().isEmpty())
00179             noteIsEmpty = false;
00180         allText += doc->pageList().at(i)->noteText();
00181 
00182         firstText = false;
00183     }
00184     //code for master page
00185     if ( !firstText )
00186         allText += QString("\n\n");
00187     allText += i18n( "Master Page Note:\n" );
00188     if ( !doc->masterPage()->noteText().isEmpty() )
00189          noteIsEmpty = false;
00190     allText += doc->masterPage()->noteText();
00191 
00192     if( noteIsEmpty )
00193         return QString::null;
00194     return allText;
00195 }
00196 
00197 #include "KPrNoteBar.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys