kpresenter

KPrCanvas.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2002-2005 Thorsten Zachmann <zachmann@kde.org>
4 Copyright (C) 2005 Casper Boemann Rasmussen <cbr@boemann.dk>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include <stdlib.h>
23#include <math.h>
24
25#include <tqprogressdialog.h>
26#include <tqfile.h>
27#include <tqtextstream.h>
28#include <tqpainter.h>
29#include <tqpaintdevicemetrics.h>
30#include <tqwmatrix.h>
31#include <tqapplication.h>
32#include <tdepopupmenu.h>
33#include <tqimage.h>
34#include <tqdatetime.h>
35#include <tqdropsite.h>
36#include <tqrect.h>
37#include <tqsize.h>
38#include <tqpoint.h>
39#include <tqclipboard.h>
40
41#include <tdeapplication.h>
42#include <kmimemagic.h>
43#include <tdelocale.h>
44#include <kiconloader.h>
45#include <kprinter.h>
46#include <tdeglobal.h>
47#include <tdeglobalsettings.h>
48#include <tdetempfile.h>
49#include <kdebug.h>
50#include <kcursor.h>
51#include <tdemessagebox.h>
52#include <tdemultipledrag.h>
53#include <tdeconfig.h>
54#include <kurl.h>
55#include <kurldrag.h>
56#include <tdeio/netaccess.h>
57
58#include <KoParagCounter.h>
59#include <KoPoint.h>
60#include <KoTextZoomHandler.h>
61#include <KoStore.h>
62#include <KoStoreDrag.h>
63#include "KoPointArray.h"
64#include <KoSpeaker.h>
65
66#include "KPrView.h"
67#include "KPrBackground.h"
68#include "KPrPixmapObject.h"
69#include "KPrFreehandObject.h"
70#include "KPrBezierCurveObject.h"
71#include "KPrGotoPage.h"
72#include "KPrTextObject.h"
73#include "KPrSoundPlayer.h"
74#include "KPrNoteBar.h"
75#include "KPrPartObject.h"
76#include "KPrUtils.h"
77#include "KPrCommand.h"
78#include "KPrPolylineObject.h"
79#include "KPrClosedLineObject.h"
80#include "KPrPage.h"
81#include "KPrVariableCollection.h"
82#include "KPrGroupObject.h"
83#include "KPrDocument.h"
84
85#include "KPrCanvas.h"
86#include "KPrCanvas.moc"
87
88#include "KPrEffectHandler.h"
89#include "KPrPageEffects.h"
90#include <unistd.h>
91
92const int KPrCanvas::MOUSE_SNAP_DISTANCE = 4;
93const int KPrCanvas::KEY_SNAP_DISTANCE = 2;
94
95KPrCanvas::KPrCanvas( TQWidget *parent, const char *name, KPrView *_view )
96: TQWidget( parent, name, WStaticContents|WResizeNoErase|WRepaintNoErase )
97, buffer( size() )
98, m_gl( _view, _view->zoomHandler() )
99, m_paintGuides( false )
100, m_objectDisplayAbove( 0 )
101{
102 m_presMenu = 0;
103 m_currentTextObjectView=0L;
104 m_activePage=0L;
105 m_xOffset = 0;
106 m_yOffset = 0;
107 m_prevSpokenTO = 0;
108
109 m_keyPressEvent = false;
110 m_drawSymetricObject = false;
111 if ( parent ) {
112 showingLastSlide = false;
113 mousePressed = false;
114 drawContour = false;
115 modType = MT_NONE;
116 m_resizeObject = 0;
117 m_editObject = 0;
118 m_rotateObject = 0;
119 setBackgroundMode( TQt::NoBackground );
120 m_view = _view;
121 setupMenus();
122 setMouseTracking( true );
123 show();
124 editMode = true;
125 m_step.m_pageNumber = 0;
126 m_step.m_step = 0;
127 m_step.m_subStep = 0;
128 goingBack = false;
129 m_drawMode = false;
130 fillBlack = true;
131 drawRubber = false;
132 m_zoomRubberDraw = false;
133 toolEditMode = TEM_MOUSE;
134 setAcceptDrops( true );
135 m_ratio = 0.0;
136 m_isMoving = false;
137 m_isResizing = false;
138 mouseSelectedObject = false;
139 m_setPageTimer = true;
140 m_drawLineInDrawMode = false;
141 soundPlayer = 0;
142 m_disableSnapping = false;
143 m_drawPolyline = false;
144 m_drawCubicBezierCurve = false;
145 m_drawLineWithCubicBezierCurve = true;
146 m_oldCubicBezierPointArray.putPoints( 0, 4, 0.0, 0.0, 0.0, 0.0,
147 0.0, 0.0, 0.0, 0.0 );
148 m_effectHandler = 0;
149 m_pageEffect = 0;
150 } else {
151 m_view = 0;
152 hide();
153 }
154
155 setFocusPolicy( TQWidget::StrongFocus );
156 setFocus();
157 setKeyCompression( true );
158 setInputMethodEnabled( true ); // ensure using the InputMethod
159 installEventFilter( this );
160 KCursor::setAutoHideCursor( this, true, true );
161 m_zoomBeforePresentation=100;
162
163 if( m_view)
164 {
165 m_activePage=m_view->kPresenterDoc()->pageList().getFirst();
166 connect( m_view->kPresenterDoc(), TQ_SIGNAL( sig_terminateEditing( KPrTextObject * ) ),
167 this, TQ_SLOT( terminateEditing( KPrTextObject * ) ) );
168 connect( m_view, TQ_SIGNAL( autoScroll( const TQPoint & )), this, TQ_SLOT( slotAutoScroll( const TQPoint &)));
169 }
170
171 if ( kospeaker )
172 connect( kospeaker, TQ_SIGNAL( customSpeakWidget(TQWidget*, const TQPoint&, uint) ),
173 this, TQ_SLOT( speakTextUnderMouse(TQWidget*, const TQPoint&, uint) ) );
174}
175
177{
178 // block all signals (save for destroyed()) to avoid crashes on exit
179 // (exitEditMode) emits signals
180 blockSignals(true);
181
182 exitEditMode( false );
183
184 delete m_presMenu;
185
186 stopSound();
187 delete soundPlayer;
188 blockSignals(false);
189}
190
191void KPrCanvas::scrollX( int x )
192{
193 // Relative movement
194 int dx = m_xOffset - x;
195 // new position
196 m_xOffset = x;
197 bitBlt( &buffer, dx, 0, &buffer );
198 scroll( dx, 0 );
199}
200
201void KPrCanvas::scrollY( int y )
202{
203 // Relative movement
204 int dy = m_yOffset - y;
205 // new position
206 m_yOffset = y;
207 bitBlt( &buffer, 0, dy, &buffer );
208 scroll( 0, dy );
209}
210
211bool KPrCanvas::eventFilter( TQObject *o, TQEvent *e )
212{
213 if ( !o || !e )
214 return true;
215 if ( m_currentTextObjectView )
216 KCursor::autoHideEventFilter( o, e );
217 switch ( e->type() )
218 {
219 case TQEvent::FocusIn:
220 if ( m_currentTextObjectView )
221 m_currentTextObjectView->focusInEvent();
222 return true;
223 case TQEvent::FocusOut:
224 if ( m_currentTextObjectView )
225 m_currentTextObjectView->focusOutEvent();
226 return true;
227 case TQEvent::KeyPress:
228 {
229 TQKeyEvent * keyev = static_cast<TQKeyEvent*>(e);
230 if ( keyev->key() == TDEGlobalSettings::contextMenuKey() ) {
231 popupContextMenu();
232 return true;
233 }
234 if ( m_currentTextObjectView &&
235 (keyev->key()==TQt::Key_Home ||keyev->key()==Key_End
236 || keyev->key()==TQt::Key_Tab || keyev->key()==Key_Prior
237 || keyev->key()==TQt::Key_Next || keyev->key() == Key_Backtab) )
238 {
239 m_currentTextObjectView->keyPressEvent( keyev );
240 return true;
241 }
242 else if ( !m_currentTextObjectView && keyev->key()==TQt::Key_Tab )
243 {
244 keyPressEvent(keyev);
245 return true;
246 }
247 break;
248 }
249 case TQEvent::AccelOverride:
250 {
251#ifndef NDEBUG
252 TQKeyEvent * keyev = static_cast<TQKeyEvent*>(e);
253 // Debug keys
254 if ( ( keyev->state() & ControlButton ) && ( keyev->state() & ShiftButton ) )
255 {
256 switch ( keyev->key() ) {
257 case TQt::Key_P: // 'P' -> paragraph debug
258 printRTDebug( 0 );
259 keyev->accept();
260 break;
261 case TQt::Key_V: // 'V' -> verbose parag debug
262 printRTDebug( 1 );
263 keyev->accept();
264 break;
265 default:
266 break;
267 }
268 }
269#endif
270 break;
271 }
272 default:
273 break;
274 }
275 return TQWidget::eventFilter(o,e);
276}
277
278bool KPrCanvas::focusNextPrevChild( bool )
279{
280 return true; // Don't allow to go out of the canvas widget by pressing "Tab"
281}
282
283void KPrCanvas::paintEvent( TQPaintEvent* paintEvent )
284{
285 if ( isUpdatesEnabled() )
286 {
287 //kdDebug(33001) << "KPrCanvas::paintEvent m_paintGuides = " << m_paintGuides << endl; //<< " " << kdBacktrace( 10 ) << endl;
288 KPrDocument *doc =m_view->kPresenterDoc();
289
290 if ( ! m_paintGuides )
291 {
292 //kdDebug(33001) << "KPrCanvas::paintEvent" << endl;
293 TQPainter bufPainter;
294 bufPainter.begin( &buffer, this ); // double-buffering - (the buffer is as big as the widget)
295 bufPainter.translate( -diffx(), -diffy() );
296 bufPainter.setBrushOrigin( -diffx(), -diffy() );
297
298 TQRect crect( paintEvent->rect() ); // the rectangle that needs to be repainted, in widget coordinates
299 bufPainter.setClipRect( crect );
300
301 //kdDebug(33001) << "KPrCanvas::paintEvent " << DEBUGRECT( crect ) << ", " << size() << endl;
302
303 crect.moveBy( diffx(), diffy() ); // now in contents coordinates
304 //kdDebug(33001) << "KPrCanvas::paintEvent after applying diffx/diffy: " << DEBUGRECT( crect ) << endl;
305
306 if ( editMode || !fillBlack )
307 bufPainter.fillRect( crect, white );
308 else
309 bufPainter.fillRect( crect, black );
310
311 KPrPage * page = editMode ? m_activePage : doc->pageList().at( m_step.m_pageNumber );
312 drawBackground( &bufPainter, crect, page, editMode );
313
314 if ( editMode )
315 {
316 SelectionMode selectionMode;
317
318 if ( toolEditMode == TEM_MOUSE || toolEditMode == TEM_ZOOM )
319 selectionMode = SM_MOVERESIZE;
320 else if ( toolEditMode == TEM_ROTATE )
321 selectionMode = SM_ROTATE;
322 else
323 selectionMode = SM_NONE;
324
325 if ( doc->showGrid() )
326 drawGrid( &bufPainter, crect );
327
328 drawEditPage( &bufPainter, crect, page, selectionMode );
329 }
330 else
331 {
332 // Center the slide in the screen, if it's smaller...
333#if 0 // this works but isn't enough - e.g. object effects need the same offsets
334 // so we should store them, but they don't work like diffx/diffy...
335 // (e.g. the painter mustn't be translated when painting the background)
336 TQRect desk = TDEGlobalSettings::desktopGeometry(this);
337 TQRect pgRect = m_view->kPresenterDoc()->pageList().at(0)->getZoomPageRect();
338 int offx = 0, offy = 0;
339 if ( desk.width() > pgRect.width() )
340 offx = ( desk.width() - pgRect.width() ) / 2;
341 if ( desk.height() > pgRect.height() )
342 offy = ( desk.height() - pgRect.height() ) / 2;
343 bufPainter.translate( offx, offy );
344#endif
345
346 PresStep step( m_step.m_pageNumber, m_step.m_step, m_step.m_subStep, m_effectTimer.isActive(), !goingBack );
347 drawPresPage( &bufPainter, crect, step );
348 if ( m_drawMode && m_drawModeLines.count() )
349 {
350 bufPainter.save();
351 bufPainter.setPen( m_view->kPresenterDoc()->presPen() );
352 for ( unsigned int i = 0; i < m_drawModeLines.count(); ++i )
353 {
354 bufPainter.drawPolyline( m_drawModeLines[i] );
355 }
356 bufPainter.restore();
357 }
358 }
359
360 bufPainter.end();
361 }
362
363
364 TQPixmap topBuffer( buffer );
365 TQPainter topPainter( &topBuffer, &buffer );
366 topPainter.translate( -diffx(), -diffy() );
367 topPainter.setBrushOrigin( -diffx(), -diffy() );
368
369 if ( editMode && doc->showGuideLines() )
370 {
371 m_gl.paintGuides( topPainter );
372 }
373
374 topPainter.setPen( TQPen( TQt::black, 1, TQt::SolidLine ) );
375 topPainter.setRasterOp( NotROP );
376 switch ( toolEditMode )
377 {
378 case MT_NONE:
379 if ( drawRubber )
380 {
381 topPainter.setPen( TQPen( black, 0, DotLine ) );
382 topPainter.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
383 }
384 break;
385 case INS_RECT:
386 if ( !m_insertRect.isNull() )
387 {
388 topPainter.drawRoundRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ),
389 m_view->getRndX(), m_view->getRndY() );
390 }
391 break;
392 case INS_ELLIPSE:
393 if ( !m_insertRect.isNull() )
394 {
395 topPainter.drawEllipse( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
396 }
397 break;
398 case INS_AUTOFORM:
399 case INS_DIAGRAMM:
400 case INS_FORMULA:
401 case INS_CLIPART:
402 case INS_PICTURE:
403 case INS_OBJECT:
404 case INS_TABLE:
405 case INS_TEXT:
406 if ( !m_insertRect.isNull() )
407 {
408 topPainter.drawRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
409 }
410 break;
411 case INS_PIE:
412 if ( !m_insertRect.isNull() )
413 {
414 drawPieObject( &topPainter, m_insertRect );
415 }
416 break;
417 case INS_LINE:
418 topPainter.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
419 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
420 break;
421 case INS_FREEHAND:
422 case INS_CLOSED_FREEHAND:
423 case INS_POLYLINE:
424 case INS_CLOSED_POLYLINE:
425 {
426 TQPointArray pointArray = m_pointArray.zoomPointArray( m_view->zoomHandler() );
427 topPainter.drawPolyline( pointArray );
428 topPainter.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
429 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
430 } break;
431 case INS_QUADRICBEZIERCURVE:
432 case INS_CUBICBEZIERCURVE:
433 case INS_CLOSED_QUADRICBEZIERCURVE:
434 case INS_CLOSED_CUBICBEZIERCURVE:
435 if ( m_drawCubicBezierCurve )
436 {
437 if ( m_indexPointArray > 0 )
438 {
439 redrawCubicBezierCurve( topPainter );
440 drawCubicBezierCurve( topPainter, m_oldCubicBezierPointArray );
441 }
442 }
443 break;
444 case INS_POLYGON:
445 drawPolygon( topPainter, m_insertRect );
446 break;
447 default:
448 break;
449 }
450 topPainter.end();
451 bitBlt( this, paintEvent->rect().topLeft(), &topBuffer, paintEvent->rect() );
452 }
453 //else kdDebug(33001) << "KPrCanvas::paintEvent with updates disabled" << endl;
454}
455
456
457void KPrCanvas::drawBackground( TQPainter *painter, const TQRect& rect, KPrPage * page, bool edit ) const
458{
459 if ( edit )
460 {
461 TQRect pageRect = page->getZoomPageRect();
462
463 if ( rect.intersects( pageRect ) )
464 {
465 if ( page->displayBackground() )
466 {
467 if ( page->masterPage() && page->useMasterBackground() )
468 page->masterPage()->background()->drawBackground( painter, m_view->zoomHandler(), rect, true );
469 else
470 page->background()->drawBackground( painter, m_view->zoomHandler(), rect, true );
471 }
472 }
473 // Include the border
474 pageRect.rLeft() -= 1;
475 pageRect.rTop() -= 1;
476 pageRect.rRight() += 1;
477 pageRect.rBottom() += 1;
478
479 TQRegion grayRegion( rect );
480 grayRegion -= pageRect;
481
482 // In edit mode we also want to draw the gray area out of the pages
483 if ( !grayRegion.isEmpty() )
484 eraseEmptySpace( painter, grayRegion, TQApplication::palette().active().brush( TQColorGroup::Mid ) );
485 }
486 else
487 {
488 // Old code, left a black area if zoomX != zoomY
489 //page->background()->draw( painter, m_view->zoomHandler(), rect, false );
490
491 TQRect desk = TDEGlobalSettings::desktopGeometry(getView());
492 TQRect crect = desk.intersect( rect );
493 if ( crect.isEmpty() || !page->displayBackground())
494 return;
495
496 if ( page->masterPage() && page->useMasterBackground() )
497 page->masterPage()->background()->drawBackground( painter, desk.size(), crect, false );
498 else
499 page->background()->drawBackground( painter, desk.size(), crect, false );
500 }
501}
502
503
504// 100% stolen from KWord
505void KPrCanvas::eraseEmptySpace( TQPainter * painter, const TQRegion & emptySpaceRegion, const TQBrush & brush ) const
506{
507 painter->save();
508 painter->setClipRegion( emptySpaceRegion, TQPainter::CoordPainter );
509 painter->setPen( TQt::NoPen );
510
511 //kdDebug(33001) << "KWDocument::eraseEmptySpace emptySpaceRegion: " << DEBUGRECT( emptySpaceRegion.boundingRect() ) << endl;
512 painter->fillRect( emptySpaceRegion.boundingRect(), brush );
513 painter->restore();
514}
515
516
517void KPrCanvas::drawObjects( TQPainter *painter, const TQPtrList<KPrObject> &objects, SelectionMode selectionMode,
518 bool contour, KPrTextView * textView, int pageNum ) const
519{
520 TQPtrListIterator<KPrObject> it( objects );
521 for ( ; it.current(); ++it )
522 {
523 SelectionMode selMode = selectionMode;
524 if ( selectionMode != SM_NONE
525 && it.current()->isSelected()
526 && ( m_view->kPresenterDoc()->isHeaderFooter(it.current())
527 || it.current()->isProtect() ) )
528 selMode = SM_PROTECT;
529
530 it.current()->draw( painter, m_view->zoomHandler(), pageNum, selMode, (it.current()->isSelected()) && contour );
531
532 it.current()->setSubPresStep( 0 );
533 it.current()->doSpecificEffects( false );
534 }
535
536 if ( textView )
537 {
538 textView->kpTextObject()->paintEdited( painter, m_view->zoomHandler(), false /*onlyChanged. Pass as param ?*/,
539 textView->cursor(), true /* idem */ );
540 }
541}
542
543
544void KPrCanvas::drawObjectsPres( TQPainter *painter, const TQPtrList<KPrObject> &_objects, PresStep step ) const
545{
546 TQPtrList<KPrObject> objects;
547
548 TQPtrListIterator<KPrObject> it( _objects );
549 for ( ; it.current(); ++it )
550 {
551 if ( objectIsAHeaderFooterHidden(it.current()) )
552 continue;
553 if ( it.current()->getAppearStep() <= step.m_step
554 && ( ! it.current()->getDisappear()
555 || it.current()->getDisappear()
556 && it.current()->getDisappearStep() > step.m_step ) )
557 {
558 if ( step.m_animate && it.current()->getAppearStep() == step.m_step && it.current()->getEffect() != EF_NONE )
559 continue;
560
561 if ( step.m_animateSub && it.current()->getAppearStep() == step.m_step )
562 {
563 it.current()->setSubPresStep( step.m_subStep );
564 it.current()->doSpecificEffects( true, false );
565 }
566
567 objects.append( it.current() );
568 }
569 }
570 drawObjects( painter, objects, SM_NONE, false, NULL, step.m_pageNumber );
571}
572
573
574void KPrCanvas::drawObjectsEdit( TQPainter *painter, const KoRect &rect, const TQPtrList<KPrObject> &_objects,
575 SelectionMode selectionMode, int pageNum ) const
576{
577 TQPtrList<KPrObject> objects;
578
579 KPrTextView * textView = NULL;
580 TQPtrListIterator<KPrObject> it( _objects );
581 for ( ; it.current(); ++it )
582 {
583 if ( objectIsAHeaderFooterHidden(it.current()) )
584 continue;
585
586 if ( rect.intersects( it.current()->getRepaintRect() ) )
587 {
588 if ( m_currentTextObjectView && m_currentTextObjectView->kpTextObject() == it.current() )
589 {
590 textView = m_currentTextObjectView;
591 }
592
593 objects.append( it.current() );
594 }
595 }
596 drawObjects( painter, objects, selectionMode, drawContour, textView, pageNum );
597}
598
599
600void KPrCanvas::drawEditPage( TQPainter *painter, const TQRect &_rect,
601 KPrPage *page, SelectionMode selectionMode ) const
602{
603 KoRect rect = m_view->zoomHandler()->unzoomRect(_rect);
604
605 int pageNum = m_view->kPresenterDoc()->pageList().findRef( page );
606 //objects on master page
607 if ( page->masterPage() && page->displayObjectFromMasterPage() )
608 drawObjectsEdit( painter, rect, page->masterPage()->objectList(), selectionMode, pageNum );
609 //objects on current page
610 drawObjectsEdit( painter, rect, displayObjectList(), selectionMode, pageNum );
611}
612
613
614void KPrCanvas::drawPresPage( TQPainter *painter, const TQRect &_rect, PresStep step ) const
615{
616 KoRect rect = m_view->zoomHandler()->unzoomRect(_rect);
617
618 KPrPage * page = m_view->kPresenterDoc()->pageList().at(step.m_pageNumber);
619 //objects on master page
620 if ( page->masterPage() && page->displayObjectFromMasterPage() )
621 drawObjectsPres( painter, page->masterPage()->objectList(), step );
622 //objects on current page
623 drawObjectsPres( painter, page->objectList(), step );
624}
625
626
627void KPrCanvas::drawGrid(TQPainter *painter, const TQRect &rect2) const
628{
629 KPrDocument *doc=m_view->kPresenterDoc();
630
631 if(!doc->isReadWrite())
632 return;
633 TQPen _pen = TQPen( doc->gridColor(), 6, TQt::DotLine );
634 painter->save();
635 painter->setPen( _pen );
636 TQRect pageRect = m_activePage->getZoomPageRect();
637
638 int zoomedX, zoomedY;
639 double offsetX = doc->getGridX();
640 double offsetY = doc->getGridY();
641
642 for ( double i = offsetX; ( zoomedX = m_view->zoomHandler()->zoomItX( i )+pageRect.left() ) < pageRect.right(); i += offsetX )
643 for ( double j = offsetY; ( zoomedY = m_view->zoomHandler()->zoomItY( j )+pageRect.top() ) < pageRect.bottom(); j += offsetY )
644 if( rect2.contains( zoomedX, zoomedY ) )
645 painter->drawPoint( zoomedX, zoomedY );
646
647 painter->restore();
648}
649
650
651// This one is used to generate the pixmaps for the HTML presentation,
652// for the pres-structure-dialog, for the sidebar previews, for template icons.
653void KPrCanvas::drawAllObjectsInPage( TQPainter *painter, const TQPtrList<KPrObject> & obj, int pageNum ) const
654{
655 TQPtrListIterator<KPrObject> it( obj );
656 for ( ; it.current(); ++it ) {
657 if ( objectIsAHeaderFooterHidden( it.current() ) )
658 continue;
659 it.current()->draw( painter, m_view->zoomHandler(), pageNum, SM_NONE, false );
660 }
661}
662
663void KPrCanvas::recalcAutoGuides( )
664{
665 TQValueList<double> horizontalPos;
666 TQValueList<double> verticalPos;
667 TQPtrListIterator<KPrObject> it( m_activePage->objectList() );
668 for ( ; it.current(); ++it )
669 {
670 if( ! it.current()->isSelected() )
671 it.current()->addSelfToGuides( horizontalPos, verticalPos);
672 }
673
674 m_gl.setAutoGuideLines( horizontalPos, verticalPos );
675}
676
677void KPrCanvas::mousePressEvent( TQMouseEvent *e )
678{
679 TQPoint contentsPoint( e->pos().x()+diffx(), e->pos().y()+diffy() );
680 KoPoint docPoint = m_view->zoomHandler()->unzoomPoint( contentsPoint );
681 m_insertRect = KoRect();
682
683 if(!m_view->koDocument()->isReadWrite())
684 return;
685
686 if ( editMode && m_view->kPresenterDoc()->showGuideLines() && toolEditMode == TEM_MOUSE && m_gl.mousePressEvent( e ) )
687 return;
688
689 m_moveStartPosMouse = objectRect( false ).topLeft();
690 if(m_currentTextObjectView)
691 {
692 KPrTextObject *txtObj=m_currentTextObjectView->kpTextObject();
693 Q_ASSERT(txtObj);
694 if(txtObj->contains( docPoint ))
695 {
696 KoPoint pos = docPoint - txtObj->innerRect().topLeft(); // in pt, but now translated into the object's coordinate system
697 // This is common to all mouse buttons, so that RMB and MMB place the cursor too
698 m_currentTextObjectView->mousePressEvent(e, m_view->zoomHandler()->ptToLayoutUnitPix( pos ) ); // in LU pixels
699 mousePressed = true;
700 m_view->enableAutoScroll();
701 if(e->button() == TQt::RightButton)
702 {
703 m_currentTextObjectView->showPopup( m_view, TQCursor::pos(), m_view->actionList() );
704 m_view->disableAutoScroll();
705 mousePressed=false;
706 }
707 else if( e->button() == TQt::MidButton )
708 {
709 TQApplication::clipboard()->setSelectionMode( true );
710 m_currentTextObjectView->paste();
711 TQApplication::clipboard()->setSelectionMode( false );
712 }
713 return;
714 }
715 }
716
717
718 KPrObject *kpobject = 0;
719
720 m_disableSnapping = e->state() & ShiftButton;
721
722 exitEditMode();
723
724 if ( editMode ) {
725 if ( e->button() == TQt::LeftButton ) {
726 mousePressed = true;
727 m_view->enableAutoScroll();
728
729 if ( m_drawPolyline && ( toolEditMode == INS_POLYLINE || toolEditMode == INS_CLOSED_POLYLINE ) )
730 {
731 m_startPoint = snapPoint( docPoint );
732 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
733
734 ++m_indexPointArray;
735 return;
736 }
737
738 if ( m_drawCubicBezierCurve && ( toolEditMode == INS_CUBICBEZIERCURVE
739 || toolEditMode == INS_QUADRICBEZIERCURVE
740 || toolEditMode == INS_CLOSED_CUBICBEZIERCURVE
741 || toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE ) ) {
742 if ( m_drawLineWithCubicBezierCurve ) {
743 TQPainter p( this );
744 p.setPen( TQPen( TQt::black, 1, TQt::SolidLine ) );
745 p.setBrush( TQt::NoBrush );
746 p.setRasterOp( TQt::NotROP );
747
748 p.translate( -diffx(), -diffy() );
749 KoPoint newStartPoint = snapPoint( docPoint );
750
751 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
752 m_view->zoomHandler()->zoomPoint( newStartPoint ) );
753
754 m_startPoint = newStartPoint;
755 p.end();
756
757 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
758
759 ++m_indexPointArray;
760 m_drawLineWithCubicBezierCurve = false;
761 }
762 else {
763 TQPainter p( this );
764 TQPen _pen = TQPen( TQt::black, 1, TQt::DashLine );
765 p.setPen( _pen );
766 p.setBrush( TQt::NoBrush );
767 p.setRasterOp( TQt::NotROP );
768
769 p.translate( -diffx(), -diffy() );
770 p.save();
771
772 KoPoint endPoint = snapPoint( docPoint );
773
774 double angle = KoPoint::getAngle( endPoint, m_startPoint );
775
776 drawFigure( L_SQUARE, &p, endPoint, _pen.color(), _pen.width(), angle, m_view->zoomHandler() ); // erase old figure
777
778 p.restore();
779
780 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
781 m_view->zoomHandler()->zoomPoint( endPoint ) );// erase old line
782
783 m_symmetricEndPoint = m_startPoint * 2 - endPoint;
784
785 p.save();
786 angle = KoPoint::getAngle( m_symmetricEndPoint, m_startPoint );
787
788 drawFigure( L_SQUARE, &p, m_symmetricEndPoint, _pen.color(), _pen.width(), angle, m_view->zoomHandler() ); // erase old figure
789
790 p.restore();
791
792 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
793 m_view->zoomHandler()->zoomPoint( m_symmetricEndPoint ) );// erase old line
794
795 m_pointArray.putPoints( m_indexPointArray, 3, m_CubicBezierSecondPoint.x(), m_CubicBezierSecondPoint.y(),
796 m_CubicBezierThirdPoint.x(), m_CubicBezierThirdPoint.y(),
797 m_startPoint.x(), m_startPoint.y() );
798 m_indexPointArray += 3;
799 m_drawLineWithCubicBezierCurve = true;
800 m_oldCubicBezierPointArray = KoPointArray();
801 m_oldCubicBezierPointArray.putPoints( 0, 4, (double)0,(double)0, (double)0,(double)0,
802 (double)0,(double)0, (double)0,(double)0 );
803 m_endPoint = m_startPoint;
804 }
805
806 return;
807 }
808
809 switch ( toolEditMode ) {
810 case TEM_MOUSE: {
811 KPrObject *kpobject = getObjectAt( docPoint, true );
812
813 if ( kpobject ) {
814 // use ctrl + Button to select / deselect object
815 if ( e->state() & ControlButton && kpobject->isSelected() )
816 deSelectObj( kpobject );
817 else if ( e->state() & ControlButton )
818 {
819 selectObj( kpobject );
820 raiseObject( kpobject );
821 m_moveStartPosMouse = objectRect( false ).topLeft();
822 }
823 else
824 {
825 if ( modType != MT_MOVE || !kpobject->isSelected() )
826 deSelectAllObj();
827
828 selectObj( kpobject );
829 raiseObject( kpobject );
830 m_moveStartPosMouse = objectRect( false ).topLeft();
831 }
832
833 // start resizing
834 if ( modType != MT_MOVE && modType != MT_NONE )
835 {
836 deSelectAllObj();
837 selectObj( kpobject );
838 raiseObject( kpobject );
839
840 m_resizeObject = kpobject;
841
842 m_ratio = static_cast<double>( kpobject->getSize().width() ) /
843 static_cast<double>( kpobject->getSize().height() );
844 m_rectBeforeResize = kpobject->getRect();
845 }
846 recalcAutoGuides();
847 if ( m_view->kPresenterDoc()->showGuideLines() && !m_disableSnapping )
848 {
849 m_gl.repaintSnapping( objectRect( false ) );
850 }
851 }
852 else
853 {
854 KPrPage *masterPage = m_activePage->masterPage();
855 if ( masterPage && m_activePage->displayObjectFromMasterPage() )
856 {
857 kpobject = masterPage->getObjectAt( docPoint, true );
858
859 if ( kpobject && objectIsAHeaderFooterHidden( kpobject ) )
860 {
861 kpobject = 0;
862 }
863 }
864
865 if ( kpobject )
866 {
867 mousePressed = false;
868 TQString msg( i18n( "The object you are trying to select belongs to the master slide. "
869 "Editing the object can only be done on the master slide.\n"
870 "Go there now?" ) );
871 m_view->disableAutoScroll(); // needed because the messagebox 'eats' the mouseRelease
872 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
873 {
874 getView()->setEditMaster( true );
875 selectObj( kpobject );
876 raiseObject( kpobject );
877 m_moveStartPosMouse = objectRect( false ).topLeft();
878 }
879 else
880 {
881 deSelectAllObj();
882 modType = MT_NONE;
883 }
884 }
885 else {
886 modType = MT_NONE;
887 if ( !( e->state() & ShiftButton ) && !( e->state() & ControlButton ) )
888 deSelectAllObj();
889
890 drawRubber = true;
891 m_rubber = KoRect( docPoint.x(), docPoint.y(), 0, 0 );
892 }
893 }
894 m_origMousePos = docPoint;
895 } break;
896 case TEM_ZOOM: {
897 modType = MT_NONE;
898 drawRubber = true;
899 m_zoomRubberDraw = false;
900 m_rubber = KoRect( docPoint.x(), docPoint.y(), 0, 0 );
901 }break;
902 case TEM_ROTATE:
903 {
904 KPrObject *kpobject = getObjectAt( docPoint );
905
906 // clear old selections even if shift or control are pressed
907 // we don't support rotating multiple objects yet
908 deSelectAllObj();
909
910 if ( kpobject && !kpobject->isProtect())
911 {
912 m_rotateObject = kpobject;
913 m_rotateStart = docPoint;
914 m_angleBeforeRotate = kpobject->getAngle();
915 selectObj( kpobject );
916 raiseObject( kpobject );
917
918 // set center of selected object bounding rect
919 m_rotateCenter = kpobject->getRealRect().center();
920 }
921 } break;
922 case INS_LINE:
923 deSelectAllObj();
924 recalcAutoGuides();
925 mousePressed = true;
926
927 m_startPoint = snapPoint( docPoint );
928 m_endPoint = m_startPoint;
929 break;
930 case INS_FREEHAND: case INS_CLOSED_FREEHAND: {
931 deSelectAllObj();
932 recalcAutoGuides();
933 mousePressed = true;
934
935 m_indexPointArray = 0;
936 m_startPoint = snapPoint( docPoint );
937 m_endPoint = m_startPoint;
938 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
939 ++m_indexPointArray;
940 } break;
941 case INS_POLYLINE: case INS_CLOSED_POLYLINE: {
942 deSelectAllObj();
943 recalcAutoGuides();
944 mousePressed = true;
945
946 m_drawPolyline = true;
947 m_indexPointArray = 0;
948 m_startPoint = snapPoint( docPoint );
949 m_endPoint = m_startPoint;
950 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
951 ++m_indexPointArray;
952 } break;
953 case INS_CUBICBEZIERCURVE: case INS_QUADRICBEZIERCURVE:
954 case INS_CLOSED_CUBICBEZIERCURVE: case INS_CLOSED_QUADRICBEZIERCURVE: {
955 deSelectAllObj();
956 recalcAutoGuides();
957 mousePressed = true;
958
959 m_drawCubicBezierCurve = true;
960 m_drawLineWithCubicBezierCurve = true;
961 m_indexPointArray = 0;
962
963 m_oldCubicBezierPointArray.putPoints( 0, 4, (double)0,(double)0, (double)0,(double)0,
964 (double)0,(double)0, (double)0,(double)0 );
965 m_startPoint = snapPoint( docPoint );
966 m_endPoint = m_startPoint;
967 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
968
969 ++m_indexPointArray;
970 } break;
971 default: {
972 deSelectAllObj();
973 recalcAutoGuides();
974 mousePressed = true;
975 KoPoint sp( snapPoint( docPoint ) );
976 m_insertRect = KoRect( sp.x(), sp.y(),0 ,0 );
977 } break;
978 }
979 }
980
981 if ( e->button() == TQt::RightButton && ( toolEditMode == INS_POLYLINE || toolEditMode == INS_CLOSED_POLYLINE )
982 && !m_pointArray.isNull() && m_drawPolyline ) {
983 if( m_indexPointArray > 1)
984 {
985 TQPainter p( this );
986 p.setPen( TQPen( black, 1, SolidLine ) );
987 p.setBrush( NoBrush );
988 p.translate( -diffx(), -diffy() );
989 p.save();
990 p.setRasterOp( NotROP );
991
992 // remove old line
993 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
994 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
995
996 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
997 m_view->zoomHandler()->zoomPoint( m_pointArray.at( m_indexPointArray - 2 ) ) );
998 p.restore();
999
1000 m_indexPointArray = TQMAX( 1, m_indexPointArray - 1 );
1001 m_pointArray.resize( m_indexPointArray );
1002 m_startPoint = m_pointArray.at( m_indexPointArray - 1 );
1003
1004 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1005 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
1006
1007 p.end();
1008 }
1009 else if( m_indexPointArray == 1)
1010 {
1011 TQPainter p( this );
1012 p.setPen( TQPen( black, 1, SolidLine ) );
1013 p.setBrush( NoBrush );
1014 p.setRasterOp( NotROP );
1015 p.translate( -diffx(), -diffy() );
1016 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1017 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
1018 p.end();
1019 m_pointArray = KoPointArray();
1020 m_indexPointArray = 0;
1021
1022 m_drawPolyline = false;
1023 m_view->disableAutoScroll();
1024 mousePressed = false;
1025 }
1026 return;
1027 }
1028
1029 if ( e->button() == TQt::RightButton && ( toolEditMode == INS_CUBICBEZIERCURVE || toolEditMode == INS_QUADRICBEZIERCURVE
1030 || toolEditMode == INS_CLOSED_CUBICBEZIERCURVE || toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE )
1031 && !m_pointArray.isNull() && m_drawCubicBezierCurve ) {
1032 if ( m_drawLineWithCubicBezierCurve ) {
1033 KoPoint point = snapPoint( docPoint );
1034 m_pointArray.putPoints( m_indexPointArray, 1, point.x(), point.y() );
1035 ++m_indexPointArray;
1036 }
1037 else {
1038 m_pointArray.putPoints( m_indexPointArray, 2, m_CubicBezierSecondPoint.x(), m_CubicBezierSecondPoint.y(),
1039 m_CubicBezierThirdPoint.x(), m_CubicBezierThirdPoint.y() );
1040 m_indexPointArray += 2;
1041 }
1042
1043 endDrawCubicBezierCurve();
1044
1045 m_gl.repaintAfterSnapping();
1046
1047 return;
1048 }
1049
1050 if ( e->button() == TQt::RightButton && toolEditMode == TEM_MOUSE ) {
1051 KPrObject * obj = getObjectAt( docPoint );
1052 if ( obj )
1053 {
1054 kpobject = obj;
1055 TQPoint pnt = TQCursor::pos();
1056 mousePressed = false;
1057 m_view->disableAutoScroll();
1058 bool state=!( e->state() & ShiftButton ) && !( e->state() & ControlButton ) && !kpobject->isSelected();
1059
1060 if ( state )
1061 deSelectAllObj();
1062 selectObj( kpobject );
1063 objectPopup( kpobject, pnt );
1064 } else {
1065 TQPoint pnt = TQCursor::pos();
1066 m_view->openPopupMenuMenuPage( pnt );
1067 m_view->disableAutoScroll();
1068 mousePressed = false;
1069 }
1070 modType = MT_NONE;
1071
1072 }
1073 else if( e->button() == TQt::RightButton && toolEditMode == TEM_ZOOM ) {
1074 TQPoint pnt = TQCursor::pos();
1075 mousePressed = false;
1076 m_view->disableAutoScroll();
1077 m_view->openPopupMenuZoom( pnt );
1078 }
1079 else if( e->button() == TQt::RightButton && toolEditMode != TEM_MOUSE ) {
1080 //deactivate tools when you click on right button
1081 setToolEditMode( TEM_MOUSE );
1082 }
1083 } else {
1084 if ( e->button() == TQt::LeftButton ) {
1085 if ( m_drawMode ) {
1086 setCursor( KPrUtils::penCursor() );
1087 m_drawLineInDrawMode = true;
1088 m_drawModeLineIndex = 0;
1089 m_drawModeLines.append( TQPointArray() );
1090 m_drawModeLines[m_drawModeLines.count() - 1].putPoints( m_drawModeLineIndex++, 1, e->x(), e->y() );
1091 }
1092 else
1093 m_view->screenNext();
1094 } else if ( e->button() == TQt::MidButton )
1095 m_view->screenPrev();
1096 else if ( e->button() == TQt::RightButton ) {
1097 if ( !m_drawMode && !spManualSwitch() )
1098 {
1100 finishPageEffect();
1101 m_view->stopAutoPresTimer();
1102 }
1103
1104 setCursor( arrowCursor );
1105 TQPoint pnt = TQCursor::pos();
1106 int ret = m_presMenu->exec( pnt );
1107 // we have to continue the timer if the menu was canceled and we draw mode is not active
1108 if ( ret == -1 && !m_presMenu->isItemChecked( PM_DM ) && !spManualSwitch() )
1109 m_view->continueAutoPresTimer();
1110 }
1111 }
1112
1113
1114#if 0 // Where do you need this ? (toshitaka)
1115 // ME: I have no idea why this is needed at all
1116 if ( toolEditMode == TEM_MOUSE )
1117 mouseMoveEvent( e );
1118#endif
1119}
1120
1121KoRect KPrCanvas::getAlignBoundingRect() const
1122{
1123 KoRect boundingRect;
1124
1125 TQPtrListIterator<KPrObject> it( m_activePage->objectList() );
1126 for ( ; it.current() ; ++it )
1127 {
1128 if ( it.current() == m_view->kPresenterDoc()->header() ||
1129 it.current() == m_view->kPresenterDoc()->footer() )
1130 continue;
1131
1132 if( it.current()->isSelected() && !it.current()->isProtect() ) {
1133 boundingRect |= it.current()->getRealRect();
1134 }
1135 }
1136 return boundingRect;
1137}
1138
1139void KPrCanvas::mouseReleaseEvent( TQMouseEvent *e )
1140{
1141 if ( editMode && m_view->kPresenterDoc()->showGuideLines() && toolEditMode == TEM_MOUSE && m_gl.mouseReleaseEvent( e ) )
1142 return;
1143
1144 TQPoint contentsPoint( e->pos().x()+diffx(), e->pos().y()+diffy() );
1145 if(m_currentTextObjectView)
1146 {
1147 m_currentTextObjectView->mouseReleaseEvent( e, contentsPoint );
1148 emit objectSelectedChanged();
1149 m_view->disableAutoScroll();
1150 mousePressed=false;
1151 return;
1152 }
1153
1154 if ( e->button() != TQt::LeftButton )
1155 return;
1156
1157 if ( m_drawMode ) {
1158 m_drawLineInDrawMode = false;
1159 m_drawModeLines[m_drawModeLines.count() - 1].putPoints( m_drawModeLineIndex++, 1, contentsPoint.x(), contentsPoint.y() );
1160 return;
1161 }
1162
1163 TQPtrList<KPrObject> _objects;
1164 _objects.setAutoDelete( false );
1165
1166 if ( ( m_drawPolyline && ( toolEditMode == INS_POLYLINE || toolEditMode == INS_CLOSED_POLYLINE ) )
1167 || ( m_drawCubicBezierCurve && ( toolEditMode == INS_CUBICBEZIERCURVE || toolEditMode == INS_QUADRICBEZIERCURVE
1168 || toolEditMode == INS_CLOSED_CUBICBEZIERCURVE || toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE ) ) ) {
1169 return;
1170 }
1171
1172 m_insertRect = m_insertRect.normalize();
1173
1174 switch ( toolEditMode ) {
1175 case TEM_MOUSE: {
1176 drawContour = false;
1177 switch ( modType ) {
1178 case MT_NONE: {
1179 if ( drawRubber ) {
1180 // used for selecting multiple object in with the mouse
1181 TQPainter p;
1182 p.begin( this );
1183 p.setRasterOp( NotROP );
1184 p.setPen( TQPen( black, 0, DotLine ) );
1185 p.translate( -diffx(), -diffy() );
1186 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1187 p.end();
1188 drawRubber = false;
1189
1190 m_rubber = m_rubber.normalize();
1191
1192 TQPtrListIterator<KPrObject> it( getObjectList() );
1193 for ( ; it.current() ; ++it )
1194 {
1195 if ( it.current()->intersects( m_rubber ) )
1196 {
1197 if( objectIsAHeaderFooterHidden(it.current()))
1198 continue;
1199 it.current()->setSelected( true );
1200 mouseSelectedObject = true;
1201 }
1202 }
1203
1204 if ( mouseSelectedObject )
1205 _repaint( false );
1206 emit objectSelectedChanged();
1207 }
1208 } break;
1209 case MT_MOVE: {
1210 KoPoint move( objectRect( false ).topLeft() - m_moveStartPosMouse );
1211 if ( move != KoPoint( 0, 0 ) )
1212 {
1213 KCommand *cmd=m_activePage->moveObject(m_view, move.x(), move.y());
1214 if(cmd)
1215 m_view->kPresenterDoc()->addCommand( cmd );
1216 } else
1217 {
1218 m_activePage->repaintObj();
1219 }
1220 m_isMoving = false;
1221 }
1222 break;
1223 case MT_RESIZE_UP:
1224 finishResizeObject( i18n( "Resize Object Up" ) );
1225 break;
1226 case MT_RESIZE_DN:
1227 finishResizeObject( i18n( "Resize Object Down" ), false );
1228 break;
1229 case MT_RESIZE_LF:
1230 finishResizeObject( i18n( "Resize Object Left" ) );
1231 break;
1232 case MT_RESIZE_RT:
1233 finishResizeObject( i18n( "Resize Object Right" ) );
1234 break;
1235 case MT_RESIZE_LU:
1236 finishResizeObject( i18n( "Resize Object Left && Up" ) );
1237 break;
1238 case MT_RESIZE_LD:
1239 finishResizeObject( i18n( "Resize Object Left && Down" ) );
1240 break;
1241 case MT_RESIZE_RU:
1242 finishResizeObject( i18n( "Resize Object Right && Up" ) );
1243 break;
1244 case MT_RESIZE_RD:
1245 finishResizeObject( i18n( "Resize Object Right && Down" ) );
1246 break;
1247 }
1248 } break;
1249 case INS_TEXT:
1250 if ( !m_insertRect.isNull() )
1251 {
1252 KPrTextObject* kptextobject = insertTextObject( m_insertRect );
1253 setToolEditMode( TEM_MOUSE );
1254
1255 // User-friendlyness: automatically start editing this textobject
1256 createEditing( kptextobject );
1257 //setTextBackground( kptextobject );
1258 //setCursor( arrowCursor );
1259 }
1260 break;
1261 case TEM_ZOOM:{
1262 drawContour = false;
1263 if( modType == MT_NONE && drawRubber )
1264 {
1265 TQPainter p;
1266 p.begin( this );
1267 p.setRasterOp( NotROP );
1268 p.setPen( TQPen( black, 0, DotLine ) );
1269 p.translate( -diffx(), -diffy() );
1270 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1271 p.end();
1272 drawRubber = false;
1273 m_rubber = m_rubber.normalize();
1274 if ( m_zoomRubberDraw )
1275 {
1276 m_view->setZoomRect( m_rubber );
1277 }
1278 else
1279 {
1280 m_view->zoomPlus();
1281 }
1282 m_zoomRubberDraw = false;
1283 }
1284 }break;
1285 case TEM_ROTATE: {
1286 drawContour = false;
1287 if ( !m_rotateObject )
1288 break;
1289 if ( m_angleBeforeRotate != m_rotateObject->getAngle() ) {
1290 TQPtrList<KPrObject> objects;
1291 objects.append( m_rotateObject );
1292
1293 /* As the object is allready rotated set the angle to
1294 * the m_angleBeforeRotate for the creation of the command, and
1295 * back afterwards. No need for executing the command */
1296 float newAngle = m_rotateObject->getAngle();
1297 m_rotateObject->rotate( m_angleBeforeRotate );
1298
1299 KPrRotateCmd *rotateCmd = new KPrRotateCmd( i18n( "Change Rotation" ), newAngle,
1300 objects, m_view->kPresenterDoc() );
1301 m_view->kPresenterDoc()->addCommand( rotateCmd );
1302
1303 m_rotateObject->rotate( newAngle );
1304 m_rotateObject = NULL;
1305 }
1306 }break;
1307 case INS_LINE:
1308 if ( m_startPoint != m_endPoint )
1309 {
1310 insertLine( m_startPoint, m_endPoint );
1311 m_endPoint = m_startPoint;
1312 }
1313 break;
1314 case INS_RECT:
1315 if ( !m_insertRect.isNull() )
1316 {
1317 insertRect( m_insertRect );
1318 }
1319 break;
1320 case INS_ELLIPSE:
1321 if ( !m_insertRect.isNull() )
1322 {
1323 insertEllipse( m_insertRect );
1324 }
1325 break;
1326 case INS_PIE:
1327 if ( !m_insertRect.isNull() )
1328 {
1329 insertPie( m_insertRect );
1330 }
1331 break;
1332 case INS_OBJECT:
1333 case INS_DIAGRAMM:
1334 case INS_TABLE:
1335 case INS_FORMULA:
1336 if ( !m_insertRect.isNull() )
1337 {
1338 KPrPartObject *kpPartObject = insertObject( m_insertRect );
1339 setToolEditMode( TEM_MOUSE );
1340
1341 if ( kpPartObject )
1342 {
1343 kpPartObject->activate( m_view );
1344 m_editObject = kpPartObject;
1345 }
1346 }
1347 break;
1348 case INS_AUTOFORM:
1349 if ( !m_insertRect.isNull() )
1350 {
1351 insertAutoform( m_insertRect );
1352 }
1353 setToolEditMode( TEM_MOUSE );
1354 break;
1355 case INS_FREEHAND:
1356 if ( !m_pointArray.isNull() )
1357 {
1358 insertFreehand( m_pointArray );
1359 }
1360 break;
1361 case INS_POLYGON:
1362 if ( !m_pointArray.isNull() )
1363 insertPolygon( m_pointArray );
1364 break;
1365 case INS_PICTURE:
1366 case INS_CLIPART:
1367 insertPicture( m_insertRect );
1368 setToolEditMode( TEM_MOUSE );
1369 break;
1370 case INS_CLOSED_FREEHAND: {
1371 if ( !m_pointArray.isNull() )
1372 insertClosedLine( m_pointArray );
1373 }break;
1374 default: break;
1375 }
1376
1377 m_gl.repaintAfterSnapping();
1378
1379 emit objectSelectedChanged();
1380
1381 if ( toolEditMode != TEM_MOUSE && editMode )
1382 repaint( false );
1383
1384 m_view->disableAutoScroll();
1385 mousePressed = false;
1386 modType = MT_NONE;
1387 m_insertRect = KoRect();
1388 mouseMoveEvent( e );
1389}
1390
1391void KPrCanvas::mouseMoveEvent( TQMouseEvent *e )
1392{
1393 if ( editMode && m_view->kPresenterDoc()->showGuideLines() && toolEditMode == TEM_MOUSE && m_gl.mouseMoveEvent( e ) )
1394 return;
1395
1396 TQPoint contentsPoint( e->pos().x()+diffx(), e->pos().y()+diffy() );
1397 KoPoint docPoint = m_view->zoomHandler()->unzoomPoint( contentsPoint );
1398 if(m_currentTextObjectView)
1399 {
1400 if (m_currentTextObjectView->isLinkVariable(e->pos()) )
1401 {
1402 setCursor(TQt::PointingHandCursor);
1403 return;
1404 }
1405 setCursor( arrowCursor );
1406
1407 KPrTextObject *txtObj=m_currentTextObjectView->kpTextObject();
1408 Q_ASSERT(txtObj);
1409 if(txtObj->contains( docPoint )&&mousePressed)
1410 {
1411 KoPoint pos = docPoint - txtObj->innerRect().topLeft();
1412 m_currentTextObjectView->mouseMoveEvent( e, m_view->zoomHandler()->ptToLayoutUnitPix( pos ) ); // in LU pixels
1413 }
1414 return;
1415 }
1416
1417 if (m_view->kPresenterDoc()->getVariableCollection()->variableSetting()->displayLink())
1418 {
1419 KPrObject *tmp_kpobject = getObjectAt( docPoint );
1420 if(tmp_kpobject && tmp_kpobject->getType() == OT_TEXT)
1421 {
1422 KPrTextObject *kptextobject = static_cast<KPrTextObject*>( tmp_kpobject );
1423 TQPoint iPoint = kptextobject->viewToInternal( e->pos(), this );
1424 KoLinkVariable* linkVar = dynamic_cast<KoLinkVariable *>( kptextobject->textObject()->variableAtPoint( iPoint ) );
1425
1426 if ( linkVar )
1427 {
1428 setCursor(TQt::PointingHandCursor);
1429 return;
1430 }
1431 }
1432 }
1433
1434 m_disableSnapping = e->state() & ShiftButton;
1435
1436 if ( editMode ) {
1437 m_view->setRulerMousePos( e->x(), e->y() );
1438
1439 if ( toolEditMode == TEM_ROTATE )
1440 {
1441 setCursor( KPrUtils::rotateCursor() );
1442 if ( !mousePressed )
1443 return;
1444 }
1445 KPrObject *kpobject;
1446 if ( ( !mousePressed || ( !drawRubber && modType == MT_NONE ) ) &&
1447 toolEditMode == TEM_MOUSE )
1448 {
1449 bool cursorAlreadySet = false;
1450 if ( (int)objectList().count() > 0 )
1451 {
1452 kpobject = m_activePage->getCursor( docPoint );
1453 if( kpobject)
1454 {
1455 setCursor( kpobject->getCursor( docPoint, modType, m_view->kPresenterDoc() ) );
1456
1457 cursorAlreadySet = true;
1458 }
1459 }
1460
1461 if ( !cursorAlreadySet )
1462 setCursor( arrowCursor );
1463 else
1464 return;
1465 } else if ( mousePressed ) {
1466 switch ( toolEditMode ) {
1467 case TEM_MOUSE: {
1468 drawContour = true;
1469 if ( modType == MT_NONE ) {
1470 if ( drawRubber )
1471 {
1472 TQPainter p;
1473 p.begin( this );
1474 p.setRasterOp( NotROP );
1475 p.setPen( TQPen( black, 0, DotLine ) );
1476 p.translate( -diffx(), -diffy() );
1477 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1478 m_rubber.setRight( docPoint.x() );
1479 m_rubber.setBottom( docPoint.y() );
1480 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1481 p.end();
1482 }
1483 } else if ( modType == MT_MOVE ) {
1484 if ( !m_isMoving )
1485 {
1486 m_moveSnapDiff= KoPoint(0,0);
1487 m_moveStartPoint = objectRect( false ).topLeft();
1488 m_isMoving = true;
1489 }
1490 moveObjectsByMouse( docPoint, e->state() & AltButton || e->state() & ControlButton );
1491 } else if ( modType != MT_NONE && m_resizeObject ) {
1492 if ( !m_isResizing )
1493 {
1494 m_isResizing = true;
1495 }
1496
1497 KoPoint sp( snapPoint( docPoint, false ) );
1498
1499 bool keepRatio = m_resizeObject->isKeepRatio();
1500 if ( e->state() & AltButton )
1501 {
1502 keepRatio = true;
1503 }
1504 bool scaleAroundCenter = false;
1505 if ( e->state() & ControlButton )
1506 {
1507 scaleAroundCenter = true;
1508 }
1509
1510 resizeObject( modType, sp, keepRatio, scaleAroundCenter );
1511 }
1512 } break;
1513 case TEM_ZOOM : {
1514 if ( drawRubber ) {
1515 TQPainter p;
1516 p.begin( this );
1517 p.setRasterOp( NotROP );
1518 p.setPen( TQPen( black, 0, DotLine ) );
1519 p.translate( -diffx(), -diffy() );
1520 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1521 m_rubber.setRight( docPoint.x() );
1522 m_rubber.setBottom( docPoint.y() );
1523 p.drawRect( m_view->zoomHandler()->zoomRect( m_rubber ) );
1524 p.end();
1525 m_zoomRubberDraw = true;
1526 }
1527 }break;
1528 case TEM_ROTATE: {
1529 if ( m_rotateObject )
1530 {
1531 drawContour = true;
1532 // angle to mouse pos
1533 double angle = KoPoint::getAngle( m_rotateCenter, docPoint );
1534 // angle to start of mouse pos
1535 double angle1 = KoPoint::getAngle( m_rotateCenter, m_rotateStart );
1536
1537 angle -= angle1;
1538 angle += m_angleBeforeRotate;
1539 if ( angle < 0 )
1540 angle += 360;
1541 else if ( angle > 360 )
1542 angle -= 360;
1543
1544 m_rotateObject->rotate( angle );
1545 _repaint( m_rotateObject );
1546 }
1547 }break;
1548 case INS_AUTOFORM:
1549 case INS_DIAGRAMM:
1550 case INS_FORMULA:
1551 case INS_CLIPART:
1552 case INS_PICTURE:
1553 case INS_OBJECT:
1554 case INS_TABLE:
1555 case INS_TEXT:
1556 {
1557 TQPainter p( this );
1558 p.setPen( TQPen( black, 1, SolidLine ) );
1559 p.setBrush( NoBrush );
1560 p.setRasterOp( NotROP );
1561 p.translate( -diffx(), -diffy() );
1562
1563 KoPoint sp( snapPoint( docPoint ) );
1564 p.drawRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
1565 updateInsertRect( sp, e->state() );
1566 p.drawRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
1567
1568 p.end();
1569
1570 mouseSelectedObject = true;
1571 } break;
1572 case INS_ELLIPSE: {
1573 TQPainter p( this );
1574 p.setPen( TQPen( black, 1, SolidLine ) );
1575 p.setBrush( NoBrush );
1576 p.setRasterOp( NotROP );
1577 p.translate( -diffx(), -diffy() );
1578
1579 KoPoint sp( snapPoint( docPoint ) );
1580 p.drawEllipse( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
1581 updateInsertRect( sp, e->state() );
1582 p.drawEllipse( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ) );
1583
1584 p.end();
1585
1586 mouseSelectedObject = true;
1587 } break;
1588 case INS_RECT: {
1589 TQPainter p( this );
1590 p.setPen( TQPen( black, 1, SolidLine ) );
1591 p.setBrush( NoBrush );
1592 p.setRasterOp( NotROP );
1593 p.translate( -diffx(), -diffy() );
1594
1595 KoPoint sp( snapPoint( docPoint ) );
1596 p.drawRoundRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ), m_view->getRndX(), m_view->getRndY() );
1597 updateInsertRect( sp, e->state() );
1598 p.drawRoundRect( m_view->zoomHandler()->zoomRect( m_insertRect.normalize() ), m_view->getRndX(), m_view->getRndY() );
1599
1600 p.end();
1601
1602 mouseSelectedObject = true;
1603 } break;
1604 case INS_LINE: {
1605 TQPainter p( this );
1606 p.setPen( TQPen( black, 1, SolidLine ) );
1607 p.setBrush( NoBrush );
1608 p.setRasterOp( NotROP );
1609 p.translate( -diffx(), -diffy() );
1610
1611 KoPoint oldEndPoint( m_endPoint );
1612 m_endPoint = snapPoint( docPoint );
1613 //remove the old line
1614 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1615 m_view->zoomHandler()->zoomPoint( oldEndPoint ) );
1616
1617 if ( e->state() & AltButton )
1618 {
1619 m_startPoint += m_endPoint - oldEndPoint;
1620 }
1621
1622 // print the new line
1623 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1624 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
1625 p.end();
1626
1627 mouseSelectedObject = true;
1628 } break;
1629 case INS_PIE: {
1630 TQPainter p( this );
1631 p.setPen( TQPen( black, 1, SolidLine ) );
1632 p.setBrush( NoBrush );
1633 p.setRasterOp( NotROP );
1634 p.translate( -diffx(), -diffy() );
1635
1636 KoPoint sp( snapPoint( docPoint ) );
1637 drawPieObject( &p, m_insertRect );
1638 updateInsertRect( sp, e->state() );
1639 drawPieObject( &p, m_insertRect );
1640
1641 p.end();
1642
1643 mouseSelectedObject = true;
1644 } break;
1645 case INS_FREEHAND:
1646 case INS_CLOSED_FREEHAND:
1647 {
1648 m_endPoint = snapPoint( docPoint );
1649 if ( m_endPoint != m_startPoint )
1650 {
1651 TQPainter p( this );
1652 p.setPen( TQPen( black, 1, SolidLine ) );
1653 p.setBrush( NoBrush );
1654 p.setRasterOp( NotROP );
1655 p.translate( -diffx(), -diffy() );
1656
1657 if ( e->state() & AltButton )
1658 {
1659 TQPointArray pointArray = m_pointArray.zoomPointArray( m_view->zoomHandler() );
1660 // erase
1661 p.drawPolyline( pointArray );
1662 m_pointArray.translate( m_endPoint.x() - m_startPoint.x(),
1663 m_endPoint.y() - m_startPoint.y() );
1664 pointArray = m_pointArray.zoomPointArray( m_view->zoomHandler() );
1665 // draw
1666 p.drawPolyline( pointArray );
1667 }
1668 else
1669 {
1670 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1671 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
1672 }
1673 p.end();
1674
1675 m_pointArray.putPoints( m_indexPointArray, 1, m_endPoint.x(), m_endPoint.y() );
1676 ++m_indexPointArray;
1677 m_startPoint = m_endPoint;
1678 }
1679
1680 mouseSelectedObject = true;
1681 } break;
1682 case INS_POLYLINE: case INS_CLOSED_POLYLINE: {
1683 TQPainter p( this );
1684 p.setPen( TQPen( black, 1, SolidLine ) );
1685 p.setBrush( NoBrush );
1686 p.setRasterOp( NotROP );
1687 p.translate( -diffx(), -diffy() );
1688
1689 KoPoint oldEndPoint( m_endPoint );
1690 m_endPoint = snapPoint( docPoint );
1691 //remove the old line
1692 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1693 m_view->zoomHandler()->zoomPoint( oldEndPoint ) );
1694
1695 if ( e->state() & AltButton )
1696 {
1697 TQPointArray pointArray = m_pointArray.zoomPointArray( m_view->zoomHandler() );
1698 // erase
1699 p.drawPolyline( pointArray );
1700 m_pointArray.translate( m_endPoint.x() - oldEndPoint.x(),
1701 m_endPoint.y() - oldEndPoint.y() );
1702 pointArray = m_pointArray.zoomPointArray( m_view->zoomHandler() );
1703 // draw
1704 p.drawPolyline( pointArray );
1705 m_startPoint += m_endPoint - oldEndPoint;
1706 }
1707
1708 // print the new line
1709 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
1710 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
1711 p.end();
1712
1713 mouseSelectedObject = true;
1714 } break;
1715 case INS_CUBICBEZIERCURVE: case INS_QUADRICBEZIERCURVE:
1716 case INS_CLOSED_CUBICBEZIERCURVE: case INS_CLOSED_QUADRICBEZIERCURVE:{
1717 TQPainter p( this );
1718 p.setPen( TQPen( black, 1, SolidLine ) );
1719 p.setBrush( NoBrush );
1720 p.setRasterOp( NotROP );
1721 p.translate( -diffx(), -diffy() );
1722
1723 KoPoint newEndPoint( snapPoint( docPoint ) );
1724
1725 drawCubicBezierCurve( p, m_oldCubicBezierPointArray );
1726
1727 if ( e->state() & AltButton )
1728 {
1729 // erase
1731
1732 KoPoint diff( newEndPoint - m_endPoint );
1733 m_pointArray.translate( diff.x(), diff.y() );
1734 m_endPoint = newEndPoint;
1735 m_startPoint += diff;
1736
1737 // draw
1739 }
1740 else
1741 {
1742 m_endPoint = newEndPoint;
1743 }
1744
1745 KoPointArray points;
1746 if ( !m_drawLineWithCubicBezierCurve )
1747 {
1748 double _firstX = m_pointArray.at( m_indexPointArray - 2 ).x();
1749 double _firstY = m_pointArray.at( m_indexPointArray - 2 ).y();
1750
1751 double _fourthX = m_pointArray.at( m_indexPointArray - 1 ).x();
1752 double _fourthY = m_pointArray.at( m_indexPointArray - 1 ).y();
1753
1754 double _midpointX = (_firstX + _fourthX ) / 2;
1755 double _midpointY = (_firstY + _fourthY ) / 2;
1756 double _diffX = _fourthX - _midpointX;
1757 double _diffY = _fourthY - _midpointY;
1758
1759 double _secondX = m_endPoint.x() - _diffX;
1760 double _secondY = m_endPoint.y() - _diffY;
1761 m_CubicBezierSecondPoint = KoPoint( _secondX, _secondY );
1762
1763 m_symmetricEndPoint = m_startPoint * 2 - m_endPoint;
1764
1765 double _thirdX = m_symmetricEndPoint.x() - _diffX;
1766 double _thirdY = m_symmetricEndPoint.y() - _diffY;
1767 m_CubicBezierThirdPoint = KoPoint( _thirdX, _thirdY );
1768
1769 if ( toolEditMode == INS_QUADRICBEZIERCURVE || toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE ) {
1770 _secondX = _thirdX;
1771 _secondY = _thirdY;
1772 m_CubicBezierSecondPoint = KoPoint( _secondX, _secondY );
1773 }
1774 points.putPoints( 0, 4, _firstX,_firstY, _secondX,_secondY, _thirdX,_thirdY, _fourthX,_fourthY );
1775 }
1776
1777 drawCubicBezierCurve( p, points );
1778 if ( points.size() > 0 )
1779 {
1780 m_oldCubicBezierPointArray = points;
1781 }
1782
1783 mouseSelectedObject = true;
1784 } break;
1785 case INS_POLYGON: {
1786 TQPainter p( this );
1787 p.setPen( TQPen( black, 1, SolidLine ) );
1788 p.setBrush( NoBrush );
1789 p.setRasterOp( NotROP );
1790 p.translate( -diffx(), -diffy() );
1791
1792 KoPoint sp( snapPoint( docPoint ) );
1793 // erase old
1794 drawPolygon( p, m_insertRect );
1795 updateInsertRect( sp, e->state() );
1796 // print new
1797 drawPolygon( p, m_insertRect );
1798
1799 mouseSelectedObject = true;
1800 } break;
1801 default: break;
1802 }
1803 }
1804 } else if ( !editMode && m_drawMode && m_drawLineInDrawMode ) {
1805 TQPainter p;
1806 p.begin( this );
1807 p.setPen( m_view->kPresenterDoc()->presPen() );
1808 p.drawLine( m_drawModeLines[m_drawModeLines.count() - 1].point( m_drawModeLineIndex - 1 ), e->pos() );
1809 p.end();
1810 m_drawModeLines[m_drawModeLines.count() - 1].putPoints( m_drawModeLineIndex++, 1, e->x(), e->y() );
1811 }
1812
1813 if ( !editMode && !m_drawMode && !m_presMenu->isVisible() && fillBlack )
1814 setCursor( blankCursor );
1815}
1816
1817void KPrCanvas::mouseDoubleClickEvent( TQMouseEvent *e )
1818{
1819 if(!m_view->koDocument()->isReadWrite())
1820 return;
1821 TQPoint contentsPoint( e->pos().x()+diffx(), e->pos().y()+diffy() );
1822 KoPoint docPoint = m_view->zoomHandler()->unzoomPoint( contentsPoint );
1823 if(m_currentTextObjectView)
1824 {
1825 KPrTextObject *txtObj=m_currentTextObjectView->kpTextObject();
1826 Q_ASSERT(txtObj);
1827 if(txtObj->contains( docPoint ))
1828 {
1829 KoPoint pos = docPoint - txtObj->getOrig();
1830 //pos=m_view->zoomHandler()->pixelToLayoutUnit(TQPoint(pos.x(),pos.y()));
1831 m_currentTextObjectView->mouseDoubleClickEvent( e, m_view->zoomHandler()->ptToLayoutUnitPix( pos ) );
1832 return;
1833 }
1834 }
1835
1836 //disallow activating objects outside the "page"
1837 if ( !m_activePage->getPageRect().contains(docPoint))
1838 return;
1839
1840
1841 if ( ( toolEditMode == INS_POLYLINE || toolEditMode == INS_CLOSED_POLYLINE ) && !m_pointArray.isNull() && m_drawPolyline )
1842 {
1843 m_startPoint = snapPoint( docPoint );
1844
1845 m_pointArray.putPoints( m_indexPointArray, 1, m_startPoint.x(), m_startPoint.y() );
1846 ++m_indexPointArray;
1847 endDrawPolyline();
1848
1849 mouseMoveEvent( e );
1850 return;
1851 }
1852
1853
1854 if ( toolEditMode != TEM_MOUSE || !editMode ) return;
1855
1856 KPrObject *kpobject = getObjectAt( docPoint );
1857 if(kpobject)
1858 {
1859 if ( kpobject->getType() == OT_TEXT )
1860 {
1861 deSelectAllObj();
1862 KPrTextObject *kptextobject = dynamic_cast<KPrTextObject*>( kpobject );
1863 if(kptextobject && (!kptextobject->isProtectContent() || kptextobject->isProtectContent()
1864 && m_view->kPresenterDoc()->cursorInProtectedArea()))
1865 {
1866 if(m_currentTextObjectView)
1867 {
1868 m_currentTextObjectView->terminate();
1869 delete m_currentTextObjectView;
1870 }
1871 m_currentTextObjectView=kptextobject->createKPTextView(this);
1872
1873 //setTextBackground( kptextobject );
1874 setCursor( arrowCursor );
1875 m_editObject = kpobject;
1876 }
1877 }
1878 else if ( kpobject->getType() == OT_PART )
1879 {
1880 deSelectAllObj();
1881 KPrPartObject * obj=dynamic_cast<KPrPartObject *>(kpobject);
1882 if(obj)
1883 {
1884 obj->activate( m_view );
1885 m_editObject = obj;
1886 }
1887 }
1888 else
1889 getView()->extraProperties();
1890 }
1891}
1892
1893void KPrCanvas::drawPieObject( TQPainter *p, const KoRect & rect )
1894{
1895 TQRect pRect( m_view->zoomHandler()->zoomRect( rect ) );
1896 switch ( m_view->getPieType() ) {
1897 case PT_PIE:
1898 p->drawPie( pRect.x(), pRect.y(), pRect.width() - 2,
1899 pRect.height() - 2, m_view->getPieAngle(), m_view->getPieLength() );
1900 break;
1901 case PT_ARC:
1902 p->drawArc( pRect.x(), pRect.y(), pRect.width() - 2,
1903 pRect.height() - 2, m_view->getPieAngle(), m_view->getPieLength() );
1904 break;
1905 case PT_CHORD:
1906 p->drawChord( pRect.x(), pRect.y(), pRect.width() - 2,
1907 pRect.height() - 2, m_view->getPieAngle(), m_view->getPieLength() );
1908 break;
1909 default: break;
1910 }
1911
1912}
1913
1914void KPrCanvas::wheelEvent( TQWheelEvent *e )
1915{
1916 if ( !editMode && !m_drawMode ) {
1917 if ( e->delta() == -120 ) // wheel down
1918 m_view->screenNext();
1919 else if ( e->delta() == 120 ) // wheel up
1920 m_view->screenPrev();
1921 e->accept();
1922 }
1923 else if ( editMode )
1924 emit sigMouseWheelEvent( e );
1925}
1926
1927void KPrCanvas::keyPressEvent( TQKeyEvent *e )
1928{
1929 if ( editMode && m_view->kPresenterDoc()->showGuideLines() && m_gl.keyPressEvent( e ) )
1930 return;
1931 if ( !editMode ) {
1932 switch ( e->key() ) {
1933 case TQt::Key_Space: case Key_Right: case Key_Down:
1934 setSwitchingMode( false );
1935 m_view->screenNext();
1936 break;
1937 case TQt::Key_Next:
1938 setSwitchingMode( false );
1939 m_view->screenNext( true );
1940 break;
1941 case TQt::Key_Backspace: case Key_Left: case Key_Up:
1942 setSwitchingMode( false );
1944 finishPageEffect( true );
1945 m_view->screenPrev();
1946 break;
1947 case TQt::Key_Prior:
1948 setSwitchingMode( false );
1950 finishPageEffect( true );
1951 m_view->screenPrev( true );
1952 break;
1953 case TQt::Key_Escape: case Key_Q: case Key_X:
1954 setSwitchingMode( false );
1956 finishPageEffect( true );
1957 m_view->screenStop();
1958 break;
1959 case TQt::Key_G:
1960 // setSwitchingMode( false ) not needed as it is allready done in slotGotoPage;
1961 if ( !spManualSwitch() )
1962 m_view->stopAutoPresTimer();
1963 slotGotoPage();
1964 break;
1965 case TQt::Key_Home: // go to first page
1966 setSwitchingMode( false );
1968 if ( !spManualSwitch() ) {
1969 m_view->setAutoPresTimer( 1 );
1970 m_setPageTimer = true;
1971 }
1972 break;
1973 case TQt::Key_End: // go to last page
1974 setSwitchingMode( false );
1975 if ( m_presentationSlidesIterator != m_presentationSlides.end() ) {
1976 gotoPage( *(--m_presentationSlides.end()) );
1977 if ( !spManualSwitch() ) {
1978 m_view->setAutoPresTimer( 1 );
1979 m_setPageTimer = true;
1980 }
1981 }
1982 break;
1983 default: break;
1984 }
1985 } else if ( m_editObject ) {
1986 if ( e->key() == TQt::Key_Escape ) {
1987 exitEditMode();
1988 }
1989 else if ( m_currentTextObjectView )
1990 {
1991 if ( !m_currentTextObjectView->kpTextObject()->isProtectContent() || (e->text().length() == 0))
1992 m_currentTextObjectView->keyPressEvent( e );
1993 else
1994 KMessageBox::information(this, i18n("Read-only content cannot be changed. No modifications will be accepted."));
1995 }
1996 }
1997 else
1998 {
1999 switch ( e->key() )
2000 {
2001 case TQt::Key_Next:
2002 m_view->nextPage();
2003 break;
2004 case TQt::Key_Prior:
2005 m_view->prevPage();
2006 break;
2007 case TQt::Key_Home: // go to first page
2008 m_view->screenFirst();
2009 break;
2010 case TQt::Key_End: // go to first page
2011 m_view->screenLast();
2012 break;
2013 default:
2014 break;
2015 }
2016
2017 if ( mouseSelectedObject )
2018 {
2019 m_disableSnapping = e->state() & ShiftButton;
2020
2021 int offsetx = 1;
2022 int offsety = 1;
2023
2024 if ( e->state() & ControlButton )
2025 {
2026 offsetx = TQMAX(1,m_view->zoomHandler()->zoomItX(10));
2027 offsety = TQMAX(1,m_view->zoomHandler()->zoomItY(10));
2028 }
2029
2030 if ( !m_keyPressEvent )
2031 {
2032 m_moveStartPosKey = objectRect( false ).topLeft();
2033 }
2034 switch ( e->key() )
2035 {
2036 case TQt::Key_Up:
2037 m_keyPressEvent = true;
2038 moveObjectsByKey( 0, -offsety );
2039 break;
2040 case TQt::Key_Down:
2041 m_keyPressEvent = true;
2042 moveObjectsByKey( 0, offsety );
2043 break;
2044 case TQt::Key_Right:
2045 m_keyPressEvent = true;
2046 moveObjectsByKey( offsetx, 0 );
2047 break;
2048 case TQt::Key_Left:
2049 m_keyPressEvent = true;
2050 moveObjectsByKey( -offsetx, 0 );
2051 break;
2052 case TQt::Key_Delete:
2053 case Key_Backspace:
2054 m_view->editDelete();
2055 break;
2056 case TQt::Key_Escape:
2057 {
2058 if ( mousePressed && toolEditMode == TEM_MOUSE )
2059 {
2060 switch (modType)
2061 {
2062 case MT_RESIZE_UP:
2063 case MT_RESIZE_DN:
2064 case MT_RESIZE_LF:
2065 case MT_RESIZE_RT:
2066 case MT_RESIZE_LU:
2067 case MT_RESIZE_LD:
2068 case MT_RESIZE_RU:
2069 case MT_RESIZE_RD:
2070 {
2071 TQRect oldBoundingRect = m_view->zoomHandler()->zoomRect( m_resizeObject->getRepaintRect() );
2072 m_resizeObject->setOrig( m_rectBeforeResize.topLeft() );
2073 m_resizeObject->setSize( m_rectBeforeResize.size() );
2074 drawContour = false;
2075 m_view->kPresenterDoc()->repaint( oldBoundingRect );
2076 m_view->kPresenterDoc()->repaint( m_resizeObject );
2077 m_ratio = 0.0;
2078 m_resizeObject = 0;
2079 m_isResizing = false;
2080 m_view->disableAutoScroll();
2081 mousePressed = false;
2082 modType = MT_NONE;
2083 return;
2084 }
2085 case MT_MOVE:
2086 {
2087 if ( m_isMoving )
2088 {
2089 drawContour = false;
2090 KoPoint move( m_moveStartPoint - objectRect( false ).topLeft() );
2091 m_activePage->moveObject( m_view, move, false );
2092 m_view->disableAutoScroll();
2093 mousePressed = false;
2094 modType = MT_NONE;
2095 m_isMoving = false;
2096 return;
2097 }
2098 break;
2099 }
2100 default:
2101 break;
2102 }
2103 }
2104 setToolEditMode( TEM_MOUSE );
2105 break;
2106 }
2107 case TQt::Key_Shift:
2108 {
2109 bool oldChangeSnap = m_disableSnapping;
2110 m_disableSnapping = e->key() == TQt::Key_Shift;
2111 if ( !oldChangeSnap && m_disableSnapping )
2112 {
2113 m_gl.repaintAfterSnapping();
2114 }
2115 // undo snapping for move by mouse
2116 if ( e->state() & TQt::LeftButton && m_isMoving )
2117 {
2118 moveObjectsByMouse( m_origMousePos, e->state() & AltButton || e->state() & ControlButton );
2119 }
2120 break;
2121 }
2122 default: break;
2123 }
2124 }
2125 else
2126 {
2127 switch ( e->key() ) {
2128 case TQt::Key_Down:
2129 m_view->getVScrollBar()->addLine();
2130 break;
2131 case TQt::Key_Up:
2132 m_view->getVScrollBar()->subtractLine();
2133 break;
2134 case TQt::Key_Right:
2135 m_view->getHScrollBar()->addLine();
2136 break;
2137 case TQt::Key_Left:
2138 m_view->getHScrollBar()->subtractLine();
2139 break;
2140 case TQt::Key_Tab:
2141 selectNext();
2142 break;
2143 case TQt::Key_Backtab:
2144 selectPrev();
2145 break;
2146 case TQt::Key_Escape:
2147 if ( toolEditMode == TEM_ZOOM )
2148 setToolEditMode( TEM_MOUSE );
2149 break;
2150 default: break;
2151 }
2152 }
2153 }
2154}
2155
2156void KPrCanvas::keyReleaseEvent( TQKeyEvent *e )
2157{
2158 if ( editMode && m_currentTextObjectView )
2159 m_currentTextObjectView->keyReleaseEvent( e );
2160 else
2161 {
2162 if ( mouseSelectedObject )
2163 {
2164 if(e->key()==TQt::Key_Up || e->key()==Key_Down || e->key()==Key_Right || e->key()==Key_Left)
2165 {
2166 if ( !e->isAutoRepeat() )
2167 {
2168 KoPoint move( objectRect( false ).topLeft() - m_moveStartPosKey);
2169 KCommand *cmd=m_activePage->moveObject(m_view, move.x(), move.y());
2170 if(cmd)
2171 m_view->kPresenterDoc()->addCommand( cmd );
2172 m_keyPressEvent = false;
2173 }
2174 emit objectSelectedChanged();
2175 }
2176 }
2177 }
2178}
2179
2180void KPrCanvas::imStartEvent( TQIMEvent * e )
2181{
2182 if ( m_editObject && m_currentTextObjectView )
2183 {
2184 if ( !m_currentTextObjectView->kpTextObject()->isProtectContent() )
2185 m_currentTextObjectView->imStartEvent( e );
2186 else
2187 KMessageBox::information(this, i18n("Read-only content cannot be changed. No modifications will be accepted."));
2188 }
2189}
2190
2191void KPrCanvas::imComposeEvent( TQIMEvent * e )
2192{
2193 if ( m_editObject && m_currentTextObjectView )
2194 {
2195 if ( !m_currentTextObjectView->kpTextObject()->isProtectContent() )
2196 m_currentTextObjectView->imComposeEvent( e );
2197 }
2198}
2199
2200void KPrCanvas::imEndEvent( TQIMEvent * e )
2201{
2202 if ( m_editObject && m_currentTextObjectView )
2203 {
2204 if ( !m_currentTextObjectView->kpTextObject()->isProtectContent() )
2205 m_currentTextObjectView->imEndEvent( e );
2206 }
2207}
2208
2209void KPrCanvas::resizeEvent( TQResizeEvent *e )
2210{
2211 if ( editMode )
2212 {
2213 TQWidget::resizeEvent( e );
2214 }
2215 else
2216 TQWidget::resizeEvent( new TQResizeEvent( TDEGlobalSettings::desktopGeometry(this).size(),
2217 e->oldSize() ) );
2218 buffer.resize( size() );
2219}
2220
2221bool KPrCanvas::close( bool alsoDelete )
2222{
2223 if ( editMode )
2224 {
2225 return TQWidget::close(alsoDelete);
2226 }
2227 else
2228 {
2229 m_view->screenStop();
2230 return false;
2231 }
2232}
2233
2234KPrObject * KPrCanvas::getObjectAt( const KoPoint &pos, bool withoutProtected )
2235{
2236 KPrObject *object = m_activePage->getObjectAt( pos, withoutProtected );
2237 if ( objectIsAHeaderFooterHidden( object ) )
2238 object = 0;
2239
2240 return object;
2241}
2242
2243void KPrCanvas::selectObj( KPrObject *kpobject )
2244{
2245 kpobject->setSelected( true );
2246 _repaint( kpobject );
2247 emit objectSelectedChanged();
2248
2249 mouseSelectedObject = true;
2250}
2251
2252void KPrCanvas::deSelectObj( KPrObject *kpobject )
2253{
2254 kpobject->setSelected( false );
2255 _repaint( kpobject );
2256
2257 if ( !m_activePage->isOneObjectSelected() )
2258 {
2259 mouseSelectedObject = false;
2260 }
2261 emit objectSelectedChanged();
2262}
2263
2264void KPrCanvas::selectAllObj()
2265{
2266 TQPtrListIterator<KPrObject> it( m_activePage->objectList() );
2267 for ( ; it.current() ; ++it )
2268 {
2269 if ( !objectIsAHeaderFooterHidden(it.current()) )
2270 it.current()->setSelected( true );
2271 }
2272
2273 mouseSelectedObject = true;
2274 _repaint( false );
2275 emit objectSelectedChanged();
2276}
2277
2278
2279void KPrCanvas::deSelectAllObj()
2280{
2281 if( m_activePage->numSelected() == 0 )
2282 return;
2283
2284 lowerObject();
2285
2286 m_activePage->deSelectAllObj();
2287
2288 //desactivate kptextview when we switch of page
2289 if(m_currentTextObjectView)
2290 {
2291 m_currentTextObjectView->terminate();
2292 m_currentTextObjectView->kpTextObject()->setEditingTextObj( false );
2293 delete m_currentTextObjectView;
2294 m_currentTextObjectView=0L;
2295 }
2296 mouseSelectedObject = false;
2297 emit objectSelectedChanged();
2298}
2299
2300void KPrCanvas::setMouseSelectedObject(bool b)
2301{
2302 mouseSelectedObject = b;
2303 emit objectSelectedChanged();
2304}
2305
2307{
2308 // create right button presentation menu
2309 m_presMenu = new TDEPopupMenu();
2310 TQ_CHECK_PTR( m_presMenu );
2311 m_presMenu->setCheckable( true );
2312 m_presMenu->insertTitle( i18n( "Slide Show" ) );
2313 m_presMenu->insertItem( i18n( "&Continue" ), this, TQ_SLOT( setSwitchingMode() ) );
2314 PM_DM = m_presMenu->insertItem( i18n( "&Drawing Mode" ), this, TQ_SLOT( setDrawingMode() ) );
2315 m_presMenu->insertSeparator();
2316 m_presMenu->insertItem( SmallIcon("goto"), i18n( "&Goto Slide..." ), this, TQ_SLOT( slotGotoPage() ) );
2317 m_presMenu->insertSeparator();
2318 m_presMenu->insertItem( i18n( "&End" ), this, TQ_SLOT( slotExitPres() ) );
2319 m_presMenu->setItemChecked( PM_DM, false );
2320 m_presMenu->setMouseTracking( true );
2321}
2322
2323void KPrCanvas::clipCut()
2324{
2325 if ( m_currentTextObjectView )
2326 m_currentTextObjectView->cut();
2327 m_view->editCut();
2328}
2329
2330void KPrCanvas::clipCopy()
2331{
2332 if ( m_currentTextObjectView )
2333 m_currentTextObjectView->copy();
2334 m_view->editCopy();
2335}
2336
2337void KPrCanvas::clipPaste()
2338{
2339 if ( m_currentTextObjectView )
2340 m_currentTextObjectView->paste();
2341 m_view->editPaste();
2342}
2343
2344void KPrCanvas::chPic()
2345{
2346 m_activePage->chPic( m_view );
2347}
2348
2350 int nWidth,
2351 int nHeight,
2352 const KURL& _fileURL,
2353 const char* format,
2354 int quality )
2355{
2356 bool res = false;
2357 const TQCursor oldCursor( cursor() );
2358 setCursor( waitCursor );
2359 TQPixmap pix( nWidth, nHeight );
2360 drawPageInPix( pix, nPage, 0, true, nWidth, nHeight );
2361 if( !pix.isNull() ){
2362 // Depending on the desired target size due to rounding
2363 // errors during zoom the resulting pixmap *might* be
2364 // 1 pixel or 2 pixels wider/higher than desired: we just
2365 // remove the additional columns/rows. This can be done
2366 // since KPresenter is leaving a minimal border below/at
2367 // the right of the image anyway.
2368 const TQSize desiredSize(nWidth, nHeight);
2369 if( desiredSize != pix.size() )
2370 pix.resize( desiredSize );
2371 // save the pixmap to the desired file
2372 KURL fileURL(_fileURL);
2373 if( fileURL.protocol().isEmpty() )
2374 fileURL.setProtocol( "file" );
2375 const bool bLocalFile = fileURL.isLocalFile();
2376 KTempFile* tmpFile = bLocalFile ? NULL : new KTempFile();
2377 if( !bLocalFile )
2378 tmpFile->setAutoDelete( true );
2379 if( bLocalFile || 0 == tmpFile->status() ){
2380 TQFile file( bLocalFile ? fileURL.path(0) : tmpFile->name() );
2381 if ( file.open( IO_ReadWrite ) ) {
2382 res = pix.save( &file, format, quality );
2383 file.close();
2384 }
2385 if( !bLocalFile ){
2386 if( res ){
2387 res = TDEIO::NetAccess::upload( tmpFile->name(), fileURL, this );
2388 }
2389 }
2390 }
2391 if( !bLocalFile ){
2392 delete tmpFile;
2393 }
2394 }
2395 setCursor( oldCursor );
2396 return res;
2397}
2398
2399void KPrCanvas::savePicture()
2400{
2401 m_activePage->savePicture( m_view );
2402}
2403
2404void KPrCanvas::setTextFormat(const KoTextFormat &format, int flags)
2405{
2406 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2407 if ( lst.isEmpty() ) return;
2408 KMacroCommand* macroCmd = new KMacroCommand( i18n("Change Text Font") );
2409 TQPtrListIterator<KoTextFormatInterface> it( lst );
2410 for ( ; it.current() ; ++it ) {
2411 KCommand *cmd = it.current()->setFormatCommand(&format, flags, true);
2412
2413 if (cmd)
2414 macroCmd->addCommand( cmd );
2415 }
2416 m_view->kPresenterDoc()->addCommand( macroCmd );
2417}
2418
2419void KPrCanvas::setTextColor( const TQColor &color )
2420{
2421 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2422 if ( lst.isEmpty() ) return;
2423 TQPtrListIterator<KoTextFormatInterface> it( lst );
2424 KMacroCommand* macroCmd = new KMacroCommand( i18n("Set Text Color") );
2425 for ( ; it.current() ; ++it ) {
2426 KCommand* cmd = it.current()->setTextColorCommand( color );
2427 if (cmd)
2428 macroCmd->addCommand( cmd );
2429 }
2430 m_view->kPresenterDoc()->addCommand( macroCmd );
2431}
2432
2433void KPrCanvas::setTextBackgroundColor( const TQColor &color )
2434{
2435 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2436 if ( lst.isEmpty() ) return;
2437 TQPtrListIterator<KoTextFormatInterface> it( lst );
2438 KMacroCommand* macroCmd = 0L;
2439 for ( ; it.current() ; ++it ) {
2440 KCommand* cmd = it.current()->setTextBackgroundColorCommand( color );
2441 if ( cmd )
2442 {
2443 if ( !macroCmd )
2444 macroCmd = new KMacroCommand( i18n("Set Text Background Color") );
2445 macroCmd->addCommand( cmd );
2446 }
2447 }
2448 if (macroCmd )
2449 m_view->kPresenterDoc()->addCommand( macroCmd );
2450}
2451
2452void KPrCanvas::setTextBold( bool b )
2453{
2454 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2455 if ( lst.isEmpty() ) return;
2456 TQPtrListIterator<KoTextFormatInterface> it( lst );
2457 KMacroCommand* macroCmd = 0L;
2458 for ( ; it.current() ; ++it ) {
2459 KCommand* cmd = it.current()->setBoldCommand( b );
2460 if ( cmd )
2461 {
2462 if ( !macroCmd )
2463 macroCmd = new KMacroCommand( i18n("Make Text Bold") );
2464 macroCmd->addCommand( cmd );
2465 }
2466 }
2467 if ( macroCmd )
2468 m_view->kPresenterDoc()->addCommand( macroCmd );
2469}
2470
2471void KPrCanvas::setTextItalic( bool b )
2472{
2473 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2474 if ( lst.isEmpty() ) return;
2475 TQPtrListIterator<KoTextFormatInterface> it( lst );
2476 KMacroCommand* macroCmd = 0L;
2477 for ( ; it.current() ; ++it ) {
2478 KCommand* cmd = it.current()->setItalicCommand( b );
2479 if ( cmd )
2480 {
2481 if ( !macroCmd )
2482 macroCmd = new KMacroCommand( i18n("Make Text Italic") );
2483 macroCmd->addCommand( cmd );
2484 }
2485 }
2486 if (macroCmd )
2487 m_view->kPresenterDoc()->addCommand( macroCmd );
2488}
2489
2490void KPrCanvas::setTextUnderline( bool b )
2491{
2492 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2493 if ( lst.isEmpty() ) return;
2494 TQPtrListIterator<KoTextFormatInterface> it( lst );
2495 KMacroCommand* macroCmd = 0L;
2496 for ( ; it.current() ; ++it ) {
2497 KCommand* cmd = it.current()->setUnderlineCommand( b );
2498 if ( cmd )
2499 {
2500 if ( !macroCmd )
2501 macroCmd = new KMacroCommand( i18n("Underline Text") );
2502 macroCmd->addCommand( cmd );
2503 }
2504 }
2505 if ( macroCmd )
2506 m_view->kPresenterDoc()->addCommand( macroCmd );
2507}
2508
2509void KPrCanvas::setTextStrikeOut( bool b )
2510{
2511 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2512 if ( lst.isEmpty() ) return;
2513 KMacroCommand* macroCmd = 0L;
2514 TQPtrListIterator<KoTextFormatInterface> it( lst );
2515 for ( ; it.current() ; ++it ) {
2516 KCommand *cmd = it.current()->setStrikeOutCommand( b );
2517 if ( cmd )
2518 {
2519 if ( !macroCmd )
2520 macroCmd = new KMacroCommand( i18n("Make Text Italic") );
2521 macroCmd->addCommand( cmd );
2522 }
2523 }
2524 if ( macroCmd )
2525 m_view->kPresenterDoc()->addCommand( macroCmd );
2526}
2527
2528void KPrCanvas::setTextFamily( const TQString &f )
2529{
2530 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2531 if ( lst.isEmpty() ) return;
2532 KMacroCommand* macroCmd = 0L;
2533 TQPtrListIterator<KoTextFormatInterface> it( lst );
2534 for ( ; it.current() ; ++it ) {
2535 KCommand* cmd = it.current()->setFamilyCommand( f );
2536 if ( cmd )
2537 {
2538 if ( !macroCmd )
2539 macroCmd = new KMacroCommand( i18n("Set Text Font") );
2540 macroCmd->addCommand( cmd );
2541 }
2542 }
2543 if ( macroCmd)
2544 m_view->kPresenterDoc()->addCommand( macroCmd );
2545}
2546
2547void KPrCanvas::setTextPointSize( int s )
2548{
2549 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2550 if ( lst.isEmpty() ) return;
2551 KMacroCommand* macroCmd = 0L;
2552 TQPtrListIterator<KoTextFormatInterface> it( lst );
2553 for ( ; it.current() ; ++it ) {
2554 KCommand* cmd = it.current()->setPointSizeCommand( s );
2555 if ( cmd )
2556 {
2557 if ( !macroCmd )
2558 macroCmd = new KMacroCommand( i18n("Change Text Size") );
2559 macroCmd->addCommand( cmd );
2560 }
2561
2562 }
2563 if (macroCmd)
2564 m_view->kPresenterDoc()->addCommand( macroCmd );
2565}
2566
2567void KPrCanvas::setTextSubScript( bool b )
2568{
2569 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2570 if ( lst.isEmpty() ) return;
2571 TQPtrListIterator<KoTextFormatInterface> it( lst );
2572 KMacroCommand* macroCmd = 0L;
2573 for ( ; it.current() ; ++it ) {
2574 KCommand* cmd = it.current()->setTextSubScriptCommand( b );
2575 if ( cmd )
2576 {
2577 if ( !macroCmd )
2578 macroCmd = new KMacroCommand( i18n("Set Text Subscript") );
2579 macroCmd->addCommand( cmd );
2580 }
2581 }
2582 if ( macroCmd )
2583 m_view->kPresenterDoc()->addCommand( macroCmd );
2584}
2585
2586void KPrCanvas::setTextSuperScript( bool b )
2587{
2588 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2589 if ( lst.isEmpty() ) return;
2590 TQPtrListIterator<KoTextFormatInterface> it( lst );
2591 KMacroCommand* macroCmd = 0L;
2592 for ( ; it.current() ; ++it ) {
2593 KCommand* cmd = it.current()->setTextSuperScriptCommand( b );
2594 if ( cmd )
2595 {
2596 if ( !macroCmd )
2597 macroCmd = new KMacroCommand( i18n("Set Text Superscript") );
2598 macroCmd->addCommand( cmd );
2599 }
2600 }
2601 if ( macroCmd )
2602 m_view->kPresenterDoc()->addCommand( macroCmd );
2603}
2604
2605void KPrCanvas::setTextDefaultFormat( )
2606{
2607 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2608 if ( lst.isEmpty() ) return;
2609 TQPtrListIterator<KoTextFormatInterface> it( lst );
2610 KMacroCommand* macroCmd = 0L;
2611 for ( ; it.current() ; ++it ) {
2612 KCommand* cmd = it.current()->setDefaultFormatCommand( );
2613 if ( cmd )
2614 {
2615 if ( !macroCmd )
2616 macroCmd = new KMacroCommand( i18n("Apply Default Format") );
2617 macroCmd->addCommand( cmd );
2618 }
2619 }
2620 if (macroCmd)
2621 m_view->kPresenterDoc()->addCommand( macroCmd );
2622}
2623
2624void KPrCanvas::setIncreaseFontSize()
2625{
2626 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2627 if ( lst.isEmpty() ) return;
2628 TQPtrListIterator<KoTextFormatInterface> it( lst );
2629 int size = it.current()->currentFormat()->pointSize();
2630 KMacroCommand* macroCmd =0L;
2631 for ( ; it.current() ; ++it ) {
2632 KCommand* cmd = it.current()->setPointSizeCommand( size+1 );
2633 if ( cmd )
2634 {
2635 if ( !macroCmd )
2636 macroCmd = new KMacroCommand( i18n("Increase Font Size") );
2637 macroCmd->addCommand( cmd );
2638 }
2639 }
2640 if ( macroCmd)
2641 m_view->kPresenterDoc()->addCommand( macroCmd );
2642}
2643
2644void KPrCanvas::setDecreaseFontSize()
2645{
2646 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2647 if ( lst.isEmpty() ) return;
2648 TQPtrListIterator<KoTextFormatInterface> it( lst );
2649 int size = it.current()->currentFormat()->pointSize();
2650 KMacroCommand* macroCmd = 0L;
2651 for ( ; it.current() ; ++it ) {
2652 KCommand* cmd = it.current()->setPointSizeCommand( size-1 );
2653 if ( cmd )
2654 {
2655 if ( !macroCmd )
2656 macroCmd = new KMacroCommand( i18n("Decrease Font Size") );
2657 macroCmd->addCommand( cmd );
2658 }
2659 }
2660 if ( macroCmd )
2661 m_view->kPresenterDoc()->addCommand( macroCmd );
2662}
2663
2664void KPrCanvas::setTextAlign( int align )
2665{
2666 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2667 if ( lst.isEmpty() ) return;
2668 TQPtrListIterator<KoTextFormatInterface> it( lst );
2669 KMacroCommand* macroCmd = 0L;
2670 for ( ; it.current() ; ++it ) {
2671 KCommand* cmd = it.current()->setAlignCommand(align);
2672 if ( cmd )
2673 {
2674 if ( !macroCmd)
2675 macroCmd = new KMacroCommand( i18n("Set Text Align") );
2676 macroCmd->addCommand( cmd );
2677 }
2678 }
2679 if ( macroCmd )
2680 m_view->kPresenterDoc()->addCommand( macroCmd );
2681}
2682
2683void KPrCanvas::setTabList( const KoTabulatorList & tabList )
2684{
2685 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2686 if ( lst.isEmpty() ) return;
2687 TQPtrListIterator<KoTextFormatInterface> it( lst );
2688 KMacroCommand* macroCmd = 0L;
2689 for ( ; it.current() ; ++it ) {
2690 KCommand* cmd = it.current()->setTabListCommand(tabList );
2691 if ( cmd )
2692 {
2693 if ( !macroCmd )
2694 macroCmd = new KMacroCommand( i18n("Change Tabulators") );
2695 macroCmd->addCommand( cmd );
2696 }
2697 }
2698 if ( macroCmd)
2699 m_view->kPresenterDoc()->addCommand( macroCmd );
2700}
2701
2702void KPrCanvas::setTextDepthPlus()
2703{
2704 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2705 if ( lst.isEmpty() ) return;
2706 double leftMargin=0.0;
2707 if(!lst.isEmpty())
2708 leftMargin=lst.first()->currentParagLayoutFormat()->margins[TQStyleSheetItem::MarginLeft];
2709 double indent = m_view->kPresenterDoc()->getIndentValue();
2710 double newVal = leftMargin + indent;
2711 TQPtrListIterator<KoTextFormatInterface> it( lst );
2712 KMacroCommand* macroCmd = 0L;
2713 for ( ; it.current() ; ++it ) {
2714 KCommand* cmd = it.current()->setMarginCommand(TQStyleSheetItem::MarginLeft, newVal);
2715 if ( cmd )
2716 {
2717 if ( !macroCmd )
2718 macroCmd = new KMacroCommand( i18n("Increase Paragraph Depth") );
2719 macroCmd->addCommand( cmd );
2720 }
2721 }
2722 if ( macroCmd )
2723 m_view->kPresenterDoc()->addCommand( macroCmd );
2724 if(!lst.isEmpty())
2725 {
2726 const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
2727 m_view->showRulerIndent( layout->margins[TQStyleSheetItem::MarginLeft], layout->margins[TQStyleSheetItem::MarginFirstLine],
2728 layout->margins[TQStyleSheetItem::MarginRight], lst.first()->rtl());
2729 }
2730}
2731
2732void KPrCanvas::setTextDepthMinus()
2733{
2734 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2735 if ( lst.isEmpty() ) return;
2736 double leftMargin=0.0;
2737 if(!lst.isEmpty())
2738 leftMargin=lst.first()->currentParagLayoutFormat()->margins[TQStyleSheetItem::MarginLeft];
2739 double indent = m_view->kPresenterDoc()->getIndentValue();
2740 TQPtrListIterator<KoTextFormatInterface> it( lst );
2741 double newVal = leftMargin - indent;
2742 KMacroCommand* macroCmd = 0L;
2743 for ( ; it.current() ; ++it ) {
2744 KCommand* cmd = it.current()->setMarginCommand(TQStyleSheetItem::MarginLeft, TQMAX( newVal, 0 ));
2745 if ( cmd )
2746 {
2747 if ( !macroCmd )
2748 macroCmd = new KMacroCommand( i18n("Decrease Paragraph Depth") );
2749 macroCmd->addCommand( cmd );
2750 }
2751 }
2752 if (macroCmd )
2753 m_view->kPresenterDoc()->addCommand( macroCmd );
2754 if(!lst.isEmpty())
2755 {
2756 const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
2757 m_view->showRulerIndent( layout->margins[TQStyleSheetItem::MarginLeft], layout->margins[TQStyleSheetItem::MarginFirstLine],
2758 layout->margins[TQStyleSheetItem::MarginRight], lst.first()->rtl());
2759 }
2760}
2761
2762void KPrCanvas::setNewFirstIndent(double _firstIndent)
2763{
2764 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2765 if ( lst.isEmpty() ) return;
2766 TQPtrListIterator<KoTextFormatInterface> it( lst );
2767 KMacroCommand* macroCmd = 0L;
2768 for ( ; it.current() ; ++it ) {
2769 KCommand* cmd = it.current()->setMarginCommand(TQStyleSheetItem::MarginFirstLine, _firstIndent);
2770 if ( cmd )
2771 {
2772 if ( !macroCmd )
2773 macroCmd = new KMacroCommand( i18n("Change First Line Indent") );
2774 macroCmd->addCommand( cmd );
2775 }
2776 }
2777 if ( macroCmd )
2778 m_view->kPresenterDoc()->addCommand( macroCmd );
2779}
2780
2781void KPrCanvas::setNewLeftIndent(double _leftIndent)
2782{
2783 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2784 if ( lst.isEmpty() ) return;
2785 TQPtrListIterator<KoTextFormatInterface> it( lst );
2786 KMacroCommand* macroCmd = 0L;
2787 for ( ; it.current() ; ++it ) {
2788 KCommand* cmd = it.current()->setMarginCommand(TQStyleSheetItem::MarginLeft, _leftIndent);
2789 if ( cmd )
2790 {
2791 if ( !macroCmd )
2792 macroCmd = new KMacroCommand( i18n("Change Left Indent") );
2793 macroCmd->addCommand( cmd );
2794 }
2795 }
2796 if ( macroCmd )
2797 m_view->kPresenterDoc()->addCommand( macroCmd );
2798}
2799
2800void KPrCanvas::setNewRightIndent(double _rightIndent)
2801{
2802 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2803 if ( lst.isEmpty() ) return;
2804 TQPtrListIterator<KoTextFormatInterface> it( lst );
2805 KMacroCommand* macroCmd = 0L;
2806 for ( ; it.current() ; ++it ) {
2807 KCommand* cmd = it.current()->setMarginCommand(TQStyleSheetItem::MarginRight, _rightIndent);
2808 if ( cmd )
2809 {
2810 if ( !macroCmd )
2811 macroCmd = new KMacroCommand( i18n("Change Right Indent") );
2812 macroCmd->addCommand( cmd );
2813 }
2814 }
2815 if ( macroCmd )
2816 m_view->kPresenterDoc()->addCommand( macroCmd );
2817}
2818
2819/*void KPrCanvas::setTextCounter(KoParagCounter counter)
2820{
2821 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
2822 if ( lst.isEmpty() ) return;
2823 TQPtrListIterator<KoTextFormatInterface> it( lst );
2824 KMacroCommand* macroCmd = 0L;
2825 for ( ; it.current() ; ++it ) {
2826 KCommand* cmd = it.current()->setCounterCommand(counter );
2827 if ( cmd )
2828 {
2829 if ( !macroCmd )
2830 macroCmd = new KMacroCommand( i18n("Change Paragraph Type") );
2831 macroCmd->addCommand( cmd );
2832 }
2833 }
2834 if ( macroCmd )
2835 m_view->kPresenterDoc()->addCommand( macroCmd );
2836}*/
2837
2838#ifndef NDEBUG
2839void KPrCanvas::printRTDebug( int info )
2840{
2841 KPrTextObject *kpTxtObj = 0;
2842 if ( m_currentTextObjectView )
2843 kpTxtObj = m_currentTextObjectView->kpTextObject();
2844 else
2845 kpTxtObj = selectedTextObjs().first();
2846 if ( kpTxtObj )
2847 kpTxtObj->textObject()->printRTDebug( info );
2848}
2849#endif
2850
2851bool KPrCanvas::haveASelectedPartObj() const
2852{
2853 return m_activePage->haveASelectedPartObj();
2854}
2855
2856bool KPrCanvas::haveASelectedGroupObj() const
2857{
2858 return m_activePage->haveASelectedGroupObj();
2859}
2860
2861bool KPrCanvas::haveASelectedPixmapObj() const
2862{
2863 return m_activePage->haveASelectedPixmapObj();
2864}
2865
2866TQPtrList<KPrTextObject> KPrCanvas::applicableTextObjects() const
2867{
2868 TQPtrList<KPrTextObject> lst;
2869 // If we're editing a text object, then that's the one we return
2870 if ( m_currentTextObjectView )
2871 lst.append( m_currentTextObjectView->kpTextObject() );
2872 else
2873 lst = selectedTextObjs();
2874 return lst;
2875}
2876
2877TQPtrList<KoTextFormatInterface> KPrCanvas::applicableTextInterfaces() const
2878{
2879 TQPtrList<KoTextFormatInterface> lst;
2880 TQPtrList<KPrObject> lstObj;
2881 // If we're editing a text object, then that's the one we return
2882 if ( m_currentTextObjectView )
2883 {
2884 if ( !m_currentTextObjectView->kpTextObject()->isProtectContent())
2885 lst.append( m_currentTextObjectView );
2886 }
2887 else
2888 {
2889 m_activePage->getAllObjectSelectedList(lstObj);
2890 TQPtrListIterator<KPrObject> it(lstObj);
2891 for ( ; it.current(); ++it ) {
2892 if ( it.current()->getType() == OT_TEXT )
2893 {
2894 KPrTextObject * obj = static_cast<KPrTextObject*>( it.current() );
2895 if ( !obj->isProtectContent() )
2896 lst.append( obj->textObject() );
2897 }
2898 }
2899 }
2900 return lst;
2901}
2902
2903TQPtrList<KPrTextObject> KPrCanvas::selectedTextObjs() const
2904{
2905 TQPtrList<KPrTextObject> lst;
2906 TQPtrListIterator<KPrObject> it(getObjectList());
2907 for ( ; it.current(); ++it ) {
2908 if ( it.current()->isSelected() && it.current()->getType() == OT_TEXT )
2909 lst.append( static_cast<KPrTextObject*>( it.current() ) );
2910 }
2911 return lst;
2912}
2913
2914void KPrCanvas::startScreenPresentation( double zoomX, double zoomY, int curPgNum /* 1-based */)
2915{
2916 //kdDebug(33001) << "KPrCanvas::startScreenPresentation curPgNum=" << curPgNum << endl;
2917
2918 //setup presentation menu
2919 m_presMenu->setItemChecked( PM_DM, false );
2920
2921 setCursor( waitCursor );
2922
2923 exitEditMode();
2924
2925 KPrDocument * doc = m_view->kPresenterDoc();
2926
2927 // Text can't zoom with a different x and y factor, yet.
2928 // So we have to choose the smallest zoom (but still paint background everywhere)
2929 double zoom = kMin( zoomX, zoomY );
2930
2931 kdDebug() << "zoomX=" << zoomX << " zoomY=" << zoomY << " zoom=" << zoom << endl;
2932
2933 m_zoomBeforePresentation = doc->zoomHandler()->zoom();
2934 kdDebug() << "old zoomed resolutions =" << doc->zoomHandler()->zoomedResolutionX() << "," << doc->zoomHandler()->zoomedResolutionY() << endl;
2935 // Seems to fail (TQt uses the wrong font sizes...)
2936 //doc->zoomHandler()->setZoomedResolution( zoomX * doc->zoomHandler()->zoomedResolutionX(),
2937 // zoomY * doc->zoomHandler()->zoomedResolutionY() );
2938 // Apply the new zooming to the existing one
2939 doc->zoomHandler()->setZoomAndResolution( tqRound( zoom * m_zoomBeforePresentation ),
2940 KoGlobal::dpiX(), KoGlobal::dpiY() );
2941
2942 doc->newZoomAndResolution( false, false );
2943
2944 // add all selected slides
2945 m_presentationSlides.clear();
2946 TQValueList<int> selected = doc->displaySelectedSlides();
2947 for ( TQValueList<int>::Iterator it = selected.begin() ; it != selected.end(); ++ it )
2948 {
2949 // ARGLLLRGLRLGRLG selectedSlides gets us 0-based numbers,
2950 // and here we want 1-based numbers !
2951 int slideno = *it + 1;
2952 m_presentationSlides.append( slideno );
2953 }
2954
2955 // no slide selected ? end the slide show immediately...
2956 if( !m_presentationSlides.count() )
2957 {
2958 //kdDebug(33001) << "No slide: end the slide show" << endl;
2959 stopScreenPresentation();
2960 return;
2961 }
2962
2963 // find first selected slide after curPgNum
2964 unsigned slide = 0;
2965 for( unsigned i = 0; i<m_presentationSlides.count(); i++ )
2966 if( m_presentationSlides[i] >= curPgNum )
2967 {
2968 slide = m_presentationSlides[i];
2969 break;
2970 }
2971
2972 setCursor( blankCursor );
2973
2974 m_step.m_pageNumber = (unsigned int) -1; // force gotoPage to do something
2975 gotoPage( slide );
2976 //kdDebug(33001) << "Page::startScreenPresentation - done" << endl;
2977}
2978
2979void KPrCanvas::stopScreenPresentation()
2980{
2981 //kdDebug(33001) << "KPrCanvas::stopScreenPresentation m_showOnlyPage=" << m_showOnlyPage << endl;
2982 setCursor( waitCursor );
2983
2984 KPrDocument * doc = m_view->kPresenterDoc();
2985 doc->zoomHandler()->setZoomAndResolution( m_zoomBeforePresentation,
2986 KoGlobal::dpiX(), KoGlobal::dpiY() );
2987 doc->newZoomAndResolution(false,false);
2988 goingBack = false;
2989 m_step.m_pageNumber = 0;
2990 editMode = true;
2991 m_drawMode = false;
2992 repaint( false );
2993 setToolEditMode( toolEditMode );
2994 setWFlags( WResizeNoErase );
2995}
2996
2997bool KPrCanvas::pNext( bool gotoNextPage )
2998{
2999 goingBack = false;
3000
3001 bool objectEffectFinished = finishObjectEffects();
3002
3003 KPrDocument * doc = m_view->kPresenterDoc();
3004
3005 if ( !gotoNextPage )
3006 {
3007 if ( finishPageEffect() )
3008 return false;
3009
3010 // clear drawed lines
3011 m_drawModeLines.clear();
3012
3013 //kdDebug(33001) << "\n-------\nKPrCanvas::pNext m_step =" << m_step.m_step << " m_subStep =" << m_step.m_subStep << endl;
3014
3015 // First try to go one sub-step further, if any object requires it
3016 // ### should we also objects on the sticky page be checked for sub steps?
3017 TQPtrListIterator<KPrObject> oit( doc->pageList().at( m_step.m_pageNumber )->objectList() );
3018 for ( int i = 0 ; oit.current(); ++oit, ++i )
3019 {
3020 KPrObject *kpobject = oit.current();
3021 if ( kpobject->getAppearStep() == static_cast<int>( m_step.m_step )
3022 && kpobject->getType() == OT_TEXT && kpobject->getEffect2() != EF2_NONE )
3023 {
3024 if ( static_cast<int>( m_step.m_subStep + 1 ) < kpobject->getSubPresSteps() )
3025 {
3026 m_step.m_subStep++;
3027 //kdDebug(33001) << "Page::pNext addSubPres m_subStep is now " << m_subStep << endl;
3028 doObjEffects();
3029 return false;
3030 }
3031 }
3032 }
3033
3034 // Then try to see if there is still one step to do in the current page
3035 if ( m_step.m_step < *( --m_pageEffectSteps.end() ) )
3036 {
3037 TQValueList<int>::ConstIterator it = m_pageEffectSteps.find( m_step.m_step );
3038 m_step.m_step = *( ++it );
3039 m_step.m_subStep = 0;
3040 //kdDebug(33001) << "Page::pNext setting currentEffectStep to " << m_step.m_step << endl;
3041
3042 // if first step on page, draw background
3043 if ( m_step.m_step == 0 )
3044 {
3045 TQPainter p;
3046 p.begin( this );
3047 drawBackground( &p,
3048 TQRect( 0, 0, kapp->desktop()->width(), kapp->desktop()->height() ),
3049 doc->pageList().at( m_step.m_pageNumber ) );
3050 p.end();
3051 }
3052
3053 doObjEffects();
3054 return false;
3055 }
3056
3057 /*
3058 * don't go to next slide if we have finished an object effect
3059 * so that we can see the hole slide before going to the next
3060 */
3061 if ( objectEffectFinished )
3062 return false;
3063 }
3064
3065 // No more steps in this page, try to go to the next page
3066 TQValueList<int>::ConstIterator test( m_presentationSlidesIterator );
3067 if ( ++test != m_presentationSlides.end() )
3068 {
3069 if ( !spManualSwitch() && m_setPageTimer )
3070 {
3071 //TODO add global presentation speed
3072 m_view->setAutoPresTimer( doc->pageList().at( (*m_presentationSlidesIterator) - 1 )->getPageTimer() / 1 );
3073 m_setPageTimer = false;
3074 return false;
3075 }
3076 m_setPageTimer = true;
3077
3078 TQRect desk = TDEGlobalSettings::desktopGeometry(this);
3079 TQPixmap _pix1( desk.width(), desk.height() );
3080 drawCurrentPageInPix( _pix1 );
3081
3082 m_view->setPageDuration( m_step.m_pageNumber );
3083
3084 m_step.m_pageNumber = *( ++m_presentationSlidesIterator ) - 1;
3085 m_step.m_subStep = 0;
3086
3087 m_pageEffectSteps = doc->getPageEffectSteps( m_step.m_pageNumber );
3088 m_step.m_step = *m_pageEffectSteps.begin();
3089
3090 TQPixmap _pix2( desk.width(), desk.height() );
3091 drawCurrentPageInPix( _pix2 );
3092
3093 TQValueList<int>::ConstIterator it( m_presentationSlidesIterator );
3094 --it;
3095
3096 KPrPage * page = doc->pageList().at( ( *it ) - 1 );
3097 PageEffect _pageEffect = page->getPageEffect();
3098
3099 bool _soundEffect = page->getPageSoundEffect();
3100 TQString _soundFileName = page->getPageSoundFileName();
3101
3102 if ( _soundEffect && !_soundFileName.isEmpty() ) {
3103 stopSound();
3104 playSound( _soundFileName );
3105 }
3106
3107 if ( m_pageEffect )
3108 finishPageEffect();
3109
3110 m_pageEffect = new KPrPageEffects( this, _pix2, _pageEffect, page->getPageEffectSpeed() );
3111 if ( m_pageEffect->doEffect() )
3112 {
3113 delete m_pageEffect;
3114 m_pageEffect = 0;
3115
3116 doObjEffects( true );
3117 }
3118 else
3119 {
3120 connect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotDoPageEffect() ) );
3121 m_pageEffectTimer.start( 50, true );
3122 }
3123
3124 return true;
3125 }
3126
3127 //kdDebug(33001) << "Page::pNext last slide -> End of presentation" << endl;
3128
3129 // When we are in manual mode or in automatic mode with no infinite loop
3130 // we display the 'End of presentation' slide, unles told explicitly by showEndOfPresentationSlide
3131 if ( ( spManualSwitch() || !spInfiniteLoop() ) && !showingLastSlide && spShowEndOfPresentationSlide() )
3132 {
3133 m_view->setPageDuration( m_step.m_pageNumber );
3134
3135 TQRect desk = TDEGlobalSettings::desktopGeometry(this);
3136 TQPixmap lastSlide( desk.width(), desk.height() );
3137 TQFont font( m_view->kPresenterDoc()->defaultFont().family() );
3138 TQPainter p( &lastSlide );
3139
3140 p.setFont( font );
3141 p.setPen( white );
3142 p.fillRect( p.viewport(), black );
3143 p.drawText( 50, 50, i18n( "End of presentation. Click to exit." ) );
3144 bitBlt( this, 0, 0, &lastSlide, 0, 0, lastSlide.width(), lastSlide.height() );
3145 showingLastSlide = true;
3146 emit stopAutomaticPresentation(); // no automatic mode for last slide
3147 }
3148 else if ( showingLastSlide || !spShowEndOfPresentationSlide() ) // after last slide stop presentation
3149 {
3150 showingLastSlide = false;
3151 m_view->screenStop();
3152 }
3153 else
3154 {
3155 m_view->setPageDuration( m_step.m_pageNumber );
3156 emit restartPresentation(); // tells automatic mode to restart
3157 m_view->setAutoPresTimer( 1 );
3158 }
3159
3160 return false;
3161}
3162
3163bool KPrCanvas::pPrev( bool gotoPreviousPage )
3164{
3165 goingBack = true;
3166 m_step.m_subStep = 0;
3167
3168 // clear drawed lines
3169 m_drawModeLines.clear();
3170
3171 if ( !gotoPreviousPage && m_step.m_step > *m_pageEffectSteps.begin() ) {
3172 TQValueList<int>::ConstIterator it = m_pageEffectSteps.find( m_step.m_step );
3173 m_step.m_step = *( --it );
3174 //hopefully there are never more than 1000 sub steps :-)
3175 m_step.m_subStep = 1000;
3176 repaint( false );
3177 return false;
3178 } else {
3179 // when we go back on the first slide, thats like starting the presentation again
3180 if ( m_presentationSlidesIterator == m_presentationSlides.begin() ) {
3181 m_pageEffectSteps = m_view->kPresenterDoc()->getPageEffectSteps( m_step.m_pageNumber );
3182 m_step.m_step = *m_pageEffectSteps.begin();
3183 goingBack = false;
3184 doObjEffects();
3185 return false;
3186 }
3187 m_view->setPageDuration( m_step.m_pageNumber );
3188
3189 m_step.m_pageNumber = *( --m_presentationSlidesIterator ) - 1;
3190
3191 KPrDocument * doc = m_view->kPresenterDoc();
3192
3193 m_pageEffectSteps = doc->getPageEffectSteps( m_step.m_pageNumber );
3194
3195 if ( gotoPreviousPage )
3196 {
3197 m_step.m_step = *( m_pageEffectSteps.begin() );
3198 goingBack = false;
3199 doObjEffects();
3200 }
3201 else
3202 {
3203 m_step.m_step = *( --m_pageEffectSteps.end() );
3204 repaint( false );
3205 }
3206
3207 return true;
3208 }
3209
3210 return false;
3211}
3212
3213bool KPrCanvas::canAssignEffect( TQPtrList<KPrObject> &objs ) const
3214{
3215 TQPtrListIterator<KPrObject> oIt( m_activePage->objectList() );
3216 for (; oIt.current(); ++oIt )
3217 {
3218 //can't assign a effect to header/footer
3219 if(m_view->kPresenterDoc()->isHeaderFooter(oIt.current()))
3220 continue;
3221 if ( oIt.current()->isSelected() )
3222 objs.append( oIt.current() );
3223 }
3224 return !objs.isEmpty();
3225}
3226
3227bool KPrCanvas::isOneObjectSelected() const
3228{
3229 return m_activePage->isOneObjectSelected();
3230}
3231
3232// This one is used to generate the pixmaps for the HTML presentation,
3233// for the pres-structure-dialog, for the sidebar previews, for template icons.
3234// Set forceWidth and/or forceHeight to override the zoom factor
3235// and obtain a pixmap of the specified width and/or height.
3236// By omitting one of them you make sure that the aspect ratio
3237// of your page is used for the resulting image.
3238void KPrCanvas::drawPageInPix( TQPixmap &_pix, int pgnum, int zoom,
3239 bool forceRealVariableValue,
3240 int forceWidth,
3241 int forceHeight )
3242{
3243 //kdDebug(33001) << "Page::drawPageInPix" << endl;
3244
3245 KPrDocument *doc = m_view->kPresenterDoc();
3246 int oldZoom = doc->zoomHandler()->zoom();
3247 bool oldDisplayFieldValue = false;
3248
3249 if( 0 < forceWidth || 0 < forceHeight )
3250 {
3251 const TQRect rect( doc->getPageRect( true ) );
3252 const double dRectHeight = static_cast<double>(rect.height());
3253 const double dRectWidth = static_cast<double>(rect.width());
3254 double dForceHeight = static_cast<double>(forceHeight);
3255 double dForceWidth = static_cast<double>(forceWidth);
3256
3257 // adjust width or height, in case one of them is missing
3258 if( 0 >= forceWidth )
3259 dForceWidth = dForceHeight * dRectWidth / dRectHeight;
3260 else if( 0 >= forceHeight )
3261 dForceHeight = dForceWidth * dRectHeight / dRectWidth;
3262
3263 // set the stretching values
3264 // ### TODO: this should probably be setZoomedResolution, please test
3265 doc->zoomHandler()->setResolution( dForceWidth / dRectWidth,
3266 dForceHeight / dRectHeight );
3267 // As of yet (Feb. 2004) the following call results
3268 // in a NOP but be prepared for the future...
3269 doc->newZoomAndResolution( false, false );
3270 }else{
3271 m_view->zoomDocument(zoom);
3272 }
3273
3274 if ( forceRealVariableValue )
3275 {
3276 oldDisplayFieldValue = m_view->kPresenterDoc()->getVariableCollection()->variableSetting()->displayFieldCode();
3277 if ( oldDisplayFieldValue )
3278 {
3279 m_view->kPresenterDoc()->getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
3280 m_view->kPresenterDoc()->recalcVariables( VT_ALL );
3281 }
3282 }
3283
3284 KPrPage * page = m_view->kPresenterDoc()->pageList().at(pgnum);
3285 TQRect rect = page->getZoomPageRect( );
3286 _pix.resize( rect.size() );
3287 _pix.fill( TQt::white );
3288
3289 TQPainter p;
3290 p.begin( &_pix );
3291
3292 bool _editMode = editMode;
3293 editMode = false;
3294
3295 drawBackground( &p, _pix.rect(), page, true );
3296
3297 // draw objects on master slide
3298 if ( page->masterPage() && page->displayObjectFromMasterPage() )
3299 drawAllObjectsInPage( &p, page->masterPage()->objectList(), pgnum );
3300
3301 //objects in current page
3302 drawAllObjectsInPage( &p, page->objectList(), pgnum );
3303
3304 editMode = _editMode;
3305 p.end();
3306
3307 if ( forceRealVariableValue )
3308 {
3309 if ( oldDisplayFieldValue )
3310 {
3311 m_view->kPresenterDoc()->getVariableCollection()->variableSetting()->setDisplayFieldCode(true);
3312 m_view->kPresenterDoc()->recalcVariables( VT_ALL );
3313 }
3314 }
3315
3316 m_view->zoomDocument(oldZoom);
3317}
3318
3319// This one is used in fullscreenmode, to generate the pixmaps used for the
3320// page effects.
3321void KPrCanvas::drawCurrentPageInPix( TQPixmap &_pix ) const
3322{
3323 //kdDebug(33001) << "Page::drawCurrentPageInPix" << endl;
3324
3325 // avoid garbage on "weird" DPIs
3326 _pix.fill(TQt::black);
3327
3328 TQPainter p;
3329 p.begin( &_pix );
3330
3331 drawBackground( &p, _pix.rect(), m_view->kPresenterDoc()->pageList().at( m_step.m_pageNumber ) );
3332 PresStep step( m_step.m_pageNumber, m_step.m_step, m_step.m_subStep, true, true );
3333 drawPresPage( &p, _pix.rect(), step );
3334
3335 p.end();
3336}
3337
3338void KPrCanvas::printPage( TQPainter* painter, PresStep step, KPrinter *printer, int rows, int cols )
3339{
3340 //kdDebug(33001) << "KPrCanvas::printPage" << endl;
3341 KPrDocument *doc = m_view->kPresenterDoc();
3342 KPrPage* page = doc->pageList().at( step.m_pageNumber );
3343 TQRect const rect = page->getZoomPageRect();
3344 bool const drawBorder = printer->option("kde-kpresenter-printslideborders").toInt() && rows>1 && cols>1;
3345
3346 int height = rect.height();
3347 int width = rect.width();
3348
3349 TQPaintDeviceMetrics metrics( printer );
3350 int begin_left = ( metrics.width() - rect.width() );
3351 int begin_top = ( metrics.height() - rect.height() );
3352
3353 rows = cols = TQMAX( rows, cols ); // all slides have the same size
3354
3355 if ( rows > 1 )
3356 {
3357 height = ( ( height - 80 ) / rows ) - 20;
3358 begin_top = 40;
3359 }
3360 if ( cols > 1 )
3361 {
3362 width = (width -5) / cols;
3363 begin_left = 5;
3364 }
3365 int top = begin_top;
3366 int left = begin_left;
3367 for (int r = 0; r < rows; r++ )
3368 {
3369 for (int c = 0; c < cols; c++ )
3370 {
3371 page = doc->pageList().at( step.m_pageNumber );
3372 if ( !page )
3373 return;
3374 painter->setViewport( TQRect(left, top, width, height) );
3375 drawBackground( painter, rect, page, true );
3376 drawPresPage( painter, rect, step );
3377 if ( drawBorder )
3378 painter->drawRect( rect );
3379 step.m_pageNumber++;
3380 left += width;
3381 }
3382 top += height + 20; // some y-space between the slides
3383 left = begin_left;
3384 }
3385
3386}
3387
3388void KPrCanvas::doObjEffects( bool isAllreadyPainted )
3389{
3390 if ( m_effectHandler )
3391 {
3392 m_effectTimer.stop();
3393 TQObject::disconnect( &m_effectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoEffect() ) );
3394
3395 m_effectHandler->finish();
3396 delete m_effectHandler;
3397 m_effectHandler = 0;
3398 }
3399
3400 TQPixmap screen_orig( kapp->desktop()->width(), kapp->desktop()->height() );
3401
3402 KPrPage *page = m_view->kPresenterDoc()->pageList().at( m_step.m_pageNumber );
3403 // YABADABADOOOOOOO.... That's a hack :-)
3404 if ( m_step.m_subStep == 0 && !isAllreadyPainted && isUpdatesEnabled() )
3405 {
3406 //kdDebug(33001) << "Page::doObjEffects - in the strange hack" << endl;
3407 TQPainter p;
3408 p.begin( &screen_orig );
3409 TQRect desktopRect = TQRect( 0, 0, kapp->desktop()->width(), kapp->desktop()->height() );
3410 drawBackground( &p, desktopRect, page );
3411 PresStep step( m_step.m_pageNumber, m_step.m_step, m_step.m_subStep, true, true );
3412 drawPresPage( &p, desktopRect ,step );
3413 p.end();
3414 bitBlt( this, 0, 0, &screen_orig );
3415 }
3416 else
3417 {
3418 bitBlt( &screen_orig, 0, 0, this );
3419 }
3420
3421 TQPtrList<KPrObject> allObjects;
3422 // master slide objects are below the objects of the normal slide
3423 if ( page->displayObjectFromMasterPage() )
3424 {
3425 TQPtrListIterator<KPrObject> it( page->masterPage()->objectList() );
3426 for ( ; it.current(); ++it ) {
3427 if ( objectIsAHeaderFooterHidden( it.current() ) )
3428 continue;
3429 else
3430 allObjects.append( it.current() );
3431 }
3432 }
3433
3434 TQPtrListIterator<KPrObject> it( page->objectList() );
3435 for ( ; it.current(); ++it )
3436 {
3437 allObjects.append( it.current() );
3438 }
3439
3440 //TODO add global presentation speed
3441 m_effectHandler = new KPrEffectHandler( m_step, goingBack, this, &screen_orig, allObjects, m_view, 1 );
3442 if ( m_effectHandler->doEffect() )
3443 {
3444 delete m_effectHandler;
3445 m_effectHandler = 0;
3446 }
3447 else
3448 {
3449 connect( &m_effectTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotDoEffect() ) );
3450 m_effectTimer.start( 50, true );
3451 }
3452
3453}
3454
3455void KPrCanvas::slotDoEffect()
3456{
3457 if ( m_effectHandler->doEffect() )
3458 {
3459 m_effectTimer.stop();
3460 TQObject::disconnect( &m_effectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoEffect() ) );
3461 delete m_effectHandler;
3462 m_effectHandler = 0;
3463 }
3464 else
3465 {
3466 m_effectTimer.start( 50, true );
3467 }
3468}
3469
3470
3471void KPrCanvas::slotDoPageEffect()
3472{
3473 if ( m_pageEffect->doEffect() )
3474 {
3475 m_pageEffectTimer.stop();
3476 TQObject::disconnect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoPageEffect() ) );
3477 delete m_pageEffect;
3478 m_pageEffect = 0;
3479
3480 doObjEffects( true );
3481 }
3482 else
3483 {
3484 m_pageEffectTimer.start( 50, true );
3485 }
3486}
3487
3488void KPrCanvas::slotAutoScroll(const TQPoint &scrollDistance)
3489{
3490 //TQPoint d = m_view->zoomHandler()->zoomPoint( scrollDistance );
3491 TQPoint d = scrollDistance;
3492 m_view->getHScrollBar()->setValue( m_view->getHScrollBar()->value() + d.x() );
3493 m_view->getVScrollBar()->setValue( m_view->getVScrollBar()->value() + d.y() );
3494}
3495
3496
3498{
3499 bool finished = false;
3500 if ( m_effectHandler )
3501 {
3502 m_effectTimer.stop();
3503 TQObject::disconnect( &m_effectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoEffect() ) );
3504 m_effectHandler->finish();
3505 delete m_effectHandler;
3506 m_effectHandler = 0;
3507 finished = true;
3508 }
3509 return finished;
3510}
3511
3512
3513bool KPrCanvas::finishPageEffect( bool cancel )
3514{
3515 bool finished = false;
3516 if ( m_pageEffect )
3517 {
3518 m_pageEffectTimer.stop();
3519 TQObject::disconnect( &m_pageEffectTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotDoPageEffect() ) );
3520 if ( !cancel )
3521 m_pageEffect->finish();
3522 delete m_pageEffect;
3523 m_pageEffect = 0;
3524
3525 if ( !cancel )
3526 {
3527 doObjEffects( true );
3528 }
3529 else if ( !spManualSwitch() )
3530 {
3531 m_view->setAutoPresTimer( 1 );
3532 m_setPageTimer = true;
3533 }
3534
3535 finished = true;
3536 }
3537 return finished;
3538}
3539
3540
3541void KPrCanvas::print( TQPainter *painter, KPrinter *printer, float /*left_margin*/, float /*top_margin*/ )
3542{
3543 PresStep step( 0, 1000, 1000 );
3544 //deSelectAllObj(); // already done in KPrView::setupPrinter
3545 int i = 0;
3546
3547 repaint( false );
3548 kapp->processEvents();
3549
3550 editMode = false;
3551 fillBlack = false;
3552
3553 //int _xOffset = diffx();
3554 //int _yOffset = diffy();
3555
3556 //m_view->setDiffX( -static_cast<int>( MM_TO_POINT( left_margin ) ) );
3557 //m_view->setDiffY( -static_cast<int>( MM_TO_POINT( top_margin ) ) );
3558
3559 TQProgressDialog progress( i18n( "Printing..." ), i18n( "Cancel" ),
3560 printer->pageList().count() + 2, this );
3561
3562 int j = 0;
3563 progress.setProgress( 0 );
3564
3565
3566 int rows = 1;
3567 int cols = 1;
3568 if ( !printer->previewOnly() )
3569 {
3570 rows = printer->option("kde-kpresenter-printrows").toInt();
3571 cols = printer->option("kde-kpresenter-printcolumns").toInt();
3572 }
3573 int const slides_per_page = rows * cols;
3574
3575 /*if ( printer->fromPage() > 1 )
3576 m_view->setDiffY( ( printer->fromPage() - 1 ) * ( getPageRect( 1, 1.0, false ).height() ) -
3577 (int)MM_TO_POINT( top_margin ) );*/
3578 int current_slide = 0;
3579 TQValueList<int> list=printer->pageList(); // 1-based
3580 TQValueList<int>::iterator it;
3581 for( it=list.begin();it!=list.end();++it)
3582 {
3583 i=(*it);
3584 progress.setProgress( ++j );
3585 kapp->processEvents();
3586
3587 if ( progress.wasCancelled() )
3588 break;
3589
3590 step.m_pageNumber = i - 1;
3591
3592 if ( step.m_pageNumber != current_slide )
3593 continue;
3594
3595 if ( !list.isEmpty() && i > list.first() )
3596 printer->newPage();
3597
3598 painter->resetXForm();
3599 painter->fillRect( m_view->kPresenterDoc()->pageList().at( m_step.m_pageNumber )->getZoomPageRect(), white );
3600
3601 printPage( painter, step, printer, rows, cols );
3602 kapp->processEvents();
3603
3604 painter->resetXForm();
3605 kapp->processEvents();
3606
3607 current_slide += slides_per_page;
3608
3609 /*m_view->setDiffY( i * ( getPageRect( 1, 1.0, false ).height() )
3610 - static_cast<int>( MM_TO_POINT( top_margin ) ) );*/
3611 }
3612
3613 TDEConfig *config=KPrFactory::global()->config();
3614 config->setGroup("Misc");
3615 bool printNotes = config->readBoolEntry("PrintNotes", true);
3616
3617 KPrNoteBar *noteBar = m_view->getNoteBar();
3618 //don't print notes when there is no note to print or it's disabled
3619 if ( noteBar && !noteBar->getNotesTextForPrinting(list).isEmpty()
3620 && !progress.wasCancelled() && printNotes )
3621 {
3622 printer->newPage();
3623 painter->resetXForm();
3624 noteBar->printNotes( painter, printer, list );
3625 painter->resetXForm();
3626 }
3627
3628 setToolEditMode( toolEditMode );
3629 //m_view->setDiffX( _xOffset );
3630 //m_view->setDiffY( _yOffset );
3631
3632 progress.setProgress( printer->pageList().count() + 2 );
3633
3634 fillBlack = true;
3635 editMode = true;
3636 repaint( false );
3637}
3638
3639
3640void KPrCanvas::updateInsertRect( const KoPoint &point, TQt::ButtonState state )
3641{
3642 if ( state & AltButton )
3643 {
3644 m_insertRect.moveBottomRight( point );
3645 }
3646 else
3647 {
3648 m_insertRect.setRight( point.x() );
3649 m_insertRect.setBottom( point.y() );
3650 }
3651}
3652
3653
3654KPrTextObject* KPrCanvas::insertTextObject( const KoRect &rect )
3655{
3656 KPrTextObject* obj = m_activePage->insertTextObject( rect );
3657 selectObj( obj );
3658 return obj;
3659}
3660
3661void KPrCanvas::insertLine( const KoPoint &startPoint, const KoPoint &endPoint )
3662{
3663 KoRect rect( startPoint, endPoint );
3664 bool rev = rect.width() < 0 || rect.height() < 0;
3665 rect = rect.normalize();
3666 LineType lt = LT_LU_RD;
3667 if ( startPoint.x() == endPoint.x() )
3668 {
3669 lt = LT_VERT;
3670 rect.setLeft( rect.left() - 5.0 );
3671 rect.setRight( rect.right() + 5.0 );
3672 }
3673 else if ( startPoint.y() == endPoint.y() )
3674 {
3675 lt = LT_HORZ;
3676 rect.setTop( startPoint.y() - 5.0 );
3677 rect.setBottom( startPoint.y() + 5.0 );
3678 }
3679 else if ( ( startPoint.x() < endPoint.x() && startPoint.y() > endPoint.y() ) ||
3680 ( startPoint.x() > endPoint.x() && startPoint.y() < endPoint.y() ) )
3681 {
3682 lt = LT_LD_RU;
3683 }
3684 m_activePage->insertLine( rect, m_view->getPen(),
3685 !rev ? m_view->getLineBegin() : m_view->getLineEnd(), !rev ? m_view->getLineEnd() : m_view->getLineBegin(),
3686 lt );
3687}
3688
3689
3690void KPrCanvas::insertRect( const KoRect &rect )
3691{
3692 m_activePage->insertRectangle( rect, m_view->getPen(), m_view->getBrush(), m_view->getFillType(),
3693 m_view->getGColor1(), m_view->getGColor2(), m_view->getGType(), m_view->getRndX(), m_view->getRndY(),
3694 m_view->getGUnbalanced(), m_view->getGXFactor(), m_view->getGYFactor() );
3695}
3696
3697void KPrCanvas::insertEllipse( const KoRect &rect )
3698{
3699 m_activePage->insertCircleOrEllipse( rect, m_view->getPen(), m_view->getBrush(), m_view->getFillType(),
3700 m_view->getGColor1(), m_view->getGColor2(),
3701 m_view->getGType(), m_view->getGUnbalanced(), m_view->getGXFactor(), m_view->getGYFactor() );
3702}
3703
3704void KPrCanvas::insertPie( const KoRect &rect )
3705{
3706 m_activePage->insertPie( rect, m_view->getPen(), m_view->getBrush(), m_view->getFillType(),
3707 m_view->getGColor1(), m_view->getGColor2(), m_view->getGType(),
3708 m_view->getPieType(), m_view->getPieAngle(), m_view->getPieLength(),
3709 m_view->getLineBegin(), m_view->getLineEnd(), m_view->getGUnbalanced(), m_view->getGXFactor(),
3710 m_view->getGYFactor() );
3711}
3712
3713void KPrCanvas::insertAutoform( const KoRect &rect )
3714{
3715 m_activePage->insertAutoform( rect, m_view->getPen(), m_view->getBrush(),
3716 m_view->getLineBegin(), m_view->getLineEnd(),
3717 m_view->getFillType(), m_view->getGColor1(), m_view->getGColor2(), m_view->getGType(),
3718 autoform, m_view->getGUnbalanced(), m_view->getGXFactor(), m_view->getGYFactor() );
3719}
3720
3721KPrPartObject* KPrCanvas::insertObject( const KoRect &rect )
3722{
3723 KPrPartObject *kpPartObject = m_activePage->insertObject( rect, partEntry );
3724 return kpPartObject;
3725}
3726
3727void KPrCanvas::insertFreehand( const KoPointArray &_pointArray )
3728{
3729 KoRect rect = _pointArray.boundingRect();
3730
3731 m_activePage->insertFreehand( getObjectPoints( _pointArray ), rect, m_view->getPen(), m_view->getLineBegin(),
3732 m_view->getLineEnd() );
3733
3734 m_pointArray = KoPointArray();
3735 m_indexPointArray = 0;
3736}
3737
3738void KPrCanvas::insertPolyline( const KoPointArray &_pointArray )
3739{
3740 if( _pointArray.count()> 1)
3741 {
3742 KoRect rect = _pointArray.boundingRect();
3743 m_activePage->insertPolyline( getObjectPoints( _pointArray ), rect, m_view->getPen(), m_view->getLineBegin(),
3744 m_view->getLineEnd() );
3745 }
3746 m_pointArray = KoPointArray();
3747 m_indexPointArray = 0;
3748}
3749
3750void KPrCanvas::insertCubicBezierCurve( const KoPointArray &_pointArray )
3751{
3752 if ( _pointArray.count() > 1 )
3753 {
3754 KoPointArray points( _pointArray );
3755 KoPointArray bezierPoints( KPrBezierCurveObject::bezier2polyline( _pointArray ) );
3756 KoRect rect = bezierPoints.boundingRect();
3757 points = getObjectPoints( points );
3758 bezierPoints = getObjectPoints( bezierPoints );
3759
3760 if ( toolEditMode == INS_CUBICBEZIERCURVE )
3761 {
3762 m_activePage->insertCubicBezierCurve( points, bezierPoints, rect, m_view->getPen(),
3763 m_view->getLineBegin(), m_view->getLineEnd() );
3764 }
3765 else if ( toolEditMode == INS_QUADRICBEZIERCURVE )
3766 {
3767 m_activePage->insertQuadricBezierCurve( points, bezierPoints, rect, m_view->getPen(),
3768 m_view->getLineBegin(), m_view->getLineEnd() );
3769 }
3770 else if ( toolEditMode == INS_CLOSED_CUBICBEZIERCURVE ||
3771 toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE )
3772 {
3773 m_activePage->insertClosedLine( bezierPoints, rect, m_view->getPen(), m_view->getBrush(),
3774 m_view->getFillType(), m_view->getGColor1(), m_view->getGColor2(),
3775 m_view->getGType(), m_view->getGUnbalanced(),
3776 m_view->getGXFactor(), m_view->getGYFactor(), toolEditMode );
3777 }
3778 }
3779 m_pointArray = KoPointArray();
3780 m_indexPointArray = 0;
3781}
3782
3783void KPrCanvas::insertPolygon( const KoPointArray &_pointArray )
3784{
3785 KoRect rect = _pointArray.boundingRect();
3786
3787 m_activePage->insertPolygon( getObjectPoints( _pointArray ), rect, m_view->getPen(), m_view->getBrush(), m_view->getFillType(),
3788 m_view->getGColor1(), m_view->getGColor2(), m_view->getGType(), m_view->getGUnbalanced(),
3789 m_view->getGXFactor(), m_view->getGYFactor(),
3790 m_view->getCheckConcavePolygon(), m_view->getCornersValue(), m_view->getSharpnessValue() );
3791
3792 m_pointArray = KoPointArray();
3793 m_indexPointArray = 0;
3794}
3795
3796void KPrCanvas::insertPicture( const KoRect &rect )
3797{
3798 TQString file = m_activePage->insPictureFile();
3799
3800 TQCursor c = cursor();
3801 setCursor( waitCursor );
3802 if ( !file.isEmpty() ) {
3803 if ( rect.width() > 10 && rect.height() > 10 )
3804 {
3805 m_activePage->insertPicture( file, rect );
3806 }
3807 else
3808 {
3809 KoPoint tl( rect.topLeft() );
3810 m_activePage->insertPicture( file, tl );
3811 }
3812 m_activePage->setInsPictureFile( TQString() );
3813 }
3814 setCursor( c );
3815}
3816
3817void KPrCanvas::insertClosedLine( const KoPointArray &_pointArray )
3818{
3819 KoRect rect = _pointArray.boundingRect();
3820
3821 m_activePage->insertClosedLine( getObjectPoints( _pointArray ), rect, m_view->getPen(), m_view->getBrush(), m_view->getFillType(),
3822 m_view->getGColor1(), m_view->getGColor2(), m_view->getGType(), m_view->getGUnbalanced(),
3823 m_view->getGXFactor(), m_view->getGYFactor(), toolEditMode );
3824
3825 m_pointArray = KoPointArray();
3826 m_indexPointArray = 0;
3827}
3828
3829void KPrCanvas::setToolEditMode( ToolEditMode _m, bool updateView )
3830{
3831 //store m_pointArray if !m_pointArray.isNull()
3832 if ( ( toolEditMode == INS_POLYLINE || toolEditMode == INS_CLOSED_POLYLINE ) && !m_pointArray.isNull())
3833 endDrawPolyline();
3834
3835 if ( ( toolEditMode == INS_CUBICBEZIERCURVE || toolEditMode == INS_QUADRICBEZIERCURVE
3836 || toolEditMode == INS_CLOSED_CUBICBEZIERCURVE || toolEditMode == INS_CLOSED_QUADRICBEZIERCURVE ) && !m_pointArray.isNull() )
3837 endDrawCubicBezierCurve();
3838
3839 exitEditMode();
3840 toolEditMode = _m;
3841
3842 if ( toolEditMode == TEM_MOUSE )
3843 {
3844 setCursor( arrowCursor );
3845 TQPoint pos = TQCursor::pos();
3846 // ### missing some coord transformation here?
3847 KoPoint docPoint( m_view->zoomHandler()->unzoomPoint( pos ) );
3848 KPrObject *obj=m_activePage->getCursor( pos);
3849 if(obj)
3850 setCursor( obj->getCursor( docPoint, modType, m_view->kPresenterDoc() ) );
3851 }
3852 else if ( toolEditMode == INS_FREEHAND || toolEditMode == INS_CLOSED_FREEHAND )
3853 setCursor( KPrUtils::penCursor() );
3854 else if ( toolEditMode == TEM_ROTATE )
3855 setCursor( KPrUtils::rotateCursor() );
3856 else
3857 setCursor( crossCursor );
3858
3859 if ( updateView )
3860 m_view->setTool( toolEditMode );
3861}
3862
3863
3864void KPrCanvas::endDrawPolyline()
3865{
3866 m_drawPolyline = false;
3867
3868 if ( toolEditMode == INS_POLYLINE )
3869 insertPolyline( m_pointArray );
3870 else if ( toolEditMode == INS_CLOSED_POLYLINE )
3871 insertClosedLine( m_pointArray );
3872
3873 emit objectSelectedChanged();
3874 if ( toolEditMode != TEM_MOUSE && editMode )
3875 repaint( false );
3876 m_view->disableAutoScroll();
3877 mousePressed = false;
3878 modType = MT_NONE;
3879}
3880
3881void KPrCanvas::endDrawCubicBezierCurve()
3882{
3883 m_drawCubicBezierCurve = false;
3884 m_oldCubicBezierPointArray = KoPointArray();
3885 insertCubicBezierCurve( m_pointArray );
3886 emit objectSelectedChanged();
3887 if ( toolEditMode != TEM_MOUSE && editMode )
3888 repaint( false );
3889 m_view->disableAutoScroll();
3890 mousePressed = false;
3891 modType = MT_NONE;
3892}
3893
3894void KPrCanvas::selectNext()
3895{
3896 if ( objectList().count() == 0 ) return;
3897
3898 if ( m_activePage->numSelected() == 0 )
3899 objectList().at( 0 )->setSelected( true );
3900 else {
3901 int i = objectList().findRef( m_activePage->getSelectedObj() );
3902 if ( i < static_cast<int>( objectList().count() ) - 1 ) {
3903 m_view->kPresenterDoc()->deSelectAllObj();
3904 objectList().at( ++i )->setSelected( true );
3905 } else {
3906 m_view->kPresenterDoc()->deSelectAllObj();
3907 objectList().at( 0 )->setSelected( true );
3908 }
3909 }
3910 m_view->showObjectRect( m_activePage->getSelectedObj() );
3911 _repaint( false );
3912}
3913
3914void KPrCanvas::selectPrev()
3915{
3916 if ( objectList().count() == 0 ) return;
3917 if ( m_activePage->numSelected() == 0 )
3918 objectList().at( objectList().count() - 1 )->setSelected( true );
3919 else {
3920 int i = objectList().findRef( m_activePage->getSelectedObj() );
3921 if ( i > 0 ) {
3922 m_view->kPresenterDoc()->deSelectAllObj();
3923 objectList().at( --i )->setSelected( true );
3924 } else {
3925 m_view->kPresenterDoc()->deSelectAllObj();
3926 objectList().at( objectList().count() - 1 )->setSelected( true );
3927 }
3928 }
3929 m_view->showObjectRect( m_activePage->getSelectedObj() );
3930 _repaint( false );
3931}
3932
3933void KPrCanvas::dragEnterEvent( TQDragEnterEvent *e )
3934{
3935 if ( m_currentTextObjectView )
3936 m_currentTextObjectView->dragEnterEvent( e );
3937 else if ( TQTextDrag::canDecode( e )
3938 || TQImageDrag::canDecode( e )
3939 || KURLDrag::canDecode(e)) {
3940 e->accept();
3941 }
3942 else
3943 e->ignore();
3944}
3945
3946void KPrCanvas::dragMoveEvent( TQDragMoveEvent *e )
3947{
3948 if( m_currentTextObjectView)
3949 {
3950 KPrTextObject * obj = textUnderMouse( e->pos());
3951 bool emitChanged = false;
3952 if ( obj )
3953 emitChanged = checkCurrentTextEdit( obj );
3954 if ( m_currentTextObjectView )
3955 {
3956 m_currentTextObjectView->dragMoveEvent( e, TQPoint() );
3957 if ( emitChanged )
3959 }
3960 }
3961 else if ( TQTextDrag::canDecode( e )
3962 || TQImageDrag::canDecode( e )
3963 || KURLDrag::canDecode(e)) {
3964 e->accept();
3965 }
3966 else
3967 e->ignore();
3968}
3969
3970void KPrCanvas::dropImage( TQMimeSource * data, bool resizeImageToOriginalSize, int posX, int posY )
3971{
3972 setToolEditMode( TEM_MOUSE );
3973 deSelectAllObj();
3974
3975 TQImage pix;
3976 TQImageDrag::decode( data, pix );
3977
3978 KTempFile tmpFile;
3979 tmpFile.setAutoDelete(true);
3980
3981 if( tmpFile.status() != 0 )
3982 return;
3983
3984 pix.save( tmpFile.name(), "PNG" );
3985 TQCursor c = cursor();
3986 setCursor( waitCursor );
3987
3988 TQPoint pos( posX + diffx(), posY + diffy() );
3989 KoPoint docPoint( m_view->zoomHandler()->unzoomPoint( pos ) );
3990
3991 m_activePage->insertPicture( tmpFile.name(), docPoint );
3992
3993 tmpFile.close();
3994
3995 if ( resizeImageToOriginalSize )
3996 picViewOriginalSize();
3997 setCursor( c );
3998}
3999
4000void KPrCanvas::dropEvent( TQDropEvent *e )
4001{
4002 //disallow dropping objects outside the "page"
4003 KoPoint docPoint = m_view->zoomHandler()->unzoomPoint( e->pos()+TQPoint(diffx(),diffy()) );
4004 if ( !m_activePage->getZoomPageRect().contains(e->pos()))
4005 return;
4006
4007 if ( TQImageDrag::canDecode( e ) ) {
4008 dropImage( e, true, e->pos().x(), e->pos().y() );
4009 e->accept();
4010 } else if ( KURLDrag::canDecode( e ) ) {
4011 setToolEditMode( TEM_MOUSE );
4012 deSelectAllObj();
4013
4014 KURL::List lst;
4015 KURLDrag::decode( e, lst );
4016
4017 KURL::List::ConstIterator it = lst.begin();
4018 for ( ; it != lst.end(); ++it ) {
4019 const KURL &url( *it );
4020
4021 TQString filename;
4022 if ( !url.isLocalFile() ) {
4023 if ( !TDEIO::NetAccess::download( url, filename, this ) )
4024 continue;
4025 } else {
4026 filename = url.path();
4027 }
4028
4029 KMimeMagicResult *res = KMimeMagic::self()->findFileType( filename );
4030
4031 if ( res && res->isValid() ) {
4032 TQString mimetype = res->mimeType();
4033 if ( mimetype.contains( "image" ) ) {
4034 TQCursor c = cursor();
4035 setCursor( waitCursor );
4036 m_activePage->insertPicture( filename, docPoint );
4037 setCursor( c );
4038 } else if ( mimetype.contains( "text" ) ) {
4039 TQCursor c = cursor();
4040 setCursor( waitCursor );
4041 TQFile f( filename );
4042 TQTextStream t( &f );
4043 TQString text = TQString(), tmp;
4044 kdDebug()<<" filename :"<<filename<<endl;
4045 if ( f.open( IO_ReadOnly ) ) {
4046 while ( !t.eof() ) {
4047 tmp = t.readLine();
4048 tmp += "\n";
4049 text.append( tmp );
4050 }
4051 f.close();
4052 }
4053 kdDebug()<<" text :"<<endl;
4054 m_activePage->insertTextObject( m_view->zoomHandler()->unzoomRect(TQRect( e->pos().x(), e->pos().y(), 250, 250 )),
4055 text, m_view );
4056
4057 setCursor( c );
4058 }
4059 }
4060 TDEIO::NetAccess::removeTempFile( filename );
4061 }
4062 }
4063 else if (m_currentTextObjectView)
4064 {
4065 m_currentTextObjectView->dropEvent( e );
4066 }
4067 else if ( TQTextDrag::canDecode( e ) ) {
4068 setToolEditMode( TEM_MOUSE );
4069 deSelectAllObj();
4070
4071 TQString text;
4072 TQTextDrag::decode( e, text );
4073 //kdDebug()<<" TQTextDrag::decode( e, text ); :"<<text<<endl;
4074 m_activePage->insertTextObject( m_view->zoomHandler()->unzoomRect( TQRect( e->pos().x(), e->pos().y(), 250, 250 )),
4075 text, m_view );
4076 e->accept();
4077 } else
4078 e->ignore();
4079
4080}
4081
4082void KPrCanvas::slotGotoPage()
4083{
4084 setSwitchingMode( false );
4085 //setCursor( blankCursor );
4086 int pg = m_step.m_pageNumber + 1;
4087
4088 m_view->setPageDuration( m_step.m_pageNumber );
4089
4090 pg = KPrGotoPage::gotoPage( m_view->kPresenterDoc(), m_presentationSlides, pg, this );
4091 gotoPage( pg );
4092
4093 if ( !spManualSwitch() ) {
4094 m_view->setAutoPresTimer( 1 );
4095 m_setPageTimer = true;
4096 }
4097}
4098
4099void KPrCanvas::gotoPage( int pg )
4100{
4101 int page = pg - 1;
4102 if ( page != m_step.m_pageNumber || m_step.m_step != *m_pageEffectSteps.begin() || m_step.m_subStep != 0 ) {
4103 // clear drawed lines
4104 m_drawModeLines.clear();
4105 goingBack = false;
4106
4107 m_step.m_pageNumber = page;
4108 kdDebug(33001) << "Page::gotoPage m_step.m_pageNumber =" << m_step.m_pageNumber << endl;
4109 m_presentationSlidesIterator = m_presentationSlides.find( m_step.m_pageNumber + 1 );
4110 editMode = false;
4111 m_drawMode = false;
4112 m_pageEffectSteps = m_view->kPresenterDoc()->getPageEffectSteps( m_step.m_pageNumber );
4113 m_step.m_step = *m_pageEffectSteps.begin();
4114 m_step.m_subStep = 0;
4115#if 0
4116 TQRect desk = TDEGlobalSettings::desktopGeometry(this);
4117 resize( desk.width(), desk.height() );
4118#endif
4119 doObjEffects();
4120 setFocus();
4121 m_view->refreshPageButton();
4122 }
4123}
4124
4126{
4127 gotoPage( *m_presentationSlides.begin() );
4128}
4129
4130KPrTextObject* KPrCanvas::kpTxtObj() const
4131{
4132 return ( ( m_editObject && m_editObject->getType() == OT_TEXT ) ?
4133 dynamic_cast<KPrTextObject*>( m_editObject ) : 0 );
4134 // ### return m_currentTextObjectView->kpTextObject()
4135}
4136
4137void KPrCanvas::copyOasisObjs()
4138{
4139 //todo copy object from selected object
4140 KoStoreDrag *kd = new KoStoreDrag( "application/vnd.oasis.opendocument.presentation", 0L );
4141 TQDragObject* dragObject = kd;
4142 TQByteArray arr;
4143 TQBuffer buffer(arr);
4144 KoStore* store = KoStore::createStore( &buffer, KoStore::Write, "application/vnd.oasis.opendocument.presentation" );
4145
4146 delete store;
4147 kd->setEncodedData( arr );
4148 TQApplication::clipboard()->setData( dragObject, TQClipboard::Clipboard );
4149}
4150
4151void KPrCanvas::copyObjs()
4152{
4153 TQDomDocument doc("DOC");
4154 TQDomElement presenter=doc.createElement("DOC");
4155 presenter.setAttribute("editor", "KPresenter");
4156 presenter.setAttribute("mime", "application/x-kpresenter");
4157
4158 doc.appendChild(presenter);
4159
4160 TQPtrList<KoDocumentChild> embeddedObjectsActivePage;
4161
4162 KoStoreDrag *kd = new KoStoreDrag( "application/x-kpresenter", 0L );
4163 TQDragObject* dragObject = kd;
4164 TQByteArray arr;
4165 TQBuffer buffer(arr);
4166 KoStore* store = KoStore::createStore( &buffer, KoStore::Write, "application/x-kpresenter" );
4167
4168 m_activePage->getAllEmbeddedObjectSelected(embeddedObjectsActivePage );
4169
4170 // Save internal embedded objects first, since it might change their URL
4171 int i = 0;
4172 TQValueList<KoPictureKey> savePictures;
4173 TQPtrListIterator<KoDocumentChild> chl( embeddedObjectsActivePage );
4174 for( ; chl.current(); ++chl ) {
4175 KoDocument* childDoc = chl.current()->document();
4176 if ( childDoc && !childDoc->isStoredExtern() )
4177 (void) childDoc->saveToStore( store, TQString::number( i++ ) );
4178 }
4179
4180 m_activePage->copyObjs(doc, presenter, savePictures);
4181
4182 KPrDocument* kprdoc = m_view->kPresenterDoc();
4183 if ( !embeddedObjectsActivePage.isEmpty())
4184 {
4185 kprdoc->saveEmbeddedObject(m_activePage, embeddedObjectsActivePage,doc,presenter);
4186 }
4187
4188 if ( !savePictures.isEmpty() ) {
4189 // Save picture list at the end of the main XML
4190 presenter.appendChild( kprdoc->pictureCollection()->saveXML( KoPictureCollection::CollectionPicture, doc, savePictures ) );
4191 // Save the actual picture data into the store
4192 kprdoc->pictureCollection()->saveToStore( KoPictureCollection::CollectionPicture, store, savePictures );
4193 // Single image -> put it in dragobject too
4194 if ( savePictures.count() == 1 )
4195 {
4196 KoPicture pic = kprdoc->pictureCollection()->findPicture( savePictures.first() );
4197 TQDragObject* picDrag = pic.dragObject( 0L );
4198 if ( picDrag ) {
4199 KMultipleDrag* multipleDrag = new KMultipleDrag( 0L );
4200 multipleDrag->addDragObject( kd );
4201 multipleDrag->addDragObject( picDrag );
4202 dragObject = multipleDrag;
4203 }
4204 }
4205 }
4206
4207 if ( store->open( "root" ) )
4208 {
4209 TQCString s = doc.toCString(); // this is already Utf8!
4210 //kdDebug(33001) << "KPrCanvas::copyObject: " << s << endl;
4211 (void)store->write( s.data(), s.size()-1 );
4212 store->close();
4213 }
4214
4215 delete store;
4216 kd->setEncodedData( arr );
4217 TQApplication::clipboard()->setData( dragObject, TQClipboard::Clipboard );
4218}
4219
4220void KPrCanvas::deleteObjs()
4221{
4222 lowerObject();
4223 KCommand *cmd=m_activePage->deleteSelectedObjects();
4224 m_view->kPresenterDoc()->deSelectAllObj();
4225 if( cmd )
4226 m_view->kPresenterDoc()->addCommand( cmd );
4227 emit objectSelectedChanged();
4228 setToolEditMode( toolEditMode );
4229}
4230
4231
4232void KPrCanvas::enterEvent( TQEvent *e )
4233{
4234 m_view->setRulerMousePos( ( ( TQMouseEvent* )e )->x(), ( ( TQMouseEvent* )e )->y() );
4235 m_view->setRulerMouseShow( true );
4236}
4237
4238void KPrCanvas::leaveEvent( TQEvent * /*e*/ )
4239{
4240 m_view->setRulerMouseShow( false );
4241}
4242
4243TQPtrList<KPrObject> KPrCanvas::objectList() const
4244{
4245 return m_activePage->objectList();
4246}
4247
4248const TQPtrList<KPrObject> &KPrCanvas::getObjectList() const
4249{
4250 return m_activePage->objectList();
4251}
4252
4253unsigned int KPrCanvas::currPgNum() const
4254{
4255 return m_view->getCurrPgNum();
4256}
4257
4258TQColor KPrCanvas::txtBackCol() const
4259{
4260 return m_view->kPresenterDoc()->txtBackCol();
4261}
4262
4263bool KPrCanvas::spInfiniteLoop() const
4264{
4265 return m_view->kPresenterDoc()->spInfiniteLoop();
4266}
4267
4268bool KPrCanvas::spShowEndOfPresentationSlide() const
4269{
4270 return m_view->kPresenterDoc()->spShowEndOfPresentationSlide();
4271}
4272
4273bool KPrCanvas::spManualSwitch() const
4274{
4275 return m_view->kPresenterDoc()->spManualSwitch();
4276}
4277
4278TQRect KPrCanvas::getPageRect( bool decBorders ) const
4279{
4280 return m_view->kPresenterDoc()->getPageRect( decBorders );
4281}
4282
4283unsigned int KPrCanvas::pageNums() const
4284{
4285 return m_view->kPresenterDoc()->getPageNums();
4286}
4287
4288void KPrCanvas::_repaint( bool /*erase*/ )
4289{
4290 m_view->kPresenterDoc()->repaint( false );
4291}
4292
4293void KPrCanvas::_repaint( const TQRect &r )
4294{
4295 m_view->kPresenterDoc()->repaint( r );
4296}
4297
4298void KPrCanvas::_repaint( KPrObject *o )
4299{
4300 m_view->kPresenterDoc()->repaint( o );
4301}
4302
4303void KPrCanvas::slotExitPres()
4304{
4305 m_view->screenStop();
4306}
4307
4308void KPrCanvas::setDrawingMode()
4309{
4310 m_presMenu->setItemChecked( PM_DM, true );
4311 m_drawMode = true;
4312
4313 setCursor( KPrUtils::penCursor() );
4314}
4315
4316void KPrCanvas::setSwitchingMode( bool continueTimer )
4317{
4318 m_presMenu->setItemChecked( PM_DM, false );
4319
4320 // the following have to be done even when nothing changed
4321 // we don't want to see the cursor nor the automatic pesentation stopped
4322 m_drawMode = false;
4323 m_drawLineInDrawMode = false;
4324 setCursor( blankCursor );
4325
4326 if ( continueTimer && !spManualSwitch() )
4327 m_view->continueAutoPresTimer();
4328}
4329
4330void KPrCanvas::exitEditMode( bool repaint )
4331{
4332 if ( m_editObject )
4333 {
4334 if ( m_editObject->getType() == OT_TEXT )
4335 {
4336 if(m_currentTextObjectView)
4337 {
4338 m_currentTextObjectView->clearSelection();
4339 //hide cursor when we desactivate textObjectView
4340 if ( repaint )
4341 {
4342 m_currentTextObjectView->drawCursor( false );
4343 m_currentTextObjectView->terminate();
4344 }
4345 KPrTextObject *kpTextObj = m_currentTextObjectView->kpTextObject();
4346 kpTextObj->setEditingTextObj( false );
4347 delete m_currentTextObjectView;
4348 m_currentTextObjectView = 0;
4349
4350 if ( repaint )
4351 _repaint( static_cast<KPrObject*>( kpTextObj ) );
4352 }
4353 // Title of slide may have changed
4354 m_view->kPresenterDoc()->updateSideBarItem( m_activePage );
4355 emit objectSelectedChanged();
4356 m_editObject = 0;
4357 }
4358 else if (m_editObject->getType() == OT_PART )
4359 {
4360 static_cast<KPrPartObject *>(m_editObject)->deactivate();
4361 _repaint( m_editObject );
4362 m_editObject = 0;
4363 return;
4364 }
4365 }
4366 //modType = MT_NONE;
4367}
4368
4369bool KPrCanvas::getPixmapOrigAndCurrentSize( KPrPixmapObject *&obj, KoSize *origSize, KoSize *currentSize )
4370{
4371 *origSize = KoSize(obj->originalSize().width(),obj->originalSize().height());
4372 *currentSize = obj->getSize();
4373 return true;
4374}
4375
4376void KPrCanvas::picViewOriginalSize()
4377{
4378 KPrDocument *doc = m_view->kPresenterDoc();
4379 KPrPixmapObject *object = m_activePage->picViewOrigHelper();
4380
4381 KoSize newSize( doc->zoomHandler()->pixelXToPt( object->originalSize().width() ),
4382 doc->zoomHandler()->pixelYToPt( object->originalSize().height() ) );
4383
4384 KoRect pageRect = m_activePage->getPageRect();
4385 double fakt = 1.0;
4386
4387 if ( newSize.width() > pageRect.width() )
4388 fakt = pageRect.width() / newSize.width();
4389 if ( newSize.height() > pageRect.height() )
4390 fakt = TQMIN( fakt, pageRect.height() / newSize.height() );
4391
4392 KoSize diff( newSize.width() * fakt - object->getSize().width(),
4393 newSize.height() * fakt - object->getSize().height() );
4394
4395 KPrResizeCmd *resizeCmd = new KPrResizeCmd( i18n( "Scale to Original Size" ),
4396 KoPoint( 0, 0 ), diff, object, doc );
4397 resizeCmd->execute();
4398 doc->addCommand( resizeCmd );
4399}
4400
4401void KPrCanvas::picViewOrig640x480()
4402{
4403 picViewOrigHelper(640, 480);
4404}
4405
4406void KPrCanvas::picViewOrig800x600()
4407{
4408 picViewOrigHelper(800, 600);
4409}
4410
4411void KPrCanvas::picViewOrig1024x768()
4412{
4413 picViewOrigHelper(1024, 768);
4414}
4415
4416void KPrCanvas::picViewOrig1280x1024()
4417{
4418 picViewOrigHelper(1280, 1024);
4419}
4420
4421void KPrCanvas::picViewOrig1600x1200()
4422{
4423 picViewOrigHelper(1600, 1200);
4424}
4425
4426void KPrCanvas::picViewOrigHelper(int x, int y)
4427{
4428 KPrPixmapObject *obj = 0;
4429 KoSize origSize;
4430 KoSize currentSize;
4431
4432 obj=m_activePage->picViewOrigHelper();
4433
4434 if ( obj && !getPixmapOrigAndCurrentSize( obj, &origSize, &currentSize ) )
4435 return;
4436 KoSize pgSize = m_activePage->getPageRect().size();
4437
4438 if ( x == -1 && y == -1 ) {
4439 x = (int)origSize.width();
4440 y = (int)origSize.height();
4441 }
4442
4443 TQSize presSize( x, y );
4444
4445 scalePixmapToBeOrigIn( currentSize, pgSize, presSize, obj );
4446}
4447
4448void KPrCanvas::picViewOrigFactor()
4449{
4450}
4451
4452void KPrCanvas::scalePixmapToBeOrigIn( const KoSize &currentSize, const KoSize &pgSize,
4453 const TQSize &presSize, KPrPixmapObject *obj )
4454{
4455 TQRect desk = TDEGlobalSettings::desktopGeometry(this);
4456 double faktX = (double)presSize.width() / (double)desk.width();
4457 double faktY = (double)presSize.height() / (double)desk.height();
4458 double w = pgSize.width() * faktX;
4459 double h = pgSize.height() * faktY;
4460
4461 KPrResizeCmd *resizeCmd = new KPrResizeCmd( i18n( "Scale Picture to Be Shown 1:1 in Presentation Mode" ),
4462 KoPoint( 0, 0 ), KoSize( w - currentSize.width(), h - currentSize.height() ),
4463 obj, m_view->kPresenterDoc() );
4464 resizeCmd->execute();
4465 m_view->kPresenterDoc()->addCommand( resizeCmd );
4466}
4467
4468void KPrCanvas::setTextBackground( KPrTextObject */*obj*/ )
4469{
4470 // This is called when double-clicking on a text object.
4471 // What should happen exactly ? (DF)
4472#if 0
4473 TQPixmap pix( m_activePage->getZoomPageRect().size() );
4474 TQPainter painter( &pix );
4475 m_activePage->background()->drawBackground( &painter, false );
4476 TQPixmap bpix( obj->getSize().toTQSize() ); // ## zoom it !
4477 bitBlt( &bpix, 0, 0, &pix, obj->getOrig().x(), obj->getOrig().y() -
4478 m_activePage->getZoomPageRect().height() * ( m_view->getCurrPgNum() - 1 ), bpix.width(), bpix.height() );
4479 TQBrush b( white, bpix );
4480 TQPalette pal( obj->textObjectView()->palette() );
4481 pal.setBrush( TQColorGroup::Base, b );
4482 obj->textObjectView()->setPalette( pal );
4483#endif
4484}
4485
4486
4487KoPoint KPrCanvas::diffGrid( KoRect &rect, double diffx, double diffy )
4488{
4489 KPrDocument * doc( m_view->kPresenterDoc() );
4490 KoPoint move( 0, 0 );
4491
4492 double tempx = ( int( rect.topLeft().x() / doc->getGridX() ) * doc->getGridX() ) - rect.topLeft().x();
4493 if ( diffx > 0 )
4494 {
4495 tempx += doc->getGridX();
4496 while ( diffx > tempx )
4497 {
4498 move.setX( tempx );
4499 tempx += doc->getGridX();
4500 }
4501 }
4502 else
4503 {
4504 while ( diffx < tempx )
4505 {
4506 move.setX( tempx );
4507 tempx -= doc->getGridX();
4508 }
4509 }
4510 double tempy = ( int( rect.topLeft().y() / doc->getGridY() ) * doc->getGridY() ) - rect.topLeft().y();
4511 if ( diffy > 0 )
4512 {
4513 tempy += doc->getGridY();
4514 while ( diffy > tempy )
4515 {
4516 move.setY( tempy );
4517 tempy += doc->getGridY();
4518 }
4519 }
4520 else
4521 {
4522 while ( diffy < tempy )
4523 {
4524 move.setY( tempy );
4525 tempy -= doc->getGridY();
4526 }
4527 }
4528
4529 return move;
4530}
4531
4532
4533void KPrCanvas::moveObjectsByKey( int x, int y )
4534{
4535 KPrDocument *doc( m_view->kPresenterDoc() );
4536
4537 KoRect rect( objectRect( false ) );
4538 double diffx = m_view->zoomHandler()->unzoomItX( x );
4539 double diffy = m_view->zoomHandler()->unzoomItY( y );
4540 KoPoint move( diffx, diffy );
4541
4542 bool snapToGrid = doc->snapToGrid() && !m_disableSnapping;
4543 bool snapToGuideLines = doc->showGuideLines() && !m_disableSnapping;
4544
4545 if ( snapToGrid )
4546 {
4547 /*
4548 * Find the distance to the next grid pos.
4549 * The 1E-10 is needed when the object is on the grid when finding the next one, as
4550 * calcualtion with doubles is tricky.
4551 */
4552 double tempx = int( rect.x() / doc->getGridX() ) * doc->getGridX();
4553 if ( diffx > 0 )
4554 {
4555 move.setX( tempx - rect.x() );
4556 while ( rect.x() - tempx >= -1E-10 )
4557 {
4558 tempx += doc->getGridX();
4559 move.setX( tempx - rect.x() );
4560 }
4561 }
4562 else if ( diffx < 0 )
4563 {
4564 move.setX( tempx - rect.x() );
4565 while ( rect.x() - tempx <= 1E-10 )
4566 {
4567 tempx -= doc->getGridX();
4568 move.setX( tempx - rect.x() );
4569 }
4570 }
4571
4572 double tempy = int( rect.y() / doc->getGridY() ) * doc->getGridY();
4573 if ( diffy > 0 )
4574 {
4575 move.setY( tempy - rect.y() );
4576 while ( rect.y() - tempy >= -1E-10 )
4577 {
4578 tempy += doc->getGridY();
4579 move.setY( tempy - rect.y() );
4580 }
4581 }
4582 else if ( diffy < 0 )
4583 {
4584 move.setY( tempy - rect.y() );
4585 while ( rect.y() - tempy <= 1E-10 )
4586 {
4587 tempy -= doc->getGridY();
4588 move.setY( tempy - rect.y() );
4589 }
4590 }
4591 }
4592
4593 if ( snapToGuideLines )
4594 {
4595 if ( !snapToGrid )
4596 {
4597 // unwind last snapping
4598 KoRect movedRect( rect );
4599 movedRect.moveBy( diffx, diffy );
4600 movedRect.moveBy( -m_moveSnapDiff.x(), -m_moveSnapDiff.y() );
4601 move -= m_moveSnapDiff;
4602
4603 m_moveSnapDiff = KoPoint( 0, 0 );
4604
4605 KoGuides::SnapStatus snapStatus = KoGuides::SNAP_NONE;
4606 m_gl.snapToGuideLines( movedRect, KEY_SNAP_DISTANCE, snapStatus, m_moveSnapDiff );
4607
4608 move += m_moveSnapDiff;
4609 }
4610 else
4611 {
4612 m_gl.diffNextGuide( rect, move );
4613 }
4614 }
4615
4616 // don't move object from canvas
4617 KoRect pageRect( m_activePage->getPageRect() );
4618 if ( rect.left() + move.x() < pageRect.left() )
4619 {
4620 move.setX( pageRect.left() - rect.left() );
4621 }
4622 else if ( rect.right() + move.x() > pageRect.right() )
4623 {
4624 move.setX( pageRect.right() - rect.right() );
4625 }
4626 if ( rect.top() + move.y() < pageRect.top() )
4627 {
4628 move.setY( pageRect.top() - rect.top() );
4629 }
4630 else if ( rect.bottom() + move.y() > pageRect.bottom() )
4631 {
4632 move.setY( pageRect.bottom() - rect.bottom() );
4633 }
4634
4635 // we only want a repaint if we have guide lines
4636 if ( snapToGuideLines )
4637 {
4638 // redraw guidelines (intentionally always)
4639 KoRect movedRect( rect );
4640 movedRect.moveBy( move.x(), move.y() );
4641 m_gl.repaintSnapping( movedRect );
4642 }
4643
4644 if ( move != KoPoint( 0, 0 ) )
4645 {
4646 //kdDebug(33001) << "moveObjectsByKey move = " << move << endl;
4647 m_activePage->moveObject( m_view, move, false );
4648 m_view->updateObjectStatusBarItem();
4649 }
4650}
4651
4652
4653void KPrCanvas::moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged )
4654{
4655 KPrDocument *doc( m_view->kPresenterDoc() );
4656
4657 KoRect rect( objectRect( false ) );
4658 KoPoint move( 0, 0 );
4659 double diffx = pos.x() - m_origMousePos.x();
4660 double diffy = pos.y() - m_origMousePos.y();
4661
4662 bool snapToGrid = doc->snapToGrid() && !m_disableSnapping;
4663 bool snapToGuideLines = doc->showGuideLines() && !m_disableSnapping;
4664
4665 move = KoPoint( diffx, diffy );
4666 m_origMousePos = pos;
4667
4668 // unwind last snapping
4669 KoRect movedRect( rect );
4670 movedRect.moveBy( diffx, diffy );
4671 movedRect.moveBy( -m_moveSnapDiff.x(), -m_moveSnapDiff.y() );
4672 move -= m_moveSnapDiff;
4673
4674 m_moveSnapDiff = KoPoint( 0, 0 ); // needed if all snapping is off
4675 KoGuides::SnapStatus snapStatus = KoGuides::SNAP_NONE;
4676
4677 if ( snapToGrid )
4678 {
4679 m_moveSnapDiff.setX( tqRound( movedRect.topLeft().x() / doc->getGridX()) * doc->getGridX()
4680 - movedRect.topLeft().x() );
4681 m_moveSnapDiff.setY( tqRound( movedRect.topLeft().y() / doc->getGridY()) * doc->getGridY()
4682 - movedRect.topLeft().y() );
4683 snapStatus = KoGuides::SNAP_BOTH;
4684 }
4685
4686 if ( snapToGuideLines )
4687 {
4688 m_gl.snapToGuideLines( movedRect, MOUSE_SNAP_DISTANCE, snapStatus, m_moveSnapDiff );
4689 }
4690
4691 move += m_moveSnapDiff;
4692
4693 // don't move object off canvas
4694 KoPoint diffDueToBorders(0,0);
4695 KoRect pageRect( m_activePage->getPageRect() );
4696 if ( rect.left() + move.x() < pageRect.left() )
4697 diffDueToBorders.setX( pageRect.left() - (rect.left() + move.x()) );
4698 else if ( rect.right() + move.x() > pageRect.right() )
4699 diffDueToBorders.setX( pageRect.right() - (rect.right() + move.x()) );
4700
4701 if ( rect.top() + move.y() < pageRect.top() )
4702 diffDueToBorders.setY( pageRect.top() - (rect.top() + move.y()) );
4703 else if ( rect.bottom() + move.y() > pageRect.bottom() )
4704 diffDueToBorders.setY( pageRect.bottom() - (rect.bottom() + move.y()) );
4705
4706 m_moveSnapDiff += diffDueToBorders;
4707 move += diffDueToBorders;
4708
4709 movedRect.moveBy( m_moveSnapDiff.x(), m_moveSnapDiff.y() );
4710 if ( keepXorYunchanged )
4711 {
4712 KoPoint diff( m_moveStartPosMouse - movedRect.topLeft() );
4713 if ( fabs( diff.x() ) > fabs( diff.y() ) )
4714 {
4715 m_moveSnapDiff.setY( m_moveSnapDiff.y() + m_moveStartPosMouse.y() - movedRect.y() );
4716 movedRect.moveTopLeft( KoPoint( movedRect.x(), m_moveStartPosMouse.y() ) );
4717 move.setY( movedRect.y() - rect.y() );
4718 }
4719 else
4720 {
4721 m_moveSnapDiff.setX( m_moveSnapDiff.x() + m_moveStartPosMouse.x() - movedRect.x() );
4722 movedRect.moveTopLeft( KoPoint( m_moveStartPosMouse.x(), movedRect.y() ) );
4723 move.setX( movedRect.x() - rect.x() );
4724 }
4725 }
4726
4727 if ( snapToGuideLines )
4728 {
4729 // redraw guidelines (intentionally always)
4730 m_gl.repaintSnapping( movedRect );
4731 }
4732
4733 if ( move != KoPoint( 0, 0 ) )
4734 {
4735 //kdDebug(33001) << "moveObjectsByMouse move = " << move << endl;
4736 m_activePage->moveObject( m_view, move, false );
4737 }
4738}
4739
4740
4741void KPrCanvas::resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio, bool scaleAroundCenter )
4742{
4743 KPrObject *kpobject = m_resizeObject;
4744
4745 TQRect oldBoundingRect( m_view->zoomHandler()->zoomRect( kpobject->getRepaintRect() ) );
4746
4747 KoRect objRect = kpobject->getRealRect();
4748 KoGuides::SnapStatus snapStatus( KoGuides::SNAP_NONE );
4749
4750 bool left = false;
4751 bool right = false;
4752 bool top = false;
4753 bool bottom = false;
4754 if ( _modType == MT_RESIZE_UP || _modType == MT_RESIZE_LU || _modType == MT_RESIZE_RU )
4755 {
4756 top = true;
4757 snapStatus |= KoGuides::SNAP_HORIZ;
4758 }
4759 if ( _modType == MT_RESIZE_DN || _modType == MT_RESIZE_LD || _modType == MT_RESIZE_RD )
4760 {
4761 bottom = true;
4762 snapStatus |= KoGuides::SNAP_HORIZ;
4763 }
4764 if ( _modType == MT_RESIZE_LF || _modType == MT_RESIZE_LU || _modType == MT_RESIZE_LD )
4765 {
4766 left = true;
4767 snapStatus |= KoGuides::SNAP_VERT;
4768 }
4769 if ( _modType == MT_RESIZE_RT || _modType == MT_RESIZE_RU || _modType == MT_RESIZE_RD )
4770 {
4771 right = true;
4772 snapStatus |= KoGuides::SNAP_VERT;
4773 }
4774
4775 double newLeft = objRect.left();
4776 double newRight = objRect.right();
4777 double newTop = objRect.top();
4778 double newBottom = objRect.bottom();
4779 if ( top )
4780 {
4781 if ( point.y() < objRect.bottom() - MIN_SIZE )
4782 {
4783 newTop = point.y();
4784 }
4785 else
4786 {
4787 newTop = objRect.bottom() - MIN_SIZE;
4788 }
4789 }
4790 if ( bottom )
4791 {
4792 if ( point.y() > objRect.top() + MIN_SIZE )
4793 {
4794 newBottom = point.y();
4795 }
4796 else
4797 {
4798 newBottom = objRect.top() + MIN_SIZE;
4799 }
4800 }
4801 if ( left )
4802 {
4803 if ( point.x() < objRect.right() - MIN_SIZE )
4804 {
4805 newLeft = point.x();
4806 }
4807 else
4808 {
4809 newLeft = objRect.right() - MIN_SIZE;
4810 }
4811 }
4812 if ( right )
4813 {
4814 if ( point.x() > objRect.left() + MIN_SIZE )
4815 {
4816 newRight = point.x();
4817 }
4818 else
4819 {
4820 newRight = objRect.left() + MIN_SIZE;
4821 }
4822 }
4823
4824 double width = newRight - newLeft;
4825 double height = newBottom - newTop;
4826
4827 if ( keepRatio && m_ratio != 0 )
4828 {
4829 if ( ( top || bottom ) && ( right || left ) )
4830 {
4831 if ( height * height * m_ratio > width * width / m_ratio )
4832 {
4833 width = height * m_ratio;
4834 }
4835 else
4836 {
4837 height = width / m_ratio;
4838 }
4839 }
4840 else if ( top || bottom )
4841 {
4842 width = height * m_ratio;
4843 }
4844 else
4845 {
4846 height = width / m_ratio;
4847 }
4848
4849 if ( top )
4850 {
4851 newTop = objRect.bottom() - height;
4852 }
4853 else
4854 {
4855 newBottom = objRect.top() + height;
4856 }
4857 if ( left )
4858 {
4859 newLeft = objRect.right() - width;
4860 }
4861 else
4862 {
4863 newRight = objRect.left() + width;
4864 }
4865 }
4866
4867 if ( scaleAroundCenter )
4868 {
4869 KoPoint center( m_rectBeforeResize.center() );
4870
4871 if ( newLeft != objRect.left() )
4872 {
4873 width = 2 * ( center.x() - newLeft );
4874 }
4875 else if ( newRight != objRect.right() )
4876 {
4877 width = 2 * ( newRight - center.x() );
4878 }
4879
4880 // if keep ratio is set caluclate witdh by ratio
4881 if ( keepRatio )
4882 {
4883 height = width / m_ratio;
4884 }
4885 else
4886 {
4887 if ( newTop != objRect.top() )
4888 {
4889 height = 2 * ( center.y() - newTop );
4890 }
4891 else if ( newBottom != objRect.bottom() )
4892 {
4893 height = 2 * ( newBottom - center.y() );
4894 }
4895 }
4896
4897 if ( width < MIN_SIZE )
4898 {
4899 width = MIN_SIZE;
4900 }
4901 if ( height < MIN_SIZE )
4902 {
4903 height = MIN_SIZE;
4904 }
4905
4906 newLeft = center.x() - width / 2;
4907 newRight = newLeft + width;
4908 newTop = center.y() - height / 2;
4909 newBottom = newTop + height;
4910 }
4911
4912 if ( newLeft != objRect.left() || newRight != objRect.right() || newTop != objRect.top() || newBottom != objRect.bottom() )
4913 {
4914 // resizeBy and moveBy have to been used to make it work with rotated objects
4915 kpobject->resizeBy( width - objRect.width(), height - objRect.height() );
4916
4917 if ( objRect.left() != newLeft || objRect.top() != newTop )
4918 {
4919 kpobject->moveBy( KoPoint( newLeft - objRect.left(), newTop - objRect.top() ) );
4920 }
4921
4922 if ( m_view->kPresenterDoc()->showGuideLines() && !m_disableSnapping )
4923 {
4924 KoRect rect( kpobject->getRealRect() );
4925 KoPoint sp( rect.topLeft() );
4926 if ( right )
4927 {
4928 sp.setX( rect.right() );
4929 }
4930 if ( bottom )
4931 {
4932 sp.setY( rect.bottom() );
4933 }
4934 m_gl.repaintSnapping( sp, snapStatus );
4935 }
4936
4937 _repaint( oldBoundingRect );
4938 _repaint( kpobject );
4939 emit objectSizeChanged();
4940 }
4941}
4942
4943
4944void KPrCanvas::finishResizeObject( const TQString &name, bool layout )
4945{
4946 if ( m_resizeObject )
4947 {
4948 KoPoint move = KoPoint( m_resizeObject->getOrig().x() - m_rectBeforeResize.x(),
4949 m_resizeObject->getOrig().y() - m_rectBeforeResize.y() );
4950 KoSize size = KoSize( m_resizeObject->getSize().width() - m_rectBeforeResize.width(),
4951 m_resizeObject->getSize().height() - m_rectBeforeResize.height() );
4952
4953 if ( ( m_resizeObject->getRect() ) != m_rectBeforeResize )
4954 {
4955 KPrResizeCmd *resizeCmd = new KPrResizeCmd( name, move, size, m_resizeObject,
4956 m_view->kPresenterDoc() );
4957 // the command is not executed as the object is allready resized.
4958 m_view->kPresenterDoc()->addCommand( resizeCmd );
4959 }
4960
4961 if ( layout )
4962 m_view->kPresenterDoc()->layout( m_resizeObject );
4963
4964 m_ratio = 0.0;
4965 m_isResizing = false;
4966 _repaint( m_resizeObject );
4967 m_resizeObject = NULL;
4968 }
4969}
4970
4971void KPrCanvas::raiseObject( KPrObject *object )
4972{
4973 if ( objectList().count() <= 1 )
4974 return;
4975
4976 if ( m_objectDisplayAbove == 0 )
4977 {
4978 if ( m_activePage->numSelected() == 1 )
4979 {
4980 m_objectDisplayAbove = object;
4981 }
4982 }
4983}
4984
4985void KPrCanvas::lowerObject()
4986{
4987 m_objectDisplayAbove = 0;
4988}
4989
4990const TQPtrList<KPrObject> KPrCanvas::displayObjectList() const
4991{
4992 TQPtrList<KPrObject> list = objectList();
4993 list.setAutoDelete( false );
4994
4995 if ( m_objectDisplayAbove )
4996 {
4997 // it can happen that the object is no longer there e.g. when
4998 // the insert of the object is undone
4999 int pos = objectList().findRef( m_objectDisplayAbove );
5000 if ( pos != -1 && m_objectDisplayAbove->isSelected() )
5001 {
5002 list.take( pos );
5003 list.append( m_objectDisplayAbove );
5004 }
5005 else
5006 {
5007 //tz not possible due to const. should const be removed?
5008 //m_objectDisplayAbove = 0;
5009 }
5010 }
5011 return list;
5012}
5013
5014void KPrCanvas::playSound( const TQString &soundFileName )
5015{
5016 if(soundPlayer)
5017 delete soundPlayer;
5018 soundPlayer = new KPrSoundPlayer( soundFileName );
5019 soundPlayer->play();
5020}
5021
5022void KPrCanvas::stopSound()
5023{
5024 if ( soundPlayer ) {
5025 soundPlayer->stop();
5026 delete soundPlayer;
5027 soundPlayer = 0;
5028 }
5029}
5030
5031void KPrCanvas::setXimPosition( int x, int y, int w, int h, TQFont *f )
5032{
5033 TQWidget::setMicroFocusHint( x - diffx(), y - diffy(), w, h, true, f );
5034}
5035
5036void KPrCanvas::createEditing( KPrTextObject *textObj )
5037{
5038 if( m_currentTextObjectView)
5039 {
5040 m_currentTextObjectView->terminate();
5041 delete m_currentTextObjectView;
5042 m_currentTextObjectView = 0;
5043 m_editObject = 0;
5044 }
5045 m_currentTextObjectView = textObj->createKPTextView( this );
5046 m_editObject = textObj;
5047}
5048
5049void KPrCanvas::terminateEditing( KPrTextObject *textObj )
5050{
5051 if ( m_currentTextObjectView && m_currentTextObjectView->kpTextObject() == textObj )
5052 {
5053 m_currentTextObjectView->terminate();
5054 delete m_currentTextObjectView;
5055 m_currentTextObjectView = 0;
5056 m_editObject = 0;
5057 }
5058}
5059
5060void KPrCanvas::drawCubicBezierCurve( TQPainter &p, KoPointArray &points )
5061{
5062 p.save();
5063 if ( !m_drawLineWithCubicBezierCurve )
5064 {
5065 TQPen pen = TQPen( TQt::black, 1, TQt::DashLine );
5066 p.setPen( pen );
5067 double angle = KoPoint::getAngle( m_endPoint, m_startPoint );
5068 drawFigure( L_SQUARE, &p, m_endPoint, pen.color(), pen.width(), angle,m_view->zoomHandler() );
5069
5070 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
5071 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
5072
5073 KoPoint symmetricEndPoint = m_startPoint * 2 - m_endPoint;
5074
5075 angle = KoPoint::getAngle( symmetricEndPoint, m_startPoint );
5076 drawFigure( L_SQUARE, &p, symmetricEndPoint, pen.color(), pen.width(), angle,m_view->zoomHandler() );
5077
5078 // TODO only 1 draw line
5079 p.drawLine( m_view->zoomHandler()->zoomPoint( m_startPoint ),
5080 m_view->zoomHandler()->zoomPoint( symmetricEndPoint ) );
5081
5082 p.save();
5083 p.setPen( TQPen( TQt::black, 1, TQt::SolidLine ) );
5084 p.drawCubicBezier( points.zoomPointArray( m_view->zoomHandler() ) );
5085 p.restore();
5086 }
5087 else
5088 {
5089 KoPoint startPoint( m_pointArray.at( m_indexPointArray - 1 ) );
5090
5091 p.drawLine( m_view->zoomHandler()->zoomPoint( startPoint ),
5092 m_view->zoomHandler()->zoomPoint( m_endPoint ) );
5093 }
5094 p.restore();
5095}
5096
5097
5099{
5100 if ( m_indexPointArray > 0 )
5101 {
5102 for ( int count = 0; count < m_indexPointArray - 4; count += 4 )
5103 {
5104 double _firstX = m_pointArray.at( count ).x();
5105 double _firstY = m_pointArray.at( count ).y();
5106
5107 double _fourthX = m_pointArray.at( count + 1 ).x();
5108 double _fourthY = m_pointArray.at( count + 1 ).y();
5109
5110 double _secondX = m_pointArray.at( count + 2 ).x();
5111 double _secondY = m_pointArray.at( count + 2 ).y();
5112
5113 double _thirdX = m_pointArray.at( count + 3 ).x();
5114 double _thirdY = m_pointArray.at( count + 3 ).y();
5115
5116 KoPointArray points;
5117 points.putPoints( 0, 4, _firstX,_firstY, _secondX,_secondY, _thirdX,_thirdY, _fourthX,_fourthY );
5118
5119 p.drawCubicBezier( points.zoomPointArray( m_view->zoomHandler() ) );
5120 }
5121 }
5122}
5123
5124
5125void KPrCanvas::drawPolygon( TQPainter &p, const KoRect &rect )
5126{
5127 KoRect nRect = rect.normalize();
5128 bool checkConcavePolygon = m_view->getCheckConcavePolygon();
5129 int cornersValue = m_view->getCornersValue();
5130 int sharpnessValue = m_view->getSharpnessValue();
5131
5132 KoRect _rect( 0, 0, nRect.width(), nRect.height() );
5133 double angle = 2 * M_PI / cornersValue;
5134 double diameter = static_cast<double>( TQMAX( _rect.width(), _rect.height() ) );
5135 double radius = diameter * 0.5;
5136
5137 KoPointArray _points( checkConcavePolygon ? cornersValue * 2 : cornersValue );
5138 _points.setPoint( 0, 0, tqRound( -radius ) );
5139
5140 double xmin = 0;
5141 double ymin = tqRound( -radius );
5142
5143 if ( checkConcavePolygon ) {
5144 angle = angle / 2.0;
5145 double a = angle;
5146 double r = radius - ( sharpnessValue / 100.0 * radius );
5147 for ( int i = 1; i < cornersValue * 2; ++i ) {
5148 double xp, yp;
5149 if ( i % 2 ) {
5150 xp = r * sin( a );
5151 yp = -r * cos( a );
5152 }
5153 else {
5154 xp = radius * sin( a );
5155 yp = -radius * cos( a );
5156 }
5157 a += angle;
5158 _points.setPoint( i, xp, yp );
5159 if (xp < xmin)
5160 xmin = xp;
5161 if (yp < ymin)
5162 ymin = yp;
5163 }
5164 }
5165 else {
5166 double a = angle;
5167 for ( int i = 1; i < cornersValue; ++i ) {
5168 double xp = radius * sin( a );
5169 double yp = -radius * cos( a );
5170 a += angle;
5171 _points.setPoint( i, xp, yp );
5172 if (xp < xmin)
5173 xmin = xp;
5174 if (yp < ymin)
5175 ymin = yp;
5176 }
5177 }
5178
5179 // calculate the points as offsets to 0,0
5180 KoRect _changRect = _points.boundingRect();
5181 double fx = _rect.width() / _changRect.width();
5182 double fy = _rect.height() / _changRect.height();
5183
5184 int _index = 0;
5185 KoPointArray tmpPoints;
5186 KoPointArray::ConstIterator it;
5187 for ( it = _points.begin(); it != _points.end(); ++it ) {
5188 KoPoint point = (*it);
5189 double tmpX = ( point.x() - xmin) * fx + nRect.x();
5190 double tmpY = ( point.y() - ymin) * fy + nRect.y();
5191
5192 tmpPoints.putPoints( _index, 1, tmpX,tmpY );
5193 ++_index;
5194 }
5195 p.drawPolygon( tmpPoints.zoomPointArray( m_view->zoomHandler() ) );
5196 m_pointArray = tmpPoints;
5197}
5198
5199
5200bool KPrCanvas::oneObjectTextSelected() const
5201{
5202 return m_activePage->oneObjectTextSelected();
5203}
5204
5205bool KPrCanvas::oneObjectTextExist() const
5206{
5207 return m_activePage->oneObjectTextExist();
5208}
5209
5210KPrPage* KPrCanvas::activePage() const
5211{
5212 return m_activePage;
5213}
5214
5215void KPrCanvas::setActivePage( KPrPage* active )
5216{
5217 Q_ASSERT(active);
5218 //kdDebug(33001)<<"KPrCanvas::setActivePage( KPrPage* active) :"<<active<<endl;
5219 // reset the m_objectDisplayAbove so that it is not display wrong on the other page
5220 m_objectDisplayAbove = 0;
5221 m_activePage = active;
5222}
5223
5225{
5226 m_paintGuides = state;
5227}
5228
5229bool KPrCanvas::objectIsAHeaderFooterHidden(KPrObject *obj) const
5230{
5231 if (( m_view->kPresenterDoc()->isHeader(obj) && !m_activePage->hasHeader() )
5232 || ( m_view->kPresenterDoc()->isFooter(obj) && !m_activePage->hasFooter() ) )
5233 return true;
5234 return false;
5235}
5236
5237int KPrCanvas::numberOfObjectSelected() const
5238{
5239 int nb = m_activePage->numSelected();
5240 return nb;
5241}
5242
5243KPrObject *KPrCanvas::getSelectedObj() const
5244{
5245 KPrObject *obj = m_activePage->getSelectedObj();
5246 return obj;
5247}
5248
5249void KPrCanvas::ungroupObjects()
5250{
5251 KMacroCommand *macro = 0;
5252 m_activePage->ungroupObjects( &macro );
5253 if ( macro )
5254 m_view->kPresenterDoc()->addCommand( macro );
5255}
5256
5257void KPrCanvas::groupObjects()
5258{
5259 m_activePage->groupObjects();
5260}
5261
5262KoRect KPrCanvas::objectRect( bool all ) const
5263{
5264 return m_activePage->getRealRect( all );
5265}
5266
5267void KPrCanvas::scrollTopLeftPoint( const TQPoint & pos )
5268{
5269 m_view->getHScrollBar()->setValue( pos.x() );
5270 m_view->getVScrollBar()->setValue( pos.y() );
5271}
5272
5273void KPrCanvas::changePicture( const KURL & url, TQWidget *window )
5274{
5275 m_activePage->changePicture( url, window );
5276}
5277
5278unsigned int KPrCanvas::objNums() const
5279{
5280 return m_activePage->objNums();
5281}
5282
5283
5284void KPrCanvas::ensureVisible( int x, int y, int xmargin, int ymargin )
5285{
5286
5287 int newy= (y+ymargin)-(visibleRect().bottom()+diffy());
5288
5289 if( newy > 0)
5290 m_view->getVScrollBar()->setValue(m_view->getVScrollBar()->value()+newy);
5291 else
5292 {
5293 newy= (y )-(visibleRect().top()+diffy());
5294 if( newy < 0)
5295 m_view->getVScrollBar()->setValue(m_view->getVScrollBar()->value()+newy - ymargin);
5296 }
5297
5298 int newx= (x+xmargin)-(visibleRect().right()+diffx());
5299 if( newx > 0)
5300 m_view->getHScrollBar()->setValue(m_view->getHScrollBar()->value()+newx);
5301 else
5302 {
5303 newx= x -(visibleRect().left()+diffx());
5304 if( newx < 0)
5305 m_view->getHScrollBar()->setValue(m_view->getHScrollBar()->value()+newx - xmargin );
5306 }
5307}
5308
5309// "Extend Contents to Object Height"
5310void KPrCanvas::textContentsToHeight()
5311{
5312 TQPtrList<KPrTextObject> lst = applicableTextObjects();
5313 if ( lst.isEmpty() )
5314 return;
5315 TQPtrListIterator<KPrTextObject> it( lst );
5316 KMacroCommand * macro = 0L;
5317 for ( ; it.current() ; ++it ) {
5318 KCommand *cmd= it.current()->textContentsToHeight();
5319 if( cmd )
5320 {
5321 if ( !macro )
5322 macro = new KMacroCommand(i18n("Extend Text Contents to Height"));
5323 macro->addCommand( cmd);
5324 _repaint( it.current() );
5325 }
5326 }
5327 if( macro )
5328 {
5329 macro->execute();
5330 m_view->kPresenterDoc()->addCommand( macro );
5331 m_view->kPresenterDoc()->repaint(this);
5332 }
5333}
5334
5335// "Resize Object to fit Contents"
5336void KPrCanvas::textObjectToContents()
5337{
5338 TQPtrList<KPrTextObject> lst = applicableTextObjects();
5339 if ( lst.isEmpty() )
5340 return;
5341 TQPtrListIterator<KPrTextObject> it( lst );
5342 KMacroCommand * macro = 0L;
5343 for ( ; it.current() ; ++it ) {
5344 KCommand *cmd= it.current()->textObjectToContents();
5345 if( cmd )
5346 {
5347 if (!macro )
5348 macro = new KMacroCommand(i18n("Extend Text to Contents"));
5349 macro->addCommand( cmd);
5350 }
5351 }
5352
5353 if( macro)
5354 {
5355 macro->execute();
5356 m_view->kPresenterDoc()->addCommand( macro );
5357 m_view->kPresenterDoc()->repaint(this);
5358 }
5359
5360}
5361
5362void KPrCanvas::flipObject( bool _horizontal )
5363{
5364 TQPtrList<KPrObject> lst;
5365 TQPtrListIterator<KPrObject> it(getObjectList());
5366 for ( ; it.current(); ++it ) {
5367 if ( it.current()->isSelected() &&
5368 it.current()->getType() != OT_AUTOFORM &&
5369 it.current()->getType() != OT_PART &&
5370 it.current()->getType() != OT_TEXT )
5371 {
5372 lst.append( it.current() );
5373 }
5374 }
5375 if ( lst.isEmpty() )
5376 return;
5377
5378 KPrFlipObjectCommand *flipCmd = new KPrFlipObjectCommand( i18n("Flip Objects"),
5379 m_view->kPresenterDoc(),
5380 _horizontal, lst );
5381 flipCmd->execute();
5382 m_view->kPresenterDoc()->addCommand( flipCmd );
5383}
5384
5385void KPrCanvas::lowerObjs( bool backward )
5386{
5387 lowerObject();
5388 m_activePage->lowerObjs( backward );
5389}
5390
5391void KPrCanvas::raiseObjs( bool forward )
5392{
5393 lowerObject();
5394 m_activePage->raiseObjs( forward );
5395}
5396
5397TQPtrList<KPrTextObject> KPrCanvas::listOfTextObjs() const
5398{
5399 TQPtrList<KPrTextObject> lst;
5400 TQPtrListIterator<KPrObject> it(getObjectList());
5401 for ( ; it.current(); ++it ) {
5402 if ( it.current()->getType() == OT_TEXT )
5403 {
5404 if ( objectIsAHeaderFooterHidden(it.current()))
5405 continue;
5406 else
5407 lst.append( static_cast<KPrTextObject*>( it.current() ));
5408 }
5409 }
5410 return lst;
5411}
5412
5413KPrTextObject* KPrCanvas::textUnderMouse( const TQPoint & point )
5414{
5415 TQPtrList<KPrTextObject> obj = listOfTextObjs();
5416 TQPtrListIterator<KPrTextObject> it2(obj );
5417 for ( ; it2.current() ; ++it2 ) {
5418 TQRect outerRect( m_view->kPresenterDoc()->zoomHandler()->zoomRect( it2.current()->getRect()) );
5419 if ( !it2.current()->isProtectContent() && outerRect.contains( point) )
5420 return it2.current();
5421 }
5422 return 0L;
5423}
5424
5425void KPrCanvas::speakTextUnderMouse(TQWidget* w, const TQPoint& p, uint flags)
5426{
5427 Q_UNUSED( flags );
5428 if ( w != this ) return;
5429 // Since text objects can't get focus without clicking with the mouse,
5430 // no point in supporting focus speaking.
5431 if ( p == TQPoint() ) return;
5432 KPrTextObject *to = textUnderMouse( w->mapFromGlobal( p ) );
5433 if ( to == m_prevSpokenTO ) return;
5434 m_prevSpokenTO = to;
5435 if ( to ) {
5436 TQString text = to->textObject()->textDocument()->plainText();
5437 if ( !text.isEmpty() ) kospeaker->sayWidget( text );
5438 }
5439}
5440
5441bool KPrCanvas::checkCurrentTextEdit( KPrTextObject * textObj )
5442{
5443 bool emitChanged = false;
5444 if ( textObj && m_currentTextObjectView && m_currentTextObjectView->kpTextObject() != textObj )
5445 {
5446 m_currentTextObjectView->kpTextObject()->setEditingTextObj( false );
5447 _repaint( m_currentTextObjectView->kpTextObject() );
5448 //don't remove selection otherwise break dnd.
5449 m_currentTextObjectView->terminate(false);
5450 delete m_currentTextObjectView;
5451 m_currentTextObjectView = 0L;
5452 emitChanged = true;
5453 }
5454
5455 // Edit the frameset under the mouse, if any
5456 if ( textObj && !m_currentTextObjectView )
5457 {
5458 m_currentTextObjectView = textObj->createKPTextView( this );
5459 emitChanged = true;
5460 }
5461 return emitChanged;
5462}
5463
5464void KPrCanvas::alignObjects( AlignType at )
5465{
5466 KPrDocument * doc = m_view->kPresenterDoc();
5467
5468 TQString name;
5469
5470 switch ( at )
5471 {
5472 case AT_LEFT:
5473 name = i18n( "Align Objects Left" );
5474 break;
5475 case AT_TOP:
5476 name = i18n( "Align Objects Top" );
5477 break;
5478 case AT_RIGHT:
5479 name = i18n( "Align Objects Right" );
5480 break;
5481 case AT_BOTTOM:
5482 name = i18n( "Align Objects Bottom" );
5483 break;
5484 case AT_HCENTER:
5485 name = i18n( "Align Objects Centered (horizontal)" );
5486 break;
5487 case AT_VCENTER:
5488 name = i18n( "Align Objects Center/Vertical" );
5489 break;
5490 }
5491
5492 TQPtrList<KPrObject> objects;
5493
5494 TQPtrListIterator<KPrObject> it( m_activePage->objectList() );
5495 for ( ; it.current() ; ++it )
5496 {
5497 if ( it.current() == m_view->kPresenterDoc()->header() ||
5498 it.current() == m_view->kPresenterDoc()->footer() )
5499 continue;
5500
5501 if( it.current()->isSelected() && !it.current()->isProtect() ) {
5502 objects.append( it.current() );
5503 }
5504 }
5505
5506 if ( objects.count() )
5507 {
5508 KCommand * cmd = new KPrAlignCmd( name, objects, at, doc );
5509 cmd->execute();
5510 doc->addCommand( cmd );
5511 }
5512}
5513
5514bool KPrCanvas::canMoveOneObject() const
5515{
5516 return m_activePage->canMoveOneObject();
5517}
5518
5519void KPrCanvas::closeObject(bool /*close*/)
5520{
5521 TQPtrList<KPrObject> lst;
5522 TQPtrListIterator<KPrObject> it(getObjectList());
5523 for ( ; it.current(); ++it ) {
5524 if ( it.current()->isSelected()
5525 && (it.current()->getType() == OT_POLYLINE || it.current()->getType() == OT_FREEHAND
5526 || it.current()->getType() == OT_QUADRICBEZIERCURVE
5527 || it.current()->getType() == OT_CUBICBEZIERCURVE ))
5528 lst.append( it.current() );
5529 }
5530 if ( lst.isEmpty())
5531 return;
5532
5533 KCommand * cmd= new KPrCloseObjectCommand( i18n("Close Object"), lst, m_view->kPresenterDoc() );
5534 cmd->execute();
5535 m_view->kPresenterDoc()->addCommand( cmd );
5536}
5537
5538void KPrCanvas::layout()
5539{
5540 TQPtrListIterator<KPrObject> it(getObjectList());
5541 for ( ; it.current(); ++it ) {
5542 if ( it.current()->getType() == OT_TEXT )
5543 static_cast<KPrTextObject *>( it.current() )->layout();
5544 }
5545}
5546
5547KoPoint KPrCanvas::snapPoint( KoPoint &pos, bool repaintSnapping )
5548{
5549 KoPoint sp( pos );
5550 KPrDocument * doc( m_view->kPresenterDoc() );
5551
5552 bool snapToGrid = doc->snapToGrid() && !m_disableSnapping;
5553 bool snapToGuideLines = doc->showGuideLines() && !m_disableSnapping;
5554
5555 KoPoint snapDiff = KoPoint( 0, 0 ); // needed if all snapping is off
5556 KoGuides::SnapStatus snapStatus = KoGuides::SNAP_NONE;
5557
5558 if ( snapToGrid )
5559 {
5560 snapDiff.setX( tqRound( sp.x() / doc->getGridX()) * doc->getGridX() - sp.x() );
5561 snapDiff.setY( tqRound( sp.y() / doc->getGridY()) * doc->getGridY() - sp.y() );
5562 snapStatus = KoGuides::SNAP_BOTH;
5563 }
5564
5565 if ( snapToGuideLines )
5566 {
5567 m_gl.snapToGuideLines( sp, MOUSE_SNAP_DISTANCE, snapStatus, snapDiff );
5568 }
5569
5570 sp += snapDiff;
5571
5572 // don't snap out of canvas
5573 KoRect pageRect( m_activePage->getPageRect() );
5574 if ( sp.x() < pageRect.left() )
5575 sp.setX( pageRect.left() );
5576 else if ( sp.x() > pageRect.right() )
5577 sp.setX( pageRect.right() );
5578
5579 if ( sp.y() < pageRect.top() )
5580 sp.setY( pageRect.top() );
5581 else if ( sp.y() > pageRect.bottom() )
5582 sp.setY( pageRect.bottom() );
5583
5584 // redraw guidelines (intentionally always)
5585 if ( repaintSnapping && snapToGuideLines )
5586 {
5587 m_gl.repaintSnapping( sp, KoGuides::SNAP_BOTH );
5588 }
5589
5590 return sp;
5591}
5592
5593
5594void KPrCanvas::alignVertical(VerticalAlignmentType _type )
5595{
5596 KCommand *cmd = m_activePage->alignVertical( _type );
5597 if ( cmd )
5598 m_view->kPresenterDoc()->addCommand( cmd );
5599}
5600
5601KPrPixmapObject * KPrCanvas::getSelectedImage() const
5602{
5603 return m_activePage->getSelectedImage();
5604}
5605
5606
5607KoPointArray KPrCanvas::getObjectPoints( const KoPointArray &pointArray )
5608{
5609 KoRect rect = pointArray.boundingRect();
5610
5611 KoPointArray points( pointArray );
5612 points.translate( -rect.x(), -rect.y() );
5613
5614 return points;
5615}
5616
5617void KPrCanvas::objectPopup( KPrObject *object, const TQPoint &point )
5618{
5619 switch ( object->getType() )
5620 {
5621 case OT_PICTURE:
5622 case OT_CLIPART:
5623 m_view->openPopupMenuObject( "picmenu_popup", point );
5624 break;
5625 case OT_TEXT:
5626 {
5627 KPrTextObject *obj=dynamic_cast<KPrTextObject *>(object);
5628 if ( obj )
5629 m_view->changeVerticalAlignmentStatus( obj->verticalAlignment() );
5630 m_view->openPopupMenuObject( "textobject_popup", point );
5631 } break;
5632 case OT_PIE:
5633 m_view->openPopupMenuObject( "piemenu_popup", point );
5634 break;
5635 case OT_RECT:
5636 case OT_ELLIPSE:
5637 m_view->openPopupMenuObject( "rectangleobject_popup", point );
5638 break;
5639 case OT_PART:
5640 m_view->openPopupMenuObject( "partobject_popup", point );
5641 break;
5642 case OT_POLYGON:
5643 m_view->openPopupMenuObject( "polygonobject_popup", point );
5644 break;
5645 case OT_POLYLINE:
5646 case OT_CUBICBEZIERCURVE:
5647 case OT_QUADRICBEZIERCURVE:
5648 case OT_FREEHAND:
5649 m_view->openPopupMenuObject( "closed_popup", point );
5650 break;
5651 case OT_LINE:
5652 case OT_CLOSED_LINE:
5653 m_view->openPopupMenuObject( "flip_popup", point );
5654 break;
5655 case OT_GROUP:
5656 if ( oneObjectTextSelected())
5657 m_view->openPopupMenuObject( "textobject_popup", point );
5658 else
5659 m_view->openPopupMenuObject( "flip_popup", point );
5660 break;
5661 default:
5662 m_view->openPopupMenuObject( "graphmenu_popup", point );
5663 break;
5664 }
5665}
5666
5667void KPrCanvas::popupContextMenu()
5668{
5669 if ( !editMode ) {
5670 if ( !m_drawMode && !spManualSwitch() )
5671 {
5673 finishPageEffect();
5674 m_view->stopAutoPresTimer();
5675 }
5676 setCursor( arrowCursor );
5677 TQPoint p( width()/2, height()/2 );
5678 int ret = m_presMenu->exec( p );
5679 // we have to continue the timer if the menu was canceled and draw mode is not active
5680 if ( ret == -1 && !m_presMenu->isItemChecked( PM_DM ) && !spManualSwitch() )
5681 m_view->continueAutoPresTimer();
5682 return;
5683 }
5684 if ( m_currentTextObjectView ) {
5685 // TODO: Better to popup at caret position.
5686 // KoTextCursor* cursor = m_currentTextObjectView->cursor();
5687 KoPoint kop = m_currentTextObjectView->kpTextObject()->getOrig();
5688 TQPoint p = m_view->zoomHandler()->zoomPoint( kop );
5689 p = mapToGlobal( p );
5690 m_currentTextObjectView->showPopup( m_view, p, m_view->actionList() );
5691 return;
5692 }
5693 if (!m_activePage) return;
5694 KPrObject* obj = m_activePage->getSelectedObj();
5695 if (obj) {
5696 KoPoint kop = obj->getOrig();
5697 TQPoint p = m_view->zoomHandler()->zoomPoint( kop );
5698 p = mapToGlobal( p );
5699 objectPopup( obj, p );
5700 } else {
5701 TQPoint p = mapToGlobal( TQPoint() );
5702 m_view->openPopupMenuMenuPage( p );
5703 }
5704}
Command to align objects.
Definition KPrCommand.h:340
void drawBackground(TQPainter *painter, const TQRect &rect, KPrPage *page, bool edit=false) const
Draws the background of page to painter.
void stopAutomaticPresentation()
Emmitted when presentation should be restarted This is used in automatic screen and infinite loop mod...
KPrPartObject * insertObject(const KoRect &rect)
Add a object.
void drawObjectsPres(TQPainter *painter, const TQPtrList< KPrObject > &_objects, PresStep step) const
Draw _objects shown at step to painter.
void drawAllObjectsInPage(TQPainter *painter, const TQPtrList< KPrObject > &obj, int pageNum) const
Draw obj to painter.
void insertLine(const KoPoint &startPoint, const KoPoint &endPoint)
Add a line.
KPrObject * getObjectAt(const KoPoint &pos, bool withoutProtected=false)
Returns the object at position pos.
void insertEllipse(const KoRect &rect)
Add a ellipse.
void doObjEffects(bool isAllreadyPainted=false)
This method animates the objects in the presentation.
void drawEditPage(TQPainter *painter, const TQRect &_rect, KPrPage *page, SelectionMode selectionMode) const
Draw _objects of page to painter.
void drawCubicBezierCurve(TQPainter &p, KoPointArray &points)
Draw a cubic bezier curve.
bool finishObjectEffects()
Finish the object effects.
void insertRect(const KoRect &rect)
Add a rectangle.
void redrawCubicBezierCurve(TQPainter &p)
Redraw the curve defined in m_pointArray.
void drawObjects(TQPainter *painter, const TQPtrList< KPrObject > &objects, SelectionMode selectionMode, bool contour, KPrTextView *textView, int pageNum) const
Draw _objects to painter.
KPrCanvas(TQWidget *parent=0, const char *name=0, KPrView *_view=0)
constructor
Definition KPrCanvas.cpp:95
void drawPresPage(TQPainter *painter, const TQRect &_rect, PresStep step) const
Draw _objects of page shown at step to painter.
void printPage(TQPainter *, PresStep step, KPrinter *printer, int rows, int cols)
Draw page defined in step to painter.
void currentObjectEditChanged()
Emitted when the current frameset edit changes.
void presGotoFirstPage()
Go to first slide of presentation.
void drawObjectsEdit(TQPainter *painter, const KoRect &rect, const TQPtrList< KPrObject > &_objects, SelectionMode selectionMode, int page) const
Draw _objects to painter.
void setPaintGuides(bool state)
Set the guide move state.
KPrTextObject * insertTextObject(const KoRect &rect)
Add a text object.
TQPtrList< KPrTextObject > selectedTextObjs() const
Returns the list of selected text objects.
void insertPicture(const KoRect &rect)
Add a picture.
void drawGrid(TQPainter *painter, const TQRect &rect2) const
draw grid
void drawPageInPix(TQPixmap &, int pgnum, int zoom, bool forceRealVariableValue=false, int forceWidth=0, int forceHeight=0)
Draw page into TQPixmap.
void objectPopup(KPrObject *object, const TQPoint &point)
Open the object popup.
void restartPresentation()
Emmitted when presentation should be restarted This is used in automatic screen and infinite loop mod...
void alignObjects(AlignType at)
Align objects.
bool pPrev(bool gotoPreviousPage=false)
Go to previous step of the presentation.
void startScreenPresentation(double zoomX, double zoomY, int curPgNum=-1)
Start a screen presentation All pages if curPgNum is -1, otherwise just curPgNum (1-based)
void setupMenus()
setup popupmenus
void insertPie(const KoRect &rect)
Add a pie/arc/chord.
~KPrCanvas()
destructor
bool exportPage(int nPage, int nWidth, int nHeight, const KURL &fileURL, const char *format, int quality=-1)
TQPtrList< KoTextFormatInterface > applicableTextInterfaces() const
Returns the list of interfaces to use for changing the text format.
virtual void paintEvent(TQPaintEvent *)
This method is used for repainting the canvas.
bool pNext(bool gotoNextPage=false)
Go to the next step in the presentation.
KoRect objectRect(bool all) const
get the rect for the objects
TQPtrList< KPrTextObject > applicableTextObjects() const
Returns the list of text objects, either selected or activated.
void insertAutoform(const KoRect &rect)
Add a autoform object.
Class for keeping a presentation step m_pageNumber the current page number 0 based m_step the current...
Definition presstep.h:32