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 <tdemultipledrag.h>
56#include <tqapplication.h>
57#include <tqfontdatabase.h>
58#include <tqpopupmenu.h>
59#include <tqclipboard.h>
61#include <KoParagCounter.h>
63#include <KoVariable.h>
64#include <KoCustomVariablesDia.h>
70#include <KoStoreDrag.h>
71#include <KoOasisStore.h>
78const TQString &KPrTextObject::tagTEXTOBJ=TDEGlobal::staticQString(
"TEXTOBJ");
79const TQString &KPrTextObject::attrLineSpacing=TDEGlobal::staticQString(
"lineSpacing");
80const TQString &KPrTextObject::attrParagSpacing=TDEGlobal::staticQString(
"paragSpacing");
81const TQString &KPrTextObject::attrMargin=TDEGlobal::staticQString(
"margin");
82const TQString &KPrTextObject::attrBulletType1=TDEGlobal::staticQString(
"bulletType1");
83const TQString &KPrTextObject::attrBulletType2=TDEGlobal::staticQString(
"bulletType2");
84const TQString &KPrTextObject::attrBulletType3=TDEGlobal::staticQString(
"bulletType3");
85const TQString &KPrTextObject::attrBulletType4=TDEGlobal::staticQString(
"bulletType4");
86const TQString &KPrTextObject::attrBulletColor1=TDEGlobal::staticQString(
"bulletColor1");
87const TQString &KPrTextObject::attrBulletColor2=TDEGlobal::staticQString(
"bulletColor2");
88const TQString &KPrTextObject::attrBulletColor3=TDEGlobal::staticQString(
"bulletColor3");
89const TQString &KPrTextObject::attrBulletColor4=TDEGlobal::staticQString(
"bulletColor4");
90const TQString &KPrTextObject::tagP=TDEGlobal::staticQString(
"P");
91const TQString &KPrTextObject::attrAlign=TDEGlobal::staticQString(
"align");
92const TQString &KPrTextObject::attrType=TDEGlobal::staticQString(
"type");
93const TQString &KPrTextObject::attrDepth=TDEGlobal::staticQString(
"depth");
94const TQString &KPrTextObject::tagTEXT=TDEGlobal::staticQString(
"TEXT");
95const TQString &KPrTextObject::attrFamily=TDEGlobal::staticQString(
"family");
96const TQString &KPrTextObject::attrPointSize=TDEGlobal::staticQString(
"pointSize");
97const TQString &KPrTextObject::attrBold=TDEGlobal::staticQString(
"bold");
98const TQString &KPrTextObject::attrItalic=TDEGlobal::staticQString(
"italic");
99const TQString &KPrTextObject::attrUnderline=TDEGlobal::staticQString(
"underline");
100const TQString &KPrTextObject::attrStrikeOut=TDEGlobal::staticQString(
"strikeOut");
101const TQString &KPrTextObject::attrColor=TDEGlobal::staticQString(
"color");
102const TQString &KPrTextObject::attrWhitespace=TDEGlobal::staticQString(
"whitespace");
103const TQString &KPrTextObject::attrTextBackColor=TDEGlobal::staticQString(
"textbackcolor");
104const TQString &KPrTextObject::attrVertAlign=TDEGlobal::staticQString(
"VERTALIGN");
107KPrTextObject::KPrTextObject( KPrDocument *doc )
111 m_textVertAlign = KP_TOP;
113 KoTextFormatCollection* fc =
new KoTextFormatCollection( doc->defaultFont(), TQt::black, doc->globalLanguage(), doc->globalHyphenation() );
115 if ( m_doc->tabStopValue() != -1 )
116 textdoc->setTabStops( m_doc->zoomHandler()->ptToLayoutUnitPixX( m_doc->tabStopValue() ));
118 m_textobj =
new KoTextObject( textdoc, m_doc->styleCollection()->findStyle(
"Standard" ),
this );
119 textdoc->setFlow(
this );
121 m_doc->backSpeller()->registerNewTextObject( m_textobj );
125 editingTextObj =
false;
133 connect( m_textobj, TQ_SIGNAL( newCommand( KCommand * ) ),
134 TQ_SLOT( slotNewCommand( KCommand * ) ) );
135 connect( m_textobj, TQ_SIGNAL( availableHeightNeeded() ),
136 TQ_SLOT( slotAvailableHeightNeeded() ) );
137 connect( m_textobj, TQ_SIGNAL( repaintChanged( KoTextObject* ) ),
138 TQ_SLOT( slotRepaintChanged() ) );
141 connect(
this, TQ_SIGNAL( repaintChanged( KPrTextObject * ) ),
142 m_doc, TQ_SLOT( slotRepaintChanged( KPrTextObject * ) ) );
143 connect(m_textobj, TQ_SIGNAL( showFormatObject(
const KoTextFormat &) ),
144 TQ_SLOT( slotFormatChanged(
const KoTextFormat &)) );
145 connect( m_textobj, TQ_SIGNAL( afterFormatting(
int, KoTextParag*,
bool* ) ),
146 TQ_SLOT( slotAfterFormatting(
int, KoTextParag*,
bool* ) ) );
147 connect( m_textobj, TQ_SIGNAL( paragraphDeleted( KoTextParag*) ),
148 TQ_SLOT( slotParagraphDeleted(KoTextParag*) ));
152KPrTextObject::~KPrTextObject()
154 textDocument()->takeFlow();
158DCOPObject* KPrTextObject::dcopObject()
161 dcop =
new KPrTextObjectIface(
this );
165void KPrTextObject::slotParagraphDeleted(KoTextParag*_parag)
167 m_doc->spellCheckParagraphDeleted( _parag,
this);
170TQBrush KPrTextObject::getBrush()
const
172 TQBrush tmpBrush( m_brush.getBrush() );
173 if(!tmpBrush.color().isValid())
174 tmpBrush.setColor(TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base ));
178void KPrTextObject::resizeTextDocument(
bool widthChanged,
bool heightChanged )
183 slotAvailableHeightNeeded();
185 recalcVerticalAlignment();
191 textDocument()->setWidth( m_doc->zoomHandler()->ptToLayoutUnitPixX( innerWidth() ) );
192 m_textobj->setLastFormattedParag( textDocument()->firstParag() );
193 m_textobj->formatMore( 2 );
197void KPrTextObject::setSize(
double _width,
double _height )
199 bool widthModified = KABS( _width - ext.width() ) > DBL_EPSILON ;
200 bool heightModified = KABS( _height - ext.height() ) > DBL_EPSILON;
201 if ( widthModified || heightModified )
203 KPrObject::setSize( _width, _height );
204 resizeTextDocument( widthModified, heightModified );
208TQDomDocumentFragment KPrTextObject::save( TQDomDocument& doc,
double offset )
210 TQDomDocumentFragment fragment=KPr2DObject::save(doc, offset);
211 fragment.appendChild(saveKTextObject( doc ));
215bool KPrTextObject::saveOasisObjectAttributes( KPOasisSaveContext &sc )
const
217 sc.xmlWriter.startElement(
"draw:text-box" );
218 m_textobj->saveOasisContent( sc.xmlWriter, sc.context );
219 sc.xmlWriter.endElement();
223const char * KPrTextObject::getOasisElementName()
const
228void KPrTextObject::saveOasisMarginElement( KoGenStyle &styleobjectauto )
const
230 kdDebug()<<
"void KPrTextObject::saveOasisMarginElement( KoGenStyle &styleobjectauto )\n";
232 styleobjectauto.addPropertyPt(
"fo:padding-top", btop );
233 if ( bbottom != 0.0 )
234 styleobjectauto.addPropertyPt(
"fo:padding-bottom", bbottom );
236 styleobjectauto.addPropertyPt(
"fo:padding-left", bleft );
238 styleobjectauto.addPropertyPt(
"fo:padding-right", bright );
241 switch( m_textVertAlign )
244 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"top" );
247 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"middle" );
250 styleobjectauto.addProperty(
"draw:textarea-vertical-align",
"bottom" );
257void KPrTextObject::loadOasis(
const TQDomElement &element, KoOasisContext& context,
260 KPr2DObject::loadOasis(element, context, info);
262 KoStyleStack &styleStack = context.styleStack();
263 styleStack.setTypeProperties(
"graphic" );
264 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-top" ) )
265 btop = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-top" ) );
266 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-bottom" ) )
267 bbottom = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-bottom" ) );
268 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-left") )
269 bleft = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-left" ) );
270 if( styleStack.hasAttributeNS( KoXmlNS::fo,
"padding-right" ) )
271 bright = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"padding-right" ) );
272 kdDebug()<<
" KPrTextObject::loadOasis : btp :"<<btop<<
" bbottom :"<<bbottom<<
" bleft :"<<bleft<<
" bright :"<<bright<<endl;
274 if ( styleStack.hasAttributeNS( KoXmlNS::draw,
"textarea-vertical-align" ) )
276 TQString alignment = styleStack.attributeNS( KoXmlNS::draw,
"textarea-vertical-align" );
277 if ( alignment ==
"top" )
278 m_textVertAlign= KP_TOP;
279 else if ( alignment ==
"middle" )
280 m_textVertAlign= KP_CENTER;
281 else if ( alignment ==
"bottom" )
282 m_textVertAlign= KP_BOTTOM;
284 kdDebug()<<
" vertical Alignment :"<< ( ( m_textVertAlign== KP_TOP ) ?
"top" : ( m_textVertAlign== KP_CENTER ) ?
"center":
"bottom" )<<endl;
285 TQDomElement tmp = KoDom::namedItemNS( element, KoXmlNS::draw,
"text-box");
286 m_textobj->loadOasisContent( tmp, context, m_doc->styleCollection() );
287 resizeTextDocument();
291double KPrTextObject::load(
const TQDomElement &element)
293 double offset=KPr2DObject::load(element);
294 TQDomElement e=element.namedItem(tagTEXTOBJ).toElement();
296 if ( e.hasAttribute(
"protectcontent"))
297 setProtectContent((
bool)e.attribute(
"protectcontent" ).toInt());
298 if (e.hasAttribute(
"bleftpt"))
299 bleft = e.attribute(
"bleftpt").toDouble();
300 if (e.hasAttribute(
"brightpt"))
301 bright = e.attribute(
"brightpt").toDouble();
302 if (e.hasAttribute(
"btoppt"))
303 btop = e.attribute(
"btoppt").toDouble();
304 if (e.hasAttribute(
"bbottompt"))
305 bbottom = e.attribute(
"bbottompt").toDouble();
306 if ( e.hasAttribute(
"verticalAlign"))
308 TQString str =e.attribute(
"verticalAlign");
309 if ( str ==
"bottom" )
310 m_textVertAlign= KP_BOTTOM;
311 else if ( str ==
"center" )
312 m_textVertAlign= KP_CENTER;
313 else if ( str ==
"top" )
314 m_textVertAlign= KP_TOP;
316 if ( e.hasAttribute(
"verticalValue" ))
317 alignVertical = e.attribute(
"verticalValue" ).toDouble();
319 loadKTextObject( e );
322 shadowCompatibility();
324 resizeTextDocument();
328void KPrTextObject::shadowCompatibility()
330 if ( shadowDistance != 0)
334 switch ( shadowDirection )
339 sx = - shadowDistance;
342 case SD_RIGHT_BOTTOM:
347 switch ( shadowDirection )
352 sy = - shadowDistance;
355 case SD_RIGHT_BOTTOM:
360 KoTextFormat tmpFormat;
361 tmpFormat.setShadow( sx, sy, shadowColor );
362 KCommand* cmd = m_textobj->setFormatCommand( &tmpFormat, KoTextFormat::ShadowText );
366 shadowDirection = SD_RIGHT_BOTTOM;
368 shadowColor = TQt::gray;
373void KPrTextObject::paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
374 int pageNum,
bool drawingShadow,
bool drawContour )
377 KPrPage *p = m_doc->pageList().at( pageNum );
381 if ( drawingShadow )
return;
382 paint( _painter, _zoomHandler,
false, 0L,
true, drawContour );
386void KPrTextObject::paintEdited( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
387 bool onlyChanged, KoTextCursor* cursor,
bool resetChanged )
390 _painter->translate( _zoomHandler->zoomItX(orig.x()), _zoomHandler->zoomItY(orig.y()) );
393 rotateObject(_painter,_zoomHandler);
394 paint( _painter, _zoomHandler, onlyChanged, cursor, resetChanged,
false );
399void KPrTextObject::paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
400 bool onlyChanged, KoTextCursor* cursor,
bool resetChanged,
403 double ow = ext.width();
404 double oh = ext.height();
405 double pw = pen.pointWidth() / 2;
407 TQPen pen3( TQt::black, 1, TQt::DotLine );
408 _painter->setPen( pen3 );
409 _painter->setRasterOp( TQt::NotXorROP );
410 _painter->drawRect( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItY(pw),
411 _zoomHandler->zoomItX(ow), _zoomHandler->zoomItY( oh) );
417 TQPen pen2 = pen.zoomedPen(_zoomHandler);
422 _painter->setPen( pen2 );
424 if ( editingTextObj && _painter->device() && _painter->device()->devType() != TQInternal::Printer)
425 _painter->setBrush( TQBrush( m_doc->txtBackCol(), TQt::SolidPattern ) );
428 if ( getFillType() == FT_BRUSH || !gradient ) {
429 _painter->setBrush( getBrush() );
432 TQSize size( _zoomHandler->zoomSize( ext ) );
433 gradient->setSize( size );
434 _painter->drawPixmap( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX(pw), gradient->pixmap(), 0, 0,
435 _zoomHandler->zoomItX( ow - 2 * pw ),
436 _zoomHandler->zoomItY( oh - 2 * pw ) );
439 if ( !editingTextObj || !onlyChanged )
443 _painter->drawRect( _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX(pw), _zoomHandler->zoomItX( ow - 2 * pw),
444 _zoomHandler->zoomItY( oh - 2 * pw) );
447 drawText( _painter, _zoomHandler, onlyChanged, cursor, resetChanged );
454 if ( m_doc->firstView() && m_doc->firstView()->getCanvas()->getEditMode() &&
455 getDrawEditRect() && getPen().style() == TQt::NoPen )
459 _painter->setPen( TQPen( TQt::gray, 1, TQt::DotLine ) );
460 _painter->setBrush( TQt::NoBrush );
461 _painter->setRasterOp( TQt::NotXorROP );
462 _painter->drawRect( 0, 0, _zoomHandler->zoomItX(ow), _zoomHandler->zoomItY( oh) );
470void KPrTextObject::drawText( TQPainter* _painter, KoTextZoomHandler *zoomHandler,
bool onlyChanged, KoTextCursor* cursor,
bool resetChanged )
473 recalcVerticalAlignment();
474 TQColorGroup cg = TQApplication::palette().active();
476 _painter->translate( m_doc->zoomHandler()->zoomItX( bLeft()), m_doc->zoomHandler()->zoomItY( bTop()+alignVertical));
477 if ( !editingTextObj || (_painter->device() && _painter->device()->devType() == TQInternal::Printer))
478 cg.setBrush( TQColorGroup::Base, TQt::NoBrush );
480 cg.setColor( TQColorGroup::Base, m_doc->txtBackCol() );
482 TQRect r = zoomHandler->zoomRect( KoRect( 0, 0, innerWidth(), innerHeight() ) );
483 bool editMode =
false;
484 if( m_doc->firstView() && m_doc->firstView()->getCanvas())
485 editMode = m_doc->firstView()->getCanvas()->getEditMode();
487 uint drawingFlags = 0;
488 if ( _painter->device() && _painter->device()->devType() != TQInternal::Printer )
489 drawingFlags |= KoTextDocument::DrawSelections;
490 if ( m_doc->backgroundSpellCheckEnabled() && editMode )
491 drawingFlags |= KoTextDocument::DrawMisspelledLine;
493 drawingFlags |= KoTextDocument::DontDrawNoteVariable;
494 if ( m_doc->viewFormattingChars() && editMode )
495 drawingFlags |= KoTextDocument::DrawFormattingChars;
503 drawParags( _painter, zoomHandler, cg, ( onlyCurrStep ? subPresStep : 0 ), subPresStep );
506 textDocument()->drawWYSIWYG(
507 _painter, r.x(), r.y(), r.width(), r.height(),
509 onlyChanged, cursor != 0, cursor, resetChanged, drawingFlags );
516 textDocument()->drawWYSIWYG(
517 _painter, r.x(), r.y(), r.width(), r.height(),
519 onlyChanged, cursor != 0, cursor, resetChanged, drawingFlags );
524int KPrTextObject::getSubPresSteps()
const
527 KoTextParag * parag = textDocument()->firstParag();
528 for ( ; parag ; parag = parag->next() )
534TQDomElement KPrTextObject::saveKTextObject( TQDomDocument& doc )
537 KTextEditParag *parag = ktextobject.document()->firstParag();
538 KTextEditDocument::TextSettings textSettings = ktextobject.document()->textSettings();
541 TQDomElement textobj=doc.createElement(tagTEXTOBJ);
542 if ( isProtectContent() )
543 textobj.setAttribute(
"protectcontent", (
int)isProtectContent());
545 textobj.setAttribute(
"bleftpt", bleft );
547 textobj.setAttribute(
"brightpt", bright );
549 textobj.setAttribute(
"btoppt", btop );
551 textobj.setAttribute(
"bbottompt", bbottom );
552 if ( m_textVertAlign != KP_TOP )
554 if ( m_textVertAlign == KP_BOTTOM )
555 textobj.setAttribute(
"verticalAlign",
"bottom" );
556 else if ( m_textVertAlign == KP_CENTER )
557 textobj.setAttribute(
"verticalAlign",
"center" );
558 else if ( m_textVertAlign == KP_TOP )
559 textobj.setAttribute(
"verticalAlign",
"top" );
560 textobj.setAttribute(
"verticalValue",alignVertical );
563 textobj.setAttribute(attrLineSpacing, ktextobject.document()->lineSpacing());
564 textobj.setAttribute(attrParagSpacing, ktextobject.document()->paragSpacing());
565 textobj.setAttribute(attrMargin, ktextobject.document()->margin());
566 textobj.setAttribute(attrBulletType1, (
int)textSettings.bulletType[0]);
567 textobj.setAttribute(attrBulletType2, (
int)textSettings.bulletType[1]);
568 textobj.setAttribute(attrBulletType3, (
int)textSettings.bulletType[2]);
569 textobj.setAttribute(attrBulletType4, (
int)textSettings.bulletType[3]);
570 textobj.setAttribute(attrBulletColor1, textSettings.bulletColor[0].name());
571 textobj.setAttribute(attrBulletColor2, textSettings.bulletColor[1].name());
572 textobj.setAttribute(attrBulletColor3, textSettings.bulletColor[2].name());
573 textobj.setAttribute(attrBulletColor4, textSettings.bulletColor[3].name());
575 KoTextParag *parag =
static_cast<KoTextParag*
> (textDocument()->firstParag());
578 saveParagraph( doc, parag, textobj, 0, parag->length()-2 );
579 parag =
static_cast<KoTextParag*
>( parag->next());
584void KPrTextObject::saveFormat( TQDomElement & element, KoTextFormat*lastFormat )
586 TQString tmpFamily, tmpColor, tmpTextBackColor;
587 unsigned int tmpBold=
false, tmpItalic=
false, tmpUnderline=
false,tmpStrikeOut=
false;
588 int tmpVerticalAlign=-1;
590 tmpFamily=lastFormat->font().family();
591 tmpBold=
static_cast<unsigned int>(lastFormat->font().bold());
592 tmpItalic=
static_cast<unsigned int>(lastFormat->font().italic());
593 tmpUnderline=
static_cast<unsigned int>(lastFormat->underline());
594 tmpStrikeOut=
static_cast<unsigned int>(lastFormat->strikeOut());
595 tmpColor=lastFormat->color().name();
596 tmpVerticalAlign=
static_cast<unsigned int>(lastFormat->vAlign());
597 if(lastFormat->textBackgroundColor().isValid())
598 tmpTextBackColor=lastFormat->textBackgroundColor().name();
600 element.setAttribute(attrFamily, tmpFamily);
601 element.setAttribute(attrPointSize, lastFormat->pointSize());
604 element.setAttribute(attrBold, tmpBold);
606 element.setAttribute(attrItalic, tmpItalic);
607 if ( lastFormat->underlineType()!= KoTextFormat::U_NONE )
609 if(lastFormat->doubleUnderline())
610 element.setAttribute(attrUnderline,
"double");
611 if(lastFormat->underlineType()==KoTextFormat::U_SIMPLE_BOLD)
612 element.setAttribute(attrUnderline,
"single-bold");
613 else if( lastFormat->underlineType()==KoTextFormat::U_WAVE)
614 element.setAttribute(attrUnderline,
"wave");
615 else if(tmpUnderline)
616 element.setAttribute(attrUnderline, tmpUnderline);
617 TQString strLineType=KoTextFormat::underlineStyleToString( lastFormat->underlineStyle() );
618 element.setAttribute(
"underlinestyleline", strLineType );
619 if ( lastFormat->textUnderlineColor().isValid() )
620 element.setAttribute(
"underlinecolor", lastFormat->textUnderlineColor().name() );
622 if ( lastFormat->strikeOutType()!= KoTextFormat::S_NONE )
624 if ( lastFormat->doubleStrikeOut() )
625 element.setAttribute(attrStrikeOut,
"double");
626 else if ( lastFormat->strikeOutType()== KoTextFormat::S_SIMPLE_BOLD)
627 element.setAttribute(attrStrikeOut,
"single-bold");
628 else if(tmpStrikeOut)
629 element.setAttribute(attrStrikeOut, tmpStrikeOut);
630 TQString strLineType=KoTextFormat::strikeOutStyleToString( lastFormat->strikeOutStyle() );
631 element.setAttribute(
"strikeoutstyleline", strLineType );
634 element.setAttribute(attrColor, tmpColor);
636 if(!tmpTextBackColor.isEmpty())
637 element.setAttribute(attrTextBackColor, tmpTextBackColor);
638 if(tmpVerticalAlign!=-1)
640 element.setAttribute(attrVertAlign,tmpVerticalAlign);
641 if(lastFormat->relativeTextSize()!=0.66)
642 element.setAttribute(
"relativetextsize",lastFormat->relativeTextSize());
645 if ( lastFormat->shadowDistanceX() != 0
646 || lastFormat->shadowDistanceY() != 0)
647 element.setAttribute(
"text-shadow", lastFormat->shadowAsCss());
648 if ( lastFormat->offsetFromBaseLine()!=0 )
649 element.setAttribute(
"offsetfrombaseline" , lastFormat->offsetFromBaseLine());
650 if ( lastFormat->wordByWord() )
651 element.setAttribute(
"wordbyword",
true);
652 if ( lastFormat->attributeFont()!= KoTextFormat::ATT_NONE )
653 element.setAttribute(
"fontattribute", KoTextFormat::attributeFontToString(lastFormat->attributeFont() ));
654 if ( !lastFormat->language().isEmpty())
655 element.setAttribute(
"language", lastFormat->language());
658TQDomElement KPrTextObject::saveHelper(
const TQString &tmpText,KoTextFormat*lastFormat , TQDomDocument &doc)
660 TQDomElement element=doc.createElement(tagTEXT);
662 saveFormat ( element, lastFormat );
664 if(tmpText.stripWhiteSpace().isEmpty())
666 element.setAttribute(attrWhitespace, tmpText.length());
667 element.appendChild(doc.createTextNode(tmpText));
671void KPrTextObject::fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles )
const
673 KPr2DObject::fillStyle( styleObjectAuto, mainStyles );
674 saveOasisMarginElement( styleObjectAuto );
677void KPrTextObject::loadKTextObject(
const TQDomElement &elem )
679 TQDomElement e = elem.firstChild().toElement();
680 KoTextParag *lastParag =
static_cast<KoTextParag *
>(textDocument()->firstParag());
685 int lineSpacing = elem.attribute( attrLineSpacing ).toInt();
686 int bottomBorder = elem.attribute( attrParagSpacing ).toInt();
689 while ( !e.isNull() ) {
690 TQValueList<TQDomElement> listVariable;
691 listVariable.clear();
693 if ( e.tagName() == tagP ) {
694 TQDomElement n = e.firstChild().toElement();
697 if( e.hasAttribute( attrType ) && n.hasAttribute( attrWhitespace ) )
698 if ( e.attribute( attrType )!=
"0" && n.attribute( attrWhitespace )==
"1" ) {
699 e = e.nextSibling().toElement();
703 KoParagLayout paragLayout = loadParagLayout(e, m_doc,
true);
707 if( e.hasAttribute(attrDepth) ) {
708 depth = e.attribute( attrDepth ).toDouble();
709 paragLayout.margins[TQStyleSheetItem::MarginLeft] = depth * MM_TO_POINT(10.0);
716 if( e.hasAttribute(attrType) )
717 type = e.attribute( attrType );
724 if(!paragLayout.counter)
725 paragLayout.counter =
new KoParagCounter;
726 paragLayout.counter->setStyle(KoParagCounter::STYLE_DISCBULLET);
727 paragLayout.counter->setNumbering(KoParagCounter::NUM_LIST);
728 paragLayout.counter->setPrefix(TQString());
729 paragLayout.counter->setSuffix(TQString());
733 if ( e.hasAttribute( attrLineSpacing ) )
734 lineSpacing = e.attribute( attrLineSpacing ).toInt();
735 if ( e.hasAttribute(
"distBefore" ) )
736 topBorder = e.attribute(
"distBefore" ).toInt();
737 if ( e.hasAttribute(
"distAfter" ) )
738 bottomBorder = e.attribute(
"distAfter" ).toInt();
741 if ( paragLayout.lineSpacingValue() == 0 )
742 paragLayout.setLineSpacingValue(lineSpacing);
743 if ( paragLayout.margins[ TQStyleSheetItem::MarginTop ] == 0 )
744 paragLayout.margins[ TQStyleSheetItem::MarginTop ] = topBorder;
745 if ( paragLayout.margins[ TQStyleSheetItem::MarginBottom ] == 0 )
746 paragLayout.margins[ TQStyleSheetItem::MarginBottom ] = bottomBorder;
747 lastParag->setParagLayout( paragLayout );
750 if(e.hasAttribute(attrAlign))
752 int tmpAlign=e.attribute( attrAlign ).toInt();
753 if(tmpAlign==1 || tmpAlign==0 )
754 lastParag->setAlign(TQt::AlignLeft);
756 lastParag->setAlign(TQt::AlignRight);
758 lastParag->setAlign(TQt::AlignHCenter);
760 lastParag->setAlign(TQt::AlignJustify);
762 kdDebug(33001) <<
"Error in e.attribute( attrAlign ).toInt()" << endl;
767 bool firstTextTag =
true;
768 while ( !n.isNull() ) {
769 if ( n.tagName() == tagTEXT ) {
771 if ( firstTextTag ) {
772 lastParag->remove( 0, 1 );
773 firstTextTag =
false;
775 KoTextFormat fm = loadFormat( n, lastParag->paragraphFormat(), m_doc->defaultFont(), m_doc->globalLanguage(),
776 m_doc->globalHyphenation() );
778 TQString txt = n.firstChild().toText().data();
780 if(n.hasAttribute(attrWhitespace)) {
781 int ws=n.attribute(attrWhitespace).toInt();
784 n=n.nextSibling().toElement();
787 lastParag->append( txt,
true );
788 lastParag->setFormat( i, txt.length(), textDocument()->formatCollection()->format( &fm ) );
792 else if ( n.tagName() ==
"CUSTOM" )
794 listVariable.append( n );
795 n = n.nextSibling().toElement();
798 n = n.nextSibling().toElement();
800 }
else if ( e.tagName() ==
"UNSORTEDLISTTYPE" ) {
806 e = e.nextSibling().toElement();
807 loadVariable( listVariable,lastParag );
811 if ( !lastParag->length() == 0 )
812 lastParag =
new KoTextParag( textDocument(), lastParag, 0 );
816void KPrTextObject::loadVariable( TQValueList<TQDomElement> & listVariable,KoTextParag *lastParag,
int offset )
818 TQValueList<TQDomElement>::Iterator it = listVariable.begin();
819 TQValueList<TQDomElement>::Iterator end = listVariable.end();
820 for ( ; it != end ; ++it )
822 TQDomElement elem = *it;
823 if ( !elem.hasAttribute(
"pos"))
825 int index = elem.attribute(
"pos").toInt();
827 TQDomElement varElem = elem.namedItem(
"VARIABLE" ).toElement();
828 if ( !varElem.isNull() )
830 TQDomElement typeElem = varElem.namedItem(
"TYPE" ).toElement();
831 int type = typeElem.attribute(
"type" ).toInt();
832 TQString key = typeElem.attribute(
"key" );
834 if (typeElem.hasAttribute(
"correct" ))
835 correct = typeElem.attribute(
"correct").toInt();
836 kdDebug(33001) <<
"loadKTextObject variable type=" << type <<
" key=" << key << endl;
837 KoVariableFormat * varFormat = key.isEmpty() ? 0 : m_doc->variableFormatCollection()->format( key.latin1() );
839 KoVariable * var =m_doc->getVariableCollection()->createVariable( type, -1, m_doc->variableFormatCollection(),
840 varFormat, lastParag->textDocument(),
841 m_doc, correct,
true );
844 var->load( varElem );
845 KoTextFormat format = loadFormat( *it, lastParag->paragraphFormat(), m_doc->defaultFont(), m_doc->globalLanguage(),
846 m_doc->globalHyphenation() );
847 lastParag->setCustomItem( index, var, lastParag->document()->formatCollection()->format( &format ));
854KoTextFormat KPrTextObject::loadFormat( TQDomElement &n, KoTextFormat * refFormat,
const TQFont & defaultFont,
855 const TQString & defaultLanguage,
bool hyphen )
858 format.setHyphenation( hyphen );
863 format.setCollection( 0 );
872 TQStringList families = fdb.families();
873 if ( families.findIndex( n.attribute( attrFamily ) ) != -1 )
874 fn.setFamily( n.attribute( attrFamily ) );
878 else if ( !refFormat )
884 int size = n.attribute( attrPointSize ).toInt();
886 if(n.hasAttribute(attrBold))
887 bold = (bool)n.attribute( attrBold ).toInt();
889 if(n.hasAttribute(attrItalic))
890 italic=(bool)n.attribute( attrItalic ).toInt();
892 if(n.hasAttribute( attrUnderline ))
894 TQString value = n.attribute( attrUnderline );
895 if ( value ==
"double" )
896 format.setUnderlineType ( KoTextFormat::U_DOUBLE);
897 else if ( value ==
"single" )
898 format.setUnderlineType ( KoTextFormat::U_SIMPLE);
899 else if ( value ==
"single-bold" )
900 format.setUnderlineType ( KoTextFormat::U_SIMPLE_BOLD);
901 else if( value ==
"wave" )
902 format.setUnderlineType( KoTextFormat::U_WAVE);
904 format.setUnderlineType ( (
bool)value.toInt() ? KoTextFormat::U_SIMPLE :KoTextFormat::U_NONE);
906 if (n.hasAttribute(
"underlinestyleline") )
907 format.setUnderlineStyle( KoTextFormat::stringToUnderlineStyle( n.attribute(
"underlinestyleline") ));
909 if (n.hasAttribute(
"underlinecolor"))
910 format.setTextUnderlineColor(TQColor(n.attribute(
"underlinecolor")));
912 if(n.hasAttribute(attrStrikeOut))
914 TQString value = n.attribute( attrStrikeOut );
915 if ( value ==
"double" )
916 format.setStrikeOutType ( KoTextFormat::S_DOUBLE);
917 else if ( value ==
"single" )
918 format.setStrikeOutType ( KoTextFormat::S_SIMPLE);
919 else if ( value ==
"single-bold" )
920 format.setStrikeOutType ( KoTextFormat::S_SIMPLE_BOLD);
922 format.setStrikeOutType ( (
bool)value.toInt() ? KoTextFormat::S_SIMPLE :KoTextFormat::S_NONE);
925 if (n.hasAttribute(
"strikeoutstyleline"))
927 TQString strLineType = n.attribute(
"strikeoutstyleline");
928 format.setStrikeOutStyle( KoTextFormat::stringToStrikeOutStyle( strLineType ));
931 TQString color = n.attribute( attrColor );
932 fn.setPointSize( size );
934 fn.setItalic( italic );
936 TQColor col( color );
938 format.setFont( fn );
939 format.setColor( col );
940 TQString textBackColor=n.attribute(attrTextBackColor);
941 if(!textBackColor.isEmpty())
943 TQColor tmpCol(textBackColor);
944 tmpCol=tmpCol.isValid() ? tmpCol : TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base );
945 format.setTextBackgroundColor(tmpCol);
947 if(n.hasAttribute(attrVertAlign))
948 format.setVAlign(
static_cast<KoTextFormat::VerticalAlignment
>(n.attribute(attrVertAlign).toInt() ) );
949 if ( n.hasAttribute(
"text-shadow") )
950 format.parseShadowFromCss( n.attribute(
"text-shadow") );
951 if ( n.hasAttribute(
"relativetextsize") )
952 format.setRelativeTextSize( n.attribute(
"relativetextsize").toDouble() ) ;
953 if ( n.hasAttribute(
"offsetfrombaseline") )
954 format.setOffsetFromBaseLine(
static_cast<int>(n.attribute(
"offsetfrombaseline").toInt() ) );
955 if ( n.hasAttribute(
"wordbyword") )
956 format.setWordByWord(
static_cast<int>(n.attribute(
"wordbyword").toInt() ) );
958 if ( n.hasAttribute(
"fontattribute") )
959 format.setAttributeFont( KoTextFormat::stringToAttributeFont(n.attribute(
"fontattribute") ) );
960 if ( n.hasAttribute(
"language"))
961 format.setLanguage( n.attribute(
"language"));
964 format.setLanguage( defaultLanguage);
971KoParagLayout KPrTextObject::loadParagLayout( TQDomElement & parentElem, KPrDocument *doc,
bool findStyle)
973 KoParagLayout layout;
981 TQDomElement element = parentElem.namedItem(
"NAME" ).toElement();
982 if ( !element.isNull() )
984 TQString styleName = element.attribute(
"value" );
985 style = doc->styleCollection()->findStyle( styleName );
988 kdError(33001) <<
"Cannot find style \"" << styleName <<
"\" specified in paragraph LAYOUT - using Standard" << endl;
989 style = doc->styleCollection()->findStyle(
"Standard" );
995 kdError(33001) <<
"Missing NAME tag in paragraph LAYOUT - using Standard" << endl;
996 style = doc->styleCollection()->findStyle(
"Standard" );
999 layout.style = style;
1002 TQDomElement element = parentElem.namedItem(
"INDENTS" ).toElement();
1003 if ( !element.isNull() )
1006 if(element.hasAttribute(
"first"))
1007 val=element.attribute(
"first").toDouble();
1008 layout.margins[TQStyleSheetItem::MarginFirstLine] = val;
1010 if(element.hasAttribute(
"left"))
1012 val=TQMAX(0, element.attribute(
"left").toDouble());
1013 layout.margins[TQStyleSheetItem::MarginLeft] = val;
1015 if(element.hasAttribute(
"right"))
1017 val=TQMAX(0, element.attribute(
"right").toDouble());
1018 layout.margins[TQStyleSheetItem::MarginRight] = val;
1020 element = parentElem.namedItem(
"LINESPACING" ).toElement();
1021 if ( !element.isNull() )
1024 if ( element.hasAttribute(
"value" ))
1026 TQString value = element.attribute(
"value" );
1027 if ( value ==
"oneandhalf" )
1029 layout.lineSpacingType = KoParagLayout::LS_ONEANDHALF;
1030 layout.setLineSpacingValue(0);
1032 else if ( value ==
"double" )
1034 layout.lineSpacingType = KoParagLayout::LS_DOUBLE;
1035 layout.setLineSpacingValue(0);
1039 layout.lineSpacingType = KoParagLayout::LS_CUSTOM;
1040 layout.setLineSpacingValue(value.toDouble());
1045 TQString type = element.attribute(
"type" );
1046 if ( type ==
"oneandhalf" )
1048 layout.lineSpacingType = KoParagLayout::LS_ONEANDHALF;
1049 layout.setLineSpacingValue(0);
1051 else if ( type ==
"double" )
1053 layout.lineSpacingType = KoParagLayout::LS_DOUBLE;
1054 layout.setLineSpacingValue(0);
1056 else if ( type ==
"custom" )
1058 layout.lineSpacingType = KoParagLayout::LS_CUSTOM;
1059 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1061 else if ( type ==
"atleast" )
1063 layout.lineSpacingType = KoParagLayout::LS_AT_LEAST;
1064 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1066 else if ( type ==
"multiple" )
1068 layout.lineSpacingType = KoParagLayout::LS_MULTIPLE;
1069 layout.setLineSpacingValue(element.attribute(
"spacingvalue" ).toDouble());
1074 element = parentElem.namedItem(
"OFFSETS" ).toElement();
1075 if ( !element.isNull() )
1078 if(element.hasAttribute(
"before"))
1079 val=TQMAX(0, element.attribute(
"before").toDouble());
1080 layout.margins[TQStyleSheetItem::MarginTop] = val;
1082 if(element.hasAttribute(
"after"))
1083 val=TQMAX(0, element.attribute(
"after").toDouble());
1084 layout.margins[TQStyleSheetItem::MarginBottom] = val;
1088 element = parentElem.namedItem(
"LEFTBORDER" ).toElement();
1089 if ( !element.isNull() )
1090 layout.leftBorder = KoBorder::loadBorder( element );
1092 layout.leftBorder.setPenWidth( 0);
1094 element = parentElem.namedItem(
"RIGHTBORDER" ).toElement();
1095 if ( !element.isNull() )
1096 layout.rightBorder = KoBorder::loadBorder( element );
1098 layout.rightBorder.setPenWidth( 0);
1100 element = parentElem.namedItem(
"TOPBORDER" ).toElement();
1101 if ( !element.isNull() )
1102 layout.topBorder = KoBorder::loadBorder( element );
1104 layout.topBorder.setPenWidth(0);
1106 element = parentElem.namedItem(
"BOTTOMBORDER" ).toElement();
1107 if ( !element.isNull() )
1108 layout.bottomBorder = KoBorder::loadBorder( element );
1110 layout.bottomBorder.setPenWidth(0);
1112 element = parentElem.namedItem(
"COUNTER" ).toElement();
1113 if ( !element.isNull() )
1115 layout.counter =
new KoParagCounter;
1116 layout.counter->load( element );
1119 KoTabulatorList tabList;
1120 element = parentElem.firstChild().toElement();
1121 for ( ; !element.isNull() ; element = element.nextSibling().toElement() )
1123 if ( element.tagName() ==
"TABULATOR" )
1127 if(element.hasAttribute(
"type"))
1128 tab.type =
static_cast<KoTabulators
>( element.attribute(
"type").toInt());
1130 if(element.hasAttribute(
"ptpos"))
1131 tab.ptPos=element.attribute(
"ptpos").toDouble();
1132 tab.filling=TF_BLANK;
1133 if(element.hasAttribute(
"filling"))
1134 tab.filling =
static_cast<KoTabulatorFilling
>( element.attribute(
"filling").toInt());
1136 if(element.hasAttribute(
"width"))
1137 tab.ptWidth=element.attribute(
"width").toDouble();
1138 tabList.append( tab );
1141 layout.setTabList( tabList );
1147void KPrTextObject::saveParagLayout(
const KoParagLayout& layout, TQDomElement & parentElem )
1149 TQDomDocument doc = parentElem.ownerDocument();
1150 TQDomElement element = doc.createElement(
"NAME" );
1151 parentElem.appendChild( element );
1153 element.setAttribute(
"value", layout.style->name() );
1155 kdWarning() <<
"KWTextParag::saveParagLayout: style==0L!" << endl;
1158 if ( layout.margins[TQStyleSheetItem::MarginFirstLine] != 0 ||
1159 layout.margins[TQStyleSheetItem::MarginLeft] != 0 ||
1160 layout.margins[TQStyleSheetItem::MarginRight] != 0 )
1162 element = doc.createElement(
"INDENTS" );
1163 parentElem.appendChild( element );
1164 if ( layout.margins[TQStyleSheetItem::MarginFirstLine] != 0 )
1165 element.setAttribute(
"first", layout.margins[TQStyleSheetItem::MarginFirstLine] );
1166 if ( layout.margins[TQStyleSheetItem::MarginLeft] != 0 )
1167 element.setAttribute(
"left", layout.margins[TQStyleSheetItem::MarginLeft] );
1168 if ( layout.margins[TQStyleSheetItem::MarginRight] != 0 )
1169 element.setAttribute(
"right", layout.margins[TQStyleSheetItem::MarginRight] );
1173 if ( layout.margins[TQStyleSheetItem::MarginTop] != 0 ||
1174 layout.margins[TQStyleSheetItem::MarginBottom] != 0 )
1176 element = doc.createElement(
"OFFSETS" );
1177 parentElem.appendChild( element );
1178 if ( layout.margins[TQStyleSheetItem::MarginTop] != 0 )
1179 element.setAttribute(
"before", layout.margins[TQStyleSheetItem::MarginTop] );
1180 if ( layout.margins[TQStyleSheetItem::MarginBottom] != 0 )
1181 element.setAttribute(
"after", layout.margins[TQStyleSheetItem::MarginBottom] );
1184 if ( layout.lineSpacingType != KoParagLayout::LS_SINGLE )
1186 element = doc.createElement(
"LINESPACING" );
1187 parentElem.appendChild( element );
1188 if ( layout.lineSpacingType == KoParagLayout::LS_ONEANDHALF )
1189 element.setAttribute(
"type",
"oneandhalf" );
1190 else if ( layout.lineSpacingType == KoParagLayout::LS_DOUBLE )
1191 element.setAttribute(
"type",
"double" );
1192 else if ( layout.lineSpacingType == KoParagLayout::LS_CUSTOM )
1194 element.setAttribute(
"type",
"custom" );
1195 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1197 else if ( layout.lineSpacingType == KoParagLayout::LS_AT_LEAST )
1199 element.setAttribute(
"type",
"atleast" );
1200 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1202 else if ( layout.lineSpacingType == KoParagLayout::LS_MULTIPLE )
1204 element.setAttribute(
"type",
"multiple" );
1205 element.setAttribute(
"spacingvalue", layout.lineSpacingValue());
1208 kdDebug(33001) <<
" error in lineSpacing Type" << endl;
1211 if ( layout.leftBorder.penWidth() > 0 )
1213 element = doc.createElement(
"LEFTBORDER" );
1214 parentElem.appendChild( element );
1215 layout.leftBorder.save( element );
1217 if ( layout.rightBorder.penWidth() > 0 )
1219 element = doc.createElement(
"RIGHTBORDER" );
1220 parentElem.appendChild( element );
1221 layout.rightBorder.save( element );
1223 if ( layout.topBorder.penWidth() > 0 )
1225 element = doc.createElement(
"TOPBORDER" );
1226 parentElem.appendChild( element );
1227 layout.topBorder.save( element );
1229 if ( layout.bottomBorder.penWidth() > 0 )
1231 element = doc.createElement(
"BOTTOMBORDER" );
1232 parentElem.appendChild( element );
1233 layout.bottomBorder.save( element );
1236 if ( layout.counter && layout.counter->numbering() != KoParagCounter::NUM_NONE )
1238 element = doc.createElement(
"COUNTER" );
1239 parentElem.appendChild( element );
1240 if (layout.counter )
1241 layout.counter->save( element );
1244 KoTabulatorList tabList = layout.tabList();
1245 KoTabulatorList::ConstIterator it = tabList.begin();
1246 for ( ; it != tabList.end() ; it++ )
1248 element = doc.createElement(
"TABULATOR" );
1249 parentElem.appendChild( element );
1250 element.setAttribute(
"type", (*it).type );
1251 element.setAttribute(
"ptpos", (*it).ptPos );
1252 element.setAttribute(
"filling", (*it).filling );
1253 element.setAttribute(
"width", (*it).ptWidth );
1257void KPrTextObject::recalcPageNum( KPrPage *page )
1259 int pgnum=m_doc->pageList().findRef(page);
1262 TQPtrListIterator<KoTextCustomItem> cit( textDocument()->allCustomItems() );
1263 for ( ; cit.current() ; ++cit )
1265 KPrPgNumVariable * var =
dynamic_cast<KPrPgNumVariable *
>( cit.current() );
1266 if ( var && !var->isDeleted() )
1268 switch ( var->subType() ) {
1269 case KPrPgNumVariable::VST_PGNUM_CURRENT:
1270 var->setPgNum( pgnum + kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber()-1);
1272 case KPrPgNumVariable::VST_CURRENT_SECTION:
1273 var->setSectionTitle( page->pageTitle() );
1275 case KPrPgNumVariable::VST_PGNUM_PREVIOUS:
1276 var->setPgNum( TQMAX( pgnum -1 , 0) +
1277 kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber());
1279 case KPrPgNumVariable::VST_PGNUM_NEXT:
1280 var->setPgNum( TQMIN( (
int)m_doc->getPageNums(), pgnum+1 ) +
1281 kPresenterDocument()->getVariableCollection()->variableSetting()->startingPageNumber());
1288 var->paragraph()->invalidate( 0 );
1289 var->paragraph()->setChanged(
true );
1294void KPrTextObject::layout()
1298 m_textobj->formatMore( 2 );
1301void KPrTextObject::invalidate()
1304 m_textobj->setLastFormattedParag( textDocument()->firstParag() );
1305 textDocument()->formatter()->setViewFormattingChars( m_doc->viewFormattingChars() );
1306 textDocument()->invalidate();
1310void KPrTextObject::drawParags( TQPainter *painter, KoTextZoomHandler* zoomHandler,
const TQColorGroup& cg,
int from,
int to )
1317 Q_ASSERT( from <= to );
1319 bool editMode=
false;
1320 if( m_doc->firstView() && m_doc->firstView()->getCanvas())
1321 editMode = m_doc->firstView()->getCanvas()->getEditMode();
1323 TQRect r = zoomHandler->zoomRect( KoRect( 0, 0, innerWidth(), innerHeight() ) );
1324 KoTextParag *parag = textDocument()->firstParag();
1326 if ( !parag->isValid() )
1329 r.setTop( m_doc->zoomHandler()->layoutUnitToPixelY( parag->rect().top() ) );
1331 r.setBottom( m_doc->zoomHandler()->layoutUnitToPixelY( parag->rect().bottom() ) );
1335 parag = parag->next();
1338 uint drawingFlags = 0;
1339 if ( m_doc->backgroundSpellCheckEnabled() && editMode )
1340 drawingFlags |= KoTextDocument::DrawMisspelledLine;
1341 textDocument()->drawWYSIWYG(
1342 painter, r.x(), r.y(), r.width(), r.height(),
1343 cg, m_doc->zoomHandler(),
1345 true , drawingFlags );
1348void KPrTextObject::drawCursor( TQPainter *p, KoTextCursor *cursor,
bool cursorVisible,
KPrCanvas* canvas )
1351 KoTextZoomHandler *zh = m_doc->zoomHandler();
1352 TQPoint origPix = zh->zoomPoint( orig+KoPoint(bLeft(), bTop()+alignVertical) );
1354 p->translate( origPix.x(), origPix.y() );
1356 rotateObject( p, zh );
1358 KoTextParag* parag = cursor->parag();
1359 TQPoint topLeft = parag->rect().topLeft();
1362 int cursorHeight = zh->layoutUnitToPixelY( topLeft.y(), parag->lineHeightOfChar( cursor->index(), 0, &lineY ) );
1363 TQPoint iPoint( topLeft.x() + cursor->x(),
1364 topLeft.y() + lineY );
1366 iPoint = zh->layoutUnitToPixel( iPoint );
1368 TQPoint vPoint = iPoint;
1374 TQRect clip( vPoint.x() - 5, vPoint.y() , 10, cursorHeight );
1375 setupClipRegion( p, clip );
1381 TQColorGroup cg = TQApplication::palette().active();
1382 cg.setColor( TQColorGroup::Base, m_doc->txtBackCol() );
1384 uint drawingFlags = KoTextDocument::DrawSelections;
1385 if ( m_doc->backgroundSpellCheckEnabled() )
1386 drawingFlags |= KoTextDocument::DrawMisspelledLine;
1387 if ( m_doc->viewFormattingChars() )
1388 drawingFlags |= KoTextDocument::DrawFormattingChars;
1391 bool wasChanged = parag->hasChanged();
1392 int oldLineChanged = parag->lineChanged();
1394 parag->lineStartOfChar( cursor->index(), 0, &line );
1395 parag->setChanged(
false );
1396 parag->setLineChanged( line );
1399 textDocument()->drawParagWYSIWYG(
1401 TQMAX(0, iPoint.x() - 5),
1402 iPoint.y(), clip.width(), clip.height(),
1403 pix, cg, m_doc->zoomHandler(),
1404 cursorVisible, cursor,
false , drawingFlags );
1407 cursor->parag()->setLineChanged( oldLineChanged );
1409 cursor->parag()->setChanged(
false );
1412 TQPoint ximPoint = vPoint;
1413 TQFont f = parag->at( cursor->index() )->format()->font();
1414 canvas->setXimPosition( ximPoint.x() + origPix.x(), ximPoint.y() + origPix.y(),
1415 0, cursorHeight - parag->lineSpacing( line ), &f );
1420 return static_cast<KPrTextDocument*
>(m_textobj->textDocument());
1423void KPrTextObject::slotNewCommand( KCommand * cmd)
1425 m_doc->addCommand(cmd);
1428int KPrTextObject::availableHeight()
const
1430 return m_textobj->availableHeight();
1433void KPrTextObject::slotAvailableHeightNeeded()
1435 int ah = m_doc->zoomHandler()->ptToLayoutUnitPixY( innerHeight() );
1436 m_textobj->setAvailableHeight( ah );
1440void KPrTextObject::slotRepaintChanged()
1442 emit repaintChanged(
this );
1445KPrTextView * KPrTextObject::createKPTextView(
KPrCanvas * _canvas,
bool temp )
1447 return new KPrTextView(
this, _canvas, temp );
1450void KPrTextObject::removeHighlight ()
1452 m_textobj->removeHighlight(
true );
1455void KPrTextObject::highlightPortion( KoTextParag * parag,
int index,
int length,
KPrCanvas* canvas,
bool repaint, KDialogBase* dialog )
1457 m_textobj->highlightPortion( parag, index, length, repaint );
1460 KPrDocument* doc = canvas->getView()->kPresenterDoc();
1463 if ( canvas->activePage()->findTextObject(
this ) )
1465 kdDebug(33001) << k_funcinfo <<
"object in current page" << endl;
1471 KPrPage* page = doc->findPage(
this );
1473 int pageNum = doc->pageList().findRef( page );
1477 canvas->getView()->skipToPage( pageNum );
1480 kdWarning(33001) <<
"object " <<
this <<
" not found in any page!?" << endl;
1483 TQRect rect = m_doc->zoomHandler()->zoomRect( getRect() );
1484 TQRect expose = m_doc->zoomHandler()->layoutUnitToPixel( parag->rect() );
1485 expose.moveBy( rect.x(), rect.y() );
1486 canvas->ensureVisible( (expose.left()+expose.right()) / 2,
1487 (expose.top()+expose.bottom()) / 2,
1488 (expose.right()-expose.left()) / 2,
1489 (expose.bottom()-expose.top()) / 2);
1491 TQRect globalRect( expose );
1492 globalRect.moveTopLeft( canvas->mapToGlobal( globalRect.topLeft() ) );
1493 KDialog::avoidArea( dialog, globalRect );
1498KCommand * KPrTextObject::pasteOasis( KoTextCursor * cursor,
const TQByteArray & data,
bool removeSelected )
1501 KMacroCommand * macroCmd =
new KMacroCommand( i18n(
"Paste Text") );
1502 if ( removeSelected && textDocument()->hasSelection( KoTextDocument::Standard ) )
1503 macroCmd->addCommand( m_textobj->removeSelectedTextCommand( cursor, KoTextDocument::Standard ) );
1504 m_textobj->emitHideCursor();
1505 m_textobj->setLastFormattedParag( cursor->parag()->prev() ?
1506 cursor->parag()->prev() : cursor->parag() );
1510 KPrOasisPasteTextCommand * cmd =
new KPrOasisPasteTextCommand( textDocument(), cursor->parag()->paragId(), cursor->index(), data );
1511 textDocument()->addCommand( cmd );
1513 macroCmd->addCommand(
new KoTextCommand( m_textobj, TQString() ) );
1514 *cursor = *( cmd->execute( cursor ) );
1516 m_textobj->formatMore( 2 );
1517 emit repaintChanged(
this );
1518 m_textobj->emitEnsureCursorVisible();
1519 m_textobj->emitUpdateUI(
true );
1520 m_textobj->emitShowCursor();
1521 m_textobj->selectionChangedNotify();
1526void KPrTextObject::setShadowParameter(
int _distance,ShadowDirection _direction,
const TQColor &_color)
1530 switch ( _direction )
1532 case SD_LEFT_BOTTOM:
1538 case SD_RIGHT_BOTTOM:
1543 switch ( _direction )
1549 case SD_LEFT_BOTTOM:
1551 case SD_RIGHT_BOTTOM:
1556 KoTextFormat tmpFormat;
1557 tmpFormat.setShadow( sx, sy, _color );
1558 KCommand* cmd = m_textobj->setFormatCommand( &tmpFormat, KoTextFormat::ShadowText );
1560 m_doc->addCommand(cmd);
1563void KPrTextObject::slotFormatChanged(
const KoTextFormat &_format)
1565 if(m_doc && m_doc->firstView())
1566 m_doc->firstView()->showFormat( _format );
1569void KPrTextObject::applyStyleChange( KoStyleChangeDefMap changed )
1571 m_textobj->applyStyleChange( changed );
1574void KPrTextObject::slotAfterFormatting(
int bottom, KoTextParag* lastFormatted,
bool* abort)
1576 recalcVerticalAlignment();
1577 int availHeight = availableHeight() - m_doc->zoomHandler()->ptToLayoutUnitPixY(alignmentValue());
1578 if ( ( bottom > availHeight ) ||
1579 ( lastFormatted && (bottom + lastFormatted->rect().height() > availHeight) ) )
1581 int difference = ( bottom + 2 ) - availHeight;
1582 if( lastFormatted && bottom + lastFormatted->rect().height() > availHeight )
1584 difference += lastFormatted->rect().height();
1588 kdDebug(33001) <<
"slotAfterFormatting We need more space in " <<
this
1589 <<
" bottom=" << bottom + lastFormatted->rect().height()
1590 <<
" availHeight=" << availHeight
1591 <<
" ->difference=" << difference << endl;
1593 kdDebug(33001) <<
"slotAfterFormatting We need more space in " <<
this
1594 <<
" bottom2=" << bottom <<
" availHeight=" << availHeight
1595 <<
" ->difference=" << difference << endl;
1598 if(difference > 0 && !isProtect())
1600 double wantedPosition = m_doc->zoomHandler()->layoutUnitPtToPt( m_doc->zoomHandler()->pixelYToPt( difference ) )
1601 + getRect().bottom();
1602 const KoPageLayout& p = m_doc->pageLayout();
1603 double pageBottom = p.ptHeight - p.ptBottom;
1604 double newBottom = TQMIN( wantedPosition, pageBottom );
1605 newBottom = TQMAX( newBottom, getOrig().y() );
1607 if ( getRect().bottom() != newBottom )
1611 KPrObject::setSize( getSize().width(), newBottom - getOrig().y() );
1613 slotAvailableHeightNeeded();
1614 m_doc->updateRuler();
1615 m_doc->repaint(
true );
1619 else if ( isProtect() )
1620 m_textobj->setLastFormattedParag( 0 );
1625KCommand * KPrTextObject::textContentsToHeight()
1631 KoTextParag * parag = textDocument()->firstParag();
1633 int textHeightLU = 0;
1634 bool lineSpacingEqual =
false;
1635 int oldLineSpacing = 0;
1636 for ( ; parag ; parag = parag->next() )
1638 int lines = parag->lines();
1640 for (
int line = 0 ; line < lines ; ++line )
1643 parag->lineInfo( line, y, h, baseLine );
1644 int ls = parag->lineSpacing( line );
1645 lineSpacingEqual = (oldLineSpacing == ls);
1646 oldLineSpacing = ls;
1647 textHeightLU += h - ls;
1651 double textHeight = m_doc->zoomHandler()->layoutUnitPtToPt( textHeightLU );
1652 double lineSpacing = ( innerHeight() - textHeight ) / numLines;
1655 if ( KABS( innerHeight() - textHeight ) < DBL_EPSILON )
1657 bool oneLine =(textDocument()->firstParag() == textDocument()->lastParag() && numLines == 1);
1658 if ( lineSpacing < 0 || oneLine)
1661 if ( (oneLine || lineSpacingEqual) && (textDocument()->firstParag()->kwLineSpacing() == lineSpacing))
1664 textDocument()->selectAll( KoTextDocument::Temp );
1665 KCommand* cmd = m_textobj->setLineSpacingCommand( 0L, lineSpacing, KoParagLayout::LS_CUSTOM, KoTextDocument::Temp );
1666 textDocument()->removeSelection( KoTextDocument::Temp );
1671KCommand * KPrTextObject::textObjectToContents()
1677 KoTextParag * parag = textDocument()->firstParag();
1678 double txtWidth = 10;
1679 for ( ; parag ; parag = parag->next() )
1680 txtWidth = TQMAX( txtWidth, m_doc->zoomHandler()->layoutUnitPtToPt( parag->widthUsed() ));
1683 int heightLU = textDocument()->height();
1684 double txtHeight = m_doc->zoomHandler()->layoutUnitPtToPt( heightLU );
1687 KoSize sizeDiff = KoSize( txtWidth, txtHeight ) - innerRect().size();
1688 if( !sizeDiff.isNull() )
1691 return new KPrResizeCmd( TQString(), KoPoint( 0, 0 ), sizeDiff,
this, m_doc);
1696void KPrTextObject::setTextMargins(
double _left,
double _top,
double _right,
double _bottom)
1704KoRect KPrTextObject::innerRect()
const
1706 KoRect inner( getRect());
1707 inner.moveBy( bLeft(), bTop());
1708 inner.setWidth( inner.width() - bLeft() - bRight() );
1709 inner.setHeight( inner.height() - bTop() - bBottom() );
1713double KPrTextObject::innerWidth()
const
1715 return getSize().width() - bLeft() - bRight();
1718double KPrTextObject::innerHeight()
const
1720 return getSize().height() - bTop() - bBottom();
1723void KPrTextObject::setVerticalAligment( VerticalAlignmentType _type)
1725 m_textVertAlign = _type;
1726 recalcVerticalAlignment();
1729void KPrTextObject::recalcVerticalAlignment()
1731 double txtHeight = m_doc->zoomHandler()->layoutUnitPtToPt( m_doc->zoomHandler()->pixelYToPt( textDocument()->height() ) ) + btop + bbottom;
1732 double diffy = getSize().height() - txtHeight;
1736 if ( diffy <= 0.0 ) {
1737 alignVertical = 0.0;
1740 switch( m_textVertAlign )
1743 alignVertical = diffy/2.0;
1746 alignVertical = 0.0;
1749 alignVertical = diffy;
1754TQPoint KPrTextObject::cursorPos(
KPrCanvas *canvas, KoTextCursor *cursor)
const
1756 KoTextZoomHandler *zh = m_doc->zoomHandler();
1757 TQPoint origPix = zh->zoomPoint( orig+KoPoint(bLeft(), bTop()+alignVertical) );
1758 KoTextParag* parag = cursor->parag();
1759 TQPoint topLeft = parag->rect().topLeft();
1763 TQPoint iPoint( topLeft.x() + cursor->x(), topLeft.y() + lineY );
1764 iPoint = zh->layoutUnitToPixel( iPoint );
1765 iPoint.rx() -= canvas->diffx();
1766 iPoint.ry() -= canvas->diffy();
1767 return origPix+iPoint;
1770KPrTextView::KPrTextView( KPrTextObject * txtObj,
KPrCanvas *_canvas,
bool temp )
1771 : KoTextView( txtObj->textObject() )
1773 setBackSpeller( txtObj->kPresenterDocument()->backSpeller() );
1778 connect( txtObj->textObject(), TQ_SIGNAL( selectionChanged(
bool) ),
1779 m_canvas, TQ_SIGNAL( selectionChanged(
bool) ) );
1780 KoTextView::setReadWrite( txtObj->kPresenterDocument()->isReadWrite() );
1781 connect( textView(), TQ_SIGNAL( cut() ), TQ_SLOT( cut() ) );
1782 connect( textView(), TQ_SIGNAL( copy() ), TQ_SLOT( copy() ) );
1783 connect( textView(), TQ_SIGNAL( paste() ), TQ_SLOT( paste() ) );
1784 updateUI(
true,
true );
1786 txtObj->setEditingTextObj(
true );
1789KPrTextView::~KPrTextView()
1793KoTextViewIface* KPrTextView::dcopObject()
1796 dcop =
new KPrTextViewIface(
this );
1801void KPrTextView::terminate(
bool removeSelection)
1803 disconnect( textView()->textObject(), TQ_SIGNAL( selectionChanged(
bool) ),
1804 m_canvas, TQ_SIGNAL( selectionChanged(
bool) ) );
1805 textView()->terminate(removeSelection);
1808void KPrTextView::cut()
1810 if ( textDocument()->hasSelection( KoTextDocument::Standard ) ) {
1812 textObject()->removeSelectedText( cursor() );
1816void KPrTextView::copy()
1819 if ( textDocument()->hasSelection( KoTextDocument::Standard ) ) {
1820 TQDragObject *drag = newDrag( 0 );
1821 TQApplication::clipboard()->setData( drag );
1825void KPrTextView::paste()
1829 TQMimeSource *data = TQApplication::clipboard()->data();
1830 TQCString returnedMimeType = KoTextObject::providesOasis( data );
1831 if ( !returnedMimeType.isEmpty() )
1833 TQByteArray arr = data->encodedData( returnedMimeType );
1837 TQFile paste(
"/tmp/oasis.tmp" );
1838 paste.open( IO_WriteOnly );
1839 paste.writeBlock( arr );
1842 KCommand *cmd = kpTextObject()->pasteOasis( cursor(), arr,
true );
1844 kpTextObject()->kPresenterDocument()->addCommand(cmd);
1851 TQString text = TQApplication::clipboard()->text();
1852 if ( !text.isEmpty() )
1853 textObject()->pasteText( cursor(), text, currentFormat(),
true );
1855 kpTextObject()->layout();
1858void KPrTextView::updateUI(
bool updateFormat,
bool force )
1860 KoTextView::updateUI( updateFormat, force );
1862 KoTextParag * parag =
static_cast<KoTextParag*
>( cursor()->parag());
1863 if ( m_paragLayout.alignment != parag->resolveAlignment() || force ) {
1864 m_paragLayout.alignment = parag->resolveAlignment();
1865 m_canvas->getView()->alignChanged( m_paragLayout.alignment );
1869 if ( !m_paragLayout.counter )
1870 m_paragLayout.counter =
new KoParagCounter;
1871 KoParagCounter::Style cstyle = m_paragLayout.counter->style();
1872 if ( parag->counter() )
1873 *m_paragLayout.counter = *parag->counter();
1876 m_paragLayout.counter->setNumbering( KoParagCounter::NUM_NONE );
1877 m_paragLayout.counter->setStyle( KoParagCounter::STYLE_NONE );
1880 if ( m_paragLayout.counter->style() != cstyle || force )
1881 m_canvas->getView()->showCounter( * m_paragLayout.counter );
1883 if(m_paragLayout.leftBorder!=parag->leftBorder() ||
1884 m_paragLayout.rightBorder!=parag->rightBorder() ||
1885 m_paragLayout.topBorder!=parag->topBorder() ||
1886 m_paragLayout.bottomBorder!=parag->bottomBorder() || force )
1888 m_paragLayout.leftBorder = parag->leftBorder();
1889 m_paragLayout.rightBorder = parag->rightBorder();
1890 m_paragLayout.topBorder = parag->topBorder();
1891 m_paragLayout.bottomBorder = parag->bottomBorder();
1896 if ( !parag->style() )
1897 kdWarning(33001) <<
"Paragraph " << parag->paragId() <<
" has no style" << endl;
1898 else if ( m_paragLayout.style != parag->style() || force )
1900 m_paragLayout.style = parag->style();
1901 m_canvas->getView()->showStyle( m_paragLayout.style->name() );
1904 if( m_paragLayout.margins[TQStyleSheetItem::MarginLeft] != parag->margin(TQStyleSheetItem::MarginLeft)
1905 || m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine] != parag->margin(TQStyleSheetItem::MarginFirstLine)
1906 || m_paragLayout.margins[TQStyleSheetItem::MarginRight] != parag->margin(TQStyleSheetItem::MarginRight)
1909 m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine] = parag->margin(TQStyleSheetItem::MarginFirstLine);
1910 m_paragLayout.margins[TQStyleSheetItem::MarginLeft] = parag->margin(TQStyleSheetItem::MarginLeft);
1911 m_paragLayout.margins[TQStyleSheetItem::MarginRight] = parag->margin(TQStyleSheetItem::MarginRight);
1912 m_canvas->getView()->showRulerIndent( m_paragLayout.margins[TQStyleSheetItem::MarginLeft],
1913 m_paragLayout.margins[TQStyleSheetItem::MarginFirstLine],
1914 m_paragLayout.margins[TQStyleSheetItem::MarginRight],
1915 parag->string()->isRightToLeft() );
1918 if( m_paragLayout.tabList() != parag->tabList() || force )
1920 m_paragLayout.setTabList( parag->tabList() );
1921 KoRuler * hr = m_canvas->getView()->getHRuler();
1923 hr->setTabList( parag->tabList() );
1927void KPrTextView::ensureCursorVisible()
1930 KoTextParag * parag = cursor()->parag();
1931 kpTextObject()->textObject()->ensureFormatted( parag );
1932 KoTextStringChar *chr = parag->at( cursor()->index() );
1933 int h = parag->lineHeightOfChar( cursor()->index() );
1934 int x = parag->rect().x() + chr->x;
1935 int y = 0;
int dummy;
1937 parag->lineHeightOfChar( cursor()->index(), &dummy, &y );
1938 y += parag->rect().y();
1940 KPrDocument *doc= m_kptextobj->kPresenterDocument();
1941 KoPoint pt= kpTextObject()->getOrig();
1942 pt.setX( doc->zoomHandler()->layoutUnitPtToPt( doc->zoomHandler()->pixelXToPt( x) ) +pt.x());
1943 pt.setY( doc->zoomHandler()->layoutUnitPtToPt( doc->zoomHandler()->pixelYToPt( y ))+pt.y() );
1945 TQPoint p = m_kptextobj->kPresenterDocument()->zoomHandler()->zoomPoint( pt );
1946 w = m_kptextobj->kPresenterDocument()->zoomHandler()->layoutUnitToPixelX( w );
1947 h = m_kptextobj->kPresenterDocument()->zoomHandler()->layoutUnitToPixelY( h );
1948 m_canvas->ensureVisible( p.x(), p.y() + h / 2, w, h / 2 + 2 );
1951bool KPrTextView::doCompletion( KoTextCursor* cursor, KoTextParag *parag,
int index )
1953 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1955 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1957 return autoFormat->doCompletion( cursor, parag, index, textObject());
1962bool KPrTextView::doToolTipCompletion( KoTextCursor* cursor, KoTextParag *parag,
int index,
int keyPress )
1964 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1966 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1968 return autoFormat->doToolTipCompletion( cursor, parag, index, textObject(), keyPress);
1972void KPrTextView::showToolTipBox(KoTextParag *parag,
int index, TQWidget *widget,
const TQPoint &pos)
1974 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1976 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1978 autoFormat->showToolTipBox(parag, index, widget, pos);
1982void KPrTextView::removeToolTipCompletion()
1984 if( m_kptextobj->kPresenterDocument()->allowAutoFormat() )
1986 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
1988 autoFormat->removeToolTipCompletion();
1991void KPrTextView::textIncreaseIndent()
1993 m_canvas->setTextDepthPlus();
1996bool KPrTextView::textDecreaseIndent()
1998 if (m_paragLayout.margins[TQStyleSheetItem::MarginLeft]>0)
2000 m_canvas->setTextDepthMinus();
2007void KPrTextView::doAutoFormat( KoTextCursor* cursor, KoTextParag *parag,
int index, TQChar ch )
2009 if( m_kptextobj->kPresenterDocument()->allowAutoFormat())
2011 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
2013 autoFormat->doAutoFormat( cursor, parag, index, ch, textObject());
2017bool KPrTextView::doIgnoreDoubleSpace(KoTextParag * parag,
int index,TQChar ch )
2019 if( m_kptextobj->kPresenterDocument()->allowAutoFormat())
2022 KoAutoFormat * autoFormat = m_kptextobj->kPresenterDocument()->getAutoFormat();
2024 return autoFormat->doIgnoreDoubleSpace( parag, index,ch );
2029void KPrTextView::startDrag()
2031 textView()->dragStarted();
2032 m_canvas->dragStarted();
2033 TQDragObject *drag = newDrag( m_canvas );
2034 if ( !kpTextObject()->kPresenterDocument()->isReadWrite() )
2038 if ( drag->drag() && TQDragObject::target() != m_canvas )
2039 textObject()->removeSelectedText( cursor() );
2043void KPrTextView::showFormat( KoTextFormat *format )
2045 m_canvas->getView()->showFormat( *format );
2048bool KPrTextView::pgUpKeyPressed()
2050 KoTextCursor *cursor = textView()->cursor();
2051 KoTextParag *s = cursor->parag();
2052 s = textDocument()->firstParag();
2054 textView()->cursor()->setParag( s );
2055 textView()->cursor()->setIndex( 0 );
2059bool KPrTextView::pgDownKeyPressed()
2061 KoTextCursor *cursor = textView()->cursor();
2062 KoTextParag *s = cursor->parag();
2063 s = textDocument()->lastParag();
2064 cursor->setParag( s );
2065 cursor->setIndex( s->length() - 1 );
2069void KPrTextView::keyPressEvent( TQKeyEvent *e )
2072 const TQPoint pos = kpTextObject()->cursorPos(m_canvas, cursor());
2073 textView()->handleKeyPressEvent( e, m_canvas, pos );
2076void KPrTextView::keyReleaseEvent( TQKeyEvent *e )
2078 handleKeyReleaseEvent(e);
2081void KPrTextView::imStartEvent( TQIMEvent *e )
2083 handleImStartEvent(e);
2086void KPrTextView::imComposeEvent( TQIMEvent *e )
2088 handleImComposeEvent(e);
2091void KPrTextView::imEndEvent( TQIMEvent *e )
2093 handleImEndEvent(e);
2096void KPrTextView::clearSelection()
2098 if ( textDocument()->hasSelection( KoTextDocument::Standard ) )
2099 textDocument()->removeSelection(KoTextDocument::Standard );
2102void KPrTextView::selectAll(
bool select)
2104 textObject()->selectAll( select );
2107void KPrTextView::drawCursor(
bool b )
2109 KoTextView::drawCursor( b );
2110 if ( !cursor()->parag() )
2112 if ( !kpTextObject()->kPresenterDocument()->isReadWrite() )
2115 TQPainter painter( m_canvas );
2116 painter.translate( -m_canvas->diffx(), -m_canvas->diffy() );
2117 painter.setBrushOrigin( -m_canvas->diffx(), -m_canvas->diffy() );
2119 kpTextObject()->drawCursor( &painter, cursor(), b, m_canvas );
2123TQPoint KPrTextView::viewToInternal(
const TQPoint & pos )
const
2126 KoTextZoomHandler* zh = kpTextObject()->kPresenterDocument()->zoomHandler();
2129 m.translate( zh->zoomItX(kpTextObject()->getSize().width() / 2.0),
2130 zh->zoomItY(kpTextObject()->getSize().height() / 2.0) );
2131 m.rotate( kpTextObject()->getAngle() );
2135 m.translate( zh->zoomItX(kpTextObject()->getOrig().x()),
2136 zh->zoomItY(kpTextObject()->getOrig().y()) );
2140 kdDebug(33001)<<
" tmp.x() :"<<tmp.x()<<
" tmp.y() "<<tmp.y()<<endl;
2142 KoRect br = KoRect( 0, 0, kpTextObject()->getSize().width(), kpTextObject()->getSize().height() );
2143 double pw = br.width();
2144 double ph = br.height();
2146 double yPos = -rr.y();
2147 double xPos = -rr.x();
2148 rr.moveTopLeft( KoPoint( -rr.width() / 2.0, -rr.height() / 2.0 ) );
2150 m.translate( zh->zoomItX(pw / 2.0),
2151 zh->zoomItY(ph / 2.0 ));
2152 m.rotate( kpTextObject()->getAngle() );
2153 m.translate( zh->zoomItX(rr.left() + xPos),
2154 zh->zoomItY(rr.top() + yPos) );
2160 kdDebug(33001)<<
" tmp.x() :"<<tmp.x()<<
" tmp.y() "<<tmp.y()<<endl;
2163 return kpTextObject()->viewToInternal( pos, m_canvas );
2166void KPrTextView::mousePressEvent( TQMouseEvent *e,
const TQPoint &)
2168 bool addParag = handleMousePressEvent( e, viewToInternal( e->pos() ),
true ,
2169 kpTextObject()->kPresenterDocument()->insertDirectCursor() );
2172 kpTextObject()->kPresenterDocument()->setModified(
true );
2175void KPrTextView::mouseDoubleClickEvent( TQMouseEvent *e,
const TQPoint &pos)
2177 handleMouseDoubleClickEvent( e, pos );
2180void KPrTextView::mouseMoveEvent( TQMouseEvent *e,
const TQPoint &_pos )
2182 if ( textView()->maybeStartDrag( e ) )
2185 textView()->handleMouseMoveEvent( e,viewToInternal( e->pos() ) );
2188bool KPrTextView::isLinkVariable(
const TQPoint & pos )
2190 const TQPoint iPoint = viewToInternal( pos );
2191 KoLinkVariable* linkVariable =
dynamic_cast<KoLinkVariable *
>( textObject()->variableAtPoint( iPoint ) );
2192 return linkVariable != 0;
2195void KPrTextView::openLink()
2197 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2198 if ( doc->getVariableCollection()->variableSetting()->displayLink() ) {
2199 KoLinkVariable* v = linkVariable();
2201 KoTextView::openLink( v );
2205void KPrTextView::mouseReleaseEvent( TQMouseEvent *,
const TQPoint & )
2207 handleMouseReleaseEvent();
2210void KPrTextView::showPopup( KPrView *view,
const TQPoint &point, TQPtrList<TDEAction>& actionList )
2212 TQString word = wordUnderCursor( *cursor() );
2213 view->unplugActionList(
"datatools" );
2214 view->unplugActionList(
"datatools_link" );
2215 view->unplugActionList(
"spell_result_action" );
2216 view->unplugActionList(
"variable_action" );
2217 TQPtrList<TDEAction> &variableList = view->variableActionList();
2218 variableList.clear();
2221 view->kPresenterDoc()->getVariableCollection()->setVariableSelected(variable());
2222 KoVariable* var = variable();
2225 variableList = view->kPresenterDoc()->getVariableCollection()->popupActionList();
2228 if( variableList.count()>0)
2230 view->plugActionList(
"variable_action", variableList );
2231 TQPopupMenu * popup = view->popupMenu(
"variable_popup");
2234 popup->popup( point );
2239 bool singleWord=
false;
2240 actionList = dataToolActionList(view->kPresenterDoc()->instance(), word, singleWord);
2242 KoLinkVariable* linkVar =
dynamic_cast<KoLinkVariable *
>( var );
2243 TQPopupMenu * popup;
2246 view->plugActionList(
"datatools", actionList );
2248 KoNoteVariable * noteVar =
dynamic_cast<KoNoteVariable *
>( var );
2249 KoCustomVariable * customVar =
dynamic_cast<KoCustomVariable *
>( var );
2251 popup = view->popupMenu(
"note_popup");
2252 else if( customVar )
2253 popup = view->popupMenu(
"custom_var_popup");
2258 TQPtrList<TDEAction> actionCheckSpellList =view->listOfResultOfCheckWord( word );
2259 if ( actionCheckSpellList.count()>0)
2261 view->plugActionList(
"spell_result_action", actionCheckSpellList );
2262 popup = view->popupMenu(
"text_popup_spell_with_result");
2265 popup = view->popupMenu(
"text_popup_spell");
2268 popup = view->popupMenu(
"text_popup");
2273 view->plugActionList(
"datatools_link", actionList );
2274 popup = view->popupMenu(
"text_popup_link");
2278 popup->popup( point );
2282void KPrTextView::insertCustomVariable(
const TQString &name)
2284 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2285 KoVariable * var =
new KoCustomVariable( textDocument(), name, doc->variableFormatCollection()->format(
"STRING" ),
2286 doc->getVariableCollection());
2287 insertVariable( var );
2290void KPrTextView::insertLink(
const TQString &_linkName,
const TQString & hrefName)
2292 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2293 KoVariable * var =
new KoLinkVariable( textDocument(), _linkName, hrefName,
2294 doc->variableFormatCollection()->format(
"STRING" ),
2295 doc->getVariableCollection());
2296 insertVariable( var );
2299void KPrTextView::insertComment(
const TQString &_comment)
2301 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2303 KoVariable * var =
new KoNoteVariable( textDocument(), _comment,
2304 doc->variableFormatCollection()->format(
"STRING" ),
2305 doc->getVariableCollection());
2306 insertVariable( var );
2309void KPrTextView::insertVariable(
int type,
int subtype )
2311 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2312 bool refreshCustomMenu =
false;
2313 KoVariable * var = 0L;
2314 if ( type == VT_CUSTOM )
2316 KoCustomVarDialog dia( m_canvas );
2317 if ( dia.exec() == TQDialog::Accepted )
2319 KoCustomVariable *v =
new KoCustomVariable( textDocument(), dia.name(),
2320 doc->variableFormatCollection()->format(
"STRING" ),
2321 doc->getVariableCollection() );
2322 v->setValue( dia.value() );
2324 refreshCustomMenu =
true;
2328 var = doc->getVariableCollection()->createVariable( type, subtype, doc->variableFormatCollection(), 0L, textDocument(),doc, 0);
2331 insertVariable( var, 0, refreshCustomMenu);
2332 doc->recalcPageNum();
2336void KPrTextView::insertVariable( KoVariable *var, KoTextFormat *format,
bool refreshCustomMenu )
2340 CustomItemsMap customItemsMap;
2341 customItemsMap.insert( 0, var );
2343 format = currentFormat();
2346 kdDebug(33001) <<
"KPrTextView::insertVariable currentFormat=" << currentFormat() << endl;
2348 textObject()->insert( cursor(), format, KoTextObject::customItemChar(),
2349 i18n(
"Insert Variable"),
2350 KoTextDocument::Standard,
2351 KoTextObject::DoNotRemoveSelected,
2353 if ( refreshCustomMenu && var->type() == VT_CUSTOM )
2354 kpTextObject()->kPresenterDocument()->refreshMenuCustomVariable();
2355 kpTextObject()->kPresenterDocument()->repaint( kpTextObject() );
2359bool KPrTextView::canDecode( TQMimeSource *e )
2361 return kpTextObject()->kPresenterDocument()->isReadWrite() && ( !KoTextObject::providesOasis( e ).isNull() || TQTextDrag::canDecode( e ) );
2364TQDragObject * KPrTextView::newDrag( TQWidget * parent )
2367 const TQCString mimeType =
"application/vnd.oasis.opendocument.text";
2368 KoStore * store = KoStore::createStore( &buffer, KoStore::Write, mimeType );
2370 Q_ASSERT( !store->bad() );
2372 KoOasisStore oasisStore( store );
2376 KPrDocument * doc = kpTextObject()->kPresenterDocument();
2378 doc->getVariableCollection()->variableSetting()->setModificationDate( TQDateTime::currentDateTime() );
2379 doc->recalcVariables( VT_DATE );
2380 doc->recalcVariables( VT_TIME );
2381 doc->recalcVariables( VT_STATISTIC );
2383 KoGenStyles mainStyles;
2384 KoSavingContext savingContext( mainStyles, 0,
false, KoSavingContext::Store );
2386 doc->styleCollection()->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
2388 KoXmlWriter* bodyWriter = oasisStore.bodyWriter();
2389 bodyWriter->startElement(
"office:body" );
2390 bodyWriter->startElement(
"office:text" );
2392 const TQString plainText = textDocument()->copySelection( *bodyWriter, savingContext, KoTextDocument::Standard );
2394 bodyWriter->endElement();
2395 bodyWriter->endElement();
2397 KoXmlWriter* contentWriter = oasisStore.contentWriter();
2398 Q_ASSERT( contentWriter );
2401 doc->writeAutomaticStyles( *contentWriter, mainStyles, savingContext,
false );
2403 oasisStore.closeContentWriter();
2405 if ( !store->open(
"styles.xml" ) )
2408 doc->saveOasisDocumentStyles( store, mainStyles, 0, savingContext, KPrDocument::SaveSelected );
2409 if ( !store->close() )
2414 KMultipleDrag* multiDrag =
new KMultipleDrag( parent );
2415 if ( !plainText.isEmpty() )
2416 multiDrag->addDragObject(
new TQTextDrag( plainText, 0 ) );
2417 KoStoreDrag* storeDrag =
new KoStoreDrag( mimeType, 0 );
2418 kdDebug() << k_funcinfo <<
"setting zip data: " << buffer.buffer().size() <<
" bytes." << endl;
2419 storeDrag->setEncodedData( buffer.buffer() );
2420 multiDrag->addDragObject( storeDrag );
2424void KPrTextView::dragEnterEvent( TQDragEnterEvent *e )
2426 if ( !canDecode( e ) )
2434void KPrTextView::dragMoveEvent( TQDragMoveEvent *e,
const TQPoint & )
2436 if ( !canDecode( e ) )
2441 TQPoint iPoint = viewToInternal( e->pos() );
2443 textObject()->emitHideCursor();
2444 placeCursor( iPoint );
2445 textObject()->emitShowCursor();
2449void KPrTextView::dropEvent( TQDropEvent * e )
2451 if ( canDecode( e ) )
2453 KPrDocument *doc = kpTextObject()->kPresenterDocument();
2455 KoTextCursor dropCursor( textDocument() );
2456 TQPoint dropPoint = viewToInternal( e->pos() );
2457 KMacroCommand *macroCmd=
new KMacroCommand(i18n(
"Paste Text"));
2458 bool addMacroCmd =
false;
2459 dropCursor.place( dropPoint, textDocument()->firstParag() );
2460 kdDebug(33001) <<
"KPrTextView::dropEvent dropCursor at parag=" << dropCursor.parag()->paragId() <<
" index=" << dropCursor.index() << endl;
2462 if ( ( e->source() == m_canvas ) &&
2463 e->action() == TQDropEvent::Move &&
2465 textDocument()->hasSelection( KoTextDocument::Standard )
2468 KCommand *cmd = textView()->prepareDropMove( dropCursor );
2471 kpTextObject()->layout();
2472 macroCmd->addCommand(cmd);
2483 textDocument()->removeSelection( KoTextDocument::Standard );
2484 textObject()->selectionChangedNotify();
2486 TQCString returnedTypeMime = KoTextObject::providesOasis( e );
2487 if ( !returnedTypeMime.isEmpty() )
2489 TQByteArray arr = e->encodedData( returnedTypeMime );
2492 KCommand *cmd = kpTextObject()->pasteOasis( cursor(), arr,
false );
2495 macroCmd->addCommand(cmd);
2503 if ( TQTextDrag::decode( e, text ) )
2504 textObject()->pasteText( cursor(), text, currentFormat(),
2508 doc->addCommand(macroCmd);
2514void KPrTextObject::saveParagraph( TQDomDocument& doc,KoTextParag * parag,TQDomElement &parentElem,
2520 TQDomElement paragraph=doc.createElement(tagP);
2522 switch(parag->resolveAlignment())
2524 case TQt::AlignLeft:
2527 case TQt::AlignRight:
2530 case TQt::AlignHCenter:
2533 case TQt::AlignJustify:
2537 paragraph.setAttribute(attrAlign, tmpAlign);
2539 saveParagLayout( parag->paragLayout(), paragraph );
2540 KoTextFormat *lastFormat = 0;
2542 for (
int i = from; i <= to; ++i ) {
2543 KoTextStringChar &c = parag->string()->at(i);
2546 TQDomElement variable = doc.createElement(
"CUSTOM");
2547 variable.setAttribute(
"pos", (i-from));
2548 saveFormat( variable, c.format() );
2549 paragraph.appendChild( variable );
2550 static_cast<KoTextCustomItem *
>( c.customItem() )->save(variable );
2552 if ( !lastFormat || c.format()->key() != lastFormat->key() ) {
2554 paragraph.appendChild(saveHelper(tmpText, lastFormat, doc));
2555 lastFormat =
static_cast<KoTextFormat*
> (c.format());
2558 tmpText+=TQString(c.c);
2561 paragraph.appendChild(saveHelper(tmpText, lastFormat, doc));
2563 paragraph.appendChild(saveHelper(tmpText, parag->string()->at(0).format(), doc));
2565 parentElem.appendChild(paragraph);
2570 return KoPen( TQt::black, 1.0, TQt::NoPen );
2573TQPoint KPrTextObject::viewToInternal(
const TQPoint & pos,
KPrCanvas* canvas )
const
2575 KoTextZoomHandler* zh = kPresenterDocument()->zoomHandler();
2576 TQPoint iPoint = pos - zh->zoomPoint(
2577 getOrig() + KoPoint( bLeft(),
2578 bTop() + alignmentValue()) );
2579 iPoint = zh->pixelToLayoutUnit(
2580 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.
virtual KoPen defaultPen() const
save() only saves if the pen is different from the default pen.
This is our KoTextDocument reimplementation, to relate it to the textobject it's in.