kpresenter

KPrTextObject.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) 2005-2006 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 #ifndef kptextobject_h
00023 #define kptextobject_h
00024 
00025 #include "KPrObject.h"
00026 #include "KoRichText.h"
00027 #include <KoTextView.h>
00028 #include <KoStyleCollection.h> // for KoStyleChangeDefMap
00029 #include <KoStyleStack.h>
00030 
00031 class QDragObject;
00032 
00033 class KoSavingContext;
00034 class KPrView;
00035 class KPrDocument;
00036 class QDomElement;
00037 class TextCmd;
00038 class KPrGradient;
00039 
00040 class KoTextView;
00041 class KoTextObject;
00042 class KPrTextView;
00043 class KCommand;
00044 class KPrCanvas;
00045 class KoPoint;
00046 class KoVariable;
00047 class KPrTextDocument;
00048 class DCOPObject;
00049 class KPrPage;
00050 class KoParagStyle;
00051 
00052 class KPrTextObject :  public QObject, public KPr2DObject, public KoTextFlow
00053 {
00054     Q_OBJECT
00055 public:
00056     KPrTextObject( KPrDocument *doc );
00057     virtual ~KPrTextObject();
00058 
00059     virtual DCOPObject* dcopObject();
00060 
00061     virtual void setSize( double _width, double _height );
00062 
00063     virtual void setDrawEditRect( bool b )
00064         { drawEditRect = b; }
00065     virtual void setDrawEmpty( bool b )
00066         { drawEmpty = b; }
00067 
00068     virtual ObjType getType() const
00069         { return OT_TEXT; }
00070     virtual QString getTypeString() const
00071         { return i18n("Text"); }
00072 
00073     virtual bool getDrawEditRect() const
00074         { return drawEditRect; }
00075     virtual bool getDrawEmpty() const
00076         { return drawEmpty; }
00077     virtual int getSubPresSteps() const;
00078 
00079     virtual QBrush getBrush() const;
00080 
00081     virtual void setShadowParameter(int _distance,ShadowDirection _direction,const QColor &_color);
00082 
00083     virtual QDomDocumentFragment save( QDomDocument& doc, double offset );
00084     virtual double load(const QDomElement &element);
00085     virtual void loadOasis(const QDomElement &element, KoOasisContext& context, KPrLoadingInfo *info);
00086     virtual void saveOasisMarginElement( KoGenStyle &styleobjectauto ) const;
00087 
00088     virtual void paint( QPainter *_painter, KoTextZoomHandler*_zoomHandler,
00089                         int pageNum, bool drawingShadow, bool drawContour );
00090     void paint( QPainter *_painter, KoTextZoomHandler*_zoomHandler, bool onlyChanged, KoTextCursor* cursor,
00091                 bool resetChanged, bool drawContour );
00092     void paintEdited( QPainter *_painter, KoTextZoomHandler*_zoomHandler,
00093                       bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
00094 
00095     void drawCursor( QPainter *p, KoTextCursor *cursor, bool cursorVisible, KPrCanvas* /*canvas*/ );
00096 
00097     void recalcPageNum( KPrPage *page );
00099     QPoint cursorPos(KPrCanvas*, KoTextCursor *) const;
00100 
00101 
00103     KoTextObject * textObject() const { return m_textobj; }
00104     virtual void addTextObjects( QPtrList<KoTextObject> &lst ) const {
00105         if ( !isProtectContent() )
00106             lst.append( m_textobj );
00107     }
00108 
00109     KPrTextDocument *textDocument() const;
00110 
00111     KPrDocument* kPresenterDocument() const { return m_doc; }
00112 
00113     KPrTextView * createKPTextView( KPrCanvas *,bool temp=false );
00114     void applyStyleChange( KoStyleChangeDefMap changed );
00115 
00116     void removeHighlight();
00117     void highlightPortion( KoTextParag * parag, int index, int length, KPrCanvas *canvas, bool repaint, KDialogBase* dialog = 0 );
00118 
00119     KCommand * pasteOasis( KoTextCursor * cursor, const QByteArray & data, bool removeSelected );
00120 
00121     void saveParagraph( QDomDocument& doc,
00122                         KoTextParag * parag,
00123                         QDomElement &parentElem,
00124                         int from /* default 0 */,
00125                         int to /* default length()-2 */ );
00126     KoParagLayout loadParagLayout( QDomElement & parentElem, KPrDocument *doc, bool useRefStyle);
00127 
00128     static KoTextFormat loadFormat( QDomElement &n, KoTextFormat * refFormat, const QFont & defaultFont,
00129                                     const QString & defaultLanguage, bool hyphen );
00130 
00131     void setEditingTextObj( bool _edit ) { editingTextObj = _edit; }
00132 
00133     KCommand *textContentsToHeight();
00134     KCommand *textObjectToContents();
00135     void setProtectContent ( bool _protect ) { textObject()->setProtectContent(_protect);}
00136     bool isProtectContent() const { return textObject()->protectContent();}
00137     void loadVariable( QValueList<QDomElement> & listVariable,KoTextParag *lastParag, int offset=0 );
00138 
00139     void layout();
00140 
00142     int availableHeight() const;
00143 
00145     void setBLeft( double b ) { bleft = b; }
00147     void setBRight( double b ) { bright = b; }
00149     void setBTop( double b ) { btop = b; }
00151     void setBBottom( double b ) { bbottom = b; }
00152 
00154     double bLeft()const { return bleft; }
00156     double bRight()const { return bright; }
00158     double bTop()const { return btop; }
00160     double bBottom()const { return bbottom; }
00161 
00162     void setTextMargins( double _left, double _top, double right, double bottom);
00163 
00164     KoRect innerRect() const;
00165     double innerWidth() const;
00166     double innerHeight() const;
00167     void resizeTextDocument( bool widthChanged = true, bool heightChanged = true );
00168 
00169     VerticalAlignmentType verticalAlignment() const { return m_textVertAlign; }
00170     void setVerticalAligment( VerticalAlignmentType _type) ;
00171     double alignmentValue() const {  return alignVertical; }
00172     virtual KPrTextObject *nextTextObject() { return this;}
00173     static void saveFormat( QDomElement & element, KoTextFormat*lastFormat );
00174 
00175     QPoint viewToInternal( const QPoint & pos, KPrCanvas* canvas ) const;
00176 
00177 signals:
00178     void repaintChanged( KPrTextObject* );
00179 
00180 protected slots:
00181     void slotFormatChanged(const KoTextFormat &);
00182     void slotAfterFormatting( int, KoTextParag*, bool* );
00183     void slotParagraphDeleted(KoTextParag*_parag);
00184 protected:
00185     virtual const char * getOasisElementName() const;
00186     virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const;
00187 
00188     virtual QDomElement saveKTextObject( QDomDocument& doc );
00189     QDomElement saveHelper(const QString &tmpText,KoTextFormat*lastFormat ,QDomDocument &doc);
00190 
00191     virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
00192 
00193     virtual void loadKTextObject( const QDomElement &e );
00194     void drawText( QPainter* _painter, KoTextZoomHandler* zoomHandler, bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
00195     void drawParags( QPainter *p, KoTextZoomHandler* zoomHandler, const QColorGroup& cg, int from, int to );
00196     void saveParagLayout( const KoParagLayout& layout, QDomElement & parentElem );
00197     void invalidate();
00198     void recalcVerticalAlignment();
00199     virtual KoPen defaultPen() const;
00200 protected slots:
00201     void slotNewCommand( KCommand *cmd );
00202     void slotAvailableHeightNeeded();
00203     void slotRepaintChanged();
00204 private:
00205     KPrTextObject &operator=( const KPrTextObject & );
00206     void shadowCompatibility();
00207     static const QString &tagTEXTOBJ, &attrLineSpacing, &attrParagSpacing,
00208         &attrMargin, &attrBulletType1, &attrBulletType2,
00209         &attrBulletType3, &attrBulletType4, &attrBulletColor1,
00210         &attrBulletColor2, &attrBulletColor3, &attrBulletColor4,
00211         &attrObjType, &tagP, &attrAlign, &attrType,
00212         &attrDepth, &tagTEXT, &attrFamily, &attrPointSize,
00213         &attrBold, &attrItalic, & attrUnderline,& attrStrikeOut,
00214         &attrColor, &attrWhitespace, &attrTextBackColor,
00215         &attrVertAlign, &attrLinkName, &attrHrefName;
00216 
00218     KoTextObject *m_textobj;
00219     KPrDocument *m_doc;
00220     KoParagLayout m_paragLayout;
00221     VerticalAlignmentType m_textVertAlign;
00222     double bleft, bright, btop, bbottom; // margins
00223     double alignVertical;
00224     bool drawEditRect, drawEmpty;
00225     bool editingTextObj;
00226 };
00227 
00228 
00229 class KPrTextView : public KoTextView
00230 {
00231     Q_OBJECT
00232 public:
00233     KPrTextView( KPrTextObject * txtObj, KPrCanvas *_canvas, bool temp=false );
00234     virtual ~KPrTextView();
00235 
00236     virtual KoTextViewIface* dcopObject();
00237 
00238     KoTextView * textView() { return this; }
00239     KPrTextObject * kpTextObject() const { return m_kptextobj; }
00240 
00241     void keyPressEvent( QKeyEvent * );
00242     void keyReleaseEvent( QKeyEvent * );
00243     void imStartEvent( QIMEvent * );
00244     void imComposeEvent( QIMEvent * );
00245     void imEndEvent( QIMEvent * );
00246     void mousePressEvent( QMouseEvent *, const QPoint &);
00247     void mouseMoveEvent( QMouseEvent *, const QPoint & );
00248     void mouseReleaseEvent( QMouseEvent *, const QPoint & );
00249     void mouseDoubleClickEvent( QMouseEvent *, const QPoint &);
00250     void dragEnterEvent( QDragEnterEvent * );
00251     void dragMoveEvent( QDragMoveEvent *, const QPoint & );
00252     void dropEvent( QDropEvent * );
00253 
00254     void clearSelection();
00255     void selectAll(bool select = true);
00256     virtual void drawCursor( bool b );
00257 
00258     const KoParagLayout & currentParagLayout() const { return m_paragLayout; }
00259     void showPopup( KPrView *view, const QPoint &point, QPtrList<KAction> &actionList );
00260     void insertVariable( int type, int subtype = 0 );
00261     void insertCustomVariable( const QString &name);
00262     void insertLink(const QString &_linkName, const QString & hrefName);
00263     void insertVariable( KoVariable *var, KoTextFormat *format =0,
00264                          bool refreshCustomMenu =false /*don't refresh variable custom menu all the time */);
00265 
00266     void terminate(bool removeSelection=true);
00267     void insertComment(const QString &_note);
00268 
00270     bool hasSelection() const;
00271 
00272     virtual void removeToolTipCompletion();
00273     bool isLinkVariable(const QPoint &);
00274     void openLink();
00275     QPoint viewToInternal( const QPoint & pos ) const;
00276 
00277 public slots:
00278     void cut();
00279     void copy();
00280     void paste();
00281     // Reimplemented from KoTextView
00282     virtual void updateUI( bool updateFormat, bool force = false );
00283     virtual void ensureCursorVisible();
00284 
00285 
00286 protected slots:
00287     virtual void startDrag();
00288 
00289 protected:
00290     bool canDecode( QMimeSource *e );
00291     QDragObject * newDrag( QWidget * parent );
00292     // Reimplemented from KoTextView
00293     virtual void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch );
00294     virtual bool doIgnoreDoubleSpace(KoTextParag * parag, int index,QChar ch );
00295     virtual bool doCompletion( KoTextCursor* cursor, KoTextParag *parag, int index );
00296     virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int  );
00297     virtual void showToolTipBox(KoTextParag *parag, int index, QWidget *widget, const QPoint &pos);
00298     virtual void textIncreaseIndent();
00299     virtual bool textDecreaseIndent();
00300     virtual void showFormat( KoTextFormat *format ) ;
00301 
00302     virtual bool pgUpKeyPressed();
00303     virtual bool pgDownKeyPressed();
00304 
00305     KPrTextObject *m_kptextobj;
00306     KPrCanvas *m_canvas;
00307     KoParagLayout m_paragLayout;
00308     QPtrList<KAction> m_actionList; // for the kodatatools
00309 };
00310 
00311 
00312 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys