lib

KoTextCustomItem.h

00001 // -*- c++ -*-
00002 /* This file is part of the KDE project
00003 
00004    Original QTextCustomItem is
00005      Copyright (C) 1999-2000 Trolltech AS.  All rights reserved.
00006    KoText modifications
00007      Copyright (C) 2001-2005 David Faure <faure@kde.org>
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 */
00024 
00025 // This file isn't standalone at this point; it's included by KoRichText.h
00026 
00034 class KOTEXT_EXPORT KoTextCustomItem
00035 {
00036 public:
00037     KoTextCustomItem( KoTextDocument *p );
00038     virtual ~KoTextCustomItem();
00039     virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) /* = 0*/;
00040 
00041     // Called after the item's paragraph has been formatted
00042     virtual void finalize() {}
00043 
00044     void move( int x, int y ) { xpos = x; ypos = y; }
00045     int x() const { return xpos; }
00046     int y() const { return ypos; }
00047 
00048     // Called when the format of the character is being changed, see KoTextStringChar::setFormat
00049     virtual void setFormat( KoTextFormat * ) { }
00050 
00051     //virtual void setPainter( QPainter*, bool adjust );
00052 
00053     enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00054     virtual Placement placement() const { return PlaceInline; }
00055     bool placeInline() { return placement() == PlaceInline; }
00056 
00057     virtual bool ownLine() const { return FALSE; }
00058     // Called for "ownline" items
00059     virtual void resize( int nwidth ) { width = nwidth; }
00060     virtual void invalidate() {};
00061 
00062     virtual bool isNested() const { return FALSE; }
00063     virtual int minimumWidth() const { return 0; }
00064     virtual int widthHint() const { return 0; }
00065     virtual int ascent() const { return height; }
00066 
00067     virtual QString richText() const { return QString::null; }
00068 
00069     int width;
00070     int height;
00071 
00072     QRect geometry() const { return QRect( xpos, ypos, width, height ); }
00073 
00074     virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
00075     virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, const QPoint & );
00076     virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00077     virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00078     virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00079     virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00080 
00081     void setParagraph( KoTextParag * p ) { parag = p; }
00082     KoTextParag *paragraph() const { return parag; }
00083 
00084     virtual void pageBreak( int /*y*/, KoTextFlow* /*flow*/ ) {}
00085 
00086     KoTextDocument *parent;
00087 
00088 
00089 
00091     KoTextDocument * textDocument() const { return parent; }
00092 
00096     virtual void setDeleted( bool b ) { m_deleted = b; }
00097 
00098     bool isDeleted() const { return m_deleted; }
00099 
00105     virtual KCommand * createCommand() { return 0L; }
00106     virtual KCommand * deleteCommand() { return 0L; }
00107 
00109     virtual void save( QDomElement& formatElem ) = 0;
00111     virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const = 0;
00113     virtual int typeId() const = 0;
00114 
00117     virtual void resize() {}
00118 
00123     virtual void recalc() { resize(); }
00124 
00127     int index() const;
00128 
00131     KoTextFormat * format() const;
00132 
00136     virtual void drawCustomItem(QPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected, int offset,  bool drawingShadow) = 0;
00137 
00138 protected:
00139     bool m_deleted;
00140 
00141 protected:
00142     int xpos;
00143     int ypos;
00144 private:
00145     KoTextParag *parag;
00146 };
KDE Home | KDE Accessibility Home | Description of Access Keys