00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KWCANVAS_H
00023 #define KWCANVAS_H
00024
00025 #include <kprinter.h>
00026 #include <KoRect.h>
00027 #include <qscrollview.h>
00028 #include <qstylesheet.h>
00029 #include <KoRichText.h>
00030 #include <KoQueryTrader.h>
00031 #include <KoPicture.h>
00032
00033 #include "KWTextParag.h"
00034 #include "KWFrame.h"
00035 #include "KWVariable.h"
00036 #include "KWCommand.h"
00037
00038 class KWTextFrameSetEdit;
00039 class KWDocument;
00040 class KWFrame;
00041 class KWFrameSet;
00042 class KWFrameSetEdit;
00043 class KWTableFrameSet;
00044 class KWFrameMoveCommand;
00045 class KWViewMode;
00046 class KWFrameViewManager;
00047 class KWGUI;
00048 class KWTableTemplate;
00049 class KoTextParag;
00050 class QTimer;
00051 class InteractionPolicy;
00052 class KWFrameView;
00053
00060 class KWCanvas : public QScrollView
00061 {
00062 Q_OBJECT
00063
00064 public:
00065 KWCanvas(const QString& viewMode, QWidget *parent, KWDocument *d, KWGUI *lGui);
00066 virtual ~KWCanvas();
00067
00068 KWDocument * kWordDocument() const { return m_doc; }
00069 KWGUI * gui() const { return m_gui; }
00070 KWFrameViewManager* frameViewManager() { return m_frameViewManager; }
00071 KWFrameSetEdit *currentFrameSetEdit() const { return m_currentFrameSetEdit; }
00072
00073 void switchViewMode( const QString& newViewMode );
00074 KWViewMode *viewMode() const { return m_viewMode; }
00075
00076 void repaintAll( bool erase = false );
00082 void repaintChanged( KWFrameSet * fs, bool resetChanged );
00083
00085 void viewportResizeEvent( QResizeEvent * );
00086
00087 void print( QPainter *painter, KPrinter *printer );
00088 bool eventFilter( QObject *o, QEvent *e );
00089 bool focusNextPrevChild( bool next);
00090
00091 void setFrameBackgroundColor( const QBrush &backColor );
00092
00093 void editFrameProperties();
00094 void editFrameProperties( KWFrameSet * frameset );
00095
00096 void pasteFrames();
00097
00098
00099 void mpCreate( const QPoint& normalPoint, bool noGrid );
00100 void mpCreatePixmap( const QPoint& normalPoint, bool noGrid );
00101
00102 void mmCreate( const QPoint& normalPoint, bool noGrid );
00103
00104 void mrEditFrame();
00105 void mrCreateText();
00106 void mrCreatePixmap();
00107 void mrCreatePart();
00108 void mrCreateFormula();
00109 void mrCreateTable();
00110
00111 enum MouseMode {
00112 MM_EDIT = 0,
00113 MM_CREATE_TEXT = 2,
00114 MM_CREATE_PIX = 3,
00115 MM_CREATE_TABLE = 5,
00116 MM_CREATE_FORMULA = 6,
00117 MM_CREATE_PART = 7
00118 };
00119 void setMouseMode( MouseMode _mm );
00120 MouseMode mouseMode()const { return m_mouseMode; }
00121
00122
00123 void insertPicture( const KoPicture& newPicture, QSize pixmapSize, bool _keepRatio );
00124 void insertPart( const KoDocumentEntry &entry );
00125 void pasteImage( QMimeSource *e, const KoPoint &docPoint );
00126
00127 void insertPictureDirect( const KoPicture& picture, const KoPoint& pos, const QSize& sz = QSize() );
00128
00129 void updateCurrentFormat();
00130
00131 void updateFrameFormat();
00132
00133
00134 unsigned int tableRows() const { return m_table.rows; }
00135 void setTableRows( unsigned int rows ) { m_table.rows=rows; }
00136 unsigned int tableCols() const { return m_table.cols; }
00137 void setTableCols( unsigned int cols ) { m_table.cols=cols; }
00138 int tableWidthMode()const { return m_table.width; }
00139 int tableHeightMode()const { return m_table.height; }
00140 bool tableIsFloating()const { return m_table.floating; }
00141 int tableFormat()const { return m_table.format;}
00142
00143 void setTableFormat(int _nb){ m_table.format=_nb;}
00144
00145 QString tableTemplateName()const { return m_table.tableTemplateName;}
00146 void setTableTemplateName(const QString &_name) { m_table.tableTemplateName=_name;}
00147
00148 void setPictureInline( bool _inline) { m_picture.pictureInline = _inline;}
00149 bool pictureInline() const { return m_picture.pictureInline; }
00150
00151 void setPictureKeepRatio( bool _keep) { m_picture.keepRatio = _keep;}
00152 bool pictureKeepRatio() const { return m_picture.keepRatio; }
00153
00154 void createTable( unsigned int rows, unsigned int cols,
00155 int wid, int hei,
00156 bool isFloating,
00157 KWTableTemplate *tt=0L, int format=31 );
00158
00161 KWTableFrameSet *getCurrentTable()const { return m_currentTable; }
00163 int currentTableRow() const;
00165 int currentTableCol() const;
00166
00167
00168 void scrollToOffset( const KoPoint & dPoint );
00169
00170
00171 void dragStarted() { m_mousePressed = false; }
00172
00173 void setXimPosition( int x, int y, int w, int h );
00174
00175 void updateRulerOffsets( int cx = -1, int cy = -1 );
00176
00177 void inlinePictureStarted();
00178
00179 void ensureCursorVisible();
00180
00181 void editFrameSet( KWFrameSet * frameSet, bool onlyText = false );
00186 void editTextFrameSet( KWFrameSet * fs, KoTextParag* parag, int index );
00187 bool checkCurrentEdit( KWFrameSet * fs, bool onlyText = false);
00188
00189
00190 NoteType footNoteType()const{return m_footEndNote.noteType;}
00191 KWFootNoteVariable::Numbering numberingFootNoteType() const { return m_footEndNote.numberingType;}
00192
00193 void setFootNoteType( NoteType _type ) { m_footEndNote.noteType = _type; }
00194 void setNumberingFootNoteType(KWFootNoteVariable::Numbering _type) { m_footEndNote.numberingType = _type; }
00195
00196 void tableSelectCell(KWTableFrameSet *table, KWFrameSet *cell);
00197 void selectAllFrames( bool select );
00198
00199 KCommand * createTextBox(const KoRect & rect );
00200
00201
00202
00203 void viewportScroll( bool up );
00204
00206 void resetStatusBarText();
00207
00210 KoPoint caretPos();
00211 void applyGrid( KoPoint &p );
00212
00213 bool overwriteMode() const { return m_overwriteMode; }
00214
00215
00216
00217
00218 KWTextFrameSetEdit* currentTextEdit() const;
00219
00220 bool insertInlinePicture();
00221
00222 protected:
00223 void drawGrid( QPainter &p, const QRect& rect );
00224
00228 virtual void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00235 void drawDocument( QPainter *painter, const QRect &crect, KWViewMode* viewMode );
00240 void drawPageBorders( QPainter * painter, const QRect & crect, const QRegion & emptySpaceRegion );
00241
00242 virtual void keyPressEvent( QKeyEvent *e );
00243 virtual void contentsMousePressEvent( QMouseEvent *e );
00244 virtual void contentsMouseMoveEvent( QMouseEvent *e );
00245 virtual void contentsMouseReleaseEvent( QMouseEvent *e );
00246 virtual void contentsMouseDoubleClickEvent( QMouseEvent *e );
00247 virtual void contentsDragEnterEvent( QDragEnterEvent *e );
00248 virtual void contentsDragMoveEvent( QDragMoveEvent *e );
00249 virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
00250 virtual void contentsDropEvent( QDropEvent *e );
00251 virtual void resizeEvent( QResizeEvent *e );
00252
00253 KWTableFrameSet * createTable();
00254
00255 void terminateCurrentEdit();
00256 bool insertInlineTable();
00257
00258 signals:
00259
00260 void currentFrameSetEditChanged();
00261
00262 void selectionChanged( bool hasSelection );
00263
00264 void currentMouseModeChanged(int newMouseMode);
00265
00266 void frameSelectedChanged();
00267
00268
00269 void docStructChanged(int _type);
00270
00271 void overwriteModeChanged( bool m_overwriteMode );
00272
00273 void viewTransformationsChanged();
00274
00275 void updateRuler();
00276
00277 private slots:
00278 void slotContentsMoving( int, int );
00279 void slotNewContentsSize();
00280 void slotMainTextHeightChanged();
00281 void doAutoScroll();
00282
00283
00284 void terminateEditing( KWFrameSet *fs );
00285
00286 private:
00291 void drawFrameSet( KWFrameSet * frameset, QPainter * painter,
00292 const QRect & crect, bool onlyChanged, bool resetChanged, KWViewMode* viewMode );
00293
00294 void drawMovingRect( QPainter & p );
00295 void deleteMovingRect();
00302 void applyAspectRatio( double ratio, KoRect& insRect );
00303
00304 #ifndef NDEBUG
00305 void printRTDebug( int );
00306 #endif
00307
00308 KWFrameViewManager *m_frameViewManager;
00309 KWDocument *m_doc;
00310 KWFrameSetEdit *m_currentFrameSetEdit;
00311 KWGUI *m_gui;
00312 QTimer *m_scrollTimer;
00313 bool m_mousePressed;
00314 bool m_printing;
00315 bool m_imageDrag;
00316
00317
00318 bool m_frameInline;
00319 FrameSetType m_frameInlineType;
00320
00321
00322
00323 KWViewMode *m_viewMode;
00324
00325
00326 MouseMode m_mouseMode;
00327 MouseMeaning m_mouseMeaning;
00328 KoRect m_resizedFrameInitialSize;
00329 double m_resizedFrameInitialMinHeight;
00330 KoRect m_insRect;
00331 bool m_deleteMovingRect;
00332 KoPicture m_kopicture;
00333 QSize m_pixmapSize;
00334 bool m_keepRatio;
00335 KoDocumentEntry m_partEntry;
00336 int m_rowColResized;
00337 bool m_temporaryStatusBarTextShown;
00338 double m_previousTableSize;
00339 KoPoint m_lastCaretPos;
00340 bool m_overwriteMode;
00341
00342
00343
00344 struct
00345 {
00346 unsigned int cols;
00347 unsigned int rows;
00348 int format;
00349 int width;
00350 int height;
00351 bool floating;
00352 QString tableTemplateName;
00353 KWTableTemplate *tt;
00354 } m_table;
00355 KWTableFrameSet *m_currentTable;
00356 InteractionPolicy *m_interactionPolicy;
00357
00358 struct
00359 {
00360 NoteType noteType;
00361 KWFootNoteVariable::Numbering numberingType;
00362 } m_footEndNote;
00363
00364 struct
00365 {
00366 bool pictureInline;
00367 bool keepRatio;
00368 }m_picture;
00369 };
00370
00378 class InteractionPolicy {
00379 public:
00388 virtual void handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) = 0;
00394 virtual KCommand* createCommand() = 0;
00399 void cancelInteraction();
00403 virtual void finishInteraction() = 0;
00404
00413 static InteractionPolicy* createPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState);
00414
00415 void hadDragEvents() { m_gotDragEvents = true; }
00416 bool gotDragEvents() { return m_gotDragEvents; }
00417
00418 protected:
00425 InteractionPolicy(KWCanvas *parent, bool doInit = true, bool includeInlineFrames = false);
00426
00427 QValueList<FrameIndex> m_indexFrame;
00428 KWCanvas *m_parent;
00429 QValueList<KWFrame*> m_frames;
00430
00431 private:
00432 void init();
00433 bool m_gotDragEvents;
00434 };
00435
00441 class FrameResizePolicy : public InteractionPolicy {
00442 public:
00443 FrameResizePolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point);
00444 void handleMouseMove(Qt::ButtonState keyState, const KoPoint &point);
00445 KCommand *createCommand();
00446 void finishInteraction();
00447
00448 private:
00449 QValueList<FrameResizeStruct> m_frameResize;
00450 bool m_top, m_bottom, m_left, m_right;
00451 KoRect m_boundingRect;
00452 KoPoint m_hotSpot;
00453 };
00454
00460 class FrameMovePolicy : public InteractionPolicy {
00461 public:
00462 FrameMovePolicy(KWCanvas *parent, KoPoint &point);
00463 void handleMouseMove(Qt::ButtonState keyState, const KoPoint &point);
00464 KCommand *createCommand();
00465 void finishInteraction();
00466 private:
00467 QValueList<FrameMoveStruct> m_frameMove;
00468 KoPoint m_hotSpot;
00469 KoPoint m_startPoint;
00470 KoRect m_boundingRect;
00471 };
00472
00476 class FrameSelectPolicy : public InteractionPolicy {
00477 public:
00478 FrameSelectPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState state, Qt::ButtonState keyState);
00479 void handleMouseMove(Qt::ButtonState keyState, const KoPoint &point);
00480 KCommand *createCommand();
00481 void finishInteraction();
00482 bool isValid() { return m_validSelection; }
00483
00484 private:
00485 bool m_validSelection;
00486 };
00487
00488 #endif