21#include "KoVariable.h"
22#include "KoVariable.moc"
23#include "KoTextZoomHandler.h"
24#include "TimeFormatWidget.h"
25#include "DateFormatWidget.h"
26#include "KoTextCommand.h"
27#include "KoTextObject.h"
28#include "KoTextParag.h"
29#include "KoOasisContext.h"
30#include <KoOasisSettings.h>
32#include <KoDocumentInfo.h>
33#include <KoOasisStyles.h>
34#include <KoXmlWriter.h>
35#include <KoDocument.h>
42#include <kdialogbase.h>
44#include <tdeinstance.h>
45#include <kcalendarsystem.h>
46#include <tdeaboutdata.h>
48#include <tqstringlist.h>
49#include <tqcombobox.h>
50#include <tqvaluelist.h>
52#include <tqradiobutton.h>
54#include "IsoDuration.h"
56class KoVariableSettings::KoVariableSettingPrivate
59 KoVariableSettingPrivate()
61 m_lastPrintingDate.setTime_t(0);
63 TQDateTime m_lastPrintingDate;
64 TQDateTime m_creationDate;
65 TQDateTime m_modificationDate;
69KoVariableSettings::KoVariableSettings()
71 d =
new KoVariableSettingPrivate;
72 m_startingPageNumber = 1;
74 m_displayComment =
true;
75 m_underlineLink =
true;
76 m_displayFieldCode =
false;
79KoVariableSettings::~KoVariableSettings()
85TQDateTime KoVariableSettings::lastPrintingDate()
const
87 return d->m_lastPrintingDate;
90void KoVariableSettings::setLastPrintingDate(
const TQDateTime & _date)
92 d->m_lastPrintingDate = _date;
95TQDateTime KoVariableSettings::creationDate()
const
97 return d->m_creationDate;
100void KoVariableSettings::setCreationDate(
const TQDateTime & _date )
102 d->m_creationDate = _date;
105TQDateTime KoVariableSettings::modificationDate()
const
107 return d->m_modificationDate;
110void KoVariableSettings::setModificationDate(
const TQDateTime & _date)
112 d->m_modificationDate = _date;
115void KoVariableSettings::saveOasis(
KoXmlWriter &settingsWriter )
const
118 settingsWriter.
addAttribute(
"config:name",
"configuration-variable-settings");
120 settingsWriter.
addConfigItem(
"underlinelink", m_underlineLink);
121 settingsWriter.
addConfigItem(
"displaycomment", m_displayComment);
122 settingsWriter.
addConfigItem(
"displayfieldcode", m_displayFieldCode);
126 if ( d->m_lastPrintingDate.isValid())
127 settingsWriter.
addConfigItem(
"lastPrintingDate", d->m_lastPrintingDate.toString(TQt::ISODate));
129 if ( d->m_creationDate.isValid())
130 settingsWriter.
addConfigItem(
"creationDate", d->m_creationDate.toString(TQt::ISODate));
132 if ( d->m_modificationDate.isValid())
133 settingsWriter.
addConfigItem(
"modificationDate", d->m_modificationDate.toString(TQt::ISODate));
140 KoOasisSettings::Items configurationSettings = settingsDoc.
itemSet(
"configuration-variable-settings" );
141 if ( !configurationSettings.isNull() )
143 m_displayLink = configurationSettings.parseConfigItemBool(
"displaylink",
true );
144 m_underlineLink = configurationSettings.parseConfigItemBool(
"underlinelink",
true );
145 m_displayComment = configurationSettings.parseConfigItemBool(
"displaycomment",
true );
146 m_displayFieldCode = configurationSettings.parseConfigItemBool(
"displayfieldcode",
false );
148 TQString str = configurationSettings.parseConfigItemString(
"lastPrintingDate" );
149 if ( !str.isEmpty() )
150 d->m_lastPrintingDate = TQDateTime::fromString( str, TQt::ISODate );
152 d->m_lastPrintingDate.setTime_t(0);
154 str = configurationSettings.parseConfigItemString(
"creationDate" );
155 if ( !str.isEmpty() ) {
156 d->m_creationDate = TQDateTime::fromString( str, TQt::ISODate );
159 str = configurationSettings.parseConfigItemString(
"modificationDate" );
160 if ( !str.isEmpty() )
161 d->m_modificationDate = TQDateTime::fromString( str, TQt::ISODate );
167void KoVariableSettings::save( TQDomElement &parentElem )
169 TQDomElement elem = parentElem.ownerDocument().createElement(
"VARIABLESETTINGS" );
170 parentElem.appendChild( elem );
171 if(m_startingPageNumber!=1)
173 elem.setAttribute(
"startingPageNumber", m_startingPageNumber );
175 elem.setAttribute(
"displaylink",(
int)m_displayLink);
176 elem.setAttribute(
"underlinelink",(
int)m_underlineLink);
177 elem.setAttribute(
"displaycomment",(
int)m_displayComment);
178 elem.setAttribute(
"displayfieldcode", (
int)m_displayFieldCode);
180 if ( d->m_lastPrintingDate.isValid())
181 elem.setAttribute(
"lastPrintingDate", d->m_lastPrintingDate.toString(TQt::ISODate));
183 if ( d->m_creationDate.isValid())
184 elem.setAttribute(
"creationDate", d->m_creationDate.toString(TQt::ISODate));
186 if ( d->m_modificationDate.isValid())
187 elem.setAttribute(
"modificationDate", d->m_modificationDate.toString(TQt::ISODate));
190void KoVariableSettings::load( TQDomElement &elem )
192 TQDomElement e = elem.namedItem(
"VARIABLESETTINGS" ).toElement();
195 if(e.hasAttribute(
"startingPageNumber"))
196 m_startingPageNumber = e.attribute(
"startingPageNumber").toInt();
197 if(e.hasAttribute(
"displaylink"))
198 m_displayLink=(bool)e.attribute(
"displaylink").toInt();
199 if(e.hasAttribute(
"underlinelink"))
200 m_underlineLink=(bool)e.attribute(
"underlinelink").toInt();
201 if(e.hasAttribute(
"displaycomment"))
202 m_displayComment=(bool)e.attribute(
"displaycomment").toInt();
203 if (e.hasAttribute(
"displayfieldcode"))
204 m_displayFieldCode=(bool)e.attribute(
"displayfieldcode").toInt();
206 if (e.hasAttribute(
"lastPrintingDate"))
207 d->m_lastPrintingDate = TQDateTime::fromString( e.attribute(
"lastPrintingDate" ), TQt::ISODate );
209 d->m_lastPrintingDate.setTime_t(0);
211 if (e.hasAttribute(
"creationDate")) {
212 d->m_creationDate = TQDateTime::fromString( e.attribute(
"creationDate" ), TQt::ISODate );
215 if (e.hasAttribute(
"modificationDate"))
216 d->m_modificationDate = TQDateTime::fromString( e.attribute(
"modificationDate" ), TQt::ISODate );
226 if ( data.type() != TQVariant::Date && data.type() != TQVariant::DateTime )
228 kdWarning(32500)<<
" Error in KoVariableDateFormat::convert. Value is a "
229 << data.typeName() <<
"(" << data.type() <<
")" << endl;
232 TQDateTime dateTime ( data.toDateTime() );
233 if ( !dateTime.isValid() )
234 return i18n(
"No date set");
236 if (m_strFormat.lower() ==
"locale" || m_strFormat.isEmpty())
237 return TDEGlobal::locale()->formatDate( dateTime.date(),
false );
238 else if ( m_strFormat.lower() ==
"localeshort" )
239 return TDEGlobal::locale()->formatDate( dateTime.date(),
true );
240 else if ( m_strFormat.lower() ==
"localedatetime" )
241 return TDEGlobal::locale()->formatDateTime( dateTime,
false );
242 else if ( m_strFormat.lower() ==
"localedatetimeshort" )
243 return TDEGlobal::locale()->formatDateTime( dateTime,
true );
245 TQString tmp ( dateTime.toString(m_strFormat) );
246 const int month = dateTime.date().month();
247 tmp.replace(
"PPPP", TDEGlobal::locale()->calendar()->monthNamePossessive(month,
false));
248 tmp.replace(
"PPP", TDEGlobal::locale()->calendar()->monthNamePossessive(month,
true));
254 return getKey( m_strFormat );
259 return TQCString(
"DATE") + props.utf8();
264 TQCString params(
key.mid( 4 ) );
265 if ( !params.isEmpty() )
267 if (params[0] ==
'1' || params[0] ==
'0')
268 params = params.mid(1);
269 m_strFormat = TQString::fromUtf8( params );
275TQStringList KoVariableDateFormat::staticFormatPropsList()
277 TQStringList listDateFormat;
278 listDateFormat<<
"locale";
279 listDateFormat<<
"localeshort";
280 listDateFormat<<
"localedatetime";
281 listDateFormat<<
"localedatetimeshort";
282 listDateFormat<<
"dd/MM/yy";
283 listDateFormat<<
"dd/MM/yyyy";
284 listDateFormat<<
"MMM dd,yy";
285 listDateFormat<<
"MMM dd,yyyy";
286 listDateFormat<<
"dd.MMM.yyyy";
287 listDateFormat<<
"MMMM dd, yyyy";
288 listDateFormat<<
"ddd, MMM dd,yy";
289 listDateFormat<<
"dddd, MMM dd,yy";
290 listDateFormat<<
"MM-dd";
291 listDateFormat<<
"yyyy-MM-dd";
292 listDateFormat<<
"dd/yy";
293 listDateFormat<<
"MMMM";
294 listDateFormat<<
"yyyy-MM-dd hh:mm";
295 listDateFormat<<
"dd.MMM.yyyy hh:mm";
296 listDateFormat<<
"MMM dd,yyyy h:mm AP";
297 listDateFormat<<
"yyyy-MM-ddThh:mm:ss";
298 return listDateFormat;
303TQStringList KoVariableDateFormat::staticTranslatedFormatPropsList()
305 TQStringList listDateFormat;
306 listDateFormat<<i18n(
"Locale date format");
307 listDateFormat<<i18n(
"Short locale date format");
308 listDateFormat<<i18n(
"Locale date & time format");
309 listDateFormat<<i18n(
"Short locale date & time format");
310 listDateFormat<<
"dd/MM/yy";
311 listDateFormat<<
"dd/MM/yyyy";
312 listDateFormat<<
"MMM dd,yy";
313 listDateFormat<<
"MMM dd,yyyy";
314 listDateFormat<<
"dd.MMM.yyyy";
315 listDateFormat<<
"MMMM dd, yyyy";
316 listDateFormat<<
"ddd, MMM dd,yy";
317 listDateFormat<<
"dddd, MMM dd,yy";
318 listDateFormat<<
"MM-dd";
319 listDateFormat<<
"yyyy-MM-dd";
320 listDateFormat<<
"dd/yy";
321 listDateFormat<<
"MMMM";
322 listDateFormat<<
"yyyy-MM-dd hh:mm";
323 listDateFormat<<
"dd.MMM.yyyy hh:mm";
324 listDateFormat<<
"MMM dd,yyyy h:mm AP";
325 listDateFormat<<
"yyyy-MM-ddThh:mm:ss";
326 return listDateFormat;
337 TQCString params(
key.mid( 4 ) );
338 if ( !params.isEmpty() )
339 m_strFormat = TQString::fromUtf8(params);
344 if ( time.type() != TQVariant::Time )
346 kdDebug(32500)<<
" Error in KoVariableTimeFormat::convert. Value is a "
347 << time.typeName() <<
"(" << time.type() <<
")" << endl;
351 if( m_strFormat.lower() ==
"locale" || m_strFormat.isEmpty() )
352 return TDEGlobal::locale()->formatTime( time.toTime() );
353 return time.toTime().toString(m_strFormat);
358 return getKey( m_strFormat );
363 return TQCString(
"TIME") + props.utf8();
368TQStringList KoVariableTimeFormat::staticFormatPropsList()
370 TQStringList listTimeFormat;
371 listTimeFormat<<
"locale";
372 listTimeFormat<<
"hh:mm";
373 listTimeFormat<<
"hh:mm:ss";
374 listTimeFormat<<
"hh:mm AP";
375 listTimeFormat<<
"hh:mm:ss AP";
376 listTimeFormat<<
"mm:ss.zzz";
377 return listTimeFormat;
381TQStringList KoVariableTimeFormat::staticTranslatedFormatPropsList()
383 TQStringList listTimeFormat;
384 listTimeFormat<<i18n(
"Locale format");
385 listTimeFormat<<
"hh:mm";
386 listTimeFormat<<
"hh:mm:ss";
387 listTimeFormat<<
"hh:mm AP";
388 listTimeFormat<<
"hh:mm:ss AP";
389 listTimeFormat<<
"mm:ss.zzz";
390 return listTimeFormat;
397 if (
string.type() != TQVariant::String )
399 kdDebug(32500)<<
" Error in KoVariableStringFormat::convert. Value is a " <<
string.typeName() << endl;
403 return string.toString();
408 return getKey( TQString() );
414 return TQCString(
"STRING") + props.utf8();
419TQString KoVariableNumberFormat::convert(
const TQVariant &value )
const
421 if ( value.type() != TQVariant::Int )
423 kdDebug(32500)<<
" Error in KoVariableNumberFormat::convert. Value is a " << value.typeName() << endl;
427 return TQString::number( value.toInt() );
432 return getKey(TQString());
435TQCString KoVariableNumberFormat::getKey(
const TQString& props )
const
437 return TQCString(
"NUMB") + props.utf8();
442KoVariableFormatCollection::KoVariableFormatCollection()
444 m_dict.setAutoDelete(
true );
453 return createFormat( key );
456KoVariableFormat * KoVariableFormatCollection::createFormat(
const TQCString &key )
458 kdDebug(32500) <<
"KoVariableFormatCollection: creating format for key=" << key << endl;
461 TQCString type = key.left(4);
462 if ( type ==
"DATE" )
464 else if ( type ==
"TIME" )
466 else if ( type ==
"NUMB" )
467 format =
new KoVariableNumberFormat();
468 else if ( type ==
"STRI" )
484 m_variableSettings = _settings;
486 m_formatCollection = formatCollection;
489KoVariableCollection::~KoVariableCollection()
491 delete m_variableSettings;
494void KoVariableCollection::clear()
501void KoVariableCollection::registerVariable(
KoVariable *var )
505 variables.append( var );
508void KoVariableCollection::unregisterVariable(
KoVariable *var )
510 variables.take( variables.findRef( var ) );
513TQValueList<KoVariable *> KoVariableCollection::recalcVariables(
int type)
515 TQValueList<KoVariable *> modifiedVariables;
516 TQPtrListIterator<KoVariable> it( variables );
517 for ( ; it.current() ; ++it )
519 KoVariable* variable = it.current();
520 if ( variable->isDeleted() )
522 if ( variable->type() == type || type == VT_ALL )
524 TQVariant oldValue = variable->
varValue();
526 if(variable->height == 0)
528 if ( variable->
varValue() != oldValue )
529 modifiedVariables.append( variable );
530 KoTextParag * parag = variable->paragraph();
534 parag->invalidate( 0 );
535 parag->setChanged(
true );
542 if( !modifiedVariables.isEmpty() )
543 emit repaintVariable();
545 return modifiedVariables;
549void KoVariableCollection::setVariableValue(
const TQString &name,
const TQString &value )
551 varValues[
name ] = value;
554TQString KoVariableCollection::getVariableValue(
const TQString &name )
const
556 if ( !varValues.contains( name ) )
557 return i18n(
"No value" );
558 return varValues[
name ];
561bool KoVariableCollection::customVariableExist(
const TQString &varname)
const
563 return varValues.contains( varname );
566void KoVariableCollection::setVariableSelected(
KoVariable * var)
572TQPtrList<TDEAction> KoVariableCollection::popupActionList()
const
574 TQPtrList<TDEAction> listAction;
576 const TQStringList subTypeList = m_varSelected->
subTypeList();
577 kdDebug() << k_funcinfo <<
"current subtype=" << m_varSelected->subType() << endl;
578 TQStringList::ConstIterator it = subTypeList.begin();
579 for (
int i = 0; it != subTypeList.end() ; ++it, ++i )
581 if ( !(*it).isEmpty() )
585 TDEToggleAction * act =
new TDEToggleAction( *it, TDEShortcut(), 0, name );
586 connect( act, TQ_SIGNAL(activated()),
this, TQ_SLOT(slotChangeSubType()) );
587 if ( i == m_varSelected->subType() )
590 listAction.append( act );
594 KoVariableFormat* format = m_varSelected->variableFormat();
599 for (
int i = 0; it != list.end() ; ++it, ++i )
602 listAction.append(
new TDEActionSeparator() );
604 if ( !(*it).isEmpty() )
607 TQString text = format->
convert( m_varSelected->varValue() );
609 TDEToggleAction * act =
new TDEToggleAction(text, TDEShortcut(), 0, (*it).utf8());
610 connect( act, TQ_SIGNAL(activated()),
this, TQ_SLOT(slotChangeFormat()) );
611 if ( (*it) == currentFormat )
613 listAction.append( act );
622void KoVariableCollection::slotChangeSubType()
624 TDEAction * act = (TDEAction *)(sender());
625 int menuNumber = TQCString(act->name()).toInt();
626 int newSubType = m_varSelected->variableSubType(menuNumber);
627 kdDebug(32500) <<
"slotChangeSubType: menuNumber=" << menuNumber <<
" newSubType=" << newSubType << endl;
628 if ( m_varSelected->subType() != newSubType )
630 KoChangeVariableSubType *cmd=
new KoChangeVariableSubType(
631 m_varSelected->subType(), newSubType, m_varSelected );
633 m_varSelected->textDocument()->emitNewCommand(cmd);
637void KoVariableCollection::slotChangeFormat()
639 TDEAction * act = (TDEAction *)(sender());
640 TQString newFormat = TQString::fromUtf8(act->name());
641 TQString oldFormat = m_varSelected->variableFormat()->formatProperties();
642 if (oldFormat != newFormat )
644 KCommand *cmd=
new KoChangeVariableFormatProperties(
645 oldFormat, newFormat, m_varSelected );
647 m_varSelected->textDocument()->emitNewCommand(cmd);
653 Q_ASSERT( coll == m_formatCollection );
655 TQStringList stringList;
656 if ( varFormat == 0L )
661 case VT_DATE_VAR_KWORD10:
663 if ( _forceDefaultFormat )
668 if ( result.isNull() )
670 varFormat = coll->
format( result );
675 case VT_TIME_VAR_KWORD10:
677 if ( _forceDefaultFormat )
682 if ( result.isNull() )
684 varFormat = coll->
format( result );
689 varFormat = coll->
format(
"NUMBER" );
696 varFormat = coll->
format(
"STRING" );
699 kdError() <<
"Footnote type not handled in KoVariableCollection: VT_FOOTNOTE" << endl;
702 kdError() <<
" Statistic type not handled in KoVariableCollection: VT_STATISTIC" << endl;
706 Q_ASSERT( varFormat );
707 if ( varFormat == 0L )
710 kdDebug(32500) <<
"Creating variable. Format=" << varFormat->
key() <<
" type=" << type << endl;
711 KoVariable * var = 0L;
714 case VT_DATE_VAR_KWORD10:
715 var =
new KoDateVariable( textdoc, subtype, varFormat,
this, _correct );
718 case VT_TIME_VAR_KWORD10:
719 var =
new KoTimeVariable( textdoc, subtype, varFormat,
this, _correct );
722 kdError() <<
"VT_PGNUM must be handled by the application's reimplementation of KoVariableCollection::createVariable" << endl;
726 var =
new KoFieldVariable( textdoc, subtype, varFormat,
this,doc );
729 var =
new KoCustomVariable( textdoc, TQString(), varFormat,
this);
732 var =
new KoMailMergeVariable( textdoc, TQString(), varFormat ,
this);
735 var =
new KoLinkVariable( textdoc,TQString(), TQString(), varFormat ,
this);
738 var =
new KoNoteVariable( textdoc, TQString(), varFormat ,
this);
746KoVariable* KoVariableCollection::loadOasisField( KoTextDocument* textdoc,
const TQDomElement& tag,
KoOasisContext& context )
748 const TQString localName( tag.localName() );
749 const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
754 if ( localName.endsWith(
"date" ) || localName.endsWith(
"time" ) )
756 TQString dataStyleName = tag.attributeNS( KoXmlNS::style,
"data-style-name", TQString() );
757 TQString dateFormat =
"locale";
758 const KoOasisStyles::DataFormatsMap& map = context.oasisStyles().dataFormats();
759 KoOasisStyles::DataFormatsMap::const_iterator it = map.find( dataStyleName );
760 if ( it != map.end() )
761 dateFormat = (*it).formatStr;
766 if ( localName ==
"time" )
769 key =
"TIME" + dateFormat;
774 key =
"DATE" + dateFormat;
777 else if (localName ==
"page-number" || localName ==
"page-count" )
782 else if (localName ==
"chapter")
787 else if (localName ==
"file-name")
792 else if (localName ==
"author-name"
793 || localName ==
"author-initials"
794 || localName ==
"subject"
795 || localName ==
"title"
796 || localName ==
"description"
797 || localName ==
"keywords")
802 else if ( localName.startsWith(
"sender-" )
803 && localName !=
"sender-firstname"
804 && localName !=
"sender-lastname"
805 && localName !=
"sender-initials"
811 else if ( localName ==
"variable-set"
812 || localName ==
"user-defined"
813 || localName ==
"user-field-get" )
821 else if ( tag.namespaceURI() == KoXmlNS::office && localName ==
"annotation" )
834 return loadOasisFieldCreateVariable( textdoc, tag, context, key, type );
837KoVariable* KoVariableCollection::loadOasisFieldCreateVariable( KoTextDocument* textdoc,
const TQDomElement& tag,
KoOasisContext& context,
const TQString &key,
int type )
839 KoVariableFormat * varFormat = key.isEmpty() ? 0 : m_formatCollection->format( key.latin1() );
842 KoVariable* var = createVariable( type, -1, m_formatCollection, varFormat, textdoc, context.koDocument(), 0 ,
true );
843 var->loadOasis( tag, context );
850KoVariable::KoVariable( KoTextDocument *textdoc,
KoVariableFormat *varFormat, KoVariableCollection *_varColl)
855 m_varFormat = varFormat;
856 m_varColl->registerVariable(
this );
860KoVariable::~KoVariable()
863 m_varColl->unregisterVariable(
this );
869 return TQStringList();
878 TQString txt =
text();
882 for (
int i = 0 ; i < (int)txt.length() ; ++i )
883 width += fm.width( txt[i] );
886 height = fmt->height();
887 m_ascent = fmt->ascent();
894 KoTextParag * parag = paragraph();
898 parag->invalidate( 0 );
899 parag->setChanged(
true );
904TQString KoVariable::fieldCode()
906 return i18n(
"Variable");
913 if (m_varColl->variableSetting()->displayFieldCode()&&!realValue)
916 str = m_varFormat->convert( m_varValue );
918 return fmt->displayedString( str);
921void KoVariable::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 )
926 drawCustomItemHelper( p, x, y, wpix, hpix, ascentpix, cg, selected, offset, fmt, font, fmt->color(), drawingShadow );
929void KoVariable::drawCustomItemHelper( TQPainter* p,
int x,
int y,
int wpix,
int hpix,
int ascentpix,
const TQColorGroup& cg,
bool selected,
int offset,
KoTextFormat* fmt,
const TQFont& font, TQColor textColor,
bool drawingShadow )
938 if ( fmt->textBackgroundColor().isValid() )
939 p->fillRect( x, y, wpix, hpix, fmt->textBackgroundColor() );
943 textColor = fmt->shadowColor();
944 p->setPen( textColor );
948 textColor = cg.color( TQColorGroup::HighlightedText );
949 p->setPen( TQPen( textColor ) );
950 p->fillRect( x, y, wpix, hpix, cg.color( TQColorGroup::Highlight ) );
953 && p->device()->devType() != TQInternal::Printer )
955 textColor = cg.color( TQColorGroup::Highlight );
956 p->setPen( TQPen ( textColor, 0, TQt::DotLine ) );
957 p->drawRect( x, y, wpix, hpix );
960 if ( !textColor.isValid() )
962 p->setPen( TQPen( textColor ) );
967 TQString str =
text();
968 KoTextParag::drawFontEffects( p, fmt, zh, font, textColor, x, ascentpix, wpix, y, hpix, str[0] );
969 int posY = y + ascentpix + offset;
970 if ( fmt->vAlign() == KoTextFormat::AlignSubScript )
971 posY +=p->fontMetrics().height() / 6;
972 if ( fmt->vAlign() != KoTextFormat::AlignSuperScript )
973 posY -= fmt->offsetFromBaseLine();
974 else if ( fmt->offsetFromBaseLine() < 0 )
975 posY -= 2*fmt->offsetFromBaseLine();
983 const int len = str.length();
986 for (
int i = 0; i < len; ++i )
988 const TQChar ch = str[i];
989 p->drawText( x, posY, TQString(ch) );
1002 TQDomElement variableElem = parentElem.ownerDocument().createElement(
"VARIABLE" );
1003 parentElem.appendChild( variableElem );
1004 TQDomElement typeElem = parentElem.ownerDocument().createElement(
"TYPE" );
1005 variableElem.appendChild( typeElem );
1006 typeElem.setAttribute(
"type",
static_cast<int>( type() ) );
1010 typeElem.setAttribute(
"key", m_varFormat->key().data() );
1011 typeElem.setAttribute(
"text",
text(
true) );
1012 if ( correctValue() != 0)
1013 typeElem.setAttribute(
"correct", correctValue() );
1017void KoVariable::load( TQDomElement & )
1022void KoVariable::loadOasis(
const TQDomElement &,
KoOasisContext& )
1034 m_varFormat = _varFormat;
1038#define addText( text, newFormat ) { \
1039 if ( !text.isEmpty() ) \
1046TQString KoVariable::convertKlocaleToTQDateTimeFormat(
const TQString & _format )
1049 TQString
format( _format );
1053 if (
format.startsWith(
"%Y" ) )
1055 addText(
text, newFormat );
1059 else if (
format.startsWith(
"%y" ) )
1061 addText(
text, newFormat );
1066 else if (
format.startsWith(
"%n" ) )
1068 addText(
text, newFormat );
1072 else if (
format.startsWith(
"%m" ) )
1074 addText(
text, newFormat );
1078 else if (
format.startsWith(
"%e" ) )
1080 addText(
text, newFormat );
1084 else if (
format.startsWith(
"%d" ) )
1086 addText(
text, newFormat );
1090 else if (
format.startsWith(
"%b" ) )
1092 addText(
text, newFormat );
1096 else if (
format.startsWith(
"%B" ) )
1098 addText(
text, newFormat );
1102 else if (
format.startsWith(
"%a" ) )
1104 addText(
text, newFormat );
1109 else if (
format.startsWith(
"%A" ) )
1111 addText(
text, newFormat );
1115 if (
format.startsWith(
"%H" ) )
1118 addText(
text, newFormat );
1122 else if (
format.startsWith(
"%k" ) )
1124 addText(
text, newFormat );
1128 else if (
format.startsWith(
"%I" ) )
1130 addText(
text, newFormat );
1133 else if (
format.startsWith(
"%l" ) )
1135 addText(
text, newFormat );
1138 else if (
format.startsWith(
"%M" ) )
1140 addText(
text, newFormat );
1144 else if (
format.startsWith(
"%S" ) )
1146 addText(
text, newFormat );
1150 else if (
format.startsWith(
"%p" ) )
1153 addText(
text, newFormat );
1164 while (
format.length() > 0 );
1173KoDateVariable::KoDateVariable( KoTextDocument *textdoc,
short int subtype,
KoVariableFormat *_varFormat, KoVariableCollection *_varColl,
int _correctDate)
1174 :
KoVariable( textdoc, _varFormat,_varColl ), m_subtype( subtype ), m_correctDate( _correctDate)
1178TQString KoDateVariable::fieldCode()
1180 if ( m_subtype == VST_DATE_FIX )
1181 return i18n(
"Date (Fixed)");
1182 else if ( m_subtype == VST_DATE_CURRENT)
1183 return i18n(
"Date");
1184 else if ( m_subtype == VST_DATE_LAST_PRINTING)
1185 return i18n(
"Last Printing");
1186 else if ( m_subtype == VST_DATE_CREATE_FILE )
1187 return i18n(
"File Creation");
1188 else if ( m_subtype == VST_DATE_MODIFY_FILE )
1189 return i18n(
"File Modification");
1191 return i18n(
"Date");
1197 TQString oldLanguage;
1198 if ( !fmt->language().isEmpty())
1200 oldLanguage=TDEGlobal::locale()->language();
1201 bool changeLanguage = TDEGlobal::locale()->setLanguage( fmt->language() );
1203 if ( changeLanguage )
1204 TDEGlobal::locale()->setLanguage( oldLanguage );
1212 if ( m_subtype == VST_DATE_CURRENT )
1213 m_varValue = TQDateTime(TQDateTime::currentDateTime().addDays(m_correctDate));
1214 else if ( m_subtype == VST_DATE_LAST_PRINTING )
1215 m_varValue = m_varColl->variableSetting()->lastPrintingDate();
1216 else if ( m_subtype == VST_DATE_CREATE_FILE )
1217 m_varValue = m_varColl->variableSetting()->creationDate();
1218 else if ( m_subtype == VST_DATE_MODIFY_FILE )
1219 m_varValue = m_varColl->variableSetting()->modificationDate();
1223 if ( m_varValue.isNull() )
1224 m_varValue = TQDateTime(TQDateTime::currentDateTime().addDays(m_correctDate));
1231 TQDomElement elem = varElem.ownerDocument().createElement(
"DATE" );
1232 varElem.appendChild( elem );
1234 TQDate date = m_varValue.toDate();
1235 date = date.addDays( -m_correctDate );
1236 elem.setAttribute(
"year", date.year() );
1237 elem.setAttribute(
"month", date.month() );
1238 elem.setAttribute(
"day", date.day() );
1239 elem.setAttribute(
"fix", m_subtype == VST_DATE_FIX );
1240 elem.setAttribute(
"correct", m_correctDate);
1241 elem.setAttribute(
"subtype", m_subtype);
1242 if ( m_varValue.type() == TQVariant::DateTime )
1244 TQTime time = m_varValue.toTime();
1245 elem.setAttribute(
"hour", time.hour() );
1246 elem.setAttribute(
"minute", time.minute() );
1247 elem.setAttribute(
"second", time.second() );
1251void KoDateVariable::load( TQDomElement& elem )
1253 KoVariable::load( elem );
1255 TQDomElement e = elem.namedItem(
"DATE" ).toElement();
1258 const bool fix = e.attribute(
"fix").toInt() == 1;
1259 if ( e.hasAttribute(
"correct"))
1260 m_correctDate = e.attribute(
"correct").toInt();
1263 const int y = e.attribute(
"year").toInt();
1264 const int month = e.attribute(
"month").toInt();
1265 const int d = e.attribute(
"day").toInt();
1266 const int h = e.attribute(
"hour").toInt();
1267 const int min = e.attribute(
"minute").toInt();
1268 const int s = e.attribute(
"second").toInt();
1269 const int ms = e.attribute(
"msecond").toInt();
1270 TQDate date( y, month, d );
1271 date = date.addDays( m_correctDate );
1272 const TQTime time( h, min, s, ms );
1274 m_varValue = TQVariant ( TQDateTime( date, time ) );
1276 m_varValue = TQVariant( date );
1279 m_subtype = fix ? VST_DATE_FIX : VST_DATE_CURRENT;
1280 if ( e.hasAttribute(
"subtype" ))
1281 m_subtype = e.attribute(
"subtype").toInt();
1290 case VST_DATE_CURRENT:
1292 if ( m_subtype == VST_DATE_FIX )
1294 writer.
addAttribute(
"text:date-value", m_varValue.toDate().toString( TQt::ISODate) );
1298 case VST_DATE_LAST_PRINTING:
1301 case VST_DATE_CREATE_FILE:
1304 case VST_DATE_MODIFY_FILE:
1308 TQString value( m_varFormat->formatProperties() );
1309 bool klocaleFormat =
false;
1310 if ( value.lower() ==
"locale" ||
1312 value.lower() ==
"localeshort" ||
1313 value.lower() ==
"localedatetime" ||
1314 value.lower() ==
"localedatetimeshort" )
1316 if ( value.lower() ==
"locale" || value.isEmpty())
1317 value = TDEGlobal::locale()->dateFormat();
1318 else if ( value.lower() ==
"localeshort" )
1319 value = TDEGlobal::locale()->dateFormatShort();
1320 else if ( value.lower() ==
"localedatetime" )
1321 value = TQString(
"%1 %2" ).arg( TDEGlobal::locale()->dateFormat() ).arg( TDEGlobal::locale()->timeFormat() );
1322 else if ( value.lower() ==
"localedatetimeshort" )
1323 value = TQString(
"%1 %2" ).arg( TDEGlobal::locale()->dateFormatShort() ).arg( TDEGlobal::locale()->timeFormat() );
1324 klocaleFormat =
true;
1326 writer.
addAttribute(
"style:data-style-name", KoOasisStyles::saveOasisDateStyle(context.mainStyles(), value, klocaleFormat ) );
1328 if ( m_correctDate != 0 )
1329 writer.
addAttribute(
"text:date-adjust", daysToISODuration( m_correctDate ) );
1333void KoDateVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
1335 const TQString localName( elem.localName() );
1336 if ( localName ==
"date" )
1339 const TQString dateValue = elem.attributeNS( KoXmlNS::text,
"date-value", TQString());
1341 if ( !dateValue.isEmpty() )
1342 dt = TQDate::fromString(dateValue, TQt::ISODate);
1344 bool fixed = (elem.hasAttributeNS( KoXmlNS::text,
"fixed") && elem.attributeNS( KoXmlNS::text,
"fixed", TQString())==
"true");
1348 m_varValue = TQVariant( dt );
1349 m_subtype = fixed ? VST_DATE_FIX : VST_DATE_CURRENT;
1352 else if ( localName.startsWith(
"print" ) )
1353 m_subtype = VST_DATE_LAST_PRINTING;
1354 else if ( localName.startsWith(
"creation" ) )
1355 m_subtype = VST_DATE_CREATE_FILE;
1356 else if ( localName.startsWith(
"modification" ) )
1357 m_subtype = VST_DATE_MODIFY_FILE;
1358 const TQString adjustStr = elem.attributeNS( KoXmlNS::text,
"date-adjust", TQString() );
1359 if ( !adjustStr.isEmpty() )
1360 m_correctDate = ISODurationToDays( adjustStr );
1363TQStringList KoDateVariable::actionTexts()
1366 lst << i18n(
"Current Date (fixed)" );
1367 lst << i18n(
"Current Date (variable)" );
1368 lst << i18n(
"Date of Last Printing" );
1369 lst << i18n(
"Date of File Creation" );
1370 lst << i18n(
"Date of File Modification" );
1376 return KoDateVariable::actionTexts();
1381 return TQCString(
"DATE") +
"locale";
1387 TQStringList stringList;
1389 DateFormatWidget* widget=
new DateFormatWidget(dialog);
1392 TDEConfig* config = KoGlobal::kofficeConfig();
1393 if( config->hasGroup(
"Date format history") )
1395 TDEConfigGroupSaver cgs( config,
"Date format history");
1396 const int noe=config->readNumEntry(
"Number Of Entries", 5);
1397 for(
int i=0;i<noe;i++)
1401 const TQString tmpString(config->readEntry(
"Last Used"+num));
1402 if(tmpString.startsWith(
"locale"))
1404 else if(stringList.contains(tmpString))
1406 else if(!tmpString.isEmpty())
1408 stringList.append(tmpString);
1414 if(!stringList.isEmpty())
1416 widget->combo1->insertItem(
"---");
1417 widget->combo1->insertStringList(stringList);
1420 TQComboBox *combo= widget->combo1;
1421 combo->setCurrentItem(combo->count() -1);
1422 widget->updateLabel();
1425 if(dialog->exec()==TQDialog::Accepted)
1427 string = widget->resultString().utf8();
1428 correct = widget->correctValue();
1435 config->setGroup(
"Date format history");
1436 stringList.remove(
string);
1437 stringList.prepend(
string);
1438 for(
int i=0;i<=count;i++)
1442 config->writeEntry(
"Last Used"+num, stringList[i]);
1446 return TQCString(
"DATE") + string;
1452KoTimeVariable::KoTimeVariable( KoTextDocument *textdoc,
short int subtype,
KoVariableFormat *varFormat, KoVariableCollection *_varColl,
int _correct)
1453 :
KoVariable( textdoc, varFormat,_varColl ), m_subtype( subtype ), m_correctTime( _correct)
1457TQString KoTimeVariable::fieldCode()
1459 return (m_subtype == VST_TIME_FIX)?i18n(
"Time (Fixed)"):i18n(
"Time");
1466 if ( !fmt->language().isEmpty() )
1468 TQString oldLanguage = TDEGlobal::locale()->language();
1469 bool changeLanguage = TDEGlobal::locale()->setLanguage( fmt->language() );
1471 if ( changeLanguage )
1472 TDEGlobal::locale()->setLanguage( oldLanguage );
1480 if ( m_subtype == VST_TIME_CURRENT )
1481 m_varValue = TQVariant( TQTime(TQTime::currentTime().addSecs(60*m_correctTime)));
1485 if ( m_varValue.toTime().isNull() )
1486 m_varValue = TQVariant( TQTime(TQTime::currentTime().addSecs(60*m_correctTime)));
1494 TQDomElement elem = parentElem.ownerDocument().createElement(
"TIME" );
1495 parentElem.appendChild( elem );
1497 TQTime time = m_varValue.toTime();
1498 time = time.addSecs(-60*m_correctTime);
1499 elem.setAttribute(
"hour", time.hour() );
1500 elem.setAttribute(
"minute", time.minute() );
1501 elem.setAttribute(
"second", time.second() );
1502 elem.setAttribute(
"msecond", time.msec() );
1503 elem.setAttribute(
"fix", m_subtype == VST_TIME_FIX );
1504 elem.setAttribute(
"correct", m_correctTime );
1507void KoTimeVariable::load( TQDomElement& elem )
1509 KoVariable::load( elem );
1511 TQDomElement e = elem.namedItem(
"TIME" ).toElement();
1514 int h = e.attribute(
"hour").toInt();
1515 int m = e.attribute(
"minute").toInt();
1516 int s = e.attribute(
"second").toInt();
1517 int ms = e.attribute(
"msecond").toInt();
1519 if ( e.hasAttribute(
"correct"))
1520 correct=e.attribute(
"correct").toInt();
1521 bool fix =
static_cast<bool>( e.attribute(
"fix").toInt() );
1525 time.setHMS( h, m, s, ms );
1526 time = time.addSecs( 60*m_correctTime );
1527 m_varValue = TQVariant( time);
1530 m_subtype = fix ? VST_TIME_FIX : VST_TIME_CURRENT;
1531 m_correctTime = correct;
1535void KoTimeVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
1537 const TQString localName( elem.localName() );
1538 Q_ASSERT( localName ==
"time" );
1539 if ( localName ==
"time" )
1542 TQDateTime dt(TQDateTime::fromString(elem.attributeNS( KoXmlNS::text,
"time-value", TQString()), TQt::ISODate));
1544 bool fixed = (elem.hasAttributeNS( KoXmlNS::text,
"fixed") && elem.attributeNS( KoXmlNS::text,
"fixed", TQString())==
"true");
1548 m_varValue = TQVariant( dt.time() );
1549 m_subtype = fixed ? VST_TIME_FIX : VST_TIME_CURRENT;
1550 TQString adjustStr = elem.attributeNS( KoXmlNS::text,
"time-adjust", TQString() );
1551 if ( !adjustStr.isEmpty() )
1552 m_correctTime = ISODurationToMinutes( adjustStr );
1559 if ( m_correctTime != 0 ) {
1560 writer.
addAttribute(
"text:time-adjust", minutesToISODuration( m_correctTime ) );
1562 if (m_subtype == VST_TIME_FIX )
1565 writer.
addAttribute(
"text:time-value", m_varValue.toTime().toString( TQt::ISODate ) );
1568 TQString value( m_varFormat->formatProperties() );
1569 bool klocaleFormat =
false;
1570 if ( value.lower() ==
"locale" )
1572 value = TDEGlobal::locale()->timeFormat();
1573 klocaleFormat =
true;
1575 writer.
addAttribute(
"style:data-style-name", KoOasisStyles::saveOasisTimeStyle(context.mainStyles(), m_varFormat->formatProperties(), klocaleFormat ) );
1583TQStringList KoTimeVariable::actionTexts()
1586 lst << i18n(
"Current Time (fixed)" );
1587 lst << i18n(
"Current Time (variable)" );
1593 return KoTimeVariable::actionTexts();
1599 TQStringList stringList;
1601 TimeFormatWidget* widget=
new TimeFormatWidget(dialog);
1603 TDEConfig* config = KoGlobal::kofficeConfig();
1605 if( config->hasGroup(
"Time format history") )
1607 TDEConfigGroupSaver cgs( config,
"Time format history" );
1608 const int noe=config->readNumEntry(
"Number Of Entries", 5);
1609 for(
int i=0;i<noe;i++)
1613 TQString tmpString(config->readEntry(
"Last Used"+num));
1614 if(tmpString.startsWith(
"locale"))
1616 else if(stringList.contains(tmpString))
1618 else if(!tmpString.isEmpty())
1620 stringList.append(tmpString);
1625 if(!stringList.isEmpty())
1627 widget->combo1->insertItem(
"---");
1628 widget->combo1->insertStringList(stringList);
1632 TQComboBox *combo= widget->combo1;
1633 combo->setCurrentItem(combo->count() -1);
1635 if(dialog->exec()==TQDialog::Accepted)
1637 string = widget->resultString().utf8();
1638 _correct = widget->correctValue();
1645 config->setGroup(
"Time format history");
1646 stringList.remove(
string);
1647 stringList.prepend(
string);
1648 for(
int i=0;i<=count;i++)
1652 config->writeEntry(
"Last Used"+num, stringList[i]);
1656 return TQCString(
"TIME"+
string );
1661 return TQCString(TQCString(
"TIME")+TQCString(
"locale") );
1668KoCustomVariable::KoCustomVariable( KoTextDocument *textdoc,
const TQString &name,
KoVariableFormat *varFormat, KoVariableCollection *_varColl )
1671 m_varValue = TQVariant( name );
1674TQString KoCustomVariable::fieldCode()
1676 return i18n(
"Custom Variable");
1681 if (m_varColl->variableSetting()->displayFieldCode()&&!realValue)
1691 TQDomElement elem = parentElem.ownerDocument().createElement(
"CUSTOM" );
1692 parentElem.appendChild( elem );
1693 elem.setAttribute(
"name", m_varValue.toString() );
1694 elem.setAttribute(
"value", value() );
1697void KoCustomVariable::load( TQDomElement& elem )
1699 KoVariable::load( elem );
1700 TQDomElement e = elem.namedItem(
"CUSTOM" ).toElement();
1703 m_varValue = TQVariant (e.attribute(
"name" ));
1704 setValue( e.attribute(
"value" ) );
1708void KoCustomVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
1710 const TQString localName( elem.localName() );
1716 if ( localName ==
"variable-set"
1717 || localName ==
"user-defined"
1718 || localName ==
"user-field-get" ) {
1719 m_varValue = elem.attributeNS( KoXmlNS::text,
"name", TQString() );
1720 setValue( elem.text() );
1728 writer.
addAttribute(
"text:name", m_varValue.toString() );
1733TQString KoCustomVariable::value()
const
1735 return m_varColl->getVariableValue( m_varValue.toString() );
1738void KoCustomVariable::setValue(
const TQString &v )
1740 m_varColl->setVariableValue( m_varValue.toString(), v );
1743TQStringList KoCustomVariable::actionTexts()
1745 return TQStringList( i18n(
"Custom..." ) );
1756KoMailMergeVariable::KoMailMergeVariable( KoTextDocument *textdoc,
const TQString &name,
KoVariableFormat *varFormat,KoVariableCollection *_varColl )
1759 m_varValue = TQVariant ( name );
1762TQString KoMailMergeVariable::fieldCode()
1764 return i18n(
"Mail Merge");
1767void KoMailMergeVariable::loadOasis(
const TQDomElement &,
KoOasisContext& )
1774 kdWarning(32500) <<
"Not implemented: OASIS saving of mail merge variables" << endl;
1779void KoMailMergeVariable::saveVariable( TQDomElement& parentElem )
1781 TQDomElement elem = parentElem.ownerDocument().createElement(
"MAILMERGE" );
1782 parentElem.appendChild( elem );
1783 elem.setAttribute(
"name", m_varValue.toString() );
1786void KoMailMergeVariable::load( TQDomElement& elem )
1788 KoVariable::load( elem );
1789 TQDomElement e = elem.namedItem(
"MAILMERGE" ).toElement();
1791 m_varValue = TQVariant( e.attribute(
"name" ) );
1794TQString KoMailMergeVariable::value()
const
1799TQString KoMailMergeVariable::text(
bool )
1802 TQString v = value();
1804 return "<" + v +
">";
1808TQStringList KoMailMergeVariable::actionTexts()
1810 return TQStringList( i18n(
"&Mail Merge..." ) );
1816KoPageVariable::KoPageVariable( KoTextDocument *textdoc,
short int subtype,
KoVariableFormat *varFormat,KoVariableCollection *_varColl )
1817 :
KoVariable( textdoc, varFormat, _varColl ), m_subtype( subtype )
1821TQString KoPageVariable::fieldCode()
1823 if ( m_subtype == VST_PGNUM_CURRENT )
1824 return i18n(
"Page Current Num");
1825 else if ( m_subtype == VST_PGNUM_TOTAL )
1826 return i18n(
"Total Page Num");
1827 else if ( m_subtype == VST_CURRENT_SECTION )
1828 return i18n(
"Current Section");
1829 else if ( m_subtype == VST_PGNUM_PREVIOUS )
1830 return i18n(
"Previous Page Number");
1831 else if ( m_subtype == VST_PGNUM_NEXT )
1832 return i18n(
"Next Page Number");
1835 return i18n(
"Current Section");
1841 TQDomElement pgNumElem = parentElem.ownerDocument().createElement(
"PGNUM" );
1842 parentElem.appendChild( pgNumElem );
1843 pgNumElem.setAttribute(
"subtype", m_subtype );
1844 if ( m_subtype != VST_CURRENT_SECTION )
1845 pgNumElem.setAttribute(
"value", m_varValue.toInt() );
1847 pgNumElem.setAttribute(
"value", m_varValue.toString() );
1850void KoPageVariable::load( TQDomElement& elem )
1852 KoVariable::load( elem );
1853 TQDomElement pgNumElem = elem.namedItem(
"PGNUM" ).toElement();
1854 if (!pgNumElem.isNull())
1856 m_subtype = pgNumElem.attribute(
"subtype").toInt();
1858 if ( m_subtype != VST_CURRENT_SECTION )
1859 m_varValue = TQVariant(pgNumElem.attribute(
"value").toInt());
1861 m_varValue = TQVariant(pgNumElem.attribute(
"value"));
1869 case VST_PGNUM_PREVIOUS:
1870 case VST_PGNUM_NEXT:
1871 case VST_PGNUM_CURRENT:
1874 if ( m_subtype == VST_PGNUM_PREVIOUS )
1878 else if ( m_subtype == VST_PGNUM_NEXT )
1882 else if ( m_subtype == VST_PGNUM_CURRENT )
1890 case VST_CURRENT_SECTION:
1897 case VST_PGNUM_TOTAL:
1907void KoPageVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
1909 const TQString localName( elem.localName() );
1910 if ( localName ==
"page-number" )
1912 m_subtype = VST_PGNUM_CURRENT;
1914 if ( elem.hasAttributeNS( KoXmlNS::text,
"select-page") )
1916 const TQString select = elem.attributeNS( KoXmlNS::text,
"select-page", TQString());
1917 if (select ==
"previous")
1918 m_subtype = VST_PGNUM_PREVIOUS;
1919 else if (select ==
"next")
1920 m_subtype = VST_PGNUM_NEXT;
1923 m_varValue = TQVariant( elem.text().toInt() );
1925 else if ( localName ==
"chapter" )
1927 m_subtype = VST_CURRENT_SECTION;
1928 m_varValue = TQVariant( elem.text() );
1933 else if ( localName ==
"page-count" )
1935 m_subtype = VST_PGNUM_TOTAL;
1936 m_varValue = TQVariant( elem.text() );
1940TQStringList KoPageVariable::actionTexts()
1943 lst << i18n(
"Page Number" );
1944 lst << i18n(
"Number of Pages" );
1945 lst << i18n(
"Section Title" );
1946 lst << i18n(
"Previous Page" );
1947 lst << i18n(
"Next Page" );
1953 return KoPageVariable::actionTexts();
1959 Q_ASSERT( m_varColl );
1961 setVariableFormat((m_subtype == VST_CURRENT_SECTION) ? fc->
format(
"STRING") : fc->
format(
"NUMBER"));
1967KoFieldVariable::KoFieldVariable( KoTextDocument *textdoc,
short int subtype,
KoVariableFormat *varFormat, KoVariableCollection *_varColl ,
KoDocument *_doc )
1968 :
KoVariable( textdoc, varFormat,_varColl ), m_subtype( subtype ), m_doc(_doc)
1972TQString KoFieldVariable::fieldCode()
1974 switch( m_subtype ) {
1976 return i18n(
"Filename");
1978 case VST_DIRECTORYNAME:
1979 return i18n(
"Directory Name");
1981 case VST_PATHFILENAME:
1982 return i18n(
"Path Filename");
1984 case VST_FILENAMEWITHOUTEXTENSION:
1985 return i18n(
"Filename Without Extension");
1987 case VST_AUTHORNAME:
1988 return i18n(
"Author Name");
1991 return i18n(
"Email");
1993 case VST_COMPANYNAME:
1994 return i18n(
"Company Name");
1996 case VST_TELEPHONE_WORK:
1997 return i18n(
"Telephone (work)");
1999 case VST_TELEPHONE_HOME:
2000 return i18n(
"Telephone (home)");
2006 return i18n(
"Country");
2008 case VST_POSTAL_CODE:
2009 return i18n(
"Postal Code");
2012 return i18n(
"City");
2015 return i18n(
"Street");
2017 case VST_AUTHORTITLE:
2018 return i18n(
"Author Title");
2021 return i18n(
"Title");
2024 return i18n(
"Subject");
2027 return i18n(
"Abstract");
2030 return i18n(
"Keywords");
2033 return i18n(
"Initials");
2036 return i18n(
"Field");
2041 if (m_varColl->variableSetting()->displayFieldCode()&&!realValue)
2051 TQDomElement elem = parentElem.ownerDocument().createElement(
"FIELD" );
2052 parentElem.appendChild( elem );
2053 elem.setAttribute(
"subtype", m_subtype );
2054 elem.setAttribute(
"value", m_varValue.toString() );
2057void KoFieldVariable::load( TQDomElement& elem )
2059 KoVariable::load( elem );
2060 TQDomElement e = elem.namedItem(
"FIELD" ).toElement();
2063 m_subtype = e.attribute(
"subtype" ).toInt();
2064 if ( m_subtype == VST_NONE )
2065 kdWarning() <<
"Field subtype of -1 found in the file !" << endl;
2066 m_varValue = TQVariant( e.attribute(
"value" ) );
2068 kdWarning() <<
"FIELD element not found !" << endl;
2071void KoFieldVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
2073 const TQString localName( elem.localName() );
2074 if ( localName ==
"file-name" ) {
2075 const TQString display = elem.attributeNS( KoXmlNS::text,
"display", TQString() );
2076 if (display ==
"path")
2077 m_subtype = VST_DIRECTORYNAME;
2078 else if (display ==
"name")
2079 m_subtype = VST_FILENAMEWITHOUTEXTENSION;
2080 else if (display ==
"name-and-extension")
2081 m_subtype = VST_FILENAME;
2083 m_subtype = VST_PATHFILENAME;
2085 else if ( localName ==
"author-name" )
2086 m_subtype = VST_AUTHORNAME;
2087 else if ( localName ==
"author-initials" )
2088 m_subtype = VST_INITIAL;
2089 else if ( localName ==
"subject" )
2090 m_subtype = VST_SUBJECT;
2091 else if ( localName ==
"title" )
2092 m_subtype = VST_TITLE;
2093 else if ( localName ==
"description" )
2094 m_subtype = VST_ABSTRACT;
2095 else if ( localName ==
"keywords" )
2096 m_subtype = VST_KEYWORDS;
2098 else if ( localName ==
"sender-company" )
2099 m_subtype = VST_COMPANYNAME;
2100 else if ( localName ==
"sender-firstname" )
2102 else if ( localName ==
"sender-lastname" )
2104 else if ( localName ==
"sender-initials" )
2106 else if ( localName ==
"sender-street" )
2107 m_subtype = VST_STREET;
2108 else if ( localName ==
"sender-country" )
2109 m_subtype = VST_COUNTRY;
2110 else if ( localName ==
"sender-postal-code" )
2111 m_subtype = VST_POSTAL_CODE;
2112 else if ( localName ==
"sender-city" )
2113 m_subtype = VST_CITY;
2114 else if ( localName ==
"sender-title" )
2115 m_subtype = VST_AUTHORTITLE;
2116 else if ( localName ==
"sender-position" )
2117 m_subtype = VST_AUTHORPOSITION;
2118 else if ( localName ==
"sender-phone-private" )
2119 m_subtype = VST_TELEPHONE_HOME;
2120 else if ( localName ==
"sender-phone-work" )
2121 m_subtype = VST_TELEPHONE_WORK;
2122 else if ( localName ==
"sender-fax" )
2123 m_subtype = VST_FAX;
2124 else if ( localName ==
"sender-email" )
2125 m_subtype = VST_EMAIL;
2127 m_varValue = TQVariant( elem.text() );
2138 writer.
addAttribute(
"text:display",
"name-and-extension" );
2140 case VST_DIRECTORYNAME:
2144 case VST_AUTHORNAME:
2150 case VST_COMPANYNAME:
2153 case VST_PATHFILENAME:
2157 case VST_FILENAMEWITHOUTEXTENSION:
2159 writer.
addAttribute(
"text:display",
"name-and-extension" );
2161 case VST_TELEPHONE_WORK:
2164 case VST_TELEPHONE_HOME:
2185 case VST_POSTAL_CODE:
2194 case VST_AUTHORTITLE:
2197 case VST_AUTHORPOSITION:
2211 switch( m_subtype ) {
2213 kdWarning() <<
"KoFieldVariable::recalc() called with m_subtype = VST_NONE !" << endl;
2216 value = m_doc->url().fileName();
2218 case VST_DIRECTORYNAME:
2219 value = m_doc->url().directory();
2221 case VST_PATHFILENAME:
2222 value=m_doc->url().path();
2224 case VST_FILENAMEWITHOUTEXTENSION:
2226 TQString file=m_doc->url().fileName();
2227 int pos=file.findRev(
".");
2229 value=file.mid(0,pos);
2234 case VST_AUTHORNAME:
2236 case VST_COMPANYNAME:
2237 case VST_TELEPHONE_WORK:
2238 case VST_TELEPHONE_HOME:
2241 case VST_POSTAL_CODE:
2244 case VST_AUTHORTITLE:
2245 case VST_AUTHORPOSITION:
2248 KoDocumentInfo * info = m_doc->documentInfo();
2249 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor *
>(info->page(
"author" ));
2251 kdWarning() <<
"Author information not found in documentInfo !" << endl;
2254 if ( m_subtype == VST_AUTHORNAME )
2255 value = authorPage->fullName();
2256 else if ( m_subtype == VST_EMAIL )
2257 value = authorPage->email();
2258 else if ( m_subtype == VST_COMPANYNAME )
2259 value = authorPage->company();
2260 else if ( m_subtype == VST_TELEPHONE_WORK )
2261 value = authorPage->telephoneWork();
2262 else if ( m_subtype == VST_TELEPHONE_HOME )
2263 value = authorPage->telephoneHome();
2264 else if ( m_subtype == VST_FAX )
2265 value = authorPage->fax();
2266 else if ( m_subtype == VST_COUNTRY )
2267 value = authorPage->country();
2268 else if ( m_subtype == VST_POSTAL_CODE )
2269 value = authorPage->postalCode();
2270 else if ( m_subtype == VST_CITY )
2271 value = authorPage->city();
2272 else if ( m_subtype == VST_STREET )
2273 value = authorPage->street();
2274 else if ( m_subtype == VST_AUTHORTITLE )
2275 value = authorPage->title();
2276 else if ( m_subtype == VST_INITIAL )
2277 value = authorPage->initial();
2278 else if ( m_subtype == VST_AUTHORPOSITION )
2279 value = authorPage->position();
2288 KoDocumentInfo * info = m_doc->documentInfo();
2289 KoDocumentInfoAbout * aboutPage =
static_cast<KoDocumentInfoAbout *
>(info->page(
"about" ));
2291 kdWarning() <<
"'About' page not found in documentInfo !" << endl;
2294 if ( m_subtype == VST_TITLE )
2295 value = aboutPage->title();
2296 else if ( m_subtype == VST_SUBJECT )
2297 value = aboutPage->subject();
2298 else if ( m_subtype == VST_KEYWORDS )
2299 value = aboutPage->keywords();
2301 value = aboutPage->abstract();
2307 if (value.isEmpty())
2308 value = m_varValue.toString();
2310 if (value.isEmpty())
2311 value = i18n(
"<None>");
2313 m_varValue = TQVariant( value );
2318TQStringList KoFieldVariable::actionTexts()
2322 lst << i18n(
"Author Name" );
2323 lst << i18n(
"Title" );
2324 lst << i18n(
"Initials" );
2325 lst << i18n(
"Position" );
2326 lst << i18n(
"Company" );
2327 lst << i18n(
"Email" );
2328 lst << i18n(
"Telephone (work)");
2329 lst << i18n(
"Telephone (private)");
2331 lst << i18n(
"Fax");
2332 lst << i18n(
"Street" );
2333 lst << i18n(
"Postal Code" );
2334 lst << i18n(
"City" );
2335 lst << i18n(
"Country");
2337 lst << i18n(
"Document Title" );
2338 lst << i18n(
"Document Abstract" );
2339 lst << i18n(
"Document Subject" );
2340 lst << i18n(
"Document Keywords" );
2342 lst << i18n(
"File Name" );
2343 lst << i18n(
"File Name without Extension" );
2344 lst << i18n(
"Directory Name" );
2345 lst << i18n(
"Directory && File Name" );
2360 case 0: v = VST_AUTHORNAME;
2362 case 1: v = VST_AUTHORTITLE;
2364 case 2: v = VST_INITIAL;
2366 case 3: v = VST_AUTHORPOSITION;
2368 case 4: v = VST_COMPANYNAME;
2370 case 5: v = VST_EMAIL;
2372 case 6: v = VST_TELEPHONE_WORK;
2374 case 7: v = VST_TELEPHONE_HOME;
2376 case 8: v = VST_FAX;
2378 case 9: v = VST_STREET;
2380 case 10: v = VST_POSTAL_CODE;
2382 case 11: v = VST_CITY;
2384 case 12: v = VST_COUNTRY;
2386 case 13: v = VST_TITLE;
2388 case 14: v = VST_ABSTRACT;
2390 case 15: v = VST_SUBJECT;
2392 case 16: v = VST_KEYWORDS;
2394 case 17: v = VST_FILENAME;
2396 case 18: v = VST_FILENAMEWITHOUTEXTENSION;
2398 case 19: v = VST_DIRECTORYNAME;
2400 case 20: v = VST_PATHFILENAME;
2411 return KoFieldVariable::actionTexts();
2417KoLinkVariable::KoLinkVariable( KoTextDocument *textdoc,
const TQString & _linkName,
const TQString & _ulr,
KoVariableFormat *varFormat,KoVariableCollection *_varColl )
2421 m_varValue = TQVariant( _linkName );
2424TQString KoLinkVariable::fieldCode()
2426 return i18n(
"Link");
2429void KoLinkVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
2431 if ( elem.localName() ==
"a" && elem.namespaceURI() == KoXmlNS::text ) {
2432 m_url = elem.attributeNS( KoXmlNS::xlink,
"href", TQString());
2433 m_varValue = TQVariant(elem.text());
2443 writer.
addAttribute(
"office:name", m_varValue.toString() );
2449TQString KoLinkVariable::text(
bool realValue)
2451 if (m_varColl->variableSetting()->displayFieldCode()&&!realValue)
2457void KoLinkVariable::saveVariable( TQDomElement& parentElem )
2459 TQDomElement linkElem = parentElem.ownerDocument().createElement(
"LINK" );
2460 parentElem.appendChild( linkElem );
2461 linkElem.setAttribute(
"linkName", m_varValue.toString() );
2462 linkElem.setAttribute(
"hrefName", m_url );
2465void KoLinkVariable::load( TQDomElement& elem )
2467 KoVariable::load( elem );
2468 TQDomElement linkElem = elem.namedItem(
"LINK" ).toElement();
2469 if (!linkElem.isNull())
2471 m_varValue = TQVariant(linkElem.attribute(
"linkName"));
2472 m_url = linkElem.attribute(
"hrefName");
2481TQStringList KoLinkVariable::actionTexts()
2483 return TQStringList( i18n(
"Link..." ) );
2487void KoLinkVariable::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 )
2489 KoTextFormat * fmt =
format();
2490 KoTextZoomHandler * zh =
textDocument()->paintingZoomHandler();
2492 bool displayLink = m_varColl->variableSetting()->displayLink();
2494 if ( m_varColl->variableSetting()->underlineLink() )
2495 font.setUnderline(
true );
2496 TQColor textColor = displayLink ? cg.color( TQColorGroup::Link ) : fmt->color();
2498 drawCustomItemHelper( p, x, y, wpix, hpix, ascentpix, cg, selected, offset, fmt, font, textColor, drawingShadow );
2505KoNoteVariable::KoNoteVariable( KoTextDocument *textdoc,
const TQString & _note,
KoVariableFormat *varFormat,KoVariableCollection *_varColl )
2507 , m_createdNoteDate( TQDate::currentDate() )
2509 m_varValue = TQVariant( _note );
2512TQString KoNoteVariable::fieldCode()
2514 return i18n(
"Note");
2517TQString KoNoteVariable::createdNote()
const
2519 return TDEGlobal::locale()->formatDate( m_createdNoteDate,
false );
2522void KoNoteVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
2524 const TQString localName = elem.localName();
2526 if ( localName ==
"annotation" && elem.namespaceURI() == KoXmlNS::office )
2529 m_createdNoteDate = TQDate::fromString( date.text(), TQt::ISODate );
2531 for ( ; !text.isNull(); text = text.nextSibling() )
2533 if ( text.isElement() )
2535 TQDomElement t = text.toElement();
2536 note += t.text() +
"\n";
2540 m_varValue = TQVariant( note );
2548 writer.
addTextNode( m_createdNoteDate.toString(TQt::ISODate) );
2550 TQStringList text = TQStringList::split(
"\n", m_varValue.toString() );
2551 for ( TQStringList::Iterator it = text.begin(); it != text.end(); ++it ) {
2559void KoNoteVariable::saveVariable( TQDomElement& parentElem )
2561 TQDomElement linkElem = parentElem.ownerDocument().createElement(
"NOTE" );
2562 parentElem.appendChild( linkElem );
2563 linkElem.setAttribute(
"note", m_varValue.toString() );
2566void KoNoteVariable::load( TQDomElement& elem )
2568 KoVariable::load( elem );
2569 TQDomElement linkElem = elem.namedItem(
"NOTE" ).toElement();
2570 if (!linkElem.isNull())
2572 m_varValue = TQVariant(linkElem.attribute(
"note"));
2581TQStringList KoNoteVariable::actionTexts()
2583 return TQStringList( i18n(
"Note..." ) );
2586TQString KoNoteVariable::text(
bool realValue)
2588 if (m_varColl->variableSetting()->displayComment() &&
2589 m_varColl->variableSetting()->displayFieldCode()&&!realValue)
2594 return TQString(
" ");
2598void KoNoteVariable::drawCustomItem( TQPainter* p,
int x,
int y,
int wpix,
int hpix,
int ascentpix,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected,
int offset,
bool drawingShadow )
2600 if ( !m_varColl->variableSetting()->displayComment())
2603 KoTextFormat * fmt =
format();
2607 p->setPen( TQPen( fmt->color() ) );
2608 if ( fmt->textBackgroundColor().isValid() )
2609 p->fillRect( x, y, wpix, hpix, fmt->textBackgroundColor() );
2612 p->setPen( TQPen( cg.color( TQColorGroup::HighlightedText ) ) );
2613 p->fillRect( x, y, wpix, hpix, cg.color( TQColorGroup::Highlight ) );
2615 else if (
textDocument() && p->device()->devType() != TQInternal::Printer
2618 p->fillRect( x, y, wpix, hpix, TQt::yellow);
2619 p->setPen( TQPen( cg.color( TQColorGroup::Highlight ), 0, TQt::DotLine ) );
2620 p->drawRect( x, y, wpix, hpix );
2623 KoVariable::drawCustomItem( p, x, y, wpix, hpix, ascentpix, cx, cy, cw, ch, cg, selected, offset, drawingShadow );
2628void KoPageVariable::setSectionTitle(
const TQString& _title )
2630 TQString title( _title );
2631 if ( title.isEmpty() )
2633 title = i18n(
"<No title>");
2635 m_varValue = TQVariant( title );
2643bool KoStatisticVariable::m_extendedType =
false;
2646KoStatisticVariable::KoStatisticVariable( KoTextDocument *textdoc,
2649 KoVariableCollection *_varColl )
2650 :
KoVariable( textdoc, varFormat, _varColl ),
2651 m_subtype( subtype )
2656TQStringList KoStatisticVariable::actionTexts()
2659 lst << i18n(
"Number of Words" );
2660 lst << i18n(
"Number of Sentences" );
2661 lst << i18n(
"Number of Lines" );
2662 lst << i18n(
"Number of Characters" );
2663 lst << i18n(
"Number of Non-Whitespace Characters" );
2664 lst << i18n(
"Number of Syllables" );
2665 lst << i18n(
"Number of Frames" );
2666 lst << i18n(
"Number of Embedded Objects" );
2667 lst << i18n(
"Number of Pictures" );
2668 if ( m_extendedType )
2669 lst << i18n(
"Number of Tables" );
2674void KoStatisticVariable::setVariableSubType(
short int subtype )
2676 m_subtype = subtype;
2677 Q_ASSERT( m_varColl );
2678 KoVariableFormatCollection* fc = m_varColl->formatCollection();
2679 setVariableFormat(fc->
format(
"NUMBER") );
2685 return KoStatisticVariable::actionTexts();
2689void KoStatisticVariable::saveVariable( TQDomElement& varElem )
2691 TQDomElement elem = varElem.ownerDocument().createElement(
"STATISTIC" );
2692 varElem.appendChild( elem );
2694 elem.setAttribute(
"type", TQString::number(m_subtype) );
2695 elem.setAttribute(
"value", TQString::number(m_varValue.toInt()) );
2699void KoStatisticVariable::load( TQDomElement &elem )
2701 KoVariable::load( elem );
2703 TQDomElement e = elem.namedItem(
"STATISTIC" ).toElement();
2704 if ( !e.isNull() ) {
2706 m_subtype = e.attribute(
"type" ).toInt();
2707 m_varValue = e.attribute(
"value" ).toInt();
2712void KoStatisticVariable::loadOasis(
const TQDomElement &elem,
KoOasisContext& )
2714 const TQString localName( elem.localName() );
2715 if ( localName ==
"object-count" )
2717 m_subtype = VST_STATISTIC_NB_EMBEDDED;
2718 m_varValue = TQVariant( elem.text().toInt() );
2720 else if ( localName ==
"table-count" )
2722 m_subtype = VST_STATISTIC_NB_TABLE;
2723 m_varValue = TQVariant( elem.text().toInt() );
2725 else if ( localName ==
"picture-count" )
2727 m_subtype = VST_STATISTIC_NB_PICTURE;
2728 m_varValue = TQVariant( elem.text().toInt() );
2730 else if ( localName ==
"word-count" )
2732 m_subtype = VST_STATISTIC_NB_WORD;
2733 m_varValue = TQVariant( elem.text().toInt() );
2735 else if ( localName ==
"character-count" )
2737 m_subtype = VST_STATISTIC_NB_CHARACTERE;
2738 m_varValue = TQVariant( elem.text().toInt() );
2740 else if ( localName ==
"frame-count" )
2742 m_subtype = VST_STATISTIC_NB_FRAME;
2743 m_varValue = TQVariant( elem.text().toInt() );
2745 else if ( localName ==
"line-count" )
2747 m_subtype = VST_STATISTIC_NB_LINES;
2748 m_varValue = TQVariant( elem.text().toInt() );
2750 else if ( localName ==
"sentence-count" )
2752 m_subtype = VST_STATISTIC_NB_SENTENCE;
2753 m_varValue = TQVariant( elem.text().toInt() );
2755 else if ( localName ==
"non-whitespace-character-count" )
2757 m_subtype = VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE;
2758 m_varValue = TQVariant( elem.text().toInt() );
2760 else if ( localName ==
"syllable-count" )
2762 m_subtype = VST_STATISTIC_NB_SYLLABLE;
2763 m_varValue = TQVariant( elem.text().toInt() );
2772 case VST_STATISTIC_NB_EMBEDDED:
2774 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2777 case VST_STATISTIC_NB_TABLE:
2779 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2782 case VST_STATISTIC_NB_PICTURE:
2784 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2787 case VST_STATISTIC_NB_FRAME:
2790 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2793 case VST_STATISTIC_NB_WORD:
2795 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2798 case VST_STATISTIC_NB_SENTENCE:
2801 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2804 case VST_STATISTIC_NB_CHARACTERE:
2806 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2809 case VST_STATISTIC_NB_LINES:
2812 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2815 case VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE:
2817 writer.
startElement(
"text:non-whitespace-character-count" );
2818 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2821 case VST_STATISTIC_NB_SYLLABLE:
2824 writer.
addTextNode( TQString::number( m_varValue.toInt() ) );
2830TQString KoStatisticVariable::fieldCode()
2832 if ( m_subtype == VST_STATISTIC_NB_FRAME )
2834 return i18n(
"Number of Frames" );
2836 else if( m_subtype == VST_STATISTIC_NB_PICTURE )
2838 return i18n(
"Number of Pictures" );
2840 else if( m_subtype == VST_STATISTIC_NB_TABLE )
2842 return i18n(
"Number of Tables" );
2844 else if( m_subtype == VST_STATISTIC_NB_EMBEDDED )
2846 return i18n(
"Number of Embedded Objects" );
2848 else if( m_subtype == VST_STATISTIC_NB_WORD )
2850 return i18n(
"Number of Words" );
2852 else if( m_subtype == VST_STATISTIC_NB_SENTENCE )
2854 return i18n(
"Number of Sentences" );
2856 else if( m_subtype == VST_STATISTIC_NB_LINES )
2858 return i18n(
"Number of Lines" );
2860 else if ( m_subtype == VST_STATISTIC_NB_CHARACTERE )
2862 return i18n(
"Number of Characters" );
2864 else if ( m_subtype == VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE )
2866 return i18n(
"Number of Non-Whitespace Characters" );
2868 else if ( m_subtype == VST_STATISTIC_NB_SYLLABLE )
2870 return i18n(
"Number of Syllables" );
2873 return i18n(
"Number of Frames" );
void setMainWidget(TQWidget *widget)
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
virtual void saveVariable(TQDomElement &parentElem)
Variable should reimplement this to implement saving.
virtual TQString text(bool realValue=false)
Returns the text to be displayed for this variable It doesn't need to be cached, convert() is fast,...
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
virtual TQStringList subTypeList()
List of available subtypes (translated). Use variableSubType() to map index to ID.
virtual void saveVariable(TQDomElement &parentElem)
Variable should reimplement this to implement saving.
static TQCString defaultFormat()
Return the default date format for old file.
virtual void resize()
Reimplement this to calculate the item width It is important to start with "if ( m_deleted ) return;"...
static TQCString formatStr(int &correct)
Ask the user and return the date format string with prefix "DATE".
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
The KOffice document class.
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
virtual short int variableSubType(short int menuNumber)
Converts menuNumber to field variable subtype number.
virtual void saveVariable(TQDomElement &parentElem)
Variable should reimplement this to implement saving.
virtual TQStringList subTypeList()
List of available subtypes (translated). Use variableSubType() to map index to ID.
virtual TQString text(bool realValue=false)
Returns the text to be displayed for this variable It doesn't need to be cached, convert() is fast,...
static FieldSubType fieldSubType(short int menuNumber)
Converts menuNumber to field variable subtype number.
Used during loading of Oasis format (and discarded at the end of the loading).
Items itemSet(const TQString &itemSetName) const
Returns the toplevel item-set named itemSetName.
virtual void saveVariable(TQDomElement &parentElem)
Variable should reimplement this to implement saving.
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
virtual void setVariableSubType(short int subtype)
Set this variable's subtype.
virtual TQStringList subTypeList()
List of available subtypes (translated). Use variableSubType() to map index to ID.
Used during saving to Oasis format (and discarded at the end of the saving).
KoTextCustomItem is the base class for custom items (i.e.
KoTextFormat * format() const
The formatting given to this 'special' character Slightly slow (does a linear search in the paragraph...
KoTextDocument * textDocument() const
The text document in which this customitem is.
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
const TQFontMetrics & refFontMetrics() const
TQFont screenFont(const KoTextZoomHandler *zh) const
Returns the font to be used at the zoom & resolution given by 'zh'.
static TQColor defaultTextColor(TQPainter *painter)
Call this when a text color is set to 'invalid', meaning 'whatever the default for the color scheme i...
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int layoutUnitToPixelX(int lupix) const
The "layout unit pixel" -> "[zoomed] view pixel" conversions.
int pixelToLayoutUnitX(int x) const
The "[zoomed] view pixel" -> "layout unit pixel" conversions.
static TQCString defaultFormat()
Return the default date format for old file.
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
virtual void saveVariable(TQDomElement &parentElem)
Variable should reimplement this to implement saving.
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
static TQCString formatStr(int &_correct)
Returns the time format string with prefix "TIME".
virtual TQStringList subTypeList()
List of available subtypes (translated). Use variableSubType() to map index to ID.
virtual void resize()
Reimplement this to calculate the item width It is important to start with "if ( m_deleted ) return;"...
A KoVariable is a custom item, i.e.
virtual void drawCustomItem(TQPainter *p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const TQColorGroup &cg, bool selected, int offset, bool drawingShadow)
All coordinates are in pixels.
virtual TQStringList subTypeList()
List of available subtypes (translated). Use variableSubType() to map index to ID.
TQVariant varValue() const
Return the variable value, as a TQVariant, before format conversion.
void drawCustomItemHelper(TQPainter *p, int x, int y, int wpix, int hpix, int ascentpix, const TQColorGroup &cg, bool selected, int offset, KoTextFormat *fmt, const TQFont &font, TQColor textColor, bool drawingShadow)
Called by drawCustomItem.
virtual TQString text(bool realValue=false)
Returns the text to be displayed for this variable It doesn't need to be cached, convert() is fast,...
virtual void resize()
Reimplement this to calculate the item width It is important to start with "if ( m_deleted ) return;"...
virtual void saveVariable(TQDomElement &parentElem)=0
Variable should reimplement this to implement saving.
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const
Save to Oasis XML.
virtual void save(TQDomElement &parentElem)
Save the variable.
void recalcAndRepaint()
Ask this variable to recalculate and to repaint itself Only use this if you're working on a single va...
A class for writing out XML (to any TQIODevice), with a special attention on performance.
void addConfigItem(const TQString &configName, const TQString &value)
Special helper for writing config item into settings.xml.
void startElement(const char *tagName, bool indentInside=true)
Start a new element, as a child of the current element.
void addTextNode(const TQString &str)
Overloaded version of addTextNode( const char* ), which is a bit slower because it needs to convert s...
void endElement()
Terminate the current element.
void addAttribute(const char *attrName, const TQString &value)
Overloaded version of addAttribute( const char*, const char* ), which is a bit slower because it need...
virtual void setChecked(bool)
const char * name(StdAction id)
KOFFICECORE_EXPORT TQDomElement namedItemNS(const TQDomNode &node, const char *nsURI, const char *localName)
A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...