23#include "KPrTextObject.h"
24#include "KPrTextObject.moc"
25#include "KPrGradient.h"
26#include "KPrCommand.h"
30#include "KPrDocument.h"
31#include "KPrBgSpellCheck.h"
32#include "KPrVariableCollection.h"
34#include <KoAutoFormat.h>
35#include <KoTextParag.h>
36#include <KoTextObject.h>
37#include <KoStyleCollection.h>
38#include <KoTextFormatter.h>
39#include <KoTextZoomHandler.h>
40#include "KPrTextViewIface.h"
41#include "KPrTextObjectIface.h"
42#include <KoOasisContext.h>
43#include <KoStyleStack.h>
44#include <tdetempfile.h>
47#include <tdeversion.h>
48#include <tdemultipledrag.h>
57#include <tqapplication.h>
58#include <tqfontdatabase.h>
59#include <tqpopupmenu.h>
60#include <tqclipboard.h>
62#include <KoParagCounter.h>
64#include <KoVariable.h>
65#include <KoCustomVariablesDia.h>
71#include <KoStoreDrag.h>
72#include <KoOasisStore.h>
79const TQString &KPrTextObject::tagTEXTOBJ=TDEGlobal::staticQString(
"TEXTOBJ");
80const TQString &KPrTextObject::attrLineSpacing=TDEGlobal::staticQString(
"lineSpacing");
81const TQString &KPrTextObject::attrParagSpacing=TDEGlobal::staticQString(
"paragSpacing");
82const TQString &KPrTextObject::attrMargin=TDEGlobal::staticQString(
"margin");
83const TQString &KPrTextObject::attrBulletType1=TDEGlobal::staticQString(
"bulletType1");
84const TQString &KPrTextObject::attrBulletType2=TDEGlobal::staticQString(
"bulletType2");
85const TQString &KPrTextObject::attrBulletType3=TDEGlobal::staticQString(
"bulletType3");
86const TQString &KPrTextObject::attrBulletType4=TDEGlobal::staticQString(
"bulletType4");
87const TQString &KPrTextObject::attrBulletColor1=TDEGlobal::staticQString(
"bulletColor1");
88const TQString &KPrTextObject::attrBulletColor2=TDEGlobal::staticQString(
"bulletColor2");
89const TQString &KPrTextObject::attrBulletColor3=TDEGlobal::staticQString(
"bulletColor3");
90const TQString &KPrTextObject::attrBulletColor4=TDEGlobal::staticQString(
"bulletColor4");
91const TQString &KPrTextObject::tagP=TDEGlobal::staticQString(
"P");
92const TQString &KPrTextObject::attrAlign=TDEGlobal::staticQString(
"align");
93const TQString &KPrTextObject::attrType=TDEGlobal::staticQString(
"type");
94const TQString &KPrTextObject::attrDepth=TDEGlobal::staticQString(
"depth");
95const TQString &KPrTextObject::tagTEXT=TDEGlobal::staticQString(
"TEXT");
96const TQString &KPrTextObject::attrFamily=TDEGlobal::staticQString(
"family");
97const TQString &KPrTextObject::attrPointSize=TDEGlobal::staticQString(
"pointSize");
98const TQString &KPrTextObject::attrBold=TDEGlobal::staticQString(
"bold");
99const TQString &KPrTextObject::attrItalic=TDEGlobal::staticQString(
"italic");
100const TQString &KPrTextObject::attrUnderline=TDEGlobal::staticQString(
"underline");
101const TQString &KPrTextObject::attrStrikeOut=TDEGlobal::staticQString(
"strikeOut");
102const TQString &KPrTextObject::attrColor=TDEGlobal::staticQString(
"color");
103const TQString &KPrTextObject::attrWhitespace=TDEGlobal::staticQString(
"whitespace");
104const TQString &KPrTextObject::attrTextBackColor=TDEGlobal::staticQString(
"textbackcolor");
105const TQString &KPrTextObject::attrVertAlign=TDEGlobal::staticQString(
"VERTALIGN");
108KPrTextObject::KPrTextObject( KPrDocument *doc )
112 m_textVertAlign = KP_TOP;
114 KoTextFormatCollection* fc =
new KoTextFormatCollection( doc->defaultFont(), TQt::black, doc->globalLanguage(), doc->globalHyphenation() );
116 if ( m_doc->tabStopValue() != -1 )
117 textdoc->setTabStops( m_doc->zoomHandler()->ptToLayoutUnitPixX( m_doc->tabStopValue() ));
119 m_textobj =
new KoTextObject( textdoc, m_doc->styleCollection()->findStyle(
"Standard" ),
this );
120 textdoc->setFlow(
this );
122 m_doc->backSpeller()->registerNewTextObject( m_textobj );
126 editingTextObj =
false;
134 connect( m_textobj, TQ_SIGNAL( newCommand( KCommand * ) ),
135 TQ_SLOT( slotNewCommand( KCommand * ) ) );
136 connect( m_textobj, TQ_SIGNAL( availableHeightNeeded() ),
137 TQ_SLOT( slotAvailableHeightNeeded() ) );
138 connect( m_textobj, TQ_SIGNAL( repaintChanged( KoTextObject* ) ),
139 TQ_SLOT( slotRepaintChanged() ) );
142 connect(
this, TQ_SIGNAL( repaintChanged( KPrTextObject * ) ),
143 m_doc, TQ_SLOT( slotRepaintChanged( KPrTextObject * ) ) );
144 connect(m_textobj, TQ_SIGNAL( showFormatObject(
const KoTextFormat &) ),
145 TQ_SLOT( slotFormatChanged(
const KoTextFormat &)) );
146 connect( m_textobj, TQ_SIGNAL( afterFormatting(
int, KoTextParag*,
bool* ) ),
147 TQ_SLOT( slotAfterFormatting(
int, KoTextParag*,
bool* ) ) );
148 connect( m_textobj, TQ_SIGNAL( paragraphDeleted( KoTextParag*) ),
149 TQ_SLOT( slotParagraphDeleted(KoTextParag*) ));
153KPrTextObject::~KPrTextObject()
155 textDocument()->takeFlow();
159DCOPObject* KPrTextObject::dcopObject()
162 dcop =
new KPrTextObjectIface(
this );
166void KPrTextObject::slotParagraphDeleted(KoTextParag*_parag)
168 m_doc->spellCheckParagraphDeleted( _parag,
this);
171TQBrush KPrTextObject::getBrush()
const
173 TQBrush tmpBrush( m_brush.getBrush() );
174 if(!tmpBrush.color().isValid())
175 tmpBrush.setColor(TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base ));
179void KPrTextObject::resizeTextDocument(
bool widthChanged,
bool heightChanged )
184 slotAvailableHeightNeeded();
186 recalcVerticalAlignment();
192 textDocument()->setWidth( m_doc->zoomHandler()->ptToLayoutUnitPixX( innerWidth() ) );
193 m_textobj->setLastFormattedParag( textDocument()->firstParag() );
194 m_textobj->formatMore( 2 );
198void KPrTextObject::setSize(
double _width,
double _height )
200 bool widthModified = KABS( _width - ext.width() ) > DBL_EPSILON ;
201 bool heightModified = KABS( _height - ext.height() ) > DBL_EPSILON;
202 if ( widthModified || heightModified )
204 KPrObject::setSize( _width, _height );
205 resizeTextDocument( widthModified, heightModified );
209TQDomDocumentFragment KPrTextObject::save( TQDomDocument& doc,
double offset )
211 TQDomDocumentFragment fragment=KPr2DObject::save(doc, offset);
212 fragment.appendChild(saveKTextObject( doc ));
216bool KPrTextObject::saveOasisObjectAttributes( KPOasisSaveContext &sc )
const
218 sc.xmlWriter.startElement(
"draw:text-box" );
219 m_textobj->saveOasisContent( sc.xmlWriter, sc.context );
220 sc.xmlWriter.endElement();
224const char * KPrTextObject::getOasisElementName()
const
229void KPrTextObject::saveOasisMarginElement( KoGenStyle &styleobjectauto )
const
231 kdDebug()<<
"void KPrTextObject::saveOasisMarginElement( KoGenStyle &styleobjectauto )\n";
233 styleobjectauto.addPropertyPt(
"fo:padding-top", btop );
234 if ( bbottom != 0.0 )
235 styleobjectauto.addPropertyPt(
"fo:padding-bottom", bbottom );
237 styleobjectauto.addPropertyPt(
"fo:padding-left", bleft );
239 styleobjectauto.addPropertyPt(
"fo:padding-right", bright );
242 switch( m_textVertAlign )
245 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"top" );
248 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"middle" );
251 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"bottom" );
258void KPrTextObject::loadOasis(
const TQDomElement &element, KoOasisContext& context,
261 KPr2DObject::loadOasis(element, context, info);
263 KoStyleStack &styleStack = context.styleStack();
264 styleStack.setTypeProperties(
"graphic" );
265 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-top" ) )
266 btop = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-top" ) );
267 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-bottom" ) )
268 bbottom = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-bottom" ) );
269 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-left") )
270 bleft = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-left" ) );
271 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-right" ) )
272 bright = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-right" ) );
273 kdDebug()<<
" KPrTextObject::loadOasis : btp :"<<btop<<
" bbottom :"<<bbottom<<
" bleft :"<<bleft<<
" bright :"<<bright<<endl;
275 if ( styleStack.hasAttributeNS( KoXmlNS::draw,
"textarea-vertical-align" ) )
277 TQString alignment = styleStack.attributeNS( KoXmlNS::draw,
"textarea-vertical-align" );
278 if ( alignment ==
"top" )
279 m_textVertAlign= KP_TOP;
280 else if ( alignment ==
"middle" )
281 m_textVertAlign= KP_CENTER;
282 else if ( alignment ==
"bottom" )
283 m_textVertAlign= KP_BOTTOM;
285 kdDebug()<<
" vertical Alignment :"<< ( ( m_textVertAlign== KP_TOP ) ?
"top" : ( m_textVertAlign== KP_CENTER ) ?
"center":
"bottom" )<<endl;
286 TQDomElement tmp = KoDom::namedItemNS( element, KoXmlNS::draw,
"text-box");
287 m_textobj->loadOasisContent( tmp, context, m_doc->styleCollection() );
288 resizeTextDocument();
292double KPrTextObject::load(
const TQDomElement &element)
294 double offset=KPr2DObject::load(element);
295 TQDomElement e=element.namedItem(tagTEXTOBJ).toElement();
297 if ( e.hasAttribute(
"protectcontent"))
298 setProtectContent((
bool)e.attribute(
"protectcontent" ).toInt());
299 if (e.hasAttribute(
"bleftpt"))
300 bleft = e.attribute(
"bleftpt").toDouble();
301 if (e.hasAttribute(
"brightpt"))
302 bright = e.attribute(
"brightpt").toDouble();
303 if (e.hasAttribute(
"btoppt"))
304 btop = e.attribute(
"btoppt").toDouble();
305 if (e.hasAttribute(
"bbottompt"))
306 bbottom = e.attribute(
"bbottompt").toDouble();
307 if ( e.hasAttribute(
"verticalAlign"))
309 TQString str =e.attribute(
"verticalAlign");
310 if ( str ==
"bottom" )
311 m_textVertAlign= KP_BOTTOM;
312 else if ( str ==
"center" )
313 m_textVertAlign= KP_CENTER;
314 else if ( str ==
"top" )
315 m_textVertAlign= KP_TOP;
317 if ( e.hasAttribute(
"verticalValue" ))
318 alignVertical = e.attribute(
"verticalValue" ).toDouble();
320 loadKTextObject( e );
323 shadowCompatibility();
325 resizeTextDocument();
329void KPrTextObject::shadowCompatibility()
331 if ( shadowDistance != 0)
335 switch ( shadowDirection )
340 sx = - shadowDistance;
343 case SD_RIGHT_BOTTOM:
348 switch ( shadowDirection )
353 sy = - shadowDistance;
356 case SD_RIGHT_BOTTOM:
361 KoTextFormat tmpFormat;
362 tmpFormat.setShadow( sx, sy, shadowColor );
363 KCommand* cmd = m_textobj->setFormatCommand( &tmpFormat, KoTextFormat::ShadowText );
367 shadowDirection = SD_RIGHT_BOTTOM;
369 shadowColor = TQt::gray;
374void KPrTextObject::paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
375 int pageNum,
bool drawingShadow,
bool drawContour )
378 KPrPage *p = m_doc->pageList().at( pageNum );
382 if ( drawingShadow )
return;
383 paint( _painter, _zoomHandler,
false, 0L,
true, drawContour );
387void KPrTextObject::paintEdited( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
388 bool onlyChanged, KoTextCursor* cursor,
bool resetChanged )
391 _painter->translate( _zoomHandler->zoomItX(orig.x()), _zoomHandler->zoomItY(orig.y()) );
394 rotateObject(_painter,_zoomHandler);
395 paint( _painter, _zoomHandler, onlyChanged, cursor, resetChanged,
false );
400void KPrTextObject::paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
401 bool onlyChanged, KoTextCursor* cursor,
bool resetChanged,
404 double ow = ext.width();
405 double oh = ext.height();
406 double pw = pen.pointWidth() / 2;
408 TQPen pen3( TQt::black, 1, TQt::DotLine );
409 _painter->setPen( pen3 );
410 _painter->setRasterOp( TQt::NotXorROP );
411 _painter->drawRect( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItY(pw),
412 _zoomHandler->zoomItX(ow), _zoomHandler->zoomItY( oh) );
418 TQPen pen2 = pen.zoomedPen(_zoomHandler);
423 _painter->setPen( pen2 );
425 if ( editingTextObj && _painter->device() && _painter->device()->devType() != TQInternal::Printer)
426 _painter->setBrush( TQBrush( m_doc->txtBackCol(), TQt::SolidPattern ) );
429 if ( getFillType() == FT_BRUSH || !gradient ) {
430 _painter->setBrush( getBrush() );
433 TQSize size( _zoomHandler->zoomSize( ext ) );
434 gradient->setSize( size );
435 _painter->drawPixmap( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX(pw), gradient->pixmap(), 0, 0,
436 _zoomHandler->zoomItX( ow - 2 * pw ),
437 _zoomHandler->zoomItY( oh - 2 * pw ) );
440 if ( !editingTextObj || !onlyChanged )
444 _painter->drawRect( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX( ow - 2 * pw),
445 _zoomHandler->zoomItY( oh - 2 * pw) );
448 drawText( _painter, _zoomHandler, onlyChanged, cursor, resetChanged );
455 if ( m_doc->firstView() && m_doc->firstView()->getCanvas()->getEditMode() &&
456 getDrawEditRect() && getPen().style() == TQt::NoPen )
460 _painter->setPen( TQPen( TQt::gray, 1, TQt::DotLine ) );
461 _painter->setBrush( TQt::NoBrush );
462 _painter->setRasterOp( TQt::NotXorROP );
463 _painter->drawRect( 0, 0, _zoomHandler->zoomItX(ow), _zoomHandler->zoomItY( oh) );
471void KPrTextObject::drawText( TQPainter* _painter, KoTextZoomHandler *zoomHandler,
bool onlyChanged, KoTextCursor* cursor,
bool resetChanged )
474 recalcVerticalAlignment();
475 TQColorGroup cg = TQApplication::palette().active();
477 _painter->translate( m_doc->zoomHandler()->zoomItX( bLeft()), m_doc->zoomHandler()->zoomItY( bTop()+alignVertical));
478 if ( !editingTextObj || (_painter->device() && _painter->device()->devType() == TQInternal::Printer))
479 cg.setBrush( TQColorGroup::Base, TQt::NoBrush );
481 cg.setColor( TQColorGroup::Base, m_doc->txtBackCol() );
483 TQRect r = zoomHandler->zoomRect( KoRect( 0, 0, innerWidth(), innerHeight() ) );
484 bool editMode =
false;
485 if( m_doc->firstView() && m_doc->firstView()->getCanvas())
486 editMode = m_doc->firstView()->getCanvas()->getEditMode();
488 uint drawingFlags = 0;
489 if ( _painter->device() && _painter->device()->devType() != TQInternal::Printer )
490 drawingFlags |= KoTextDocument::DrawSelections;
491 if ( m_doc->backgroundSpellCheckEnabled() && editMode )
492 drawingFlags |= KoTextDocument::DrawMisspelledLine;
494 drawingFlags |= KoTextDocument::DontDrawNoteVariable;
495 if ( m_doc->viewFormattingChars() && editMode )
496 drawingFlags |= KoTextDocument::DrawFormattingChars;
504 drawParags( _painter, zoomHandler, cg, ( onlyCurrStep ? subPresStep : 0 ), subPresStep );
507 textDocument()->drawWYSIWYG(
508 _painter, r.x(), r.y(), r.width(), r.height(),
510 onlyChanged, cursor != 0, cursor, resetChanged, drawingFlags );
517 textDocument()->drawWYSIWYG(
518 _painter, r.x(), r.y(), r.width(), r.height(),
520 onlyChanged, cursor != 0, cursor, resetChanged, drawingFlags );
525int KPrTextObject::getSubPresSteps()
const
528 KoTextParag * parag = textDocument()->firstParag();
529 for ( ; parag ; parag = parag->next() )
535TQDomElement KPrTextObject::saveKTextObject( TQDomDocument& doc )
538 KTextEditParag *parag = ktextobject.document()->firstParag();
539 KTextEditDocument::TextSettings textSettings = ktextobject.document()->textSettings();
542 TQDomElement textobj=doc.createElement(tagTEXTOBJ);
543 if ( isProtectContent() )
544 textobj.setAttribute(
"protectcontent", (
int)isProtectContent());
546 textobj.setAttribute(
"bleftpt", bleft );
548 textobj.setAttribute(
"brightpt", bright );
550 textobj.setAttribute(
"btoppt", btop );
552 textobj.setAttribute(
"bbottompt", bbottom );
553 if ( m_textVertAlign != KP_TOP )
555 if ( m_textVertAlign == KP_BOTTOM )
556 textobj.setAttribute(
"verticalAlign",
"bottom" );
557 else if ( m_textVertAlign == KP_CENTER )
558 textobj.setAttribute(
"verticalAlign",
"center" );
559 else if ( m_textVertAlign == KP_TOP )
560 textobj.setAttribute(
"verticalAlign",
"top" );
561 textobj.setAttribute(
"verticalValue",alignVertical );
564 textobj.setAttribute(attrLineSpacing, ktextobject.document()->lineSpacing());
565 textobj.setAttribute(attrParagSpacing, ktextobject.document()->paragSpacing());
566 textobj.setAttribute(attrMargin, ktextobject.document()->margin());
567 textobj.setAttribute(attrBulletType1, (
int)textSettings.bulletType[0]);
568 textobj.setAttribute(attrBulletType2, (
int)textSettings.bulletType[1]);
569 textobj.setAttribute(attrBulletType3, (
int)textSettings.bulletType[2]);
570 textobj.setAttribute(attrBulletType4, (
int)textSettings.bulletType[3]);
571 textobj.setAttribute(attrBulletColor1, textSettings.bulletColor[0].name());
572 textobj.setAttribute(attrBulletColor2, textSettings.bulletColor[1].name());
573 textobj.setAttribute(attrBulletColor3, textSettings.bulletColor[2].name());
574 textobj.setAttribute(attrBulletColor4, textSettings.bulletColor[3].name());
576 KoTextParag *parag =
static_cast<KoTextParag*
> (textDocument()->firstParag());
579 saveParagraph( doc, parag, textobj, 0, parag->length()-2 );
580 parag =
static_cast<KoTextParag*
>( parag->next());
585void KPrTextObject::saveFormat( TQDomElement & element, KoTextFormat*lastFormat )
587 TQString tmpFamily, tmpColor, tmpTextBackColor;
588 unsigned int tmpBold=
false, tmpItalic=
false, tmpUnderline=
false,tmpStrikeOut=
false;
589 int tmpVerticalAlign=-1;
591 tmpFamily=lastFormat->font().family();
592 tmpBold=
static_cast<unsigned int>(lastFormat->font().bold());
593 tmpItalic=
static_cast<unsigned int>(lastFormat->font().italic());
594 tmpUnderline=
static_cast<unsigned int>(lastFormat->underline());
595 tmpStrikeOut=
static_cast<unsigned int>(lastFormat->strikeOut());
596 tmpColor=lastFormat->color().name();
597 tmpVerticalAlign=
static_cast<unsigned int>(lastFormat->vAlign());
598 if(lastFormat->textBackgroundColor().isValid())
599 tmpTextBackColor=lastFormat->textBackgroundColor().name();
601 element.setAttribute(attrFamily, tmpFamily);
602 element.setAttribute(attrPointSize, lastFormat->pointSize());
605 element.setAttribute(attrBold, tmpBold);
607 element.setAttribute(attrItalic, tmpItalic);
608 if ( lastFormat->underlineType()!= KoTextFormat::U_NONE )
610 if(lastFormat->doubleUnderline())
611 element.setAttribute(attrUnderline,
"double");
612 if(lastFormat->underlineType()==KoTextFormat::U_SIMPLE_BOLD)
613 element.setAttribute(attrUnderline,
"single-bold");
614 else if( lastFormat->underlineType()==KoTextFormat::U_WAVE)
615 element.setAttribute(attrUnderline,
"wave");
616 else if(tmpUnderline)
617 element.setAttribute(attrUnderline, tmpUnderline);
618 TQString strLineType=KoTextFormat::underlineStyleToString( lastFormat->underlineStyle() );
619 element.setAttribute(
"underlinestyleline", strLineType );
620 if ( lastFormat->textUnderlineColor().isValid() )
621 element.setAttribute(
"underlinecolor", lastFormat->textUnderlineColor().name() );
623 if ( lastFormat->strikeOutType()!= KoTextFormat::S_NONE )
625 if ( lastFormat->doubleStrikeOut() )
626 element.setAttribute(attrStrikeOut,
"double");
627 else if ( lastFormat->strikeOutType()== KoTextFormat::S_SIMPLE_BOLD)
628 element.setAttribute(attrStrikeOut,
"single-bold");
629 else if(tmpStrikeOut)
630 element.setAttribute(attrStrikeOut, tmpStrikeOut);
631 TQString strLineType=KoTextFormat::strikeOutStyleToString( lastFormat->strikeOutStyle() );
632 element.setAttribute(
"strikeoutstyleline", strLineType );
635 element.setAttribute(attrColor, tmpColor);
637 if(!tmpTextBackColor.isEmpty())
638 element.setAttribute(attrTextBackColor, tmpTextBackColor);
639 if(tmpVerticalAlign!=-1)
641 element.setAttribute(attrVertAlign,tmpVerticalAlign);
642 if(lastFormat->relativeTextSize()!=0.66)
643 element.setAttribute(
"relativetextsize",lastFormat->relativeTextSize());
646 if ( lastFormat->shadowDistanceX() != 0
647 || lastFormat->shadowDistanceY() != 0)
648 element.setAttribute(
"text-shadow", lastFormat->shadowAsCss());
649 if ( lastFormat->offsetFromBaseLine()!=0 )
650 element.setAttribute(
"offsetfrombaseline" , lastFormat->offsetFromBaseLine());
651 if ( lastFormat->wordByWord() )
652 element.setAttribute(
"wordbyword",
true);
653 if ( lastFormat->attributeFont()!= KoTextFormat::ATT_NONE )
654 element.setAttribute(
"fontattribute", KoTextFormat::attributeFontToString(lastFormat->attributeFont() ));
655 if ( !lastFormat->language().isEmpty())
656 element.setAttribute(
"language", lastFormat->language());
659TQDomElement KPrTextObject::saveHelper(
const TQString &tmpText,KoTextFormat*lastFormat , TQDomDocument &doc)
661 TQDomElement element=doc.createElement(tagTEXT);
663 saveFormat ( element, lastFormat );
665 if(tmpText.stripWhiteSpace().isEmpty())
667 element.setAttribute(attrWhitespace, tmpText.length());
668 element.appendChild(doc.createTextNode(tmpText));
672void KPrTextObject::fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles )
const
674 KPr2DObject::fillStyle( styleObjectAuto, mainStyles );
675 saveOasisMarginElement( styleObjectAuto );
678void KPrTextObject::loadKTextObject(
const TQDomElement &elem )
680 TQDomElement e = elem.firstChild().toElement();
681 KoTextParag *lastParag =
static_cast<KoTextParag *
>(textDocument()->firstParag());
686 int lineSpacing = elem.attribute( attrLineSpacing ).toInt();
687 int bottomBorder = elem.attribute( attrParagSpacing ).toInt();
690 while ( !e.isNull() ) {
691 TQValueList<TQDomElement> listVariable;
692 listVariable.clear();
694 if ( e.tagName() == tagP ) {
695 TQDomElement n = e.firstChild().toElement();
698 if( e.hasAttribute( attrType ) && n.hasAttribute( attrWhitespace ) )
699 if ( e.attribute( attrType )!=
"0" && n.attribute( attrWhitespace )==
"1" ) {
700 e = e.nextSibling().toElement();
704 KoParagLayout paragLayout = loadParagLayout(e, m_doc,
true);
708 if( e.hasAttribute(attrDepth) ) {
709 depth = e.attribute( attrDepth ).toDouble();
710 paragLayout.margins[TQStyleSheetItem::MarginLeft] = depth * MM_TO_POINT(10.0);
717 if( e.hasAttribute(attrType) )
718 type = e.attribute( attrType );
725 if(!paragLayout.counter)
726 paragLayout.counter =
new KoParagCounter;
727 paragLayout.counter->setStyle(KoParagCounter::STYLE_DISCBULLET);
728 paragLayout.counter->setNumbering(KoParagCounter::NUM_LIST);
729 paragLayout.counter->setPrefix(TQString());
730 paragLayout.counter->setSuffix(TQString());
734 if ( e.hasAttribute( attrLineSpacing ) )
735 lineSpacing = e.attribute( attrLineSpacing ).toInt();
736 if ( e.hasAttribute(
"distBefore" ) )
737 topBorder = e.attribute(
"distBefore" ).toInt();
738 if ( e.hasAttribute(
"distAfter" ) )
739 bottomBorder = e.attribute(
"distAfter" ).toInt();
742 if ( paragLayout.lineSpacingValue() == 0 )
743 paragLayout.setLineSpacingValue(lineSpacing);
744 if ( paragLayout.margins[ TQStyleSheetItem::MarginTop ] == 0 )
745 paragLayout.margins[ TQStyleSheetItem::MarginTop ] = topBorder;
746 if ( paragLayout.margins[ TQStyleSheetItem::MarginBottom ] == 0 )
747 paragLayout.margins[ TQStyleSheetItem::MarginBottom ] = bottomBorder;
748 lastParag->setParagLayout( paragLayout );
751 if(e.hasAttribute(attrAlign))
753 int tmpAlign=e.attribute( attrAlign ).toInt();
754 if(tmpAlign==1 || tmpAlign==0 )
755 lastParag->setAlign(TQt::AlignLeft);
757 lastParag->setAlign(TQt::AlignRight);
759 lastParag->setAlign(TQt::AlignHCenter);
761 lastParag->setAlign(TQt::AlignJustify);
763 kdDebug(33001) <<
"Error in e.attribute( attrAlign ).toInt()" << endl;
768 bool firstTextTag =
true;
769 while ( !n.isNull() ) {
770 if ( n.tagName() == tagTEXT ) {
772 if ( firstTextTag ) {
773 lastParag->remove( 0, 1 );
774 firstTextTag =
false;
776 KoTextFormat fm = loadFormat( n, lastParag->paragraphFormat(), m_doc->defaultFont(), m_doc->globalLanguage(),
777 m_doc->globalHyphenation() );
779 TQString txt = n.firstChild().toText().data();
781 if(n.hasAttribute(attrWhitespace)) {
782 int ws=n.attribute(attrWhitespace).toInt();
785 n=n.nextSibling().toElement();
788 lastParag->append( txt,
true );
789 lastParag->setFormat( i, txt.length(), textDocument()->formatCollection()->format( &fm ) );
793 else if ( n.tagName() ==
"CUSTOM" )
795 listVariable.append( n );
796 n = n.nextSibling().toElement();
799 n = n.nextSibling().toElement();
801 }
else if ( e.tagName() ==
"UNSORTEDLISTTYPE" ) {
807 e = e.nextSibling().toElement();
808 loadVariable( listVariable,lastParag );
812 if ( !lastParag->length() == 0 )
813 lastParag =
new KoTextParag( textDocument(), lastParag, 0 );
817void KPrTextObject::loadVariable( TQValueList<TQDomElement> & listVariable,KoTextParag *lastParag,
int offset )
819 TQValueList<TQDomElement>::Iterator it = listVariable.begin();
820 TQValueList<TQDomElement>::Iterator end = listVariable.end();
821 for ( ; it != end ; ++it )
823 TQDomElement elem = *it;
824 if ( !elem.hasAttribute(
"pos"))
826 int index = elem.attribute(
"pos").toInt();
828 TQDomElement varElem = elem.namedItem(
"VARIABLE" ).toElement();
829 if ( !varElem.isNull() )
831 TQDomElement typeElem = varElem.namedItem(
"TYPE" ).toElement();
832 int type = typeElem.attribute(
"type" ).toInt();
833 TQString key = typeElem.attribute(
"key" );
835 if (typeElem.hasAttribute(
"correct" ))
836 correct = typeElem.attribute(
"correct").toInt();
837 kdDebug(33001) <<
"loadKTextObject variable type=" << type <<
" key=" << key << endl;
838 KoVariableFormat * varFormat = key.isEmpty() ? 0 : m_doc->variableFormatCollection()->format( key.latin1() );
840 KoVariable * var =m_doc->getVariableCollection()->createVariable( type, -1, m_doc->variableFormatCollection(),
841 varFormat, lastParag->textDocument(),
842 m_doc, correct,
true );
845 var->load( varElem );
846 KoTextFormat format = loadFormat( *it, lastParag->paragraphFormat(), m_doc->defaultFont(), m_doc->globalLanguage(),
847 m_doc->globalHyphenation() );
848 lastParag->setCustomItem( index, var, lastParag->document()->formatCollection()->format( &format ));
855KoTextFormat KPrTextObject::loadFormat( TQDomElement &n, KoTextFormat * refFormat,
const TQFont & defaultFont,
856 const TQString & defaultLanguage,
bool hyphen )
859 format.setHyphenation( hyphen );
864 format.setCollection( 0 );
873 TQStringList families = fdb.families();
874 if ( families.findIndex( n.attribute( attrFamily ) ) != -1 )
875 fn.setFamily( n.attribute( attrFamily ) );
879 else if ( !refFormat )
885 int size = n.attribute( attrPointSize ).toInt();
887 if(n.hasAttribute(attrBold))
888 bold = (bool)n.attribute( attrBold ).toInt();
890 if(n.hasAttribute(attrItalic))
891 italic=(
bool)n.attribute( attrItalic ).toInt();
893 if(n.hasAttribute( attrUnderline ))
895 TQString value = n.attribute( attrUnderline );
896 if ( value ==
"double" )
897 format.setUnderlineType ( KoTextFormat::U_DOUBLE);
898 else if ( value ==
"single" )
899 format.setUnderlineType ( KoTextFormat::U_SIMPLE);
900 else if ( value ==
"single-bold" )
901 format.setUnderlineType ( KoTextFormat::U_SIMPLE_BOLD);
902 else if( value ==
"wave" )
903 format.setUnderlineType( KoTextFormat::U_WAVE);
905 format.setUnderlineType ( (
bool)value.toInt() ? KoTextFormat::U_SIMPLE :KoTextFormat::U_NONE);
907 if (n.hasAttribute(
"underlinestyleline") )
908 format.setUnderlineStyle( KoTextFormat::stringToUnderlineStyle( n.attribute(
"underlinestyleline") ));
910 if (n.hasAttribute(
"underlinecolor"))
911 format.setTextUnderlineColor(TQColor(n.attribute(
"underlinecolor")));
913 if(n.hasAttribute(attrStrikeOut))
915 TQString value = n.attribute( attrStrikeOut );
916 if ( value ==
"double" )
917 format.setStrikeOutType ( KoTextFormat::S_DOUBLE);
918 else if ( value ==
"single" )
919 format.setStrikeOutType ( KoTextFormat::S_SIMPLE);
920 else if ( value ==
"single-bold" )
921 format.setStrikeOutType ( KoTextFormat::S_SIMPLE_BOLD);
923 format.setStrikeOutType ( (
bool)value.toInt() ? KoTextFormat::S_SIMPLE :KoTextFormat::S_NONE);
926 if (n.hasAttribute(
"strikeoutstyleline"))
928 TQString strLineType = n.attribute(
"strikeoutstyleline");
929 format.setStrikeOutStyle( KoTextFormat::stringToStrikeOutStyle( strLineType ));
932 TQString color = n.attribute( attrColor );
933 fn.setPointSize( size );
935 fn.setItalic( italic );
937 TQColor col( color );
939 format.setFont( fn );
940 format.setColor( col );
941 TQString textBackColor=n.attribute(attrTextBackColor);
942 if(!textBackColor.isEmpty())
944 TQColor tmpCol(textBackColor);
945 tmpCol=tmpCol.isValid() ? tmpCol : TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base );
946 format.setTextBackgroundColor(tmpCol);
948 if(n.hasAttribute(attrVertAlign))
949 format.setVAlign(
static_cast<KoTextFormat::VerticalAlignment
>(n.attribute(attrVertAlign).toInt() ) );
950 if ( n.hasAttribute(
"text-shadow") )
951 format.parseShadowFromCss( n.attribute(
"text-shadow") );
952 if ( n.hasAttribute(
"relativetextsize") )
953 format.setRelativeTextSize( n.attribute(
"relativetextsize").toDouble() ) ;
954 if ( n.hasAttribute(
"offsetfrombaseline") )
955 format.setOffsetFromBaseLine(
static_cast<int>(n.attribute(
"offsetfrombaseline").toInt() ) );
956 if ( n.hasAttribute(
"wordbyword") )
957 format.setWordByWord(
static_cast<int>(n.attribute(
"wordbyword").toInt() ) );
959 if ( n.hasAttribute(
"fontattribute") )
960 format.setAttributeFont( KoTextFormat::stringToAttributeFont(n.attribute(
"fontattribute") ) );
961 if ( n.hasAttribute(
"language"))
962 format.setLanguage( n.attribute(
"language"));
965 format.setLanguage( defaultLanguage);
972KoParagLayout KPrTextObject::loadParagLayout( TQDomElement & parentElem, KPrDocument *doc,
bool findStyle)
974 KoParagLayout layout;
982 TQDomElement element = parentElem.namedItem(
"NAME" ).toElement();
983 if ( !element.isNull() )
985 TQString styleName = element.attribute(
"value" );
986 style = doc->styleCollection()->findStyle( styleName );
989 kdError(33001) <<
"Cannot find style \"" << styleName <<
"\" specified in paragraph LAYOUT - using Standard" << endl;
990 style = doc->styleCollection()->findStyle(
"Standard" );
996 kdError(33001) <<
"Missing NAME tag in paragraph LAYOUT - using Standard" << endl;
997 style = doc->styleCollection()->findStyle(
"Standard" );
1000 layout.style = style;
1003 TQDomElement element = parentElem.namedItem(
"INDENTS" ).toElement();
1004 if ( !element.isNull() )
1007 if(element.hasAttribute(
"first"))
1008 val=element.attribute(
"first").toDouble();
1009 layout.margins[TQStyleSheetItem::MarginFirstLine] = val;
1011 if(element.hasAttribute(
"left"))
1013 val=TQMAX(0, element.attribute(
"left").toDouble());
1014 layout.margins[TQStyleSheetItem::MarginLeft] = val;
1016 if(element.hasAttribute(
"right"))
1018 val=TQMAX(0, element.attribute(
"right").toDouble());
1019 layout.margins[TQStyleSheetItem::MarginRight] = val;
1021 element = parentElem.namedItem(
"LINESPACING" ).toElement();
1022 if ( !element.isNull() )
1025 if ( element.hasAttribute(
"value" ))
1027 TQString value = element.attribute(
"value" );
1028 if ( value ==
"oneandhalf" )
1030 layout.lineSpacingType = KoParagLayout::LS_ONEANDHALF;
1031 layout.setLineSpacingValue(0);
1033 else if ( value ==
"double" )
1035 layout.lineSpacingType = KoParagLayout::LS_DOUBLE;
1036 layout.setLineSpacingValue(0);
1040 layout.lineSpacingType = KoParagLayout::LS_CUSTOM;
1041 layout.setLineSpacingValue(value.toDouble());
1046 TQString type = element.attribute(
"type" );
1047 if ( type ==
"oneandhalf" )
1049 layout.lineSpacingType = KoParagLayout::LS_ONEANDHALF;
1050 layout.setLineSpacingValue(0);
1052 else if ( type ==
"double" )
1054 layout.lineSpacingType = KoParagLayout::LS_DOUBLE;
1055 layout.setLineSpacingValue(0);
1057 else if ( type ==
"custom" )
1059 layout.lineSpacingType = KoParagLayout::LS_CUSTOM;
1060 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1062 else if ( type ==
"atleast" )
1064 layout.lineSpacingType = KoParagLayout::LS_AT_LEAST;
1065 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1067 else if ( type ==
"multiple" )
1069 layout.lineSpacingType = KoParagLayout::LS_MULTIPLE;
1070 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1075 element = parentElem.namedItem(
"OFFSETS" ).toElement();
1076 if ( !element.isNull() )
1079 if(element.hasAttribute(
"before"))
1080 val=TQMAX(0, element.attribute(
"before").toDouble());
1081 layout.margins[TQStyleSheetItem::MarginTop] = val;
1083 if(element.hasAttribute(
"after"))
1084 val=TQMAX(0, element.attribute(
"after").toDouble());
1085 layout.margins[TQStyleSheetItem::MarginBottom] = val;
1089 element = parentElem.namedItem(
"LEFTBORDER" ).toElement();
1090 if ( !element.isNull() )
1091 layout.leftBorder = KoBorder::loadBorder( element );
1093 layout.leftBorder.setPenWidth( 0);
1095 element = parentElem.namedItem(
"RIGHTBORDER" ).toElement();
1096 if ( !element.isNull() )
1097 layout.rightBorder = KoBorder::loadBorder( element );
1099 layout.rightBorder.setPenWidth( 0);
1101 element = parentElem.namedItem(
"TOPBORDER" ).toElement();
1102 if ( !element.isNull() )
1103 layout.topBorder = KoBorder::loadBorder( element );
1105 layout.topBorder.setPenWidth(0);
1107 element = parentElem.namedItem(
"BOTTOMBORDER" ).toElement();
1108 if ( !element.isNull() )
1109 layout.bottomBorder = KoBorder::loadBorder( element );
1111 layout.bottomBorder.setPenWidth(0);
1113 element = parentElem.namedItem(
"COUNTER" ).toElement();
1114 if ( !element.isNull() )
1116 layout.counter =
new KoParagCounter;
1117 layout.counter->load( element );
1120 KoTabulatorList tabList;
1121 element = parentElem.firstChild().toElement();
1122 for ( ; !element.isNull() ; element = element.nextSibling().toElement() )
1124 if ( element.tagName() ==
"TABULATOR" )
1128 if(element.hasAttribute(
"type"))
1129 tab.type =
static_cast<KoTabulators
>( element.attribute(
"type").toInt());
1131 if(element.hasAttribute(
"ptpos"))
1132 tab.ptPos=element.attribute(
"ptpos").toDouble();
1133 tab.filling=TF_BLANK;
1134 if(element.hasAttribute(
"filling"))
1135 tab.filling =
static_cast<KoTabulatorFilling
>( element.attribute(
"filling").toInt());
1137 if(element.hasAttribute(
"width"))
1138 tab.ptWidth=element.attribute(
"width").toDouble();
1139 tabList.append( tab );
1142 layout.setTabList( tabList );
1148void KPrTextObject::saveParagLayout(
const KoParagLayout& layout, TQDomElement & parentElem )
1150 TQDomDocument doc = parentElem.ownerDocument();
1151 TQDomElement element = doc.createElement(
"NAME" );
1152 parentElem.appendChild( element );
1154 element.setAttribute(
"value", layout.style->name() );
1156 kdWarning() <<
"KWTextParag::saveParagLayout: style==0L!" << endl;
1159 if ( layout.margins[TQStyleSheetItem::MarginFirstLine] != 0 ||
1160 layout.margins[TQStyleSheetItem::MarginLeft] != 0 ||
1161 layout.margins[TQStyleSheetItem::MarginRight] != 0 )
1163 element = doc.createElement(
"INDENTS" );
1164 parentElem.appendChild( element );
1165 if ( layout.margins[TQStyleSheetItem::MarginFirstLine] != 0 )
1166 element.setAttribute(
"first", layout.margins[TQStyleSheetItem::MarginFirstLine] );
1167 if ( layout.margins[TQStyleSheetItem::MarginLeft] != 0 )
1168 element.setAttribute(
"left", layout.margins[TQStyleSheetItem::MarginLeft] );
1169 if ( layout.margins[TQStyleSheetItem::MarginRight] != 0 )
1170 element.setAttribute(
"right", layout.margins[TQStyleSheetItem::MarginRight] );
1174 if ( layout.margins[TQStyleSheetItem::MarginTop] != 0 ||
1175 layout.margins[TQStyleSheetItem::MarginBottom] != 0 )
1177 element = doc.createElement(
"OFFSETS" );
1178 parentElem.appendChild( element );
1179 if ( layout.margins[TQStyleSheetItem::MarginTop] != 0 )
1180 element.setAttribute(
"before", layout.margins[TQStyleSheetItem::MarginTop] );
1181 if ( layout.margins[TQStyleSheetItem::MarginBottom] != 0 )
1182 element.setAttribute(
"after", layout.margins[TQStyleSheetItem::MarginBottom] );
1185 if ( layout.lineSpacingType != KoParagLayout::LS_SINGLE )
1187 element = doc.createElement(
"LINESPACING" );
1188 parentElem.appendChild( element );
1189 if ( layout.lineSpacingType == KoParagLayout::LS_ONEANDHALF )
1190 element.setAttribute(
"type",
"oneandhalf" );
1191 else if ( layout.lineSpacingType == KoParagLayout::LS_DOUBLE )
1192 element.setAttribute(
"type",
"double" );
1193 else if ( layout.lineSpacingType == KoParagLayout::LS_CUSTOM )
1195 element.setAttribute(
"type",
"custom" );
1196 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1198 else if ( layout.lineSpacingType == KoParagLayout::LS_AT_LEAST )
1200 element.setAttribute(
"type",
"atleast" );
1201 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1203 else if ( layout.lineSpacingType == KoParagLayout::LS_MULTIPLE )
1205 element.setAttribute(
"type",
"multiple" );
1206 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1209 kdDebug(33001) <<
" error in lineSpacing Type" << endl;
1212 if ( layout.leftBorder.penWidth() > 0 )
1214 element = doc.createElement(
"LEFTBORDER" );
1215 parentElem.appendChild( element );
1216 layout.leftBorder.save( element );
1218 if ( layout.rightBorder.penWidth() > 0 )
1220 element = doc.createElement(
"RIGHTBORDER" );
1221 parentElem.appendChild( element );
1222 layout.rightBorder.save( element );
1224 if ( layout.topBorder.penWidth() > 0 )
1226 element = doc.createElement(
"TOPBORDER" );
1227 parentElem.appendChild( element );
1228 layout.topBorder.save( element );
1230 if ( layout.bottomBorder.penWidth() > 0 )
1232 element = doc.createElement(
"BOTTOMBORDER" );
1233 parentElem.appendChild( element );
1234 layout.bottomBorder.save( element );
1237 if ( layout.counter && layout.counter->numbering() != KoParagCounter::NUM_NONE )
1239 element = doc.createElement(
"COUNTER" );
1240 parentElem.appendChild( element );
1241 if (layout.counter )
1242 layout.counter->save( element );
1245 KoTabulatorList tabList = layout.tabList();
1246 KoTabulatorList::ConstIterator it = tabList.begin();
1247 for ( ; it != tabList.end() ; it++ )
1249 element = doc.createElement(
"TABULATOR" );
1250 parentElem.appendChild( element );
1251 element.setAttribute(
"type", (*it).type );
1252 element.setAttribute(
"ptpos", (*it).ptPos );
1253 element.setAttribute(
"filling", (*it).filling );
1254 element.setAttribute(
"width", (*it).ptWidth );
1258void KPrTextObject::recalcPageNum( KPrPage *page )
1260 int pgnum=m_doc->pageList().findRef(page);
1263 TQPtrListIterator<KoTextCustomItem> cit( textDocument()->allCustomItems() );
1264 for ( ; cit.current() ; ++cit )
1267 if ( var && !var->isDeleted() )
1269 switch ( var->subType() ) {
1270 case KPrPgNumVariable::VST_PGNUM_CURRENT:
1271 var->setPgNum( pgnum + kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber()-1);
1273 case KPrPgNumVariable::VST_CURRENT_SECTION:
1274 var->setSectionTitle( page->pageTitle() );
1276 case KPrPgNumVariable::VST_PGNUM_PREVIOUS:
1277 var->setPgNum( TQMAX( pgnum -1 , 0) +
1278 kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber());
1280 case KPrPgNumVariable::VST_PGNUM_NEXT:
1281 var->setPgNum( TQMIN( (
int)m_doc->getPageNums(), pgnum+1 ) +
1282 kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber());
1289 var->paragraph()->invalidate( 0 );
1290 var->paragraph()->setChanged(
true );
1295void KPrTextObject::layout()
1299 m_textobj->formatMore( 2 );
1302void KPrTextObject::invalidate()
1305 m_textobj->setLastFormattedParag( textDocument()->firstParag() );
1306 textDocument()->formatter()->setViewFormattingChars( m_doc->viewFormattingChars() );
1307 textDocument()->invalidate();
1311void KPrTextObject::drawParags( TQPainter *painter, KoTextZoomHandler* zoomHandler,
const TQColorGroup& cg,
int from,
int to )
1318 Q_ASSERT( from <= to );
1320 bool editMode=
false;
1321 if( m_doc->firstView() && m_doc->firstView()->getCanvas())
1322 editMode = m_doc->firstView()->getCanvas()->getEditMode();
1324 TQRect r = zoomHandler->zoomRect( KoRect( 0, 0, innerWidth(), innerHeight() ) );
1325 KoTextParag *parag = textDocument()->firstParag();
1327 if ( !parag->isValid() )
1330 r.setTop( m_doc->zoomHandler()->layoutUnitToPixelY( parag->rect().top() ) );
1332 r.setBottom( m_doc->zoomHandler()->layoutUnitToPixelY( parag->rect().bottom() ) );
1336 parag = parag->next();
1339 uint drawingFlags = 0;
1340 if ( m_doc->backgroundSpellCheckEnabled() && editMode )
1341 drawingFlags |= KoTextDocument::DrawMisspelledLine;
1342 textDocument()->drawWYSIWYG(
1343 painter, r.x(), r.y(), r.width(), r.height(),
1344 cg, m_doc->zoomHandler(),
1346 true , drawingFlags );
1349void KPrTextObject::drawCursor( TQPainter *p, KoTextCursor *cursor,
bool cursorVisible,
KPrCanvas* canvas )
1352 KoTextZoomHandler *zh = m_doc->zoomHandler();
1353 TQPoint origPix = zh->zoomPoint( orig+KoPoint(bLeft(), bTop()+alignVertical) );
1355 p->translate( origPix.x(), origPix.y() );
1357 rotateObject( p, zh );
1359 KoTextParag* parag = cursor->parag();
1360 TQPoint topLeft = parag->rect().topLeft();
1363 int cursorHeight = zh->layoutUnitToPixelY( topLeft.y(), parag->lineHeightOfChar( cursor->index(), 0, &lineY ) );
1364 TQPoint iPoint( topLeft.x() + cursor->x(),
1365 topLeft.y() + lineY );
1367 iPoint = zh->layoutUnitToPixel( iPoint );
1369 TQPoint vPoint = iPoint;
1375 TQRect clip( vPoint.x() - 5, vPoint.y() , 10, cursorHeight );
1376 setupClipRegion( p, clip );
1382 TQColorGroup cg = TQApplication::palette().active();
1383 cg.setColor( TQColorGroup::Base, m_doc->txtBackCol() );
1385 uint drawingFlags = KoTextDocument::DrawSelections;
1386 if ( m_doc->backgroundSpellCheckEnabled() )
1387 drawingFlags |= KoTextDocument::DrawMisspelledLine;
1388 if ( m_doc->viewFormattingChars() )
1389 drawingFlags |= KoTextDocument::DrawFormattingChars;
1392 bool wasChanged = parag->hasChanged();
1393 int oldLineChanged = parag->lineChanged();
1395 parag->lineStartOfChar( cursor->index(), 0, &line );
1396 parag->setChanged(
false );
1397 parag->setLineChanged( line );
1400 textDocument()->drawParagWYSIWYG(
1402 TQMAX(0, iPoint.x() - 5),
1403 iPoint.y(), clip.width(), clip.height(),
1404 pix, cg, m_doc->zoomHandler(),
1405 cursorVisible, cursor,
false , drawingFlags );
1408 cursor->parag()->setLineChanged( oldLineChanged );
1410 cursor->parag()->setChanged(
false );
1413 TQPoint ximPoint = vPoint;
1414 TQFont f = parag->at( cursor->index() )->format()->font();
1415 canvas->setXimPosition( ximPoint.x() + origPix.x(), ximPoint.y() + origPix.y(),
1416 0, cursorHeight - parag->lineSpacing( line ), &f );
1424void KPrTextObject::slotNewCommand( KCommand * cmd)
1426 m_doc->addCommand(cmd);
1429int KPrTextObject::availableHeight()
const
1431 return m_textobj->availableHeight();
1434void KPrTextObject::slotAvailableHeightNeeded()
1436 int ah = m_doc->zoomHandler()->ptToLayoutUnitPixY( innerHeight() );
1437 m_textobj->setAvailableHeight( ah );
1441void KPrTextObject::slotRepaintChanged()
1443 emit repaintChanged(
this );
1446KPrTextView * KPrTextObject::createKPTextView(
KPrCanvas * _canvas,
bool temp )
1448 return new KPrTextView(
this, _canvas, temp );
1451void KPrTextObject::removeHighlight ()
1453 m_textobj->removeHighlight(
true );
1456void KPrTextObject::highlightPortion( KoTextParag * parag,
int index,
int length,
KPrCanvas* canvas,
bool repaint, KDialogBase* dialog )
1458 m_textobj->highlightPortion( parag, index, length, repaint );
1461 KPrDocument* doc = canvas->getView()->kPresenterDoc();
1464 if ( canvas->activePage()->findTextObject(
this ) )
1466 kdDebug(33001) << k_funcinfo <<
"object in current page" << endl;
1472 KPrPage* page = doc->findPage(
this );
1474 int pageNum = doc->pageList().findRef( page );
1478 canvas->getView()->skipToPage( pageNum );
1481 kdWarning(33001) <<
"object " <<
this <<
" not found in any page!?" << endl;
1484 TQRect rect = m_doc->zoomHandler()->zoomRect( getRect() );
1485 TQRect expose = m_doc->zoomHandler()->layoutUnitToPixel( parag->rect() );
1486 expose.moveBy( rect.x(), rect.y() );
1487 canvas->ensureVisible( (expose.left()+expose.right()) / 2,
1488 (expose.top()+expose.bottom()) / 2,
1489 (expose.right()-expose.left()) / 2,
1490 (expose.bottom()-expose.top()) / 2);
1491#if KDE_IS_VERSION(3,1,90)
1493 TQRect globalRect( expose );
1494 globalRect.moveTopLeft( canvas->mapToGlobal( globalRect.topLeft() ) );
1495 KDialog::avoidArea( dialog, globalRect );
1501KCommand * KPrTextObject::pasteOasis( KoTextCursor * cursor,
const TQByteArray & data,
bool removeSelected )
1504 KMacroCommand * macroCmd =
new KMacroCommand( i18n(
"Paste Text") );
1505 if ( removeSelected && textDocument()->hasSelection( KoTextDocument::Standard ) )
1506 macroCmd->addCommand( m_textobj->removeSelectedTextCommand( cursor, KoTextDocument::Standard ) );
1507 m_textobj->emitHideCursor();
1508 m_textobj->setLastFormattedParag( cursor->parag()->prev() ?
1509 cursor->parag()->prev() : cursor->parag() );
1514 textDocument()->addCommand( cmd );
1516 macroCmd->addCommand(
new KoTextCommand( m_textobj, TQString() ) );
1517 *cursor = *( cmd->execute( cursor ) );
1519 m_textobj->formatMore( 2 );
1520 emit repaintChanged(
this );
1521 m_textobj->emitEnsureCursorVisible();
1522 m_textobj->emitUpdateUI(
true );
1523 m_textobj->emitShowCursor();
1524 m_textobj->selectionChangedNotify();
1529void KPrTextObject::setShadowParameter(
int _distance,ShadowDirection _direction,
const TQColor &_color)
1533 switch ( _direction )
1535 case SD_LEFT_BOTTOM:
1541 case SD_RIGHT_BOTTOM:
1546 switch ( _direction )
1552 case SD_LEFT_BOTTOM:
1554 case SD_RIGHT_BOTTOM:
1559 KoTextFormat tmpFormat;
1560 tmpFormat.setShadow( sx, sy, _color );
1561 KCommand* cmd = m_textobj->setFormatCommand( &tmpFormat, KoTextFormat::ShadowText );
1563 m_doc->addCommand(cmd);
1566void KPrTextObject::slotFormatChanged(
const KoTextFormat &_format)
1568 if(m_doc && m_doc->firstView())
1569 m_doc->firstView()->showFormat( _format );
1572void KPrTextObject::applyStyleChange( KoStyleChangeDefMap changed )
1574 m_textobj->applyStyleChange( changed );
1577void KPrTextObject::slotAfterFormatting(
int bottom, KoTextParag* lastFormatted,
bool* abort)
1579 recalcVerticalAlignment();
1580 int availHeight = availableHeight() - m_doc->zoomHandler()->ptToLayoutUnitPixY(alignmentValue());
1581 if ( ( bottom > availHeight ) ||
1582 ( lastFormatted && (bottom + lastFormatted->rect().height() > availHeight) ) )
1584 int difference = ( bottom + 2 ) - availHeight;
1585 if( lastFormatted && bottom + lastFormatted->rect().height() > availHeight )
1587 difference += lastFormatted->rect().height();
1591 kdDebug(33001) <<
"slotAfterFormatting We need more space in " <<
this
1592 <<
" bottom=" << bottom + lastFormatted->rect().height()
1593 <<
" availHeight=" << availHeight
1594 <<
" ->difference=" << difference << endl;
1596 kdDebug(33001) <<
"slotAfterFormatting We need more space in " <<
this
1597 <<
" bottom2=" << bottom <<
" availHeight=" << availHeight
1598 <<
" ->difference=" << difference << endl;
1601 if(difference > 0 && !isProtect())
1603 double wantedPosition = m_doc->zoomHandler()->layoutUnitPtToPt( m_doc->zoomHandler()->pixelYToPt( difference ) )
1604 + getRect().bottom();
1605 const KoPageLayout& p = m_doc->pageLayout();
1606 double pageBottom = p.ptHeight - p.ptBottom;
1607 double newBottom = TQMIN( wantedPosition, pageBottom );
1608 newBottom = TQMAX( newBottom, getOrig().y() );
1610 if ( getRect().bottom() != newBottom )
1614 KPrObject::setSize( getSize().width(), newBottom - getOrig().y() );
1616 slotAvailableHeightNeeded();
1617 m_doc->updateRuler();
1618 m_doc->repaint(
true );
1622 else if ( isProtect() )
1623 m_textobj->setLastFormattedParag( 0 );
1628KCommand * KPrTextObject::textContentsToHeight()
1634 KoTextParag * parag = textDocument()->firstParag();
1636 int textHeightLU = 0;
1637 bool lineSpacingEqual =
false;
1638 int oldLineSpacing = 0;
1639 for ( ; parag ; parag = parag->next() )
1641 int lines = parag->lines();
1643 for (
int line = 0 ; line < lines ; ++line )
1646 parag->lineInfo( line, y, h, baseLine );
1647 int ls = parag->lineSpacing( line );
1648 lineSpacingEqual = (oldLineSpacing == ls);
1649 oldLineSpacing = ls;
1650 textHeightLU += h - ls;
1654 double textHeight = m_doc->zoomHandler()->layoutUnitPtToPt( textHeightLU );
1655 double lineSpacing = ( innerHeight() - textHeight ) / numLines;
1658 if ( KABS( innerHeight() - textHeight ) < DBL_EPSILON )
1660 bool oneLine =(textDocument()->firstParag() == textDocument()->lastParag() && numLines == 1);
1661 if ( lineSpacing < 0 || oneLine)
1664 if ( (oneLine || lineSpacingEqual) && (textDocument()->firstParag()->kwLineSpacing() == lineSpacing))
1667 textDocument()->selectAll( KoTextDocument::Temp );
1668 KCommand* cmd = m_textobj->setLineSpacingCommand( 0L, lineSpacing, KoParagLayout::LS_CUSTOM, KoTextDocument::Temp );
1669 textDocument()->removeSelection( KoTextDocument::Temp );
1674KCommand * KPrTextObject::textObjectToContents()
1680 KoTextParag * parag = textDocument()->firstParag();
1681 double txtWidth = 10;
1682 for ( ; parag ; parag = parag->next() )
1683 txtWidth = TQMAX( txtWidth, m_doc->zoomHandler()->layoutUnitPtToPt( parag->widthUsed() ));
1686 int heightLU = textDocument()->height();
1687 double txtHeight = m_doc->zoomHandler()->layoutUnitPtToPt( heightLU );
1690 KoSize sizeDiff = KoSize( txtWidth, txtHeight ) - innerRect().size();
1691 if( !sizeDiff.isNull() )
1694 return new KPrResizeCmd( TQString(), KoPoint( 0, 0 ), sizeDiff,
this, m_doc);
1699void KPrTextObject::setTextMargins(
double _left,
double _top,
double _right,
double _bottom)
1707KoRect KPrTextObject::innerRect()
const
1709 KoRect inner( getRect());
1710 inner.moveBy( bLeft(), bTop());
1711 inner.setWidth( inner.width() - bLeft() - bRight() );
1712 inner.setHeight( inner.height() - bTop() - bBottom() );
1716double KPrTextObject::innerWidth()
const
1718 return getSize().width() - bLeft() - bRight();
1721double KPrTextObject::innerHeight()
const
1723 return getSize().height() - bTop() - bBottom();
1726void KPrTextObject::setVerticalAligment( VerticalAlignmentType _type)
1728 m_textVertAlign = _type;
1729 recalcVerticalAlignment();
1732void KPrTextObject::recalcVerticalAlignment()
1734 double txtHeight = m_doc->zoomHandler()->layoutUnitPtToPt( m_doc->zoomHandler()->pixelYToPt( textDocument()->height() ) ) + btop + bbottom;
1735 double diffy = getSize().height() - txtHeight;
1739 if ( diffy <= 0.0 ) {
1740 alignVertical = 0.0;
1743 switch( m_textVertAlign )
1746 alignVertical = diffy/2.0;
1749 alignVertical = 0.0;
1752 alignVertical = diffy;
1757TQPoint KPrTextObject::cursorPos(
KPrCanvas *canvas, KoTextCursor *cursor)
const
1759 KoTextZoomHandler *zh = m_doc->zoomHandler();
1760 TQPoint origPix = zh->zoomPoint( orig+KoPoint(bLeft(), bTop()+alignVertical) );
1761 KoTextParag* parag = cursor->parag();
1762 TQPoint topLeft = parag->rect().topLeft();
1766 TQPoint iPoint( topLeft.x() + cursor->x(), topLeft.y() + lineY );
1767 iPoint = zh->layoutUnitToPixel( iPoint );
1768 iPoint.rx() -= canvas->diffx();
1769 iPoint.ry() -= canvas->diffy();
1770 return origPix+iPoint;
1773KPrTextView::KPrTextView( KPrTextObject * txtObj,
KPrCanvas *_canvas,
bool temp )
1774 : KoTextView( txtObj->textObject() )
1776 setBackSpeller( txtObj->kPresenterDocument()->backSpeller() );
1781 connect( txtObj->textObject(), TQ_SIGNAL( selectionChanged(
bool) ),
1782 m_canvas, TQ_SIGNAL( selectionChanged(
bool) ) );
1783 KoTextView::setReadWrite( txtObj->kPresenterDocument()->isReadWrite() );
1784 connect( textView(), TQ_SIGNAL( cut() ), TQ_SLOT( cut() ) );
1785 connect( textView(), TQ_SIGNAL( copy() ), TQ_SLOT( copy() ) );
1786 connect( textView(), TQ_SIGNAL( paste() ), TQ_SLOT( paste() ) );
1787 updateUI(
true,
true );
1789 txtObj->setEditingTextObj(
true );
1792KPrTextView::~KPrTextView()
1796KoTextViewIface* KPrTextView::dcopObject()
1799 dcop =
new KPrTextViewIface(
this );
1804void KPrTextView::terminate(
bool removeSelection)
1806 disconnect( textView()->textObject(), TQ_SIGNAL( selectionChanged(
bool) ),
1807 m_canvas, TQ_SIGNAL( selectionChanged(
bool) ) );
1808 textView()->terminate(removeSelection);
1811void KPrTextView::cut()
1813 if ( textDocument()->hasSelection( KoTextDocument::Standard ) ) {
1815 textObject()->removeSelectedText( cursor() );
1819void KPrTextView::copy()
1822 if ( textDocument()->hasSelection( KoTextDocument::Standard ) ) {
1823 TQDragObject *drag = newDrag( 0 );
1824 TQApplication::clipboard()->setData( drag );
1828void KPrTextView::paste()
1832 TQMimeSource *data = TQApplication::clipboard()->data();
1833 TQCString returnedMimeType = KoTextObject::providesOasis( data );
1834 if ( !returnedMimeType.isEmpty() )
1836 TQByteArray arr = data->encodedData( returnedMimeType );
1840 TQFile paste(
"/tmp/oasis.tmp" );
1841 paste.open( IO_WriteOnly );
1842 paste.writeBlock( arr );
1845 KCommand *cmd = kpTextObject()->pasteOasis( cursor(), arr,
true );
1847 kpTextObject()->kPresenterDocument()->addCommand(cmd);
1854 TQString text = TQApplication::clipboard()->text();
1855 if ( !text.isEmpty() )
1856 textObject()->pasteText( cursor(), text, currentFormat(),
true );
1858 kpTextObject()->layout();
1861void KPrTextView::updateUI(
bool updateFormat,
bool force )
1863 KoTextView::updateUI( updateFormat, force );
1865 KoTextParag * parag =
static_cast<KoTextParag*
>( cursor()->parag());
1866 if ( m_paragLayout.alignment != parag->resolveAlignment() || force ) {
1867 m_paragLayout.alignment = parag->resolveAlignment();
1868 m_canvas->getView()->alignChanged( m_paragLayout.alignment );
1872 if ( !m_paragLayout.counter )
1873 m_paragLayout.counter =
new KoParagCounter;
1874 KoParagCounter::Style cstyle = m_paragLayout.counter->style();
1875 if ( parag->counter() )
1876 *m_paragLayout.counter = *parag->counter();
1879 m_paragLayout.counter->setNumbering( KoParagCounter::NUM_NONE );
1880 m_paragLayout.counter->setStyle( KoParagCounter::STYLE_NONE );
1883 if ( m_paragLayout.counter->style() != cstyle || force )
1884 m_canvas->getView()->showCounter( * m_paragLayout.counter );
1886 if(m_paragLayout.leftBorder!=parag->leftBorder() ||
1887 m_paragLayout.rightBorder!=parag->rightBorder() ||
1888 m_paragLayout.topBorder!=parag->topBorder() ||
1889 m_paragLayout.bottomBorder!=parag->bottomBorder() || force )
1891 m_paragLayout.leftBorder = parag->leftBorder();
1892 m_paragLayout.rightBorder = parag->rightBorder();
1893 m_paragLayout.topBorder = parag->topBorder();
1894 m_paragLayout.bottomBorder = parag->bottomBorder();
1899 if ( !parag->style() )
1900 kdWarning(33001) <<
"Paragraph " << parag->paragId() <<
" has no style" << endl;
1901 else if ( m_paragLayout.style != parag->style() || force )
1903 m_paragLayout.style = parag->style();
1904 m_canvas->getView()->showStyle( m_paragLayout.style->name() );
1907 if( m_paragLayout.margins[TQStyleSheetItem::MarginLeft] != parag->margin(TQStyleSheetItem::MarginLeft)
1908 || m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine] != parag->margin(TQStyleSheetItem::MarginFirstLine)
1909 || m_paragLayout.margins[TQStyleSheetItem::MarginRight] != parag->margin(TQStyleSheetItem::MarginRight)
1912 m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine] = parag->margin(TQStyleSheetItem::MarginFirstLine);
1913 m_paragLayout.margins[TQStyleSheetItem::MarginLeft] = parag->margin(TQStyleSheetItem::MarginLeft);
1914 m_paragLayout.margins[TQStyleSheetItem::MarginRight] = parag->margin(TQStyleSheetItem::MarginRight);
1915 m_canvas->getView()->showRulerIndent( m_paragLayout.margins[TQStyleSheetItem::MarginLeft],
1916 m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine],
1917 m_paragLayout.margins[TQStyleSheetItem::MarginRight],
1918 parag->string()->isRightToLeft() );
1921 if( m_paragLayout.tabList() != parag->tabList() || force )
1923 m_paragLayout.setTabList( parag->tabList() );
1924 KoRuler * hr = m_canvas->getView()->getHRuler();
1926 hr->setTabList( parag->tabList() );
1930void KPrTextView::ensureCursorVisible()
1933 KoTextParag * parag = cursor()->parag();
1934 kpTextObject()->textObject()->ensureFormatted( parag );
1935 KoTextStringChar *chr = parag->at( cursor()->index() );
1936 int h = parag->lineHeightOfChar( cursor()->index() );
1937 int x = parag->rect().x() + chr->x;
1938 int y = 0;
int dummy;
1940 parag->lineHeightOfChar( cursor()->index(), &dummy, &y );
1941 y += parag->rect().y();
1943 KPrDocument *doc= m_kptextobj->kPresenterDocument();
1944 KoPoint pt= kpTextObject()->getOrig();
1945 pt.setX( doc->zoomHandler()->layoutUnitPtToPt( doc->zoomHandler()->pixelXToPt( x) ) +pt.x());
1946 pt.setY( doc->zoomHandler()->layoutUnitPtToPt( doc->zoomHandler()->pixelYToPt( y ))+pt.y() );
1948 TQPoint p = m_kptextobj->kPresenterDocument()->zoomHandler()->zoomPoint( pt );
1949 w = m_kptextobj->kPresenterDocument()->zoomHandler()->layoutUnitToPixelX( w );
1950 h = m_kptextobj->kPresenterDocument()->zoomHandler()->layoutUnitToPixelY( h );
1951 m_canvas->ensureVisible( p.x(), p.y() + h / 2, w, h / 2 + 2 );
1954bool KPrTextView::doCompletion( KoTextCursor* cursor, KoTextParag *parag,
int index )
1956 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1958 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1960 return autoFormat->doCompletion( cursor, parag, index, textObject());
1965bool KPrTextView::doToolTipCompletion( KoTextCursor* cursor, KoTextParag *parag,
int index,
int keyPress )
1967 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1969 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1971 return autoFormat->doToolTipCompletion( cursor, parag, index, textObject(), keyPress);
1975void KPrTextView::showToolTipBox(KoTextParag *parag,
int index, TQWidget *widget,
const TQPoint &pos)
1977 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1979 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1981 autoFormat->showToolTipBox(parag, index, widget, pos);
1985void KPrTextView::removeToolTipCompletion()
1987 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1989 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1991 autoFormat->removeToolTipCompletion();
1994void KPrTextView::textIncreaseIndent()
1996 m_canvas->setTextDepthPlus();
1999bool KPrTextView::textDecreaseIndent()
2001 if (m_paragLayout.margins[TQStyleSheetItem::MarginLeft]>0)
2003 m_canvas->setTextDepthMinus();
2010void KPrTextView::doAutoFormat( KoTextCursor* cursor, KoTextParag *parag,
int index, TQChar ch )
2012 if( m_kptextobj->kPresenterDocument()->allowAutoFormat())
2014 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
2016 autoFormat->doAutoFormat( cursor, parag, index, ch, textObject());
2020bool KPrTextView::doIgnoreDoubleSpace(KoTextParag * parag,
int index,TQChar ch )
2022 if( m_kptextobj->kPresenterDocument()->allowAutoFormat())
2025 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
2027 return autoFormat->doIgnoreDoubleSpace( parag, index,ch );
2032void KPrTextView::startDrag()
2034 textView()->dragStarted();
2035 m_canvas->dragStarted();
2036 TQDragObject *drag = newDrag( m_canvas );
2037 if ( !kpTextObject()->kPresenterDocument()->isReadWrite() )
2041 if ( drag->drag() && TQDragObject::target() != m_canvas )
2042 textObject()->removeSelectedText( cursor() );
2046void KPrTextView::showFormat( KoTextFormat *format )
2048 m_canvas->getView()->showFormat( *format );
2051bool KPrTextView::pgUpKeyPressed()
2053 KoTextCursor *cursor = textView()->cursor();
2054 KoTextParag *s = cursor->parag();
2055 s = textDocument()->firstParag();
2057 textView()->cursor()->setParag( s );
2058 textView()->cursor()->setIndex( 0 );
2062bool KPrTextView::pgDownKeyPressed()
2064 KoTextCursor *cursor = textView()->cursor();
2065 KoTextParag *s = cursor->parag();
2066 s = textDocument()->lastParag();
2067 cursor->setParag( s );
2068 cursor->setIndex( s->length() - 1 );
2072void KPrTextView::keyPressEvent( TQKeyEvent *e )
2075 const TQPoint pos = kpTextObject()->cursorPos(m_canvas, cursor());
2076 textView()->handleKeyPressEvent( e, m_canvas, pos );
2079void KPrTextView::keyReleaseEvent( TQKeyEvent *e )
2081 handleKeyReleaseEvent(e);
2084void KPrTextView::imStartEvent( TQIMEvent *e )
2086 handleImStartEvent(e);
2089void KPrTextView::imComposeEvent( TQIMEvent *e )
2091 handleImComposeEvent(e);
2094void KPrTextView::imEndEvent( TQIMEvent *e )
2096 handleImEndEvent(e);
2099void KPrTextView::clearSelection()
2101 if ( textDocument()->hasSelection( KoTextDocument::Standard ) )
2102 textDocument()->removeSelection(KoTextDocument::Standard );
2105void KPrTextView::selectAll(
bool select)
2107 textObject()->selectAll( select );
2110void KPrTextView::drawCursor(
bool b )
2112 KoTextView::drawCursor( b );
2113 if ( !cursor()->parag() )
2115 if ( !kpTextObject()->kPresenterDocument()->isReadWrite() )
2118 TQPainter painter( m_canvas );
2119 painter.translate( -m_canvas->diffx(), -m_canvas->diffy() );
2120 painter.setBrushOrigin( -m_canvas->diffx(), -m_canvas->diffy() );
2122 kpTextObject()->drawCursor( &painter, cursor(), b, m_canvas );
2126TQPoint KPrTextView::viewToInternal(
const TQPoint & pos )
const
2129 KoTextZoomHandler* zh = kpTextObject()->kPresenterDocument()->zoomHandler();
2132 m.translate( zh->zoomItX(kpTextObject()->getSize().width() / 2.0),
2133 zh->zoomItY(kpTextObject()->getSize().height() / 2.0) );
2134 m.rotate( kpTextObject()->getAngle() );
2138 m.translate( zh->zoomItX(kpTextObject()->getOrig().x()),
2139 zh->zoomItY(kpTextObject()->getOrig().y()) );
2143 kdDebug(33001)<<
" tmp.x() :"<<tmp.x()<<
" tmp.y() "<<tmp.y()<<endl;
2145 KoRect br = KoRect( 0, 0, kpTextObject()->getSize().width(), kpTextObject()->getSize().height() );
2146 double pw = br.width();
2147 double ph = br.height();
2149 double yPos = -rr.y();
2150 double xPos = -rr.x();
2151 rr.moveTopLeft( KoPoint( -rr.width() / 2.0, -rr.height() / 2.0 ) );
2153 m.translate( zh->zoomItX(pw / 2.0),
2154 zh->zoomItY(ph / 2.0 ));
2155 m.rotate( kpTextObject()->getAngle() );
2156 m.translate( zh->zoomItX(rr.left() + xPos),
2157 zh->zoomItY(rr.top() + yPos) );
2163 kdDebug(33001)<<
" tmp.x() :"<<tmp.x()<<
" tmp.y() "<<tmp.y()<<endl;
2166 return kpTextObject()->viewToInternal( pos, m_canvas );
2169void KPrTextView::mousePressEvent( TQMouseEvent *e,
const TQPoint &)
2171 bool addParag = handleMousePressEvent( e, viewToInternal( e->pos() ),
true ,
2172 kpTextObject()->kPresenterDocument()->insertDirectCursor() );
2175 kpTextObject()->kPresenterDocument()->setModified(
true );
2178void KPrTextView::mouseDoubleClickEvent( TQMouseEvent *e,
const TQPoint &pos)
2180 handleMouseDoubleClickEvent( e, pos );
2183void KPrTextView::mouseMoveEvent( TQMouseEvent *e,
const TQPoint &_pos )
2185 if ( textView()->maybeStartDrag( e ) )
2188 textView()->handleMouseMoveEvent( e,viewToInternal( e->pos() ) );
2191bool KPrTextView::isLinkVariable(
const TQPoint & pos )
2193 const TQPoint iPoint = viewToInternal( pos );
2194 KoLinkVariable* linkVariable =
dynamic_cast<KoLinkVariable *
>( textObject()->variableAtPoint( iPoint ) );
2195 return linkVariable != 0;
2198void KPrTextView::openLink()
2200 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2201 if ( doc->getVariableCollection()->variableSetting()->displayLink() ) {
2202 KoLinkVariable* v = linkVariable();
2204 KoTextView::openLink( v );
2208void KPrTextView::mouseReleaseEvent( TQMouseEvent *,
const TQPoint & )
2210 handleMouseReleaseEvent();
2213void KPrTextView::showPopup( KPrView *view,
const TQPoint &point, TQPtrList<TDEAction>& actionList )
2215 TQString word = wordUnderCursor( *cursor() );
2216 view->unplugActionList(
"datatools" );
2217 view->unplugActionList(
"datatools_link" );
2218 view->unplugActionList(
"spell_result_action" );
2219 view->unplugActionList(
"variable_action" );
2220 TQPtrList<TDEAction> &variableList = view->variableActionList();
2221 variableList.clear();
2224 view->kPresenterDoc()->getVariableCollection()->setVariableSelected(variable());
2225 KoVariable* var = variable();
2228 variableList = view->kPresenterDoc()->getVariableCollection()->popupActionList();
2231 if( variableList.count()>0)
2233 view->plugActionList(
"variable_action", variableList );
2234 TQPopupMenu * popup = view->popupMenu(
"variable_popup");
2237 popup->popup( point );
2242 bool singleWord=
false;
2243 actionList = dataToolActionList(view->kPresenterDoc()->instance(), word, singleWord);
2245 KoLinkVariable* linkVar =
dynamic_cast<KoLinkVariable *
>( var );
2246 TQPopupMenu * popup;
2249 view->plugActionList(
"datatools", actionList );
2251 KoNoteVariable * noteVar =
dynamic_cast<KoNoteVariable *
>( var );
2252 KoCustomVariable * customVar =
dynamic_cast<KoCustomVariable *
>( var );
2254 popup = view->popupMenu(
"note_popup");
2255 else if( customVar )
2256 popup = view->popupMenu(
"custom_var_popup");
2261 TQPtrList<TDEAction> actionCheckSpellList =view->listOfResultOfCheckWord( word );
2262 if ( actionCheckSpellList.count()>0)
2264 view->plugActionList(
"spell_result_action", actionCheckSpellList );
2265 popup = view->popupMenu(
"text_popup_spell_with_result");
2268 popup = view->popupMenu(
"text_popup_spell");
2271 popup = view->popupMenu(
"text_popup");
2276 view->plugActionList(
"datatools_link", actionList );
2277 popup = view->popupMenu(
"text_popup_link");
2281 popup->popup( point );
2285void KPrTextView::insertCustomVariable(
const TQString &name)
2287 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2288 KoVariable * var =
new KoCustomVariable( textDocument(), name, doc->variableFormatCollection()->format(
"STRING" ),
2289 doc->getVariableCollection());
2290 insertVariable( var );
2293void KPrTextView::insertLink(
const TQString &_linkName,
const TQString & hrefName)
2295 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2296 KoVariable * var =
new KoLinkVariable( textDocument(), _linkName, hrefName,
2297 doc->variableFormatCollection()->format(
"STRING" ),
2298 doc->getVariableCollection());
2299 insertVariable( var );
2302void KPrTextView::insertComment(
const TQString &_comment)
2304 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2306 KoVariable * var =
new KoNoteVariable( textDocument(), _comment,
2307 doc->variableFormatCollection()->format(
"STRING" ),
2308 doc->getVariableCollection());
2309 insertVariable( var );
2312void KPrTextView::insertVariable(
int type,
int subtype )
2314 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2315 bool refreshCustomMenu =
false;
2316 KoVariable * var = 0L;
2317 if ( type == VT_CUSTOM )
2319 KoCustomVarDialog dia( m_canvas );
2320 if ( dia.exec() == TQDialog::Accepted )
2322 KoCustomVariable *v =
new KoCustomVariable( textDocument(), dia.name(),
2323 doc->variableFormatCollection()->format(
"STRING" ),
2324 doc->getVariableCollection() );
2325 v->setValue( dia.value() );
2327 refreshCustomMenu =
true;
2331 var = doc->getVariableCollection()->createVariable( type, subtype, doc->variableFormatCollection(), 0L, textDocument(),doc, 0);
2334 insertVariable( var, 0, refreshCustomMenu);
2335 doc->recalcPageNum();
2339void KPrTextView::insertVariable( KoVariable *var, KoTextFormat *format,
bool refreshCustomMenu )
2343 CustomItemsMap customItemsMap;
2344 customItemsMap.insert( 0, var );
2346 format = currentFormat();
2349 kdDebug(33001) <<
"KPrTextView::insertVariable currentFormat=" << currentFormat() << endl;
2351 textObject()->insert( cursor(), format, KoTextObject::customItemChar(),
2352 i18n(
"Insert Variable"),
2353 KoTextDocument::Standard,
2354 KoTextObject::DoNotRemoveSelected,
2356 if ( refreshCustomMenu && var->type() == VT_CUSTOM )
2357 kpTextObject()->kPresenterDocument()->refreshMenuCustomVariable();
2358 kpTextObject()->kPresenterDocument()->repaint( kpTextObject() );
2362bool KPrTextView::canDecode( TQMimeSource *e )
2364 return kpTextObject()->kPresenterDocument()->isReadWrite() && ( !KoTextObject::providesOasis( e ).isNull() || TQTextDrag::canDecode( e ) );
2367TQDragObject * KPrTextView::newDrag( TQWidget * parent )
2370 const TQCString mimeType =
"application/vnd.oasis.opendocument.text";
2371 KoStore * store = KoStore::createStore( &buffer, KoStore::Write, mimeType );
2373 Q_ASSERT( !store->bad() );
2375 KoOasisStore oasisStore( store );
2379 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2381 doc->getVariableCollection()->variableSetting()->setModificationDate( TQDateTime::currentDateTime() );
2382 doc->recalcVariables( VT_DATE );
2383 doc->recalcVariables( VT_TIME );
2384 doc->recalcVariables( VT_STATISTIC );
2386 KoGenStyles mainStyles;
2387 KoSavingContext savingContext( mainStyles, 0,
false, KoSavingContext::Store );
2389 doc->styleCollection()->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
2391 KoXmlWriter* bodyWriter = oasisStore.bodyWriter();
2392 bodyWriter->startElement(
"office:body" );
2393 bodyWriter->startElement(
"office:text" );
2395 const TQString plainText = textDocument()->copySelection( *bodyWriter, savingContext, KoTextDocument::Standard );
2397 bodyWriter->endElement();
2398 bodyWriter->endElement();
2400 KoXmlWriter* contentWriter = oasisStore.contentWriter();
2401 Q_ASSERT( contentWriter );
2404 doc->writeAutomaticStyles( *contentWriter, mainStyles, savingContext,
false );
2406 oasisStore.closeContentWriter();
2408 if ( !store->open(
"styles.xml" ) )
2411 doc->saveOasisDocumentStyles( store, mainStyles, 0, savingContext, KPrDocument::SaveSelected );
2412 if ( !store->close() )
2417 KMultipleDrag* multiDrag =
new KMultipleDrag( parent );
2418 if ( !plainText.isEmpty() )
2419 multiDrag->addDragObject(
new TQTextDrag( plainText, 0 ) );
2420 KoStoreDrag* storeDrag =
new KoStoreDrag( mimeType, 0 );
2421 kdDebug() << k_funcinfo <<
"setting zip data: " << buffer.buffer().size() <<
" bytes." << endl;
2422 storeDrag->setEncodedData( buffer.buffer() );
2423 multiDrag->addDragObject( storeDrag );
2427void KPrTextView::dragEnterEvent( TQDragEnterEvent *e )
2429 if ( !canDecode( e ) )
2437void KPrTextView::dragMoveEvent( TQDragMoveEvent *e,
const TQPoint & )
2439 if ( !canDecode( e ) )
2444 TQPoint iPoint = viewToInternal( e->pos() );
2446 textObject()->emitHideCursor();
2447 placeCursor( iPoint );
2448 textObject()->emitShowCursor();
2452void KPrTextView::dropEvent( TQDropEvent * e )
2454 if ( canDecode( e ) )
2456 KPrDocument *doc = kpTextObject()->kPresenterDocument();
2458 KoTextCursor dropCursor( textDocument() );
2459 TQPoint dropPoint = viewToInternal( e->pos() );
2460 KMacroCommand *macroCmd=
new KMacroCommand(i18n(
"Paste Text"));
2461 bool addMacroCmd =
false;
2462 dropCursor.place( dropPoint, textDocument()->firstParag() );
2463 kdDebug(33001) <<
"KPrTextView::dropEvent dropCursor at parag=" << dropCursor.parag()->paragId() <<
" index=" << dropCursor.index() << endl;
2465 if ( ( e->source() == m_canvas ) &&
2466 e->action() == TQDropEvent::Move &&
2468 textDocument()->hasSelection( KoTextDocument::Standard )
2471 KCommand *cmd = textView()->prepareDropMove( dropCursor );
2474 kpTextObject()->layout();
2475 macroCmd->addCommand(cmd);
2486 textDocument()->removeSelection( KoTextDocument::Standard );
2487 textObject()->selectionChangedNotify();
2489 TQCString returnedTypeMime = KoTextObject::providesOasis( e );
2490 if ( !returnedTypeMime.isEmpty() )
2492 TQByteArray arr = e->encodedData( returnedTypeMime );
2495 KCommand *cmd = kpTextObject()->pasteOasis( cursor(), arr,
false );
2498 macroCmd->addCommand(cmd);
2506 if ( TQTextDrag::decode( e, text ) )
2507 textObject()->pasteText( cursor(), text, currentFormat(),
2511 doc->addCommand(macroCmd);
2517void KPrTextObject::saveParagraph( TQDomDocument& doc,KoTextParag * parag,TQDomElement &parentElem,
2523 TQDomElement paragraph=doc.createElement(tagP);
2525 switch(parag->resolveAlignment())
2527 case TQt::AlignLeft:
2530 case TQt::AlignRight:
2533 case TQt::AlignHCenter:
2536 case TQt::AlignJustify:
2540 paragraph.setAttribute(attrAlign, tmpAlign);
2542 saveParagLayout( parag->paragLayout(), paragraph );
2543 KoTextFormat *lastFormat = 0;
2545 for (
int i = from; i <= to; ++i ) {
2546 KoTextStringChar &c = parag->string()->at(i);
2549 TQDomElement variable = doc.createElement(
"CUSTOM");
2550 variable.setAttribute(
"pos", (i-from));
2551 saveFormat( variable, c.format() );
2552 paragraph.appendChild( variable );
2553 static_cast<KoTextCustomItem *
>( c.customItem() )->save(variable );
2555 if ( !lastFormat || c.format()->key() != lastFormat->key() ) {
2557 paragraph.appendChild(saveHelper(tmpText, lastFormat, doc));
2558 lastFormat =
static_cast<KoTextFormat*
> (c.format());
2561 tmpText+=TQString(c.c);
2564 paragraph.appendChild(saveHelper(tmpText, lastFormat, doc));
2566 paragraph.appendChild(saveHelper(tmpText, parag->string()->at(0).format(), doc));
2568 parentElem.appendChild(paragraph);
2571KoPen KPrTextObject::defaultPen()
const
2573 return KoPen( TQt::black, 1.0, TQt::NoPen );
2576TQPoint KPrTextObject::viewToInternal(
const TQPoint & pos,
KPrCanvas* canvas )
const
2578 KoTextZoomHandler* zh = kPresenterDocument()->zoomHandler();
2579 TQPoint iPoint = pos - zh->zoomPoint(
2580 getOrig() + KoPoint( bLeft(),
2581 bTop() + alignmentValue()) );
2582 iPoint = zh->pixelToLayoutUnit(
2583 TQPoint( iPoint.x() + canvas->diffx(), iPoint.y() + canvas->diffy() ) );
Class KPCanvas - There is a single instance of this class for a given view.
Temporary information used only during loading.
Command created when pasting oasis-formatted text.
"current page number" and "number of pages" variables
This is our KoTextDocument reimplementation, to relate it to the textobject it's in.