kpresenter

KPrCanvas.h
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
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21
22#ifndef __KPRCANVAS__
23#define __KPRCANVAS__
24
25#include <tqwidget.h>
26#include <tqptrlist.h>
27#include <tqpicture.h>
28#include <tqvaluelist.h>
29#include <tqpixmap.h>
30#include <tqpointarray.h>
31#include <tqvaluevector.h>
32#include <tqtimer.h>
33
34#include <KoGuides.h>
35#include <KoRuler.h>
36#include <KoQueryTrader.h>
37#include "KoPointArray.h"
38#include "global.h"
39#include <KoRect.h>
40#include <KoTextFormat.h>
41#include "presstep.h"
42
43class KURL;
44class KoTextFormatInterface;
45class KPrView;
46class KPrDocument;
47class TQPainter;
48class KTextEdit;
49class KPrTextObject;
50class KPrObject;
51class TDEPopupMenu;
52class TQResizeEvent;
53class TQPaintEvent;
54class TQDragEnterEvent;
55class TQDragMoveEvent;
56class TQDropEvent;
57class TQFocusEvent;
58class TQMouseEvent;
59class TQWheelEvent;
60class TQKeyEvent;
61class KPrPixmapObject;
62class KPrBackGround;
63class TQRect;
64class TQSize;
65class TQPoint;
66class KPrSoundPlayer;
67class KoTextObject;
68class KoParagCounter;
69class KPrPage;
70class KPrinter;
71class KPrTextView;
72class KPrPartObject;
73class KCommand;
74class KPrEffectHandler;
75class KPrPageEffects;
81class KPrCanvas : public TQWidget
82{
83 TQ_OBJECT
84
85
86public:
87
89 KPrCanvas( TQWidget *parent=0,const char *name=0,KPrView *_view=0 );
91 ~KPrCanvas();
92
93 KPrView * getView()const { return m_view; }
94
95 // The equivalent of contentsX() and contentsY() for a TQScrollView
96 // The Canvas is a widget, not a scrollview (because we handle the scrollbars ourselves,
97 // to have the "goto page" buttons at the bottom of the scrollbars etc.)
98 int diffx() const { return m_xOffset; }
99 int diffy() const { return m_yOffset; }
100 void setDiffX( int _diffX ) { m_xOffset = _diffX; }
101 void setDiffY( int _diffY ) { m_yOffset = _diffY; }
102 void scrollX( int x );
103 void scrollY( int y );
104
105 // public functions
106 void selectAllObj();
107 void deSelectAllObj();
108 void selectObj( KPrObject* );
109 void deSelectObj( KPrObject* );
110 void setTextFormat(const KoTextFormat &format, int flags);
111
112 void setTextColor( const TQColor & );
113 void setTextBackgroundColor( const TQColor & );
114 void setTextAlign( int );
115 void setTextDepthPlus();
116 void setTextDepthMinus();
117 void setNewRightIndent(double _rightIndent);
118 void setNewLeftIndent(double _leftIndent);
119 void setNewFirstIndent(double _firstIndent);
120 //void setTextCounter(KoParagCounter counter);
121 void setTabList( const KoTabulatorList & tabList );
122 void setTextBold( bool b );
123 void setTextItalic( bool b );
124 void setTextUnderline( bool b );
125 void setTextStrikeOut( bool b );
126 void setTextFamily( const TQString &f );
127 void setTextPointSize( int s );
128 void setTextSubScript( bool b );
129 void setTextSuperScript( bool b );
130 void setTextDefaultFormat( );
131 void setIncreaseFontSize();
132 void setDecreaseFontSize();
133 KPrTextObject* kpTxtObj() const;
134
139 void startScreenPresentation( double zoomX, double zoomY, int curPgNum = -1);
140 void stopScreenPresentation();
141
147 bool pNext( bool gotoNextPage = false );
148
154 bool pPrev( bool gotoPreviousPage = false );
155
157 unsigned int presPage() const { return m_step.m_pageNumber + 1; }
159 int presStep() const { return m_step.m_step; }
160 int numPresSteps() const { return m_pageEffectSteps.count(); }
161 int numPresPages() const { return m_presentationSlides.count(); }
162
163 bool canAssignEffect( TQPtrList<KPrObject> &objs ) const;
164
165 void print( TQPainter*, KPrinter*, float, float );
166
167
168 void setPartEntry( KoDocumentEntry& _e )
169 { partEntry = _e; }
170 void setToolEditMode( ToolEditMode _m, bool updateView = true );
171 void setAutoForm( const TQString &_autoform )
172 { autoform = _autoform; }
173
187 void drawPageInPix( TQPixmap&, int pgnum, int zoom,
188 bool forceRealVariableValue = false,
189 int forceWidth = 0,
190 int forceHeight = 0 );
191
216 bool exportPage( int nPage, int nWidth, int nHeight,
217 const KURL& fileURL,
218 const char* format,
219 int quality = -1 );
220
221 void gotoPage( int pg );
222
227 void presGotoFirstPage();
228
229 KPrPage* activePage() const;
230
231 bool oneObjectTextExist() const;
232 bool oneObjectTextSelected() const;
233 bool isOneObjectSelected() const;
235 TQPtrList<KPrTextObject> selectedTextObjs() const;
241 TQPtrList<KoTextFormatInterface> applicableTextInterfaces() const;
245 TQPtrList<KPrTextObject> applicableTextObjects() const;
246
247 void setMouseSelectedObject(bool b);
248
249 bool haveASelectedPartObj() const;
250 bool haveASelectedGroupObj() const;
251 bool haveASelectedPixmapObj() const;
252
253 KPrTextView *currentTextObjectView() const { return m_currentTextObjectView; }
254
255 TQPtrList<KPrObject> objectList() const;
256
257 // get - set data
258 const TQPtrList<KPrObject> & getObjectList() const;
259
260 void playSound( const TQString &soundFileName );
261 void stopSound();
262
264 void dragStarted() { mousePressed = false; }
265
266 void setXimPosition( int x, int y, int w, int h, TQFont *f );
267 void createEditing( KPrTextObject *textObj );
268
269
276 void insertLine( const KoPoint &startPoint, const KoPoint &endPoint );
277
283 void insertRect( const KoRect &rect);
284
290 void insertEllipse( const KoRect &rect );
291
297 void insertPie( const KoRect &rect );
298
304 KPrTextObject* insertTextObject( const KoRect &rect );
305
311 void insertPicture( const KoRect &rect );
312 void changePicture( const KURL & url, TQWidget *window );
313
314 int numberOfObjectSelected() const;
315 KPrObject *getSelectedObj() const;
316 KPrPixmapObject *getSelectedImage() const;
317
318 bool getEditMode() const { return editMode; }
319
320 void ungroupObjects();
321 void groupObjects();
322
323 unsigned int objNums() const;
324
325 void ensureVisible( int x, int y, int xmargin, int ymargin );
326
335 KoRect objectRect( bool all ) const;
336
337 void scrollTopLeftPoint( const TQPoint & pos );
338
339 void textContentsToHeight();
340 void textObjectToContents();
341
342 void flipObject( bool _horizontal );
343
344 void lowerObjs( bool backward );
345 void raiseObjs( bool forward );
346
355 void alignObjects( AlignType at );
356
357 bool canMoveOneObject()const;
358 TQPtrList<KPrTextObject> listOfTextObjs() const;
359
360 TQPixmap getPicturePixmap() const;
361 void closeObject(bool _close);
362 void layout();
363 void alignVertical(VerticalAlignmentType _type );
364 void savePicture();
365
366 void dropImage( TQMimeSource * data, bool resizeImageToOriginalSize = false , int posX = 10, int posY=10 );
367 KoGuides & guideLines() { return m_gl; }
368
375 void objectPopup( KPrObject *object, const TQPoint &point );
376
377public slots:
378 // use repaint = false when the KPrCanvas is destroyed to avaid a possible crash
379 void exitEditMode( bool repaint = true );
380
381 void clipCut();
382 void clipCopy();
383 void clipPaste();
384 void deleteObjs();
385 void copyObjs();
386 void copyOasisObjs();
387
388 void chPic();
389 void picViewOriginalSize();
390 void picViewOrig640x480();
391 void picViewOrig800x600();
392 void picViewOrig1024x768();
393 void picViewOrig1280x1024();
394 void picViewOrig1600x1200();
395 void picViewOrigFactor();
396 void setActivePage( KPrPage* active );
397
404 void setPaintGuides( bool state );
405
406signals:
407
408 // signals to notify of changes
409 void fontChanged( const TQFont & );
410 void colorChanged( const TQColor & );
411 void alignChanged( int );
422 void objectSelectedChanged();
423 void objectSizeChanged();
426
427 void selectionChanged( bool hasSelection );
428 void sigMouseWheelEvent( TQWheelEvent * );
429
430protected:
431 struct PicCache
432 {
433 TQPicture pic;
434 int num;
435 int subPresStep;
436 };
437
438 // functions for displaying
442 virtual void paintEvent( TQPaintEvent* );
443
448 void drawBackground( TQPainter* painter, const TQRect& rect, KPrPage * page, bool edit = false ) const;
449
453 void drawAllObjectsInPage( TQPainter *painter, const TQPtrList<KPrObject> & obj, int pageNum ) const;
454
459 void drawObjectsPres( TQPainter *painter, const TQPtrList<KPrObject> &_objects, PresStep step ) const;
460
466 void drawObjectsEdit( TQPainter *painter, const KoRect &rect, const TQPtrList<KPrObject> &_objects,
467 SelectionMode selectionMode, int page ) const;
468
476 void drawObjects( TQPainter *painter, const TQPtrList<KPrObject> &objects, SelectionMode selectionMode,
477 bool contour, KPrTextView * textView, int pageNum ) const;
478
483 void drawEditPage( TQPainter *painter, const TQRect &_rect,
484 KPrPage *page, SelectionMode selectionMode ) const;
485
490 void drawPresPage( TQPainter *painter, const TQRect &_rect, PresStep step ) const;
491
493 void drawGrid(TQPainter *painter, const TQRect &rect2) const;
494
500 bool finishObjectEffects();
501
502 bool finishPageEffect( bool cancel = false );
503
504 void drawCurrentPageInPix( TQPixmap& ) const;
505 virtual void mousePressEvent( TQMouseEvent *e );
506 virtual void mouseReleaseEvent( TQMouseEvent *e );
507 virtual void mouseMoveEvent( TQMouseEvent *e );
508 virtual void mouseDoubleClickEvent( TQMouseEvent *e );
509 virtual void wheelEvent( TQWheelEvent *e );
510 virtual void resizeEvent( TQResizeEvent *e );
511 virtual bool close( bool alsoDelete );
518 KPrObject *getObjectAt( const KoPoint &pos, bool withoutProtected = false );
519 virtual void focusInEvent( TQFocusEvent* ) {}
520 virtual void focusOutEvent( TQFocusEvent* ) {}
521 virtual void enterEvent( TQEvent *e );
522 virtual void leaveEvent( TQEvent *e );
523 virtual void dragEnterEvent( TQDragEnterEvent *e );
524 virtual void dragMoveEvent( TQDragMoveEvent *e );
525 virtual void dropEvent( TQDropEvent *e );
526 virtual void keyPressEvent( TQKeyEvent *e );
527 virtual void keyReleaseEvent( TQKeyEvent *e );
528 virtual void imStartEvent( TQIMEvent * e );
529 virtual void imComposeEvent( TQIMEvent * e );
530 virtual void imEndEvent( TQIMEvent * e );
531
532 void eraseEmptySpace( TQPainter * painter, const TQRegion & emptySpaceRegion, const TQBrush & brush ) const;
533
535 void setupMenus();
536
537 unsigned int currPgNum() const;
538 TQColor txtBackCol() const;
539 bool spInfiniteLoop() const;
540 bool spShowEndOfPresentationSlide() const;
541 bool spManualSwitch() const;
542 TQRect getPageRect( bool decBorders = true ) const;
543 unsigned int pageNums() const;
544
545 void _repaint( bool erase=true );
546 void _repaint( const TQRect &r );
547 void _repaint( KPrObject *o );
548
553 void printPage( TQPainter*, PresStep step, KPrinter *printer, int rows, int cols );
554
558 void doObjEffects( bool isAllreadyPainted = false );
559
565 KPrPartObject *insertObject( const KoRect &rect );
566
572 void insertAutoform( const KoRect &rect );
573 void insertFreehand( const KoPointArray &_pointArray );
574 void insertPolyline( const KoPointArray &_pointArray );
575 void insertCubicBezierCurve( const KoPointArray &_pointArray );
576 void insertPolygon( const KoPointArray &_pointArray );
577 void insertClosedLine( const KoPointArray &_pointArray );
578
579 void selectNext();
580 void selectPrev();
581
582 void scalePixmapToBeOrigIn( const KoSize &currentSize, const KoSize &pgSize,
583 const TQSize &presSize, KPrPixmapObject *obj );
584 bool getPixmapOrigAndCurrentSize( KPrPixmapObject *&obj, KoSize *origSize, KoSize *currentSize );
585 void setTextBackground( KPrTextObject *obj );
586 virtual bool eventFilter( TQObject *o, TQEvent *e );
587 virtual bool focusNextPrevChild( bool );
588
589 void endDrawPolyline();
590
594 void drawCubicBezierCurve( TQPainter &p, KoPointArray &points );
595 //void drawCubicBezierCurve( int _dx, int _dy );
596 void endDrawCubicBezierCurve();
597
603 void redrawCubicBezierCurve( TQPainter &p );
604
605
606#ifndef NDEBUG
607 void printRTDebug( int info );
608#endif
609
610 KoRect getAlignBoundingRect() const;
611
612private:
613 void picViewOrigHelper(int x, int y);
614
621 void moveObjectsByKey( int x, int y );
622
629 void moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged );
630
631 //---- stuff needed for resizing ----
633 void resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio, bool scaleAroundCenter );
635 void finishResizeObject( const TQString &name, bool layout = true );
636
645 void raiseObject( KPrObject *object );
649 void lowerObject();
659 const TQPtrList<KPrObject> displayObjectList() const;
660
667 bool m_setPageTimer;
668
670 void drawPolygon( TQPainter &p, const KoRect &rect );
671
673 void drawPieObject( TQPainter *p, const KoRect &rect );
674
675 TQPoint limitOfPoint(const TQPoint& _point) const;
676
680 bool objectIsAHeaderFooterHidden(KPrObject *obj) const;
681
682 KPrTextObject* textUnderMouse( const TQPoint & point );
683 bool checkCurrentTextEdit( KPrTextObject * textObj );
684
698 KoPoint snapPoint( KoPoint &pos, bool repaintSnapping = true );
699
711 KoPoint diffGrid( KoRect &rect, double diffx, double diffy );
712
713 void recalcAutoGuides( );
714
720 KoPointArray getObjectPoints( const KoPointArray &pointArray );
721
722
734 void updateInsertRect( const KoPoint &point, TQt::ButtonState state );
735
742 void popupContextMenu();
743
744private slots:
745 void toFontChanged( const TQFont &font ) { emit fontChanged( font ); }
746 void toColorChanged( const TQColor &color ) { emit colorChanged( color ); }
747 void toAlignChanged( int a ) { emit alignChanged( a ); }
753 void setDrawingMode();
760 void setSwitchingMode( bool continueTimer = true );
761 void slotGotoPage();
762 void slotExitPres();
763 void terminateEditing( KPrTextObject * );
764
771 void slotDoEffect();
772
773 void slotDoPageEffect();
774
778 void slotAutoScroll(const TQPoint &scrollDist);
779
784 void speakTextUnderMouse(TQWidget* w, const TQPoint& p, uint flags);
785
786private:
788 static const int MOUSE_SNAP_DISTANCE;
790 static const int KEY_SNAP_DISTANCE;
791 // variables
793 TDEPopupMenu *m_presMenu;
794 bool showingLastSlide;
795 bool mousePressed;
796 bool drawContour;
797 ModifyType modType;
798
800 KPrObject * m_editObject;
801
802 bool fillBlack;
803 KPrView *m_view;
804 bool editMode, goingBack;
809 bool m_drawMode;
814 bool m_drawLineInDrawMode;
815
821 TQValueVector<TQPointArray> m_drawModeLines;
822
827 int m_drawModeLineIndex;
828
829 bool mouseSelectedObject;
831 PresStep m_step;
832 float _presFakt;
833 int m_showOnlyPage; // 1-based (-1 = all)
835 TQValueList<int> m_pageEffectSteps;
837 TQValueList<int> m_presentationSlides;
839 TQValueList<int>::Iterator m_presentationSlidesIterator;
841 KPrEffectHandler *m_effectHandler;
842
843 KPrPageEffects *m_pageEffect;
844
846 TQTimer m_effectTimer;
847
848 TQTimer m_pageEffectTimer;
849
851 int PM_DM;
852 int delPageId;
853 bool drawRubber;
855 KoRect m_rubber;
856
857 //---- stuff needed for resizing ----
859 KPrObject *m_resizeObject;
861 KoRect m_rectBeforeResize;
863 double m_ratio;
864 bool m_isResizing;
865
866 //---- stuff needed for moving ----
867 bool m_isMoving;
868 KoPoint m_moveStartPoint;
869
870 //---- stuff needed for rotating ----
872 KPrObject *m_rotateObject;
874 KoPoint m_rotateCenter;
876 KoPoint m_rotateStart;
878 double m_angleBeforeRotate;
879
880 ToolEditMode toolEditMode;
882 KoRect m_insertRect;
883 KoDocumentEntry partEntry;
884 TQString autoform;
885 TQPixmap buffer;
886
887 KPrTextView *m_currentTextObjectView;
888
889 KPrSoundPlayer *soundPlayer;
890
891 KoPointArray m_pointArray, m_oldCubicBezierPointArray;
892 TQPoint m_dragStartPoint, m_dragEndPoint, m_dragSymmetricEndPoint;
894 KoPoint m_startPoint;
896 KoPoint m_endPoint;
897 KoPoint m_symmetricEndPoint;
898 KoPoint m_CubicBezierSecondPoint, m_CubicBezierThirdPoint;
899 int m_indexPointArray;
900 bool m_drawPolyline;
901 bool m_drawCubicBezierCurve;
902 bool m_drawLineWithCubicBezierCurve;
903 bool m_zoomRubberDraw;
904
905 KPrPage *m_activePage;
906 int m_xOffset, m_yOffset;
907 int m_xOffsetSaved, m_yOffsetSaved; // saved when going fullscreen
908
910 KoPoint m_moveStartPosMouse;
912 KoPoint m_moveSnapDiff;
914 bool m_disableSnapping;
916 KoPoint m_origMousePos;
918 KoPoint m_moveStartPosKey;
919
920 KPrPage * m_activePageBeforePresentation;
921 int m_zoomBeforePresentation;
922
923 bool m_keyPressEvent;
924 bool m_drawSymetricObject;
925
927 KoGuides m_gl;
929 bool m_paintGuides;
930
932 KPrObject * m_objectDisplayAbove;
933
935 KPrTextObject *m_prevSpokenTO;
936};
937
938#endif // __KPRCANVAS__
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.
int presStep() const
returns the current step of the presentation
Definition KPrCanvas.h:159
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 dragStarted()
for KPrTextView
Definition KPrCanvas.h:264
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.
unsigned int presPage() const
returns the current page of the presentation 1 based
Definition KPrCanvas.h:157
~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