diff options
| author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
|---|---|---|
| committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
| commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
| tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kpresenter/KPrNoteBar.cpp | |
| download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip | |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpresenter/KPrNoteBar.cpp')
| -rw-r--r-- | kpresenter/KPrNoteBar.cpp | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/kpresenter/KPrNoteBar.cpp b/kpresenter/KPrNoteBar.cpp new file mode 100644 index 000000000..f44865f1f --- /dev/null +++ b/kpresenter/KPrNoteBar.cpp @@ -0,0 +1,197 @@ +// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*- +/* This file is part of the KDE project + Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + + +#include <qlayout.h> +#include <qpainter.h> +#include <qpaintdevicemetrics.h> +#include <qsimplerichtext.h> +#include <qlabel.h> + +#include <kglobalsettings.h> +#include <kprinter.h> +#include <kdebug.h> +#include <ktextedit.h> +#include <klocale.h> + +#include "KPrNoteBar.h" +#include "KPrView.h" +#include "KPrDocument.h" +#include "KPrPage.h" + + +KPrNoteBar::KPrNoteBar( QWidget *_parent, KPrView *_view ) + : QWidget( _parent ), + view( _view ), + initialize( true ) +{ + QBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() ); + + label = new QLabel(i18n("Note"), this); + + textEdit = new KTextEdit( this ); + + QFont font = KoGlobal::defaultFont(); + textEdit->setCurrentFont( font ); + + int currentPageNum = view->getCurrentPresPage(); // 1 base. + QString text=QString::null; + if (currentPageNum!=-1) + text = view->kPresenterDoc()->pageList().at(currentPageNum - 1)->noteText( ); + textEdit->setText( text ); + + connect( textEdit, SIGNAL( textChanged() ), + this, SLOT( slotTextChanged() ) ); + + connect( textEdit, SIGNAL( selectionChanged() ), + this, SLOT( slotSelectionChanged() ) ); + + connect( textEdit, SIGNAL( copyAvailable( bool ) ), + this, SLOT( slotSelectionChanged() ) ); + + connect( textEdit, SIGNAL( undoAvailable( bool ) ), + this, SLOT( slotUndoAvailable( bool ) ) ); + + connect( textEdit, SIGNAL( redoAvailable( bool ) ), + this, SLOT( slotRedoAvailable( bool ) ) ); + + topLayout->addWidget( label ); + topLayout->addWidget( textEdit ); +} + +KPrNoteBar::~KPrNoteBar() +{ + delete textEdit; +} + +void KPrNoteBar::setCurrentNoteText( const QString &_text ) +{ + initialize = true; + textEdit->setText( _text ); + initialize = false; +} + +void KPrNoteBar::slotTextChanged() +{ + int currentPageNum = view->getCurrPgNum(); // 1 base. + if ( currentPageNum > 0 && !initialize ) { + if ( view->editMaster() ) + view->kPresenterDoc()->refreshAllNoteBarMasterPage(textEdit->text() , view); + else + view->kPresenterDoc()->refreshAllNoteBar(currentPageNum -1,textEdit->text() , view); + textEdit->setModified( true ); + } +} + +void KPrNoteBar::slotSelectionChanged() +{ + kdDebug(33001) << "slotSelectionChanged(): " << textEdit->hasSelectedText() << endl; +} + +void KPrNoteBar::slotCopyAvailable( bool yes ) +{ + kdDebug(33001) << "slotCopyAvailable( " << yes << " )" << endl; +} + +void KPrNoteBar::slotUndoAvailable( bool /*yes*/ ) +{ + //kdDebug(33001) << "slotUndoAvailable( " << yes << " )" << endl; +} + +void KPrNoteBar::slotRedoAvailable( bool /*yes*/ ) +{ + //kdDebug(33001) << "slotRedoAvailable( " << yes << " )" << endl; +} + +void KPrNoteBar::printNotes( QPainter *_painter, KPrinter *_printer, QValueList<int> _list ) +{ + // base code from $QTDIR/example/textedit/textedit.cpp + _painter->save(); + + QPaintDeviceMetrics metrics( _painter->device() ); + int dpix = metrics.logicalDpiX(); + int dpiy = metrics.logicalDpiY(); + + const int margin = 72; // pt + QRect body( margin * dpix / 72, margin * dpiy / 72, + metrics.width() - margin * dpix / 72 * 2, + metrics.height() - margin * dpiy / 72 * 2 ); + + QFont font = KoGlobal::defaultFont(); + QString allText = getNotesTextForPrinting(_list); + QString str = QStyleSheet::convertFromPlainText( allText ); + + QSimpleRichText richText( str, font, QString::null, QStyleSheet::defaultSheet(), + QMimeSourceFactory::defaultFactory(), body.height() ); + + richText.setWidth( _painter, body.width() ); + + QRect viewRect( body ); + do { + richText.draw( _painter, body.left(), body.top(), viewRect, colorGroup() ); + viewRect.moveBy( 0, body.height() ); + _painter->translate( 0, -body.height() ); + _painter->setFont( font ); + + if ( viewRect.top() >= richText.height() ) + break; + + _printer->newPage(); + } while ( true ); + + _painter->restore(); +} + +QString KPrNoteBar::getNotesTextForPrinting(QValueList<int> _list) const +{ + QString allText = QString::null; + bool firstText = true; + bool noteIsEmpty = true; + int pageCount = 1; + KPrDocument *doc=view->kPresenterDoc(); + for ( int i = 0; i < static_cast<int>( doc->pageList().count() ); i++, ++pageCount ) + { + if (_list.contains(i+1)==0) // that slide isn't printed, don't print its note either + continue; + + if ( !firstText ) + allText += QString("\n\n"); + + allText += i18n( "Slide Note %1:\n" ).arg( pageCount ); + if(noteIsEmpty && !doc->pageList().at(i)->noteText().isEmpty()) + noteIsEmpty = false; + allText += doc->pageList().at(i)->noteText(); + + firstText = false; + } + //code for master page + if ( !firstText ) + allText += QString("\n\n"); + allText += i18n( "Master Page Note:\n" ); + if ( !doc->masterPage()->noteText().isEmpty() ) + noteIsEmpty = false; + allText += doc->masterPage()->noteText(); + + if( noteIsEmpty ) + return QString::null; + return allText; +} + +#include "KPrNoteBar.moc" |
