lib Library API Documentation

kotextcustomitem.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
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 //void KoTextCustomItem::setPainter( QPainter*, bool adjust ){ if ( adjust ) width = 0; }
00029 //void KoTextCustomItem::setPainter( QPainter*, bool ){ resize(); } // changed for kotext
00030 
00031 bool KoTextCustomItem::enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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     //kdDebug(32500) << "KoTextCustomItem::format index=" << index() << " format=" << parag->at( index() )->format() << endl;
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     //kdDebug(32500)<<" x :"<<_x<<" y :"<<_y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
00076 
00077     // Calculate index only once
00078     // Hmm, should pass it to drawCustomItem...
00079     int charIndex = index();
00080     KoTextStringChar* stringChar = paragraph()->at( charIndex );
00081 
00082     // Convert x, y, cx, cy, cw and ch from Layout Units to pixels.
00083     int x = zh->layoutUnitToPixelX(_x) /*+ stringChar->pixelxadj*/;
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     //kdDebug(32500)<<"After  x :"<<x<<" y :"<<y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
00092     int ascentpix = zh->layoutUnitToPixelY( _y, ascent() );
00093 
00094     KoTextFormat * fmt = stringChar->format();
00095 
00096     //bool forPrint = ( p->device()->devType() == QInternal::Printer );
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(); // the item-specific delete stuff hasn't been done
00149         }
00150         item->setDeleted( true );
00151     }
00152 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:27 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003