kpresenter

KPrCanvas.h

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00004    Copyright (C) 2002-2005 Thorsten Zachmann <zachmann@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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     // The equivalent of contentsX() and contentsY() for a QScrollView
00096     // The Canvas is a widget, not a scrollview (because we handle the scrollbars ourselves,
00097     // to have the "goto page" buttons at the bottom of the scrollbars etc.)
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     // public functions
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     //void setTextCounter(KoParagCounter counter);
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     // get - set data
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     // use repaint = false when the KPrCanvas is destroyed to avaid a possible crash
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     // signals to notify of changes
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     // functions for displaying
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 );
00511     virtual bool close( bool alsoDelete );
00518     KPrObject *getObjectAt( const KoPoint &pos, bool withoutProtected = false );
00519     virtual void focusInEvent( QFocusEvent* ) {}
00520     virtual void focusOutEvent( QFocusEvent* ) {}
00521     virtual void enterEvent( QEvent *e );
00522     virtual void leaveEvent( QEvent *e );
00523     virtual void dragEnterEvent( QDragEnterEvent *e );
00524     virtual void dragMoveEvent( QDragMoveEvent *e );
00525     virtual void dropEvent( QDropEvent *e );
00526     virtual void keyPressEvent( QKeyEvent *e );
00527     virtual void keyReleaseEvent( QKeyEvent *e );
00528     virtual void imStartEvent( QIMEvent * e );
00529     virtual void imComposeEvent( QIMEvent * e );
00530     virtual void imEndEvent( QIMEvent * e );
00531 
00532     void eraseEmptySpace( QPainter * painter, const QRegion & emptySpaceRegion, const QBrush & brush ) const;
00533 
00535     void setupMenus();
00536 
00537     unsigned int currPgNum() const;
00538     QColor txtBackCol() const;
00539     bool spInfiniteLoop() const;
00540     bool spShowEndOfPresentationSlide() const;
00541     bool spManualSwitch() const;
00542     QRect getPageRect( bool decBorders = true ) const;
00543     unsigned int pageNums() const;
00544 
00545     void _repaint( bool erase=true );
00546     void _repaint( const QRect &r );
00547     void _repaint( KPrObject *o );
00548 
00553     void printPage( QPainter*, PresStep step, KPrinter *printer, int rows, int cols );
00554 
00558     void doObjEffects( bool isAllreadyPainted = false );
00559 
00565     KPrPartObject *insertObject( const KoRect &rect );
00566 
00572     void insertAutoform( const KoRect &rect );
00573     void insertFreehand( const KoPointArray &_pointArray );
00574     void insertPolyline( const KoPointArray &_pointArray );
00575     void insertCubicBezierCurve( const KoPointArray &_pointArray );
00576     void insertPolygon( const KoPointArray &_pointArray );
00577     void insertClosedLine( const KoPointArray &_pointArray );
00578 
00579     void selectNext();
00580     void selectPrev();
00581 
00582     void scalePixmapToBeOrigIn( const KoSize &currentSize, const KoSize &pgSize,
00583                                 const QSize &presSize, KPrPixmapObject *obj );
00584     bool getPixmapOrigAndCurrentSize( KPrPixmapObject *&obj, KoSize *origSize, KoSize *currentSize );
00585     void setTextBackground( KPrTextObject *obj );
00586     virtual bool eventFilter( QObject *o, QEvent *e );
00587     virtual bool focusNextPrevChild( bool );
00588 
00589     void endDrawPolyline();
00590 
00594     void drawCubicBezierCurve( QPainter &p, KoPointArray &points );
00595     //void drawCubicBezierCurve( int _dx, int _dy );
00596     void endDrawCubicBezierCurve();
00597 
00603     void redrawCubicBezierCurve( QPainter &p );
00604 
00605 
00606 #ifndef NDEBUG
00607     void printRTDebug( int info );
00608 #endif
00609 
00610     KoRect getAlignBoundingRect() const;
00611 
00612 private:
00613     void picViewOrigHelper(int x, int y);
00614 
00621     void moveObjectsByKey( int x, int y );
00622 
00629     void moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged );
00630 
00631     //---- stuff needed for resizing ----
00633     void resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio, bool scaleAroundCenter );
00635     void finishResizeObject( const QString &name, bool layout = true );
00636 
00645     void raiseObject( KPrObject *object );
00649     void lowerObject();
00659     const QPtrList<KPrObject> displayObjectList() const; 
00660 
00667     bool m_setPageTimer;
00668 
00670     void drawPolygon( QPainter &p, const KoRect &rect );
00671 
00673     void drawPieObject( QPainter *p,  const KoRect &rect );
00674 
00675     QPoint limitOfPoint(const QPoint& _point) const;
00676 
00680     bool objectIsAHeaderFooterHidden(KPrObject *obj) const;
00681 
00682     KPrTextObject* textUnderMouse( const QPoint & point );
00683     bool checkCurrentTextEdit( KPrTextObject * textObj );
00684 
00698     KoPoint snapPoint( KoPoint &pos, bool repaintSnapping = true );
00699 
00711     KoPoint diffGrid( KoRect &rect, double diffx, double diffy );
00712 
00713     void recalcAutoGuides( );
00714 
00720     KoPointArray getObjectPoints( const KoPointArray &pointArray );
00721 
00722 
00734     void updateInsertRect( const KoPoint &point, Qt::ButtonState state );
00735 
00742     void popupContextMenu();
00743 
00744 private slots:
00745     void toFontChanged( const QFont &font ) { emit fontChanged( font ); }
00746     void toColorChanged( const QColor &color ) { emit colorChanged( color ); }
00747     void toAlignChanged( int a ) { emit alignChanged( a ); }
00753     void setDrawingMode();
00760     void setSwitchingMode( bool continueTimer = true );
00761     void slotGotoPage();
00762     void slotExitPres();
00763     void terminateEditing( KPrTextObject * );
00764 
00771     void slotDoEffect();
00772 
00773     void slotDoPageEffect();
00774 
00778     void slotAutoScroll(const QPoint &scrollDist);
00779 
00784     void speakTextUnderMouse(QWidget* w, const QPoint& p, uint flags);
00785 
00786 private:
00788     static const int MOUSE_SNAP_DISTANCE;
00790     static const int KEY_SNAP_DISTANCE;
00791     // variables
00793     KPopupMenu *m_presMenu;
00794     bool showingLastSlide;
00795     bool mousePressed;
00796     bool drawContour;
00797     ModifyType modType;
00798 
00800     KPrObject * m_editObject;
00801 
00802     bool fillBlack;
00803     KPrView *m_view;
00804     bool editMode, goingBack;
00809     bool m_drawMode;
00814     bool m_drawLineInDrawMode;
00815 
00821     QValueVector<QPointArray> m_drawModeLines;
00822 
00827     int m_drawModeLineIndex;
00828 
00829     bool mouseSelectedObject;
00831     PresStep m_step;
00832     float _presFakt;
00833     int m_showOnlyPage; // 1-based (-1 = all)
00835     QValueList<int> m_pageEffectSteps;
00837     QValueList<int> m_presentationSlides;
00839     QValueList<int>::Iterator m_presentationSlidesIterator;
00841     KPrEffectHandler *m_effectHandler;
00842 
00843     KPrPageEffects *m_pageEffect;
00844 
00846     QTimer m_effectTimer;
00847 
00848     QTimer m_pageEffectTimer;
00849 
00851     int PM_DM;
00852     int delPageId;
00853     bool drawRubber;
00855     KoRect m_rubber;
00856 
00857     //---- stuff needed for resizing ----
00859     KPrObject *m_resizeObject;
00861     KoRect m_rectBeforeResize;
00863     double m_ratio;
00864     bool m_isResizing;
00865 
00866     //---- stuff needed for moving ----
00867     bool m_isMoving;
00868     KoPoint m_moveStartPoint;
00869 
00870     //---- stuff needed for rotating ----
00872     KPrObject *m_rotateObject;
00874     KoPoint m_rotateCenter;
00876     KoPoint m_rotateStart;
00878     double m_angleBeforeRotate;
00879 
00880     ToolEditMode toolEditMode;
00882     KoRect m_insertRect;
00883     KoDocumentEntry partEntry;
00884     QString autoform;
00885     QPixmap buffer;
00886 
00887     KPrTextView *m_currentTextObjectView;
00888 
00889     KPrSoundPlayer *soundPlayer;
00890 
00891     KoPointArray m_pointArray, m_oldCubicBezierPointArray;
00892     QPoint m_dragStartPoint, m_dragEndPoint, m_dragSymmetricEndPoint;
00894     KoPoint m_startPoint;
00896     KoPoint m_endPoint;
00897     KoPoint m_symmetricEndPoint;
00898     KoPoint m_CubicBezierSecondPoint, m_CubicBezierThirdPoint;
00899     int m_indexPointArray;
00900     bool m_drawPolyline;
00901     bool m_drawCubicBezierCurve;
00902     bool m_drawLineWithCubicBezierCurve;
00903     bool m_zoomRubberDraw;
00904 
00905     KPrPage *m_activePage;
00906     int m_xOffset, m_yOffset;
00907     int m_xOffsetSaved, m_yOffsetSaved; // saved when going fullscreen
00908 
00910     KoPoint m_moveStartPosMouse;
00912     KoPoint m_moveSnapDiff;
00914     bool m_disableSnapping;
00916     KoPoint m_origMousePos;
00918     KoPoint m_moveStartPosKey; 
00919 
00920     KPrPage * m_activePageBeforePresentation;
00921     int m_zoomBeforePresentation;
00922 
00923     bool m_keyPressEvent;
00924     bool m_drawSymetricObject;
00925 
00927     KoGuides m_gl;
00929     bool m_paintGuides;
00930 
00932     KPrObject * m_objectDisplayAbove;
00933 
00935     KPrTextObject *m_prevSpokenTO;
00936 };
00937 
00938 #endif // __KPRCANVAS__
KDE Home | KDE Accessibility Home | Description of Access Keys