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