lib Library API Documentation

kovariable.h

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef kovariable_h 00021 #define kovariable_h 00022 00023 #include <qstring.h> 00024 #include <qdatetime.h> 00025 #include <qasciidict.h> 00026 #include <qptrlist.h> 00027 #include <qmap.h> 00028 #include <qobject.h> 00029 #include <kaction.h> 00030 #include "korichtext.h" 00031 #include <qvariant.h> 00032 00033 class QDomElement; 00034 // Always add new types at the _end_ of this list (but before VT_ALL of course). 00035 // (and update KWView::setupActions) 00036 enum VariableType { VT_NONE = -1, 00037 VT_DATE = 0, VT_DATE_VAR_KWORD10 = 1, 00038 VT_TIME = 2, VT_TIME_VAR_KWORD10 = 3, 00039 VT_PGNUM = 4, 00040 VT_CUSTOM = 6, VT_MAILMERGE = 7, VT_FIELD = 8, VT_LINK = 9, 00041 VT_NOTE = 10, VT_FOOTNOTE = 11, 00042 VT_ALL=256 }; 00043 00044 enum VariableFormat { VF_DATE = 0, VF_TIME = 1, VF_STRING = 2, VF_NUM = 3 }; 00045 00046 class KoVariable; 00047 00048 class KoVariableSettings 00049 { 00050 public: 00051 KoVariableSettings(); 00052 virtual ~KoVariableSettings(); 00053 00054 // don't remove startingPage or startingPageNumber! - Clarence 00055 00056 int startingPage()const { return m_startingPageNumber; } 00057 void setStartingPage(int num) { m_startingPageNumber=num; } 00058 00059 int startingPageNumber()const { return startingPage(); } 00060 void setStartingPageNumber(int num) { setStartingPage(num); } 00061 00062 bool displayLink() const{ return m_displayLink; } 00063 void setDisplayLink( bool b) { m_displayLink=b; } 00064 00065 bool underlineLink() const { return m_underlineLink; } 00066 void setUnderlineLink( bool b) { m_underlineLink=b; } 00067 00068 bool displayComment() const { return m_displayComment; } 00069 void setDisplayComment( bool b) { m_displayComment=b; } 00070 00071 bool displayFieldCode() const { return m_displayFieldCode; } 00072 void setDisplayFieldCode( bool b) { m_displayFieldCode=b; } 00073 00074 virtual void save( QDomElement &parentElem ); 00075 virtual void load( QDomElement &elem ); 00076 00077 QDateTime lastPrintingDate() const; 00078 void setLastPrintingDate( const QDateTime & _date); 00079 00080 QDateTime creationDate() const; 00081 void setCreationDate( const QDateTime & _date); 00082 00083 QDateTime modificationDate() const; 00084 void setModificationDate( const QDateTime & _date); 00085 00086 00087 private: 00088 int m_startingPageNumber; 00089 bool m_displayLink; 00090 bool m_displayComment; 00091 bool m_underlineLink; 00092 bool m_displayFieldCode; 00093 class KoVariableSettingPrivate; 00094 KoVariableSettingPrivate *d; 00095 }; 00096 00104 class KoVariableFormat 00105 { 00106 public: 00107 KoVariableFormat() {} 00108 virtual ~KoVariableFormat() {} 00113 virtual QCString key() const = 0; 00119 virtual QCString getKey( const QString& props ) const = 0; 00123 virtual void load( const QCString &key ) = 0; 00127 virtual QString convert(const QVariant& data ) const = 0; 00133 virtual void setFormatProperties( const QString& ) {} 00137 virtual QString formatProperties() const { return QString::null; } 00141 virtual QStringList formatPropsList() const { return QStringList(); } 00145 virtual QStringList translatedFormatPropsList() const { return QStringList(); } 00146 }; 00147 00152 class KoVariableDateFormat : public KoVariableFormat 00153 { 00154 public: 00155 KoVariableDateFormat(); 00156 virtual QString convert(const QVariant& data ) const; 00157 virtual QCString key() const; 00158 virtual QCString getKey( const QString& props ) const; 00159 virtual void load( const QCString &key ); 00160 00162 virtual void setFormatProperties( const QString& props ) { 00163 m_strFormat = props; 00164 } 00166 virtual QString formatProperties() const { return m_strFormat; } 00167 00169 virtual QStringList formatPropsList() const { return staticFormatPropsList(); } 00170 00172 virtual QStringList translatedFormatPropsList() const { return staticTranslatedFormatPropsList(); } 00173 00174 static QStringList staticFormatPropsList(); 00175 static QStringList staticTranslatedFormatPropsList(); 00176 00177 private: 00178 QString m_strFormat; 00179 }; 00180 00184 class KoVariableTimeFormat : public KoVariableFormat 00185 { 00186 public: 00187 KoVariableTimeFormat(); 00188 virtual QString convert(const QVariant& data ) const; 00189 virtual QCString key() const; 00190 virtual QCString getKey( const QString& props ) const; 00191 virtual void load( const QCString & /*key*/ ); 00192 00194 virtual void setFormatProperties( const QString& props ) { 00195 m_strFormat = props; 00196 } 00198 virtual QString formatProperties() const { return m_strFormat; } 00199 00201 virtual QStringList formatPropsList() const { return staticFormatPropsList(); } 00202 00204 virtual QStringList translatedFormatPropsList() const { return staticTranslatedFormatPropsList(); } 00205 00206 static QStringList staticFormatPropsList(); 00207 static QStringList staticTranslatedFormatPropsList(); 00208 00209 private: 00210 QString m_strFormat; 00211 }; 00212 00216 class KoVariableStringFormat : public KoVariableFormat 00217 { 00218 public: 00219 KoVariableStringFormat() : KoVariableFormat() {} 00220 virtual QString convert(const QVariant& data ) const; 00221 virtual QCString key() const; 00222 virtual QCString getKey( const QString& props ) const; 00223 virtual void load( const QCString & /*key*/ ) {} 00224 }; 00225 00226 class KoVariableNumberFormat : public KoVariableFormat 00227 { 00228 public: 00229 KoVariableNumberFormat() : KoVariableFormat() {} 00230 virtual QString convert(const QVariant& data ) const; 00231 virtual QCString key() const; 00232 virtual QCString getKey( const QString& props ) const; 00233 virtual void load( const QCString & /*key*/ ) {} 00234 }; 00235 00242 class KoVariableFormatCollection 00243 { 00244 public: 00245 KoVariableFormatCollection(); 00246 00250 void clear() { m_dict.clear(); } 00251 00255 KoVariableFormat *format( const QCString &key ); 00256 00257 // TODO Refcounting and removing unused formats 00258 // Not critical, that we don't delete unused formats until closing the doc... 00259 protected: 00260 KoVariableFormat *createFormat( const QCString &key ); 00261 00262 private: 00263 QAsciiDict<KoVariableFormat> m_dict; 00264 }; 00265 00266 class KoVariable; 00267 class KoVariableFormat; 00268 class KoDocument; 00269 class KoVariableFormatCollection; 00270 class KoTextDocument; 00271 class KoVariableCollection; 00272 class KoVariableCollection : public QObject 00273 { 00274 Q_OBJECT 00275 public: 00276 // Note that the KoVariableSettings becomes owned by the collection; 00277 // we take it as argument so that it can be subclassed though. 00278 KoVariableCollection(KoVariableSettings *settings, KoVariableFormatCollection *formatCollection); 00279 ~KoVariableCollection(); 00280 void registerVariable( KoVariable *var ); 00281 void unregisterVariable( KoVariable *var ); 00282 void recalcVariables(int type); 00283 void recalcVariables(KoVariable *var); 00284 00285 // For custom variables 00286 void setVariableValue( const QString &name, const QString &value ); 00287 QString getVariableValue( const QString &name ) const; 00288 00289 const QPtrList<KoVariable>& getVariables() const { 00290 return variables; 00291 } 00292 00293 bool customVariableExist(const QString &varname)const ; 00294 00295 virtual KoVariable *createVariable( int type, short int subtype, KoVariableFormatCollection * coll, KoVariableFormat *varFormat,KoTextDocument *textdoc, KoDocument * doc, int _correct , bool _forceDefaultFormat=false ); 00296 00297 KoVariableSettings *variableSetting() const { return m_variableSettings; } 00298 KoVariableFormatCollection *formatCollection() const { return m_formatCollection; } 00299 00301 void setVariableSelected(KoVariable * var); 00302 KoVariable *selectedVariable()const {return m_varSelected;} 00303 00305 QPtrList<KAction> popupActionList(); 00306 00307 signals: 00308 void repaintVariable(); 00309 00310 protected slots: 00311 // This is here because variables and formats are not QObjects 00312 void slotChangeSubType(); 00313 void slotChangeFormat(); 00314 00315 private: 00316 //typedef QMap<KAction *, int> VariableSubTextMap; 00317 //VariableSubTextMap m_variableSubTextMap; 00318 00319 QPtrList<KoVariable> variables; 00320 QMap< QString, QString > varValues; // for custom variables 00321 KoVariableSettings *m_variableSettings; 00322 KoVariable *m_varSelected; 00323 KoVariableFormatCollection *m_formatCollection; 00324 }; 00325 00326 00327 // ---------------------------------------------------------------------------------------------- 00328 00329 class KoDocument; 00330 class KoVariable; 00331 class QDomElement; 00332 class KoTextFormat; 00333 00338 class KoVariable : public KoTextCustomItem 00339 { 00340 public: 00341 KoVariable( KoTextDocument *fs, KoVariableFormat *varFormat,KoVariableCollection *varColl ); 00342 virtual ~KoVariable(); 00343 00344 virtual VariableType type() const = 0; 00345 virtual short int subType() const { return 0; } 00346 00347 // KoTextCustomItem stuff 00348 virtual Placement placement() const { return PlaceInline; } 00349 virtual void resize(); 00350 virtual int ascent() const { return m_ascent; } // for text, ascent != height! 00351 virtual int widthHint() const { return width; } 00352 virtual int minimumWidth() const { return width; } 00353 virtual void drawCustomItem( QPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected, int offset, bool drawingShadow); 00358 void drawCustomItemHelper( QPainter* p, int x, int y, int wpix, int hpix, int ascentpix, const QColorGroup& cg, bool selected, int offset, KoTextFormat* fmt, const QFont& font, QColor textColor, bool drawingShadow ); 00359 00360 void setVariableFormat( KoVariableFormat *_varFormat ); 00361 00362 KoVariableFormat *variableFormat() const 00363 { return m_varFormat; } 00364 00365 KoVariableCollection *variableColl() const 00366 { return m_varColl; } 00367 00373 virtual QString text(bool realValue=false); 00374 00375 virtual QString fieldCode(); 00376 00378 QVariant varValue() const { return m_varValue; } 00379 00386 void recalcAndRepaint(); 00387 00389 void save( QDomElement &parentElem ); 00390 virtual void load( QDomElement &elem ); 00391 00395 virtual int typeId() const { return 4; } 00396 00398 virtual QStringList subTypeText(); 00399 00401 virtual void setVariableSubType( short int /*subtype*/ ) {} 00402 00406 virtual short int variableSubType(short int menuNumber){ return menuNumber; } 00407 00408 protected: 00410 virtual void saveVariable( QDomElement &parentElem ) = 0; 00411 virtual int correctValue() const { return 0;} 00412 00413 KoVariableFormat *m_varFormat; 00414 KoVariableCollection *m_varColl; 00415 QVariant m_varValue; 00416 int m_ascent; 00417 00418 //typedef QMap<KAction *, int> SubTextMap; 00419 //SubTextMap m_subTextMap; 00420 class Private; 00421 Private *d; 00422 }; 00423 00427 class KoDateVariable : public KoVariable 00428 { 00429 public: 00430 KoDateVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *_varFormat,KoVariableCollection *_varColl , int _correctDate = 0); 00431 00432 virtual VariableType type() const 00433 { return VT_DATE; } 00434 00435 enum { VST_DATE_FIX = 0, VST_DATE_CURRENT = 1, VST_DATE_LAST_PRINTING = 2, VST_DATE_CREATE_FILE = 3, VST_DATE_MODIFY_FILE =4 }; 00436 static QStringList actionTexts(); 00437 00438 virtual void recalc(); 00439 virtual QString fieldCode(); 00440 virtual void resize(); 00441 void setDate( const QDate & _date ) { m_varValue = QVariant(_date); } 00442 00443 virtual void saveVariable( QDomElement &parentElem ); 00444 virtual int correctValue() const { return m_correctDate;} 00445 virtual void load( QDomElement &elem ); 00446 virtual QStringList subTypeText(); 00448 virtual void setVariableSubType( short int subtype ) 00449 { m_subtype = subtype; } 00450 virtual short int subType() const { return m_subtype; } 00454 static QCString formatStr( int & correct ); 00458 static QCString defaultFormat(); 00459 00460 protected: 00461 short int m_subtype; 00462 int m_correctDate; 00463 }; 00464 00468 class KoTimeVariable : public KoVariable 00469 { 00470 public: 00471 KoTimeVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat, KoVariableCollection *_varColl, int _correct); 00472 00473 virtual VariableType type() const 00474 { return VT_TIME; } 00475 00476 enum { VST_TIME_FIX = 0, VST_TIME_CURRENT = 1 }; 00477 static QStringList actionTexts(); 00478 00479 virtual void recalc(); 00480 virtual void resize(); 00481 virtual QString fieldCode(); 00482 00483 void setTime( const QTime & _time ) { m_varValue = QVariant(_time); } 00484 00485 virtual void saveVariable( QDomElement &parentElem ); 00486 virtual int correctValue() const { return m_correctTime;} 00487 virtual void load( QDomElement &elem ); 00488 00489 virtual QStringList subTypeText(); 00490 virtual void setVariableSubType( short int subtype ) 00491 { m_subtype = subtype; } 00492 virtual short int subType() const { return m_subtype; } 00496 static QCString formatStr(int & _correct); 00500 static QCString defaultFormat(); 00501 00502 protected: 00503 short int m_subtype; 00504 int m_correctTime; 00505 }; 00506 00507 00512 class KoCustomVariable : public KoVariable 00513 { 00514 public: 00515 KoCustomVariable(KoTextDocument *textdoc , const QString &name, KoVariableFormat *varFormat,KoVariableCollection *_varcoll ); 00516 00517 virtual VariableType type() const 00518 { return VT_CUSTOM; } 00519 static QStringList actionTexts(); 00520 00521 virtual void saveVariable( QDomElement &parentElem ); 00522 virtual void load( QDomElement &elem ); 00523 00524 QString name() const { return m_varValue.toString(); } 00525 virtual void recalc(); 00526 virtual QString fieldCode(); 00527 00528 virtual QString text(bool realValue=false); 00529 00530 QString value() const; 00531 void setValue( const QString &v ); 00532 00533 protected: 00534 }; 00535 00536 00542 class KoFieldVariable : public KoVariable 00543 { 00544 public: 00545 KoFieldVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat,KoVariableCollection *_varColl, KoDocument *_doc ); 00546 00547 // Do not change existing values, they are saved in document files 00548 enum FieldSubType { VST_NONE = -1, 00549 VST_FILENAME = 0, VST_DIRECTORYNAME = 1, 00550 VST_AUTHORNAME = 2, VST_EMAIL = 3, VST_COMPANYNAME = 4, 00551 VST_PATHFILENAME = 5, VST_FILENAMEWITHOUTEXTENSION=6, 00552 VST_TELEPHONE = 7, VST_FAX = 8, VST_COUNTRY = 9, 00553 VST_TITLE = 10, VST_ABSTRACT = 11, 00554 VST_POSTAL_CODE = 12, VST_CITY = 13, VST_STREET = 14, 00555 VST_AUTHORTITLE = 15, VST_INITIAL = 16}; 00556 00557 virtual VariableType type() const 00558 { return VT_FIELD; } 00559 00560 virtual void saveVariable( QDomElement &parentElem ); 00561 virtual void load( QDomElement &elem ); 00562 virtual QString fieldCode(); 00563 00564 virtual void recalc(); 00565 virtual QString text(bool realValue=false); 00566 00567 QString value() const { return m_varValue.toString(); } 00568 00569 static QStringList actionTexts(); 00573 virtual short int variableSubType( short int menuNumber ); 00577 static FieldSubType fieldSubType( short int menuNumber); 00578 00579 virtual QStringList subTypeText(); 00580 virtual void setVariableSubType( short int subtype ) 00581 { m_subtype = subtype; } 00582 virtual short int subType() const { return m_subtype; } 00583 00584 protected: 00585 short int m_subtype; 00586 KoDocument *m_doc; 00587 }; 00588 00589 class KoMailMergeVariable : public KoVariable 00590 { 00591 public: 00592 KoMailMergeVariable( KoTextDocument *textdoc, const QString &name, KoVariableFormat *varFormat, KoVariableCollection *_varColl ); 00593 00594 virtual VariableType type() const 00595 { return VT_MAILMERGE; } 00596 static QStringList actionTexts(); 00597 virtual QString fieldCode(); 00598 00599 virtual void saveVariable( QDomElement &parentElem ); 00600 virtual void load( QDomElement &elem ); 00601 00602 virtual QString text(bool realValue=false); 00603 QString name() const { return m_varValue.toString(); } 00604 virtual QString value() const; 00605 00606 protected: 00607 }; 00608 00615 class KoPgNumVariable : public KoVariable 00616 { 00617 public: 00618 KoPgNumVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat ,KoVariableCollection *_varColl); 00619 00620 virtual VariableType type() const 00621 { return VT_PGNUM; } 00622 00623 enum { VST_PGNUM_CURRENT = 0, VST_PGNUM_TOTAL = 1, VST_CURRENT_SECTION = 2 , VST_PGNUM_PREVIOUS = 3, VST_PGNUM_NEXT = 4 }; 00624 static QStringList actionTexts(); 00625 virtual QString fieldCode(); 00626 00627 virtual QStringList subTypeText(); 00628 00629 virtual void setVariableSubType( short int subtype ); 00630 00631 // For the 'current page' variable. This is called by the app e.g. when painting 00632 // a given page (see KWTextFrameSet::drawFrame and KPTextObject::recalcPageNum) 00633 void setPgNum( int pgNum ) { m_varValue = QVariant( pgNum); } 00634 // For the 'current section title' variable. Same thing. 00635 void setSectionTitle( const QString& title ); 00636 00637 virtual short int subType() const { return m_subtype; } 00638 00639 virtual void recalc() = 0; 00640 00641 virtual void saveVariable( QDomElement &parentElem ); 00642 virtual void load( QDomElement &elem ); 00643 protected: 00644 short int m_subtype; 00645 }; 00646 00647 class KoLinkVariable : public KoVariable 00648 { 00649 public: 00650 KoLinkVariable( KoTextDocument *textdoc, const QString & _linkName, const QString & _ulr,KoVariableFormat *varFormat, KoVariableCollection *_varColl ); 00651 virtual void drawCustomItem( QPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int /*cx*/, int /*cy*/, int /*cw*/, int /*ch*/, const QColorGroup& cg, bool selected, int offset, bool drawingShadow ); 00652 00653 virtual VariableType type() const 00654 { return VT_LINK; } 00655 00656 static QStringList actionTexts(); 00657 virtual QString fieldCode(); 00658 00659 virtual void saveVariable( QDomElement &parentElem ); 00660 virtual void load( QDomElement &elem ); 00661 00662 virtual QString text(bool realValue=false); 00663 QString value() const { return m_varValue.toString(); } 00664 QString url() const { return m_url;} 00665 00666 virtual void recalc(); 00667 00668 void setLink(const QString & _linkName, const QString &_url) 00669 { 00670 m_varValue=QVariant(_linkName); 00671 m_url=_url; 00672 } 00673 00674 protected: 00675 QString m_url; 00676 }; 00677 00678 // A custom item that display a small yellow rect. Right-clicking on it shows the comment. 00679 class KoNoteVariable : public KoVariable 00680 { 00681 public: 00682 KoNoteVariable( KoTextDocument *textdoc, const QString & _note,KoVariableFormat *varFormat, KoVariableCollection *_varColl ); 00683 virtual void drawCustomItem( QPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int /*cx*/, int /*cy*/, int /*cw*/, int /*ch*/, const QColorGroup& cg, bool selected, int offset, bool drawingShadow ); 00684 00685 virtual VariableType type() const 00686 { return VT_NOTE; } 00687 00688 static QStringList actionTexts(); 00689 virtual QString fieldCode(); 00690 00691 virtual void saveVariable( QDomElement &parentElem ); 00692 virtual void load( QDomElement &elem ); 00693 00694 virtual QString text(bool realValue=false); 00695 QString note() const { return m_varValue.toString(); } 00696 void setNote( const QString & _note) { m_varValue = QVariant(_note); } 00697 virtual void recalc(); 00698 }; 00699 00700 00701 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:04:03 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003