00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KoRichText.h"
00021 #include "KoTextFormat.h"
00022 #include "KoTextParag.h"
00023 #include "KoTextZoomHandler.h"
00024 #include "KoTextDocument.h"
00025 #include <kdebug.h>
00026 #include <kcommand.h>
00027
00028
00029
00030
00031
00032 bool KoTextCustomItem::enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd )
00033 {
00034 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; Q_UNUSED( atEnd ) return true;
00035
00036 }
00037 bool KoTextCustomItem::enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, const QPoint & )
00038 {
00039 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return true;
00040 }
00041 bool KoTextCustomItem::next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
00042 {
00043 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return true;
00044 }
00045 bool KoTextCustomItem::prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
00046 {
00047 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return true;
00048 }
00049 bool KoTextCustomItem::down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
00050 {
00051 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return true;
00052 }
00053 bool KoTextCustomItem::up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
00054 {
00055 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return true;
00056 }
00057
00058 int KoTextCustomItem::index() const
00059 {
00060 Q_ASSERT( paragraph() );
00061 KoTextParag * parag = paragraph();
00062 return parag->findCustomItem( this );
00063 }
00064
00065 KoTextFormat * KoTextCustomItem::format() const
00066 {
00067 KoTextParag * parag = paragraph();
00068
00069 return parag->at( index() )->format();
00070 }
00071
00072
00073 void KoTextCustomItem::draw(QPainter* p, int _x, int _y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected )
00074 {
00075 KoTextZoomHandler *zh=textDocument()->paintingZoomHandler();
00076
00077
00078
00079
00080 int charIndex = index();
00081 KoTextStringChar* stringChar = paragraph()->at( charIndex );
00082
00083
00084 int x = zh->layoutUnitToPixelX(_x) ;
00085 int y = zh->layoutUnitToPixelY(_y);
00086 cx = zh->layoutUnitToPixelX(cx);
00087 cy = zh->layoutUnitToPixelY(cy);
00088 cw = zh->layoutUnitToPixelX(_x,cw);
00089 ch = zh->layoutUnitToPixelY(_y,ch);
00090 int wpix = zh->layoutUnitToPixelX(_x,width);
00091 int hpix = zh->layoutUnitToPixelX(_y,height);
00092
00093 int ascentpix = zh->layoutUnitToPixelY( _y, ascent() );
00094
00095 KoTextFormat * fmt = stringChar->format();
00096
00097
00098 p->setFont( fmt->screenFont( zh ) );
00099
00100 int offset=0;
00101 if ( fmt->vAlign() == KoTextFormat::AlignSuperScript )
00102 offset = -( hpix - p->fontMetrics().height() );
00103
00104 if ( fmt->shadowDistanceX() != 0 || fmt->shadowDistanceY() != 0 ) {
00105 int sx = fmt->shadowX( zh );
00106 int sy = fmt->shadowY( zh );
00107 if ( sx != 0 || sy != 0 )
00108 {
00109 p->save();
00110 p->translate( sx, sy );
00111 drawCustomItem(p, x, y, wpix, hpix, ascentpix, cx, cy, cw, ch, cg, selected, offset, true);
00112 p->restore();
00113 }
00114 }
00115 drawCustomItem(p, x, y, wpix, hpix, ascentpix, cx, cy, cw, ch, cg, selected, offset, false);
00116 }
00117
00119
00120 void CustomItemsMap::insertItems( const KoTextCursor & startCursor, int size )
00121 {
00122 if ( isEmpty() )
00123 return;
00124
00125 KoTextCursor cursor( startCursor );
00126 for ( int i = 0; i < size; ++i )
00127 {
00128 CustomItemsMap::Iterator it = find( i );
00129 if ( it != end() )
00130 {
00131 kDebug(32500) << "CustomItemsMap::insertItems setting custom item " << it.value() << endl;
00132 cursor.parag()->setCustomItem( cursor.index(), it.value(), 0 );
00133 it.value()->setDeleted( false );
00134 }
00135 cursor.gotoRight();
00136 }
00137 }
00138
00139 void CustomItemsMap::deleteAll( KMacroCommand *macroCmd )
00140 {
00141 KoTextCustomItem* item;
00142 foreach( item, *this )
00143 {
00144 KCommand * itemCmd = item->deleteCommand();
00145 if ( itemCmd && macroCmd )
00146 {
00147 macroCmd->addCommand( itemCmd );
00148 itemCmd->execute();
00149 }
00150 item->setDeleted( true );
00151 }
00152 }