driver.h
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be> 00004 * 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License version 2 as published by the Free Software Foundation. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 **/ 00020 00021 #ifndef DRIVER_H 00022 #define DRIVER_H 00023 00024 #if !defined( _TDEPRINT_COMPILE ) && defined( __GNUC__ ) 00025 #warning internal header, do not use except if you are a TDEPrint developer 00026 #endif 00027 00028 #include <tqstring.h> 00029 #include <tqptrlist.h> 00030 #include <tqdict.h> 00031 #include <tqmap.h> 00032 #include <tqrect.h> 00033 #include <tqsize.h> 00034 00035 #include <tdelibs_export.h> 00036 00037 class DriverItem; 00038 class TQListView; 00039 00040 /*********************** 00041 * Forward definitions * 00042 ***********************/ 00043 00044 class DrBase; 00045 class DrMain; 00046 class DrGroup; 00047 class DrConstraint; 00048 class DrPageSize; 00049 00050 /************************************* 00051 * Base class for all driver objects * 00052 *************************************/ 00053 00061 class TDEPRINT_EXPORT DrBase 00062 { 00063 public: 00064 enum Type { Base = 0, Main, ChoiceGroup, Group, String, Integer, Float, List, Boolean }; 00065 00066 DrBase(); 00067 virtual ~DrBase(); 00068 00069 Type type() const { return m_type; } 00070 bool isOption() const { return (m_type >= DrBase::String); } 00071 00072 const TQString& get(const TQString& key) const { return m_map[key]; } 00073 void set(const TQString& key, const TQString& val) { m_map[key] = val; } 00074 bool has(const TQString& key) const { return m_map.contains(key); } 00075 const TQString& name() const { return m_name; } 00076 void setName(const TQString& s) { m_name = s; } 00077 bool conflict() const { return m_conflict; } 00078 void setConflict(bool on) { m_conflict = on; } 00079 00080 virtual TQString valueText(); 00081 virtual TQString prettyText(); 00082 virtual void setValueText(const TQString&); 00083 virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00084 virtual void setOptions(const TQMap<TQString,TQString>& opts); 00085 virtual void getOptions(TQMap<TQString,TQString>& opts, bool incldef = false); 00086 virtual DrBase* clone(); 00087 00088 protected: 00089 TQMap<TQString,TQString> m_map; 00090 QString m_name; // used as a search key, better to have defined directly 00091 Type m_type; 00092 bool m_conflict; 00093 }; 00094 00095 /********************** 00096 * Option group class * 00097 **********************/ 00098 00106 class TDEPRINT_EXPORT DrGroup : public DrBase 00107 { 00108 public: 00109 DrGroup(); 00110 ~DrGroup(); 00111 00112 void addOption(DrBase *opt); 00113 void addGroup(DrGroup *grp); 00114 void addObject(DrBase *optgrp); 00115 void clearConflict(); 00116 void removeOption(const TQString& name); 00117 void removeGroup(DrGroup *grp); 00118 bool isEmpty(); 00119 00120 virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00121 DrBase* findOption(const TQString& name, DrGroup **parentGroup = 0); 00122 DrGroup* findGroup(DrGroup *grp, DrGroup **parentGroup = 0); 00123 void setOptions(const TQMap<TQString,TQString>& opts); 00124 void getOptions(TQMap<TQString,TQString>& opts, bool incldef = false); 00125 DrBase* clone(); 00126 00127 const TQPtrList<DrGroup>& groups() { return m_subgroups; } 00128 const TQPtrList<DrBase>& options() { return m_listoptions; } 00129 00130 static TQString groupForOption( const TQString& optname ); 00131 00132 protected: 00133 void createTree(DriverItem *parent); 00134 void flattenGroup(TQMap<TQString, DrBase*>&, int&); 00135 00136 protected: 00137 TQPtrList<DrGroup> m_subgroups; 00138 TQDict<DrBase> m_options; 00139 TQPtrList<DrBase> m_listoptions; // keep track of order of appearance 00140 }; 00141 00142 /********************* 00143 * Main driver class * 00144 *********************/ 00145 00153 class TDEPRINT_EXPORT DrMain : public DrGroup 00154 { 00155 public: 00156 DrMain(); 00157 ~DrMain(); 00158 00159 DriverItem* createTreeView(TQListView *parent); 00160 void addConstraint(DrConstraint *c) { m_constraints.append(c); } 00161 int checkConstraints(); 00162 DrPageSize* findPageSize(const TQString& name) { return m_pagesizes.find(name); } 00163 void addPageSize(DrPageSize *sz); 00164 void removeOptionGlobally(const TQString& name); 00165 void removeGroupGlobally(DrGroup *grp); 00166 TQMap<TQString, DrBase*> flatten(); 00167 DrMain* cloneDriver(); 00168 00169 protected: 00170 TQPtrList<DrConstraint> m_constraints; 00171 TQDict<DrPageSize> m_pagesizes; 00172 }; 00173 00174 /********************************************************** 00175 * Choice group class: a choice that involve a sub-option * 00176 **********************************************************/ 00177 00185 class DrChoiceGroup : public DrGroup 00186 { 00187 public: 00188 DrChoiceGroup(); 00189 ~DrChoiceGroup(); 00190 00191 DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00192 }; 00193 00194 /*********************** 00195 * String option class * 00196 ***********************/ 00197 00205 class TDEPRINT_EXPORT DrStringOption : public DrBase 00206 { 00207 public: 00208 DrStringOption(); 00209 ~DrStringOption(); 00210 00211 virtual TQString valueText(); 00212 virtual void setValueText(const TQString& s); 00213 00214 protected: 00215 QString m_value; 00216 }; 00217 00218 /********************************** 00219 * Integer numerical option class * 00220 **********************************/ 00221 00229 class TDEPRINT_EXPORT DrIntegerOption : public DrBase 00230 { 00231 public: 00232 DrIntegerOption(); 00233 ~DrIntegerOption(); 00234 00235 virtual TQString valueText(); 00236 virtual void setValueText(const TQString& s); 00237 TQString fixedVal(); 00238 00239 protected: 00240 int m_value; 00241 }; 00242 00243 /******************************** 00244 * Float numerical option class * 00245 ********************************/ 00246 00254 class TDEPRINT_EXPORT DrFloatOption : public DrBase 00255 { 00256 public: 00257 DrFloatOption(); 00258 ~DrFloatOption(); 00259 00260 virtual TQString valueText(); 00261 virtual void setValueText(const TQString& s); 00262 TQString fixedVal(); 00263 00264 protected: 00265 float m_value; 00266 }; 00267 00268 /*********************** 00269 * Single choice class * 00270 ***********************/ 00271 00279 class TDEPRINT_EXPORT DrListOption : public DrBase 00280 { 00281 public: 00282 DrListOption(); 00283 ~DrListOption(); 00284 00285 void addChoice(DrBase *ch) { m_choices.append(ch); } 00286 TQPtrList<DrBase>* choices() { return &m_choices; } 00287 DrBase* currentChoice() const { return m_current; } 00288 DrBase* findChoice(const TQString& txt); 00289 void setChoice(int choicenum); 00290 00291 virtual TQString valueText(); 00292 virtual TQString prettyText(); 00293 virtual void setValueText(const TQString& s); 00294 void setOptions(const TQMap<TQString,TQString>& opts); 00295 void getOptions(TQMap<TQString,TQString>& opts, bool incldef = false); 00296 DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00297 DrBase* clone(); 00298 00299 protected: 00300 TQPtrList<DrBase> m_choices; 00301 DrBase *m_current; 00302 }; 00303 00311 class TDEPRINT_EXPORT DrBooleanOption : public DrListOption 00312 { 00313 /* just an overloaded class, with different type */ 00314 public: 00315 DrBooleanOption() : DrListOption() { m_type = DrBase::Boolean; } 00316 ~DrBooleanOption() {} 00317 }; 00318 00319 /******************** 00320 * Constraint class * 00321 ********************/ 00322 00330 class DrConstraint 00331 { 00332 public: 00333 DrConstraint(const TQString& o1, const TQString& o2, const TQString& c1 = TQString::null, const TQString& c2 = TQString::null); 00334 DrConstraint(const DrConstraint&); 00335 00336 bool check(DrMain*); 00337 00338 protected: 00339 QString m_opt1, m_opt2; 00340 QString m_choice1, m_choice2; 00341 DrListOption *m_option1, *m_option2; 00342 }; 00343 00344 /******************* 00345 * Page Size class * 00346 *******************/ 00347 00355 class DrPageSize 00356 { 00357 public: 00358 DrPageSize(const TQString& s, float width, float height, float left, float bottom, float right, float top); 00359 DrPageSize(const DrPageSize&); 00360 00366 float pageWidth() const { return m_width; } 00367 float pageHeight() const { return m_height; } 00368 float leftMargin() const { return m_left; } 00369 float rightMargin() const { return m_right; } 00370 float topMargin() const { return m_top; } 00371 float bottomMargin() const { return m_bottom; } 00372 TQString pageName() const { return m_name; } 00373 00374 TQSize pageSize() const; 00375 TQRect pageRect() const; 00376 TQSize margins() const; 00377 00378 protected: 00379 QString m_name; 00380 float m_width, m_height, m_left, m_bottom, m_right, m_top; 00381 }; 00382 00383 #endif