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., 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( _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 #include <kdelibs_export.h>
00036 
00037 class DriverItem;
00038 class QListView;
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 KDEPRINT_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 QString& get(const QString& key) const        { return m_map[key]; }
00073     void set(const QString& key, const QString& val)    { m_map[key] = val; }
00074     bool has(const QString& key) const          { return m_map.contains(key); }
00075     const QString& name() const             { return m_name; }
00076     void setName(const QString& s)              { m_name = s; }
00077     bool conflict() const                   { return m_conflict; }
00078     void setConflict(bool on)               { m_conflict = on; }
00079 
00080     virtual QString valueText();
00081     virtual QString prettyText();
00082     virtual void setValueText(const QString&);
00083     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00084     virtual void setOptions(const QMap<QString,QString>& opts);
00085     virtual void getOptions(QMap<QString,QString>& opts, bool incldef = false);
00086     virtual DrBase* clone();
00087 
00088 protected:
00089     QMap<QString,QString>   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 KDEPRINT_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 QString& name);
00117     void removeGroup(DrGroup *grp);
00118     bool isEmpty();
00119 
00120     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00121     DrBase* findOption(const QString& name, DrGroup **parentGroup = 0);
00122     DrGroup* findGroup(DrGroup *grp, DrGroup **parentGroup = 0);
00123     void setOptions(const QMap<QString,QString>& opts);
00124     void getOptions(QMap<QString,QString>& opts, bool incldef = false);
00125     DrBase* clone();
00126 
00127     const QPtrList<DrGroup>& groups()   { return m_subgroups; }
00128     const QPtrList<DrBase>& options()   { return m_listoptions; }
00129 
00130     static QString groupForOption( const QString& optname );
00131 
00132 protected:
00133     void createTree(DriverItem *parent);
00134     void flattenGroup(QMap<QString, DrBase*>&, int&);
00135 
00136 protected:
00137     QPtrList<DrGroup>   m_subgroups;
00138     QDict<DrBase>   m_options;
00139     QPtrList<DrBase>    m_listoptions;  // keep track of order of appearance
00140 };
00141 
00142 /*********************
00143  * Main driver class *
00144  *********************/
00145 
00153 class KDEPRINT_EXPORT DrMain : public DrGroup
00154 {
00155 public:
00156     DrMain();
00157     ~DrMain();
00158 
00159     DriverItem* createTreeView(QListView *parent);
00160     void addConstraint(DrConstraint *c)     { m_constraints.append(c); }
00161     int checkConstraints();
00162     DrPageSize* findPageSize(const QString& name)   { return m_pagesizes.find(name); }
00163     void addPageSize(DrPageSize *sz);
00164     void removeOptionGlobally(const QString& name);
00165     void removeGroupGlobally(DrGroup *grp);
00166     QMap<QString, DrBase*> flatten();
00167     DrMain* cloneDriver();
00168 
00169 protected:
00170     QPtrList<DrConstraint>  m_constraints;
00171     QDict<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 KDEPRINT_EXPORT DrStringOption : public DrBase
00206 {
00207 public:
00208     DrStringOption();
00209     ~DrStringOption();
00210 
00211     virtual QString valueText();
00212     virtual void setValueText(const QString& s);
00213 
00214 protected:
00215     QString m_value;
00216 };
00217 
00218 /**********************************
00219  * Integer numerical option class *
00220  **********************************/
00221 
00229 class KDEPRINT_EXPORT DrIntegerOption : public DrBase
00230 {
00231 public:
00232     DrIntegerOption();
00233     ~DrIntegerOption();
00234 
00235     virtual QString valueText();
00236     virtual void setValueText(const QString& s);
00237     QString fixedVal();
00238 
00239 protected:
00240     int m_value;
00241 };
00242 
00243 /********************************
00244  * Float numerical option class *
00245  ********************************/
00246 
00254 class KDEPRINT_EXPORT DrFloatOption : public DrBase
00255 {
00256 public:
00257     DrFloatOption();
00258     ~DrFloatOption();
00259 
00260     virtual QString valueText();
00261     virtual void setValueText(const QString& s);
00262     QString fixedVal();
00263 
00264 protected:
00265     float   m_value;
00266 };
00267 
00268 /***********************
00269  * Single choice class *
00270  ***********************/
00271 
00279 class KDEPRINT_EXPORT DrListOption : public DrBase
00280 {
00281 public:
00282     DrListOption();
00283     ~DrListOption();
00284 
00285     void addChoice(DrBase *ch)  { m_choices.append(ch); }
00286     QPtrList<DrBase>* choices() { return &m_choices; }
00287     DrBase* currentChoice() const   { return m_current; }
00288     DrBase* findChoice(const QString& txt);
00289     void setChoice(int choicenum);
00290 
00291     virtual QString valueText();
00292     virtual QString prettyText();
00293     virtual void setValueText(const QString& s);
00294     void setOptions(const QMap<QString,QString>& opts);
00295     void getOptions(QMap<QString,QString>& opts, bool incldef = false);
00296     DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00297     DrBase* clone();
00298 
00299 protected:
00300     QPtrList<DrBase>    m_choices;
00301     DrBase      *m_current;
00302 };
00303 
00311 class KDEPRINT_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 QString& o1, const QString& o2, const QString& c1 = QString::null, const QString& c2 = QString::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 QString& 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     QString pageName() const   { return m_name; }
00373 
00374     QSize pageSize() const;
00375     QRect pageRect() const;
00376     QSize 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
KDE Home | KDE Accessibility Home | Description of Access Keys