kpresenter

KPrNoteBar.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include <tqlayout.h>
22#include <tqpainter.h>
23#include <tqpaintdevicemetrics.h>
24#include <tqsimplerichtext.h>
25#include <tqlabel.h>
26
27#include <tdeglobalsettings.h>
28#include <kprinter.h>
29#include <kdebug.h>
30#include <ktextedit.h>
31#include <tdelocale.h>
32
33#include "KPrNoteBar.h"
34#include "KPrView.h"
35#include "KPrDocument.h"
36#include "KPrPage.h"
37
38
39KPrNoteBar::KPrNoteBar( TQWidget *_parent, KPrView *_view )
40 : TQWidget( _parent ),
41 view( _view ),
42 initialize( true )
43{
44 TQBoxLayout *topLayout = new TQVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
45
46 label = new TQLabel(i18n("Note"), this);
47
48 textEdit = new KTextEdit( this );
49
50 TQFont font = KoGlobal::defaultFont();
51 textEdit->setCurrentFont( font );
52
53 int currentPageNum = view->getCurrentPresPage(); // 1 base.
54 TQString text=TQString();
55 if (currentPageNum!=-1)
56 text = view->kPresenterDoc()->pageList().at(currentPageNum - 1)->noteText( );
57 textEdit->setText( text );
58
59 connect( textEdit, TQ_SIGNAL( textChanged() ),
60 this, TQ_SLOT( slotTextChanged() ) );
61
62 connect( textEdit, TQ_SIGNAL( selectionChanged() ),
63 this, TQ_SLOT( slotSelectionChanged() ) );
64
65 connect( textEdit, TQ_SIGNAL( copyAvailable( bool ) ),
66 this, TQ_SLOT( slotSelectionChanged() ) );
67
68 connect( textEdit, TQ_SIGNAL( undoAvailable( bool ) ),
69 this, TQ_SLOT( slotUndoAvailable( bool ) ) );
70
71 connect( textEdit, TQ_SIGNAL( redoAvailable( bool ) ),
72 this, TQ_SLOT( slotRedoAvailable( bool ) ) );
73
74 topLayout->addWidget( label );
75 topLayout->addWidget( textEdit );
76}
77
78KPrNoteBar::~KPrNoteBar()
79{
80 delete textEdit;
81}
82
83void KPrNoteBar::setCurrentNoteText( const TQString &_text )
84{
85 initialize = true;
86 textEdit->setText( _text );
87 initialize = false;
88}
89
90void KPrNoteBar::slotTextChanged()
91{
92 int currentPageNum = view->getCurrPgNum(); // 1 base.
93 if ( currentPageNum > 0 && !initialize ) {
94 if ( view->editMaster() )
95 view->kPresenterDoc()->refreshAllNoteBarMasterPage(textEdit->text() , view);
96 else
97 view->kPresenterDoc()->refreshAllNoteBar(currentPageNum -1,textEdit->text() , view);
98 textEdit->setModified( true );
99 }
100}
101
102void KPrNoteBar::slotSelectionChanged()
103{
104 kdDebug(33001) << "slotSelectionChanged(): " << textEdit->hasSelectedText() << endl;
105}
106
107void KPrNoteBar::slotCopyAvailable( bool yes )
108{
109 kdDebug(33001) << "slotCopyAvailable( " << yes << " )" << endl;
110}
111
112void KPrNoteBar::slotUndoAvailable( bool /*yes*/ )
113{
114 //kdDebug(33001) << "slotUndoAvailable( " << yes << " )" << endl;
115}
116
117void KPrNoteBar::slotRedoAvailable( bool /*yes*/ )
118{
119 //kdDebug(33001) << "slotRedoAvailable( " << yes << " )" << endl;
120}
121
122void KPrNoteBar::printNotes( TQPainter *_painter, KPrinter *_printer, TQValueList<int> _list )
123{
124 // base code from $TQTDIR/example/textedit/textedit.cpp
125 _painter->save();
126
127 TQPaintDeviceMetrics metrics( _painter->device() );
128 int dpix = metrics.logicalDpiX();
129 int dpiy = metrics.logicalDpiY();
130
131 const int margin = 72; // pt
132 TQRect body( margin * dpix / 72, margin * dpiy / 72,
133 metrics.width() - margin * dpix / 72 * 2,
134 metrics.height() - margin * dpiy / 72 * 2 );
135
136 TQFont font = KoGlobal::defaultFont();
137 TQString allText = getNotesTextForPrinting(_list);
138 TQString str = TQStyleSheet::convertFromPlainText( allText );
139
140 TQSimpleRichText richText( str, font, TQString(), TQStyleSheet::defaultSheet(),
141 TQMimeSourceFactory::defaultFactory(), body.height() );
142
143 richText.setWidth( _painter, body.width() );
144
145 TQRect viewRect( body );
146 do {
147 richText.draw( _painter, body.left(), body.top(), viewRect, colorGroup() );
148 viewRect.moveBy( 0, body.height() );
149 _painter->translate( 0, -body.height() );
150 _painter->setFont( font );
151
152 if ( viewRect.top() >= richText.height() )
153 break;
154
155 _printer->newPage();
156 } while ( true );
157
158 _painter->restore();
159}
160
161TQString KPrNoteBar::getNotesTextForPrinting(TQValueList<int> _list) const
162{
163 TQString allText = TQString();
164 bool firstText = true;
165 bool noteIsEmpty = true;
166 int pageCount = 1;
167 KPrDocument *doc=view->kPresenterDoc();
168 for ( int i = 0; i < static_cast<int>( doc->pageList().count() ); i++, ++pageCount )
169 {
170 if (_list.contains(i+1)==0) // that slide isn't printed, don't print its note either
171 continue;
172
173 if ( !firstText )
174 allText += TQString("\n\n");
175
176 allText += i18n( "Slide Note %1:\n" ).arg( pageCount );
177 if(noteIsEmpty && !doc->pageList().at(i)->noteText().isEmpty())
178 noteIsEmpty = false;
179 allText += doc->pageList().at(i)->noteText();
180
181 firstText = false;
182 }
183 //code for master page
184 if ( !firstText )
185 allText += TQString("\n\n");
186 allText += i18n( "Master Page Note:\n" );
187 if ( !doc->masterPage()->noteText().isEmpty() )
188 noteIsEmpty = false;
189 allText += doc->masterPage()->noteText();
190
191 if( noteIsEmpty )
192 return TQString();
193 return allText;
194}
195
196#include "KPrNoteBar.moc"