00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __KPRCANVAS__
00024 #define __KPRCANVAS__
00025
00026 #include <qwidget.h>
00027 #include <qptrlist.h>
00028 #include <qpicture.h>
00029 #include <qvaluelist.h>
00030 #include <qpixmap.h>
00031 #include <qpointarray.h>
00032 #include <qvaluevector.h>
00033 #include <qtimer.h>
00034
00035 #include <KoGuides.h>
00036 #include <KoRuler.h>
00037 #include <KoQueryTrader.h>
00038 #include "KoPointArray.h"
00039 #include "global.h"
00040 #include <KoRect.h>
00041 #include <KoTextFormat.h>
00042 #include "presstep.h"
00043
00044 class KURL;
00045 class KoTextFormatInterface;
00046 class KPrView;
00047 class KPrDocument;
00048 class QPainter;
00049 class KTextEdit;
00050 class KPrTextObject;
00051 class KPrObject;
00052 class KPopupMenu;
00053 class QResizeEvent;
00054 class QPaintEvent;
00055 class QDragEnterEvent;
00056 class QDragMoveEvent;
00057 class QDropEvent;
00058 class QFocusEvent;
00059 class QMouseEvent;
00060 class QWheelEvent;
00061 class QKeyEvent;
00062 class KPrPixmapObject;
00063 class KPrBackGround;
00064 class QRect;
00065 class QSize;
00066 class QPoint;
00067 class KPrSoundPlayer;
00068 class KoTextObject;
00069 class KoParagCounter;
00070 class KPrPage;
00071 class KPrinter;
00072 class KPrTextView;
00073 class KPrPartObject;
00074 class KCommand;
00075 class KPrEffectHandler;
00076 class KPrPageEffects;
00082 class KPrCanvas : public QWidget
00083 {
00084 Q_OBJECT
00085
00086 public:
00087
00089 KPrCanvas( QWidget *parent=0,const char *name=0,KPrView *_view=0 );
00091 ~KPrCanvas();
00092
00093 KPrView * getView()const { return m_view; }
00094
00095
00096
00097
00098 int diffx() const { return m_xOffset; }
00099 int diffy() const { return m_yOffset; }
00100 void setDiffX( int _diffX ) { m_xOffset = _diffX; }
00101 void setDiffY( int _diffY ) { m_yOffset = _diffY; }
00102 void scrollX( int x );
00103 void scrollY( int y );
00104
00105
00106 void selectAllObj();
00107 void deSelectAllObj();
00108 void selectObj( KPrObject* );
00109 void deSelectObj( KPrObject* );
00110 void setTextFormat(const KoTextFormat &format, int flags);
00111
00112 void setTextColor( const QColor & );
00113 void setTextBackgroundColor( const QColor & );
00114 void setTextAlign( int );
00115 void setTextDepthPlus();
00116 void setTextDepthMinus();
00117 void setNewRightIndent(double _rightIndent);
00118 void setNewLeftIndent(double _leftIndent);
00119 void setNewFirstIndent(double _firstIndent);
00120
00121 void setTabList( const KoTabulatorList & tabList );
00122 void setTextBold( bool b );
00123 void setTextItalic( bool b );
00124 void setTextUnderline( bool b );
00125 void setTextStrikeOut( bool b );
00126 void setTextFamily( const QString &f );
00127 void setTextPointSize( int s );
00128 void setTextSubScript( bool b );
00129 void setTextSuperScript( bool b );
00130 void setTextDefaultFormat( );
00131 void setIncreaseFontSize();
00132 void setDecreaseFontSize();
00133 KPrTextObject* kpTxtObj() const;
00134
00139 void startScreenPresentation( double zoomX, double zoomY, int curPgNum = -1);
00140 void stopScreenPresentation();
00141
00147 bool pNext( bool gotoNextPage = false );
00148
00154 bool pPrev( bool gotoPreviousPage = false );
00155
00157 unsigned int presPage() const { return m_step.m_pageNumber + 1; }
00159 int presStep() const { return m_step.m_step; }
00160 int numPresSteps() const { return m_pageEffectSteps.count(); }
00161 int numPresPages() const { return m_presentationSlides.count(); }
00162
00163 bool canAssignEffect( QPtrList<KPrObject> &objs ) const;
00164
00165 void print( QPainter*, KPrinter*, float, float );
00166
00167
00168 void setPartEntry( KoDocumentEntry& _e )
00169 { partEntry = _e; }
00170 void setToolEditMode( ToolEditMode _m, bool updateView = true );
00171 void setAutoForm( const QString &_autoform )
00172 { autoform = _autoform; }
00173
00187 void drawPageInPix( QPixmap&, int pgnum, int zoom,
00188 bool forceRealVariableValue = false,
00189 int forceWidth = 0,
00190 int forceHeight = 0 );
00191
00216 bool exportPage( int nPage, int nWidth, int nHeight,
00217 const KURL& fileURL,
00218 const char* format,
00219 int quality = -1 );
00220
00221 void gotoPage( int pg );
00222
00227 void presGotoFirstPage();
00228
00229 KPrPage* activePage() const;
00230
00231 bool oneObjectTextExist() const;
00232 bool oneObjectTextSelected() const;
00233 bool isOneObjectSelected() const;
00235 QPtrList<KPrTextObject> selectedTextObjs() const;
00241 QPtrList<KoTextFormatInterface> applicableTextInterfaces() const;
00245 QPtrList<KPrTextObject> applicableTextObjects() const;
00246
00247 void setMouseSelectedObject(bool b);
00248
00249 bool haveASelectedPartObj() const;
00250 bool haveASelectedGroupObj() const;
00251 bool haveASelectedPixmapObj() const;
00252
00253 KPrTextView *currentTextObjectView() const { return m_currentTextObjectView; }
00254
00255 QPtrList<KPrObject> objectList() const;
00256
00257
00258 const QPtrList<KPrObject> & getObjectList() const;
00259
00260 void playSound( const QString &soundFileName );
00261 void stopSound();
00262
00264 void dragStarted() { mousePressed = false; }
00265
00266 void setXimPosition( int x, int y, int w, int h, QFont *f );
00267 void createEditing( KPrTextObject *textObj );
00268
00269
00276 void insertLine( const KoPoint &startPoint, const KoPoint &endPoint );
00277
00283 void insertRect( const KoRect &rect);
00284
00290 void insertEllipse( const KoRect &rect );
00291
00297 void insertPie( const KoRect &rect );
00298
00304 KPrTextObject* insertTextObject( const KoRect &rect );
00305
00311 void insertPicture( const KoRect &rect );
00312 void changePicture( const KURL & url, QWidget *window );
00313
00314 int numberOfObjectSelected() const;
00315 KPrObject *getSelectedObj() const;
00316 KPrPixmapObject *getSelectedImage() const;
00317
00318 bool getEditMode() const { return editMode; }
00319
00320 void ungroupObjects();
00321 void groupObjects();
00322
00323 unsigned int objNums() const;
00324
00325 void ensureVisible( int x, int y, int xmargin, int ymargin );
00326
00335 KoRect objectRect( bool all ) const;
00336
00337 void scrollTopLeftPoint( const QPoint & pos );
00338
00339 void textContentsToHeight();
00340 void textObjectToContents();
00341
00342 void flipObject( bool _horizontal );
00343
00344 void lowerObjs( bool backward );
00345 void raiseObjs( bool forward );
00346
00355 void alignObjects( AlignType at );
00356
00357 bool canMoveOneObject()const;
00358 QPtrList<KPrTextObject> listOfTextObjs() const;
00359
00360 QPixmap getPicturePixmap() const;
00361 void closeObject(bool _close);
00362 void layout();
00363 void alignVertical( VerticalAlignmentType _type );
00364 void savePicture();
00365
00366 void dropImage( QMimeSource * data, bool resizeImageToOriginalSize = false , int posX = 10, int posX=10 );
00367 KoGuides & guideLines() { return m_gl; }
00368
00375 void objectPopup( KPrObject *object, const QPoint &point );
00376
00377 public slots:
00378
00379 void exitEditMode( bool repaint = true );
00380
00381 void clipCut();
00382 void clipCopy();
00383 void clipPaste();
00384 void deleteObjs();
00385 void copyObjs();
00386 void copyOasisObjs();
00387
00388 void chPic();
00389 void picViewOriginalSize();
00390 void picViewOrig640x480();
00391 void picViewOrig800x600();
00392 void picViewOrig1024x768();
00393 void picViewOrig1280x1024();
00394 void picViewOrig1600x1200();
00395 void picViewOrigFactor();
00396 void setActivePage( KPrPage* active );
00397
00404 void setPaintGuides( bool state );
00405
00406 signals:
00407
00408
00409 void fontChanged( const QFont & );
00410 void colorChanged( const QColor & );
00411 void alignChanged( int );
00416 void stopAutomaticPresentation();
00421 void restartPresentation();
00422 void objectSelectedChanged();
00423 void objectSizeChanged();
00425 void currentObjectEditChanged();
00426
00427 void selectionChanged( bool hasSelection );
00428 void sigMouseWheelEvent( QWheelEvent * );
00429
00430 protected:
00431 struct PicCache
00432 {
00433 QPicture pic;
00434 int num;
00435 int subPresStep;
00436 };
00437
00438
00442 virtual void paintEvent( QPaintEvent* );
00443
00448 void drawBackground( QPainter* painter, const QRect& rect, KPrPage * page, bool edit = false ) const;
00449
00453 void drawAllObjectsInPage( QPainter *painter, const QPtrList<KPrObject> & obj, int pageNum ) const;
00454
00459 void drawObjectsPres( QPainter *painter, const QPtrList<KPrObject> &_objects, PresStep step ) const;
00460
00466 void drawObjectsEdit( QPainter *painter, const KoRect &rect, const QPtrList<KPrObject> &_objects,
00467 SelectionMode selectionMode, int page ) const;
00468
00476 void drawObjects( QPainter *painter, const QPtrList<KPrObject> &objects, SelectionMode selectionMode,
00477 bool contour, KPrTextView * textView, int pageNum ) const;
00478
00483 void drawEditPage( QPainter *painter, const QRect &_rect,
00484 KPrPage *page, SelectionMode selectionMode ) const;
00485
00490 void drawPresPage( QPainter *painter, const QRect &_rect, PresStep step ) const;
00491
00493 void drawGrid(QPainter *painter, const QRect &rect2) const;
00494
00500 bool finishObjectEffects();
00501
00502 bool finishPageEffect( bool cancel = false );
00503
00504 void drawCurrentPageInPix( QPixmap& ) const;
00505 virtual void mousePressEvent( QMouseEvent *e );
00506 virtual void mouseReleaseEvent( QMouseEvent *e );
00507 virtual void mouseMoveEvent( QMouseEvent *e );
00508 virtual void mouseDoubleClickEvent( QMouseEvent *e );
00509 virtual void wheelEvent( QWheelEvent *e );
00510 virtual void resizeEvent( QResizeEvent *e );
00517 KPrObject *getObjectAt( const KoPoint &pos, bool withoutProtected = false );
00518 virtual void focusInEvent( QFocusEvent* ) {}
00519 virtual void focusOutEvent( QFocusEvent* ) {}
00520 virtual void enterEvent( QEvent *e );
00521 virtual void leaveEvent( QEvent *e );
00522 virtual void dragEnterEvent( QDragEnterEvent *e );
00523 virtual void dragMoveEvent( QDragMoveEvent *e );
00524 virtual void dropEvent( QDropEvent *e );
00525 virtual void keyPressEvent( QKeyEvent *e );
00526 virtual void keyReleaseEvent( QKeyEvent *e );
00527 virtual void imStartEvent( QIMEvent * e );
00528 virtual void imComposeEvent( QIMEvent * e );
00529 virtual void imEndEvent( QIMEvent * e );
00530
00531 void eraseEmptySpace( QPainter * painter, const QRegion & emptySpaceRegion, const QBrush & brush ) const;
00532
00534 void setupMenus();
00535
00536 unsigned int currPgNum() const;
00537 QColor txtBackCol() const;
00538 bool spInfiniteLoop() const;
00539 bool spManualSwitch() const;
00540 QRect getPageRect( bool decBorders = true ) const;
00541 unsigned int pageNums() const;
00542
00543 void _repaint( bool erase=true );
00544 void _repaint( const QRect &r );
00545 void _repaint( KPrObject *o );
00546
00551 void printPage( QPainter*, PresStep step, KPrinter *printer, int rows, int cols );
00552
00556 void doObjEffects( bool isAllreadyPainted = false );
00557
00563 KPrPartObject *insertObject( const KoRect &rect );
00564
00570 void insertAutoform( const KoRect &rect );
00571 void insertFreehand( const KoPointArray &_pointArray );
00572 void insertPolyline( const KoPointArray &_pointArray );
00573 void insertCubicBezierCurve( const KoPointArray &_pointArray );
00574 void insertPolygon( const KoPointArray &_pointArray );
00575 void insertClosedLine( const KoPointArray &_pointArray );
00576
00577 void selectNext();
00578 void selectPrev();
00579
00580 void scalePixmapToBeOrigIn( const KoSize ¤tSize, const KoSize &pgSize,
00581 const QSize &presSize, KPrPixmapObject *obj );
00582 bool getPixmapOrigAndCurrentSize( KPrPixmapObject *&obj, KoSize *origSize, KoSize *currentSize );
00583 void setTextBackground( KPrTextObject *obj );
00584 virtual bool eventFilter( QObject *o, QEvent *e );
00585 virtual bool focusNextPrevChild( bool );
00586
00587 void endDrawPolyline();
00588
00592 void drawCubicBezierCurve( QPainter &p, KoPointArray &points );
00593
00594 void endDrawCubicBezierCurve();
00595
00601 void redrawCubicBezierCurve( QPainter &p );
00602
00603
00604 #ifndef NDEBUG
00605 void printRTDebug( int info );
00606 #endif
00607
00608 KoRect getAlignBoundingRect() const;
00609
00610 private:
00611 void picViewOrigHelper(int x, int y);
00612
00619 void moveObjectsByKey( int x, int y );
00620
00627 void moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged );
00628
00629
00631 void resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio, bool scaleAroundCenter );
00633 void finishResizeObject( const QString &name, bool layout = true );
00634
00643 void raiseObject( KPrObject *object );
00647 void lowerObject();
00657 const QPtrList<KPrObject> displayObjectList() const;
00658
00665 bool m_setPageTimer;
00666
00668 void drawPolygon( QPainter &p, const KoRect &rect );
00669
00671 void drawPieObject( QPainter *p, const KoRect &rect );
00672
00673 QPoint limitOfPoint(const QPoint& _point) const;
00674
00678 bool objectIsAHeaderFooterHidden(KPrObject *obj) const;
00679
00680 KPrTextObject* textUnderMouse( const QPoint & point );
00681 bool checkCurrentTextEdit( KPrTextObject * textObj );
00682
00696 KoPoint snapPoint( KoPoint &pos, bool repaintSnapping = true );
00697
00709 KoPoint diffGrid( KoRect &rect, double diffx, double diffy );
00710
00711 void recalcAutoGuides( );
00712
00718 KoPointArray getObjectPoints( const KoPointArray &pointArray );
00719
00720
00732 void updateInsertRect( const KoPoint &point, Qt::ButtonState state );
00733
00740 void popupContextMenu();
00741
00742 private slots:
00743 void toFontChanged( const QFont &font ) { emit fontChanged( font ); }
00744 void toColorChanged( const QColor &color ) { emit colorChanged( color ); }
00745 void toAlignChanged( int a ) { emit alignChanged( a ); }
00751 void setDrawingMode();
00758 void setSwitchingMode( bool continueTimer = true );
00759 void slotGotoPage();
00760 void slotExitPres();
00761 void terminateEditing( KPrTextObject * );
00762
00769 void slotDoEffect();
00770
00771 void slotDoPageEffect();
00772
00776 void slotAutoScroll(const QPoint &scrollDist);
00777
00782 void speakTextUnderMouse(QWidget* w, const QPoint& p, uint flags);
00783
00784 private:
00786 static const int MOUSE_SNAP_DISTANCE;
00788 static const int KEY_SNAP_DISTANCE;
00789
00791 KPopupMenu *m_presMenu;
00792 bool showingLastSlide;
00793 bool mousePressed;
00794 bool drawContour;
00795 ModifyType modType;
00796
00798 KPrObject * m_editObject;
00799
00800 bool fillBlack;
00801 KPrView *m_view;
00802 bool editMode, goingBack;
00807 bool m_drawMode;
00812 bool m_drawLineInDrawMode;
00813
00819 QValueVector<QPointArray> m_drawModeLines;
00820
00825 int m_drawModeLineIndex;
00826
00827 bool mouseSelectedObject;
00829 PresStep m_step;
00830 float _presFakt;
00831 int m_showOnlyPage;
00833 QValueList<int> m_pageEffectSteps;
00835 QValueList<int> m_presentationSlides;
00837 QValueList<int>::Iterator m_presentationSlidesIterator;
00839 KPrEffectHandler *m_effectHandler;
00840
00841 KPrPageEffects *m_pageEffect;
00842
00844 QTimer m_effectTimer;
00845
00846 QTimer m_pageEffectTimer;
00847
00849 int PM_DM;
00850 int delPageId;
00851 bool drawRubber;
00853 KoRect m_rubber;
00854
00855
00857 KPrObject *m_resizeObject;
00859 KoRect m_rectBeforeResize;
00861 double m_ratio;
00862 bool m_isResizing;
00863
00864
00865 bool m_isMoving;
00866 KoPoint m_moveStartPoint;
00867
00868
00870 KPrObject *m_rotateObject;
00872 KoPoint m_rotateCenter;
00874 KoPoint m_rotateStart;
00876 double m_angleBeforeRotate;
00877
00878 ToolEditMode toolEditMode;
00880 KoRect m_insertRect;
00881 KoDocumentEntry partEntry;
00882 QString autoform;
00883 QPixmap buffer;
00884
00885 KPrTextView *m_currentTextObjectView;
00886
00887 KPrSoundPlayer *soundPlayer;
00888
00889 KoPointArray m_pointArray, m_oldCubicBezierPointArray;
00890 QPoint m_dragStartPoint, m_dragEndPoint, m_dragSymmetricEndPoint;
00892 KoPoint m_startPoint;
00894 KoPoint m_endPoint;
00895 KoPoint m_symmetricEndPoint;
00896 KoPoint m_CubicBezierSecondPoint, m_CubicBezierThirdPoint;
00897 int m_indexPointArray;
00898 bool m_drawPolyline;
00899 bool m_drawCubicBezierCurve;
00900 bool m_drawLineWithCubicBezierCurve;
00901 bool m_zoomRubberDraw;
00902
00903 KPrPage *m_activePage;
00904 int m_xOffset, m_yOffset;
00905 int m_xOffsetSaved, m_yOffsetSaved;
00906
00908 KoPoint m_moveStartPosMouse;
00910 KoPoint m_moveSnapDiff;
00912 bool m_disableSnapping;
00914 KoPoint m_origMousePos;
00916 KoPoint m_moveStartPosKey;
00917
00918 KPrPage * m_activePageBeforePresentation;
00919 int m_zoomBeforePresentation;
00920
00921 bool m_keyPressEvent;
00922 bool m_drawSymetricObject;
00923
00925 KoGuides m_gl;
00927 bool m_paintGuides;
00928
00930 KPrObject * m_objectDisplayAbove;
00931
00933 KPrTextObject *m_prevSpokenTO;
00934 };
00935
00936 #endif // __KPRCANVAS__