20#include "KWVariable.h"
22#include "KWTextFrameSet.h"
23#include "KWTextDocument.h"
24#include "KWMailMergeDataBase.h"
25#include "KWDocument.h"
27#include "KWViewMode.h"
28#include "KWPageManager.h"
30#include <KoVariable.h>
31#include <KoXmlWriter.h>
38KWVariableSettings::KWVariableSettings() : KoVariableSettings()
40 m_footNoteCounter.setSuffix( TQString() );
41 m_endNoteCounter.setSuffix( TQString() );
43 m_endNoteCounter.setStyle( KoParagCounter::STYLE_ROM_NUM_L );
46void KWVariableSettings::changeFootNoteCounter( KoParagCounter _c )
48 m_footNoteCounter = _c;
51void KWVariableSettings::changeEndNoteCounter( KoParagCounter _c )
53 m_endNoteCounter = _c;
56void KWVariableSettings::saveNoteConfiguration( KoXmlWriter& writer )
const
58 writer.startElement(
"text:notes-configuration" );
59 writer.addAttribute(
"text:note-class",
"footnote" );
61 m_footNoteCounter.saveOasisListLevel( writer,
false );
62 writer.addAttribute(
"text:footnotes-position",
"page" );
63 writer.addAttribute(
"text:start-numbering-at",
"document" );
65 writer.startElement(
"text:notes-configuration" );
66 writer.addAttribute(
"text:note-class",
"endnote" );
68 m_endNoteCounter.saveOasisListLevel( writer,
false );
69 writer.addAttribute(
"text:start-numbering-at",
"document" );
73void KWVariableSettings::loadNoteConfiguration(
const TQDomElement& parent )
76 forEachElement( e, parent )
78 if ( e.localName() ==
"notes-configuration" && e.namespaceURI() == KoXmlNS::text )
80 const TQString noteClass = e.attributeNS( KoXmlNS::text,
"note-class", TQString() );
81 if ( noteClass ==
"footnote" ) {
82 m_footNoteCounter.loadOasisListStyle( e, TQDomElement(), TQDomElement(), -1,
true,
false, 1,
false );
83 m_footNoteCounter.setNumbering( KoParagCounter::NUM_FOOTNOTE );
84 m_footNoteCounter.setRestartCounter(
false );
86 else if ( noteClass ==
"endnote" ) {
87 m_endNoteCounter.loadOasisListStyle( e, TQDomElement(), TQDomElement(), -1,
true,
false, 1,
false );
88 m_endNoteCounter.setNumbering( KoParagCounter::NUM_FOOTNOTE );
89 m_endNoteCounter.setRestartCounter(
false );
95void KWVariableSettings::save( TQDomElement &parentElem )
97 KoVariableSettings::save( parentElem );
98 TQDomDocument doc = parentElem.ownerDocument();
99 TQDomElement footNoteSettingElem = doc.createElement(
"FOOTNOTESETTING" );
100 parentElem.appendChild( footNoteSettingElem );
101 m_footNoteCounter.save( footNoteSettingElem );
102 TQDomElement endNoteSettingElem = doc.createElement(
"ENDNOTESETTING" );
103 parentElem.appendChild( endNoteSettingElem );
104 m_endNoteCounter.save( endNoteSettingElem );
107void KWVariableSettings::load( TQDomElement &elem )
109 KoVariableSettings::load( elem );
110 TQDomElement footNoteSettings = elem.namedItem(
"FOOTNOTESETTING" ).toElement();
111 if ( !footNoteSettings.isNull() )
112 m_footNoteCounter.load( footNoteSettings );
113 TQDomElement endNoteSettings = elem.namedItem(
"ENDNOTESETTING" ).toElement();
114 if ( !endNoteSettings.isNull() )
115 m_endNoteCounter.load( endNoteSettings );
118KWVariableCollection::KWVariableCollection(KWVariableSettings *_setting, KoVariableFormatCollection* coll)
119 : KoVariableCollection(_setting, coll)
123KoVariable* KWVariableCollection::loadOasisField( KoTextDocument* textdoc,
const TQDomElement& tag, KoOasisContext& context )
125 const TQString localName( tag.localName() );
126 const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
130 if ( localName ==
"note" )
132 TQString key =
"STRING";
133 int type = VT_FOOTNOTE;
134 return loadOasisFieldCreateVariable( textdoc, tag, context, key, type );
136 else if ( localName ==
"table-count" ||
137 localName ==
"object-count" ||
138 localName ==
"picture-count" ||
139 localName ==
"paragraph-count" ||
140 localName ==
"word-count" ||
141 localName ==
"character-count" ||
142 localName ==
"sentence-count" ||
143 localName ==
"line-count" ||
144 localName ==
"frame-count" ||
145 localName ==
"non-whitespace-character-count" ||
146 localName ==
"syllable-count")
148 TQString key =
"NUMBER";
149 int type = VT_STATISTIC;
150 return loadOasisFieldCreateVariable( textdoc, tag, context, key, type );
153 return KoVariableCollection::loadOasisField( textdoc, tag, context );
156 return KoVariableCollection::loadOasisField( textdoc, tag, context );
159KoVariable *KWVariableCollection::createVariable(
int type,
short int subtype, KoVariableFormatCollection * coll, KoVariableFormat *varFormat,KoTextDocument *textdoc, KoDocument * doc,
int _correct,
bool _forceDefaultFormat,
bool loadFootNote )
161 KWDocument *m_doc =
static_cast<KWDocument *
>(doc);
162 KoVariable * var = 0L;
166 varFormat = (subtype == KoPageVariable::VST_CURRENT_SECTION) ? coll->format(
"STRING") : coll->format(
"NUMBER");
176 varFormat = coll->format(
"STRING");
181 varFormat = coll->format(
"NUMBER");
182 var =
new KWStatisticVariable( textdoc, subtype, varFormat,
this, m_doc );
185 return KoVariableCollection::createVariable( type, subtype, coll, varFormat, textdoc, doc, _correct, _forceDefaultFormat );
193KWPgNumVariable::KWPgNumVariable( KoTextDocument *textdoc,
int subtype, KoVariableFormat *varFormat ,KoVariableCollection *_varColl, KWDocument *doc )
194 : KoPageVariable( textdoc, subtype, varFormat ,_varColl ), m_doc(doc)
198void KWPgNumVariable::recalc()
200 if ( !m_doc->layoutViewMode()->hasPages() )
208 if ( m_subtype == VST_PGNUM_TOTAL )
210 m_varValue = TQVariant(m_doc->pageCount()+m_varColl->variableSetting()->startingPageNumber()-1);
219TQString KWPgNumVariable::text(
bool realValue)
221 if (m_varColl->variableSetting()->displayFieldCode()&& !realValue)
224 else if ( m_subtype != VST_CURRENT_SECTION && !m_doc->layoutViewMode()->hasPages() && !realValue)
227 return m_varFormat->convert( m_varValue );
233KWMailMergeVariable::KWMailMergeVariable( KoTextDocument *textdoc,
const TQString &name, KoVariableFormat *varFormat,KoVariableCollection *_varColl, KWDocument *doc )
234 : KoMailMergeVariable( textdoc, name, varFormat,_varColl ), m_doc(doc)
238TQString KWMailMergeVariable::value()
const
240 return m_doc->mailMergeDataBase()->getValue( m_varValue.toString() );
243TQString KWMailMergeVariable::text(
bool realValue)
245 if (m_varColl->variableSetting()->displayFieldCode()&& !realValue)
248 TQString v = value();
249 if ( m_doc->mailMergeDataBase()->isSampleRecord() )
250 return "<" + v +
">";
254void KWMailMergeVariable::recalc()
261KWFootNoteVariable::KWFootNoteVariable( KoTextDocument *textdoc, KoVariableFormat *varFormat, KoVariableCollection *varColl, KWDocument *doc )
262 : KoVariable( textdoc, varFormat, varColl ),
265 m_numberingType( Auto ),
269 m_varValue = TQVariant( TQString() );
272void KWFootNoteVariable::setNumberingType( Numbering _type )
274 m_numberingType = _type;
276 setVariableFormat(m_doc->variableFormatCollection()->format(
"STRING"));
279void KWFootNoteVariable::loadOasis(
const TQDomElement& footNoteTag, KoOasisContext& context )
283 const TQString
id = footNoteTag.attributeNS( KoXmlNS::text,
"id", TQString() );
285 if ( footNoteTag.hasAttributeNS( KoXmlNS::text,
"note-class" ) )
287 const TQString str = footNoteTag.attributeNS( KoXmlNS::text,
"note-class", TQString() );
288 if ( str ==
"footnote" )
289 m_noteType = FootNote;
290 else if ( str ==
"endnote" )
291 m_noteType = EndNote;
293 kdWarning()<<
" Unknown footnote type: '" << str <<
"'" << endl;
294 m_noteType = FootNote;
298 TQDomElement element;
299 TQDomElement bodyElement;
300 forEachElement( element, footNoteTag )
302 if ( element.namespaceURI() != KoXmlNS::text )
305 const TQString localName = element.localName();
306 if( localName ==
"note-citation" )
308 if ( element.hasAttributeNS( KoXmlNS::text,
"label" ) )
309 m_numberingType = Manual;
311 m_numberingType = Auto;
312 if ( m_numberingType == Auto )
315 m_numDisplay = element.text().toInt();
321 m_varValue = TQVariant( element.text() );
323 }
else if ( localName ==
"note-body" ) {
324 bodyElement = element;
327 Q_ASSERT( !bodyElement.isNull() );
329 Q_ASSERT( !m_frameset );
330 m_frameset =
new KWFootNoteFrameSet( m_doc,
id );
331 m_frameset->setFrameSetInfo( KWFrameSet::FI_FOOTNOTE );
333 m_frameset->setFootNoteVariable(
this );
334 m_frameset->createInitialFrame( 0 );
335 m_doc->addFrameSet( m_frameset );
338 m_frameset->loadOasisContent( bodyElement, context );
341void KWFootNoteVariable::saveOasis( KoXmlWriter& writer, KoSavingContext& context )
const
343 if(! m_frameset)
return;
348 writer.startElement(
"text:note" );
349 writer.addAttribute(
"text:id",m_frameset->name() );
350 writer.addAttribute(
"text:note-class", m_noteType == FootNote ?
"footnote" :
"endnote" );
352 writer.startElement(
"text:note-citation" );
353 if ( m_numberingType == Auto )
354 writer.addTextNode( TQString(
"%1" ).arg( m_numDisplay ) );
357 writer.addAttribute(
"text:label", m_varValue.toString() );
358 writer.addTextNode(m_varValue.toString() );
362 writer.startElement(
"text:note-body" );
364 m_frameset->saveOasisContent( writer, context );
370void KWFootNoteVariable::saveVariable( TQDomElement &parentElem )
372 TQDomElement footnoteElem = parentElem.ownerDocument().createElement(
"FOOTNOTE" );
373 parentElem.appendChild( footnoteElem );
375 if ( m_numberingType == Auto )
376 footnoteElem.setAttribute(
"value", m_numDisplay );
378 footnoteElem.setAttribute(
"value", m_varValue.toString() );
379 footnoteElem.setAttribute(
"notetype", m_noteType == FootNote ?
"footnote" :
"endnote" );
380 footnoteElem.setAttribute(
"numberingtype", m_numberingType == Auto ?
"auto" :
"manual" );
381 Q_ASSERT( m_frameset );
383 footnoteElem.setAttribute(
"frameset", m_frameset->name() );
386void KWFootNoteVariable::load( TQDomElement &elem )
388 KoVariable::load( elem );
389 TQDomElement footnoteElem = elem.namedItem(
"FOOTNOTE" ).toElement();
390 if (!footnoteElem.isNull())
393 TQString str = footnoteElem.attribute(
"notetype").lower();
394 if ( str ==
"footnote" )
395 m_noteType = FootNote;
396 else if ( str ==
"endnote" )
397 m_noteType = EndNote;
399 kdWarning() <<
"Unknown footnote type: '" << str <<
"'" << endl;
401 str = footnoteElem.attribute(
"numberingtype").lower();
403 m_numberingType = Auto;
404 else if ( str ==
"manual")
405 m_numberingType = Manual;
407 kdWarning() <<
"Unknown footnote numbering: '" << str <<
"'" << endl;
409 if ( m_numberingType == Auto )
411 m_numDisplay = footnoteElem.attribute(
"value").toInt();
415 m_varValue = TQVariant(footnoteElem.attribute(
"value"));
417 str = footnoteElem.attribute(
"frameset");
418 m_doc->addFootNoteRequest( str,
this );
422void KWFootNoteVariable::formatedNote()
424 if ( m_numberingType == Auto )
426 m_varValue = TQVariant(applyStyle());
430TQString KWFootNoteVariable::applyStyle()
432 KWVariableSettings* settings =
static_cast<KWVariableSettings*
>(m_varColl->variableSetting());
433 KoParagCounter tmpCounter = (m_noteType == FootNote) ? settings->footNoteCounter() : settings->endNoteCounter();
436 int val = m_numDisplay + tmpCounter.startNumber()-1;
437 Q_ASSERT( val >= 0 );
439 return i18n(
"ERROR");
440 switch ( tmpCounter.style() )
442 case KoParagCounter::STYLE_NUM:
445 case KoParagCounter::STYLE_ALPHAB_L:
446 tmp=KoParagCounter::makeAlphaLowerNumber( val );
448 case KoParagCounter::STYLE_ALPHAB_U:
449 tmp=KoParagCounter::makeAlphaUpperNumber( val );
451 case KoParagCounter::STYLE_ROM_NUM_L:
452 tmp = KoParagCounter::makeRomanNumber( val ).lower();
454 case KoParagCounter::STYLE_ROM_NUM_U:
455 tmp = KoParagCounter::makeRomanNumber( val ).upper();
457 case KoParagCounter::STYLE_CUSTOMBULLET:
459 tmp = tmpCounter.customBulletCharacter();
466 tmp.prepend( tmpCounter.prefix() );
467 tmp.append( tmpCounter.suffix() );
471TQString KWFootNoteVariable::text(
bool realValue)
473 if (m_varColl->variableSetting()->displayFieldCode()&& !realValue)
475 return m_varFormat->convert( m_varValue );
478void KWFootNoteVariable::setNumDisplay(
int val )
485TQString KWFootNoteVariable::fieldCode()
487 return (noteType()==FootNote) ?i18n(
"Footnote"):i18n(
"Endnote");
490void KWFootNoteVariable::drawCustomItem( TQPainter* p,
int x,
int y,
int wpix,
int hpix,
int ascentpix,
int ,
int ,
int ,
int ,
const TQColorGroup& cg,
bool selected,
int _offset,
bool drawingShadow )
492 KoTextFormat * fmt = format();
493 KoTextZoomHandler * zh = textDocument()->paintingZoomHandler();
496 TQFont font( fmt->screenFont( zh ) );
497 int pointSize = ( ( font.pointSize() * 2 ) / 3 );
498 font.setPointSize( pointSize );
500 int offset = _offset;
503 int h = zh->layoutUnitToPixelY( height );
504 offset = -( h - TQFontMetrics(font).height() );
507 TQColor textColor( fmt->color() );
508 drawCustomItemHelper( p, x, y, wpix, hpix, ascentpix, cg, selected, offset, fmt, font, textColor, drawingShadow );
511void KWFootNoteVariable::finalize()
513 Q_ASSERT( m_frameset );
516 Q_ASSERT( !m_frameset->isDeleted() );
517 if ( m_frameset->isDeleted() )
522 int pageNum = this->pageNum();
526 KWFrame* footNoteFrame = m_frameset->frame( 0 );
528 if ( framePage != pageNum )
536 m_doc->delayedRecalcFrames( TQMIN( pageNum, framePage ) );
537 m_doc->delayedRepaintAllViews();
541void KWFootNoteVariable::resize()
545 KoTextFormat *fmt = format();
546 TQFont font( fmt->refFont() );
547 if ( fmt->vAlign() == KoTextFormat::AlignNormal )
549 int pointSize = ( ( font.pointSize() * 2 ) / 3 );
550 font.setPointSize( pointSize );
552 TQFontMetrics fm( font );
553 TQString txt = text();
555 for (
int i = 0 ; i < (int)txt.length() ; ++i )
556 width += fm.charWidth( txt, i );
558 width = tqRound( KoTextZoomHandler::ptToLayoutUnitPt( width ) );
559 height = fmt->height();
560 m_ascent = fmt->ascent();
564void KWFootNoteVariable::setDeleted(
bool del )
566 kdDebug() <<
"KWFootNoteVariable::setDeleted " << del << endl;
569 Q_ASSERT( m_frameset );
571 m_frameset->deleteAllFrames();
572 m_frameset->setVisible(
false );
577 Q_ASSERT( m_frameset );
579 kdDebug() <<
"Making frameset " << m_frameset <<
" visible" << endl;
580 m_frameset->setVisible(
true );
581 if ( m_frameset->isDeleted() )
582 m_frameset->createInitialFrame( 0 );
583 Q_ASSERT( m_frameset->isVisible() );
596 m_doc->recalcFrames();
599 m_frameset->layout();
600 KoVariable::setDeleted( del );
602 m_doc->delayedRepaintAllViews();
605int KWFootNoteVariable::pageNum()
const
607 int page = m_doc->pageManager()->pageNumber(varY());
608 Q_ASSERT( page <= m_doc->lastPage() );
612double KWFootNoteVariable::varY()
const
615 int paragy = paragraph()->rect().y();
619 kdDebug(32001) <<
"KWFootNoteVariable::varY too early, no updateFrames yet" << endl;
631 if ( containingFrame )
634 double varY = dPoint.y();
647KWStatisticVariable::KWStatisticVariable( KoTextDocument *textdoc,
int subtype, KoVariableFormat *varFormat,KoVariableCollection *_varColl, KWDocument *doc )
648 : KoStatisticVariable( textdoc, subtype, varFormat, _varColl ),
653void KWStatisticVariable::recalc()
656 ulong charsWithSpace = 0L;
657 ulong charsWithoutSpace = 0L;
659 ulong sentences = 0L;
661 ulong syllables = 0L;
662 bool frameInfo = ( m_subtype == VST_STATISTIC_NB_WORD ||
663 m_subtype == VST_STATISTIC_NB_SENTENCE ||
664 m_subtype == VST_STATISTIC_NB_LINES ||
665 m_subtype == VST_STATISTIC_NB_CHARACTERE);
666 TQPtrListIterator<KWFrameSet> framesetIt( m_doc->framesetsIterator() );
668 for ( framesetIt.toFirst(); framesetIt.current(); ++framesetIt )
673 if ( m_subtype == VST_STATISTIC_NB_FRAME )
677 else if( m_subtype == VST_STATISTIC_NB_PICTURE && frameSet->
type() == FT_PICTURE )
681 else if( m_subtype == VST_STATISTIC_NB_TABLE && frameSet->
type() == FT_TABLE )
685 else if( m_subtype == VST_STATISTIC_NB_EMBEDDED && frameSet->
type() == FT_PART )
693 frameSet->statistics( 0L, charsWithSpace, charsWithoutSpace,
694 words, sentences, syllables, lines,
false );
699 if( m_subtype == VST_STATISTIC_NB_WORD )
703 else if( m_subtype == VST_STATISTIC_NB_SENTENCE )
707 else if( m_subtype == VST_STATISTIC_NB_LINES )
711 else if ( m_subtype == VST_STATISTIC_NB_CHARACTERE )
715 else if ( m_subtype == VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE )
717 nb = charsWithoutSpace;
719 else if ( m_subtype == VST_STATISTIC_NB_SYLLABLE )
727 m_varValue = TQVariant(nb);
733TQString KWStatisticVariable::text(
bool realValue)
735 if ( m_varColl->variableSetting()->displayFieldCode() && !realValue )
738 return m_varFormat->convert( m_varValue );
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
virtual FrameSetType type() const
The type of frameset.
Info frameSetInfo() const
Returns the type of TextFrameSet this is.
bool isVisible(KWViewMode *viewMode=0L) const
Returns true if the frameset is visible.
bool hasFramesInPageArray() const
Allows to detect that updateFrames() hasn't been called yet (e.g.
This class represents a single frame.
int pageNumber() const
The page on which this frame is.
"current page number" and "number of pages" variables
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
KoTextObject * textObject() const
Return the contained text object.
KWFrame * internalToDocument(const KoPoint &relPoint, KoPoint &dPoint) const
Convert the in the internal qtextdoc coordinates (in layout units) into a point in the document coord...
void renumberFootNotes(bool repaint=true)
(Assuming this==main frameset), recalc the foot note numbers