1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* This file is part of the KDE project
Copyright (C) 2001 David Faure <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoRichText.h"
#include "KoTextFormat.h"
#include "KoTextParag.h"
#include "KoTextZoomHandler.h"
#include "KoTextDocument.h"
#include <kdebug.h>
#include <kcommand.h>
//void KoTextCustomItem::setPainter( TQPainter*, bool adjust ){ if ( adjust ) width = 0; }
//void KoTextCustomItem::setPainter( TQPainter*, bool ){ resize(); } // changed for kotext
bool KoTextCustomItem::enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; Q_UNUSED( atEnd ) return TRUE;
}
bool KoTextCustomItem::enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, const TQPoint & )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE;
}
bool KoTextCustomItem::next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE;
}
bool KoTextCustomItem::prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE;
}
bool KoTextCustomItem::down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE;
}
bool KoTextCustomItem::up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy )
{
doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE;
}
int KoTextCustomItem::index() const
{
Q_ASSERT( paragraph() );
KoTextParag * parag = paragraph();
return parag->findCustomItem( this );
}
KoTextFormat * KoTextCustomItem::format() const
{
KoTextParag * parag = paragraph();
//kdDebug(32500) << "KoTextCustomItem::format index=" << index() << " format=" << parag->at( index() )->format() << endl;
return parag->at( index() )->format();
}
void KoTextCustomItem::draw(TQPainter* p, int _x, int _y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected )
{
KoTextZoomHandler *zh=textDocument()->paintingZoomHandler();
//kdDebug(32500)<<" x :"<<_x<<" y :"<<_y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
// Calculate index only once
// Hmm, should pass it to drawCustomItem...
int charIndex = index();
KoTextStringChar* stringChar = paragraph()->at( charIndex );
// Convert x, y, cx, cy, cw and ch from Layout Units to pixels.
int x = zh->tqlayoutUnitToPixelX(_x) /*+ stringChar->pixelxadj*/;
int y = zh->tqlayoutUnitToPixelY(_y);
cx = zh->tqlayoutUnitToPixelX(cx);
cy = zh->tqlayoutUnitToPixelY(cy);
cw = zh->tqlayoutUnitToPixelX(_x,cw);
ch = zh->tqlayoutUnitToPixelY(_y,ch);
int wpix = zh->tqlayoutUnitToPixelX(_x,width);
int hpix = zh->tqlayoutUnitToPixelX(_y,height);
//kdDebug(32500)<<"After x :"<<x<<" y :"<<y<<" cx :"<<cx<<" cy :"<<cy<<" ch :"<<ch<<" cw :"<<cw<<endl;
int ascentpix = zh->tqlayoutUnitToPixelY( _y, ascent() );
KoTextFormat * fmt = stringChar->format();
//bool forPrint = ( p->device()->devType() == TQInternal::Printer );
p->setFont( fmt->screenFont( zh ) );
int offset=0;
if ( fmt->vAlign() == KoTextFormat::AlignSuperScript )
offset = -( hpix - p->fontMetrics().height() );
if ( fmt->shadowDistanceX() != 0 || fmt->shadowDistanceY() != 0 ) {
int sx = fmt->shadowX( zh );
int sy = fmt->shadowY( zh );
if ( sx != 0 || sy != 0 )
{
p->save();
p->translate( sx, sy );
drawCustomItem(p, x, y, wpix, hpix, ascentpix, cx, cy, cw, ch, cg, selected, offset, true);
p->restore();
}
}
drawCustomItem(p, x, y, wpix, hpix, ascentpix, cx, cy, cw, ch, cg, selected, offset, false);
}
////////////////
void CustomItemsMap::insertItems( const KoTextCursor & startCursor, int size )
{
if ( isEmpty() )
return;
KoTextCursor cursor( startCursor );
for ( int i = 0; i < size; ++i )
{
CustomItemsMap::Iterator it = tqfind( i );
if ( it != end() )
{
kdDebug(32500) << "CustomItemsMap::insertItems setting custom item " << it.data() << endl;
cursor.parag()->setCustomItem( cursor.index(), it.data(), 0 );
it.data()->setDeleted( false );
}
cursor.gotoRight();
}
}
void CustomItemsMap::deleteAll( KMacroCommand *macroCmd )
{
Iterator it = begin();
for ( ; it != end(); ++it )
{
KoTextCustomItem * item = it.data();
KCommand * itemCmd = item->deleteCommand();
if ( itemCmd && macroCmd )
{
macroCmd->addCommand( itemCmd );
itemCmd->execute(); // the item-specific delete stuff hasn't been done
}
item->setDeleted( true );
}
}
|