F:/KPlato/koffice/libs/kotext/KoTextCustomItem.cpp

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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 //void KoTextCustomItem::setPainter( QPainter*, bool adjust ){ if ( adjust ) width = 0; }
00030 //void KoTextCustomItem::setPainter( QPainter*, bool ){ resize(); } // changed for kotext
00031 
00032 bool KoTextCustomItem::enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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 *&parag, 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     //kDebug(32500) << "KoTextCustomItem::format index=" << index() << " format=" << parag->at( index() )->format() << endl;
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     //kDebug(32500)<<" x :"<<_x<<" y :"<<_y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
00077 
00078     // Calculate index only once
00079     // Hmm, should pass it to drawCustomItem...
00080     int charIndex = index();
00081     KoTextStringChar* stringChar = paragraph()->at( charIndex );
00082 
00083     // Convert x, y, cx, cy, cw and ch from Layout Units to pixels.
00084     int x = zh->layoutUnitToPixelX(_x) /*+ stringChar->pixelxadj*/;
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     //kDebug(32500)<<"After  x :"<<x<<" y :"<<y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
00093     int ascentpix = zh->layoutUnitToPixelY( _y, ascent() );
00094 
00095     KoTextFormat * fmt = stringChar->format();
00096 
00097     //bool forPrint = ( p->device()->devType() == QInternal::Printer );
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(); // the item-specific delete stuff hasn't been done
00149         }
00150         item->setDeleted( true );
00151     }
00152 }

Généré le Wed Nov 22 23:41:09 2006 pour KPlato par  doxygen 1.5.1-p1