kdeprint Library API Documentation

driver.h

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@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., 59 Temple Place - Suite 330, 00018 * Boston, MA 02111-1307, USA. 00019 **/ 00020 00021 #ifndef DRIVER_H 00022 #define DRIVER_H 00023 00024 #if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ ) 00025 #warning internal header, do not use except if you are a KDEPrint developer 00026 #endif 00027 00028 #include <qstring.h> 00029 #include <qptrlist.h> 00030 #include <qdict.h> 00031 #include <qmap.h> 00032 #include <qrect.h> 00033 #include <qsize.h> 00034 00035 class DriverItem; 00036 class QListView; 00037 00038 /*********************** 00039 * Forward definitions * 00040 ***********************/ 00041 00042 class DrBase; 00043 class DrMain; 00044 class DrGroup; 00045 class DrConstraint; 00046 class DrPageSize; 00047 00048 /************************************* 00049 * Base class for all driver objects * 00050 *************************************/ 00051 00059 class DrBase 00060 { 00061 public: 00062 enum Type { Base = 0, Main, ChoiceGroup, Group, String, Integer, Float, List, Boolean }; 00063 00064 DrBase(); 00065 virtual ~DrBase(); 00066 00067 Type type() const { return m_type; } 00068 bool isOption() const { return (m_type >= DrBase::String); } 00069 00070 const QString& get(const QString& key) const { return m_map[key]; } 00071 void set(const QString& key, const QString& val) { m_map[key] = val; } 00072 bool has(const QString& key) const { return m_map.contains(key); } 00073 const QString& name() const { return m_name; } 00074 void setName(const QString& s) { m_name = s; } 00075 bool conflict() const { return m_conflict; } 00076 void setConflict(bool on) { m_conflict = on; } 00077 00078 virtual QString valueText(); 00079 virtual QString prettyText(); 00080 virtual void setValueText(const QString&); 00081 virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00082 virtual void setOptions(const QMap<QString,QString>& opts); 00083 virtual void getOptions(QMap<QString,QString>& opts, bool incldef = false); 00084 virtual DrBase* clone(); 00085 00086 protected: 00087 QMap<QString,QString> m_map; 00088 QString m_name; // used as a search key, better to have defined directly 00089 Type m_type; 00090 bool m_conflict; 00091 }; 00092 00093 /********************** 00094 * Option group class * 00095 **********************/ 00096 00104 class DrGroup : public DrBase 00105 { 00106 public: 00107 DrGroup(); 00108 ~DrGroup(); 00109 00110 void addOption(DrBase *opt); 00111 void addGroup(DrGroup *grp); 00112 void addObject(DrBase *optgrp); 00113 void clearConflict(); 00114 void removeOption(const QString& name); 00115 void removeGroup(DrGroup *grp); 00116 bool isEmpty(); 00117 00118 virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00119 DrBase* findOption(const QString& name, DrGroup **parentGroup = 0); 00120 DrGroup* findGroup(DrGroup *grp, DrGroup **parentGroup = 0); 00121 void setOptions(const QMap<QString,QString>& opts); 00122 void getOptions(QMap<QString,QString>& opts, bool incldef = false); 00123 DrBase* clone(); 00124 00125 const QPtrList<DrGroup>& groups() { return m_subgroups; } 00126 const QPtrList<DrBase>& options() { return m_listoptions; } 00127 00128 static QString groupForOption( const QString& optname ); 00129 00130 protected: 00131 void createTree(DriverItem *parent); 00132 void flattenGroup(QMap<QString, DrBase*>&, int&); 00133 00134 protected: 00135 QPtrList<DrGroup> m_subgroups; 00136 QDict<DrBase> m_options; 00137 QPtrList<DrBase> m_listoptions; // keep track of order of appearance 00138 }; 00139 00140 /********************* 00141 * Main driver class * 00142 *********************/ 00143 00151 class DrMain : public DrGroup 00152 { 00153 public: 00154 DrMain(); 00155 ~DrMain(); 00156 00157 DriverItem* createTreeView(QListView *parent); 00158 void addConstraint(DrConstraint *c) { m_constraints.append(c); } 00159 int checkConstraints(); 00160 DrPageSize* findPageSize(const QString& name) { return m_pagesizes.find(name); } 00161 void addPageSize(DrPageSize *sz); 00162 void removeOptionGlobally(const QString& name); 00163 void removeGroupGlobally(DrGroup *grp); 00164 QMap<QString, DrBase*> flatten(); 00165 DrMain* cloneDriver(); 00166 00167 protected: 00168 QPtrList<DrConstraint> m_constraints; 00169 QDict<DrPageSize> m_pagesizes; 00170 }; 00171 00172 /********************************************************** 00173 * Choice group class: a choice that involve a sub-option * 00174 **********************************************************/ 00175 00183 class DrChoiceGroup : public DrGroup 00184 { 00185 public: 00186 DrChoiceGroup(); 00187 ~DrChoiceGroup(); 00188 00189 DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00190 }; 00191 00192 /*********************** 00193 * String option class * 00194 ***********************/ 00195 00203 class DrStringOption : public DrBase 00204 { 00205 public: 00206 DrStringOption(); 00207 ~DrStringOption(); 00208 00209 virtual QString valueText(); 00210 virtual void setValueText(const QString& s); 00211 00212 protected: 00213 QString m_value; 00214 }; 00215 00216 /********************************** 00217 * Integer numerical option class * 00218 **********************************/ 00219 00227 class DrIntegerOption : public DrBase 00228 { 00229 public: 00230 DrIntegerOption(); 00231 ~DrIntegerOption(); 00232 00233 virtual QString valueText(); 00234 virtual void setValueText(const QString& s); 00235 QString fixedVal(); 00236 00237 protected: 00238 int m_value; 00239 }; 00240 00241 /******************************** 00242 * Float numerical option class * 00243 ********************************/ 00244 00252 class DrFloatOption : public DrBase 00253 { 00254 public: 00255 DrFloatOption(); 00256 ~DrFloatOption(); 00257 00258 virtual QString valueText(); 00259 virtual void setValueText(const QString& s); 00260 QString fixedVal(); 00261 00262 protected: 00263 float m_value; 00264 }; 00265 00266 /*********************** 00267 * Single choice class * 00268 ***********************/ 00269 00277 class DrListOption : public DrBase 00278 { 00279 public: 00280 DrListOption(); 00281 ~DrListOption(); 00282 00283 void addChoice(DrBase *ch) { m_choices.append(ch); } 00284 QPtrList<DrBase>* choices() { return &m_choices; } 00285 DrBase* currentChoice() const { return m_current; } 00286 DrBase* findChoice(const QString& txt); 00287 void setChoice(int choicenum); 00288 00289 virtual QString valueText(); 00290 virtual QString prettyText(); 00291 virtual void setValueText(const QString& s); 00292 void setOptions(const QMap<QString,QString>& opts); 00293 void getOptions(QMap<QString,QString>& opts, bool incldef = false); 00294 DriverItem* createItem(DriverItem *parent, DriverItem *after = 0); 00295 DrBase* clone(); 00296 00297 protected: 00298 QPtrList<DrBase> m_choices; 00299 DrBase *m_current; 00300 }; 00301 00309 class DrBooleanOption : public DrListOption 00310 { 00311 /* just an overloaded class, with different type */ 00312 public: 00313 DrBooleanOption() : DrListOption() { m_type = DrBase::Boolean; } 00314 ~DrBooleanOption() {} 00315 }; 00316 00317 /******************** 00318 * Constraint class * 00319 ********************/ 00320 00328 class DrConstraint 00329 { 00330 public: 00331 DrConstraint(const QString& o1, const QString& o2, const QString& c1 = QString::null, const QString& c2 = QString::null); 00332 DrConstraint(const DrConstraint&); 00333 00334 bool check(DrMain*); 00335 00336 protected: 00337 QString m_opt1, m_opt2; 00338 QString m_choice1, m_choice2; 00339 DrListOption *m_option1, *m_option2; 00340 }; 00341 00342 /******************* 00343 * Page Size class * 00344 *******************/ 00345 00353 class DrPageSize 00354 { 00355 public: 00356 DrPageSize(const QString& s, float width, float height, float left, float bottom, float right, float top); 00357 DrPageSize(const DrPageSize&); 00358 00364 float pageWidth() const { return m_width; } 00365 float pageHeight() const { return m_height; } 00366 float leftMargin() const { return m_left; } 00367 float rightMargin() const { return m_right; } 00368 float topMargin() const { return m_top; } 00369 float bottomMargin() const { return m_bottom; } 00370 QString pageName() const { return m_name; } 00371 00372 QSize pageSize() const; 00373 QRect pageRect() const; 00374 QSize margins() const; 00375 00376 protected: 00377 QString m_name; 00378 float m_width, m_height, m_left, m_bottom, m_right, m_top; 00379 }; 00380 00381 #endif
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:23:16 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003