• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDEPrint

driver.h

Go to the documentation of this file.
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 //krazy:excludeall=dpointer,inline (no guarantee about binary compatibility)
00022 
00023 #ifndef DRIVER_H
00024 #define DRIVER_H
00025 
00026 #if defined( _KDEPRINT_COMPILE )
00027 /* internal header, do not use except if you are a KDEPrint developer */
00028 
00029 #include <kdeprint_export.h>
00030 
00031 #include <QtCore/QHash>
00032 #include <QtCore/QList>
00033 #include <QtCore/QMap>
00034 #include <QtCore/QRect>
00035 #include <QtCore/QSize>
00036 #include <QtCore/QString>
00037 
00038 class DriverItem;
00039 class QTreeWidget;
00040 
00041 /***********************
00042  * Forward definitions *
00043  ***********************/
00044 
00045 class DrBase;
00046 class DrMain;
00047 class DrGroup;
00048 class DrConstraint;
00049 class DrPageSize;
00050 
00051 /*************************************
00052  * Base class for all driver objects *
00053  *************************************/
00054 
00062 class KDEPRINT_EXPORT DrBase
00063 {
00064 public:
00065     enum Type { Base = 0, Main, ChoiceGroup, Group, String, Integer, Float, List, Boolean };
00066 
00067     DrBase();
00068     virtual ~DrBase();
00069 
00070     Type type() const      {
00071         return m_type;
00072     }
00073     bool isOption() const      {
00074         return (m_type >= DrBase::String);
00075     }
00076 
00077     QString get(const QString& key) const   {
00078         return m_map[key];
00079     }
00080     void set(const QString& key, const QString& val) {
00081         m_map[key] = val;
00082     }
00083     bool has(const QString& key) const    {
00084         return m_map.contains(key);
00085     }
00086     QString name() const    {
00087         return m_name;
00088     }
00089     void setName(const QString& s)    {
00090         m_name = s;
00091     }
00092     bool conflict() const      {
00093         return m_conflict;
00094     }
00095     void setConflict(bool on)    {
00096         m_conflict = on;
00097     }
00098 
00099     virtual QString valueText();
00100     virtual QString prettyText();
00101     virtual void setValueText(const QString&);
00102     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00103     virtual void setOptions(const QMap<QString, QString>& opts);
00104     virtual void getOptions(QMap<QString, QString>& opts, bool incldef = false);
00105     virtual DrBase* clone();
00106 
00107 protected:
00108     QMap<QString, QString> m_map;
00109     QString   m_name;  // used as a search key, better to have defined directly
00110     Type   m_type;
00111     bool   m_conflict;
00112 };
00113 
00114 /**********************
00115  * Option group class *
00116  **********************/
00117 
00125 class KDEPRINT_EXPORT DrGroup : public DrBase
00126 {
00127 public:
00128     DrGroup();
00129     ~DrGroup();
00130 
00131     void addOption(DrBase *opt);
00132     void addGroup(DrGroup *grp);
00133     void addObject(DrBase *optgrp);
00134     void clearConflict();
00135     void removeOption(const QString& name);
00136     void removeGroup(DrGroup *grp);
00137     bool isEmpty();
00138 
00139     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00140     DrBase* findOption(const QString& name, DrGroup **parentGroup = 0);
00141     DrGroup* findGroup(DrGroup *grp, DrGroup **parentGroup = 0);
00142     void setOptions(const QMap<QString, QString>& opts);
00143     void getOptions(QMap<QString, QString>& opts, bool incldef = false);
00144     DrBase* clone();
00145 
00146     QList<DrGroup*> groups() {
00147         return m_subgroups;
00148     }
00149     const QList<DrBase*>& options() {
00150         return m_listoptions;
00151     }
00152 
00153     static QString groupForOption(const QString& optname);
00154 
00155 protected:
00156     void createTree(DriverItem *parent);
00157     void flattenGroup(QMap<QString, DrBase*>&, int&);
00158 
00159 protected:
00160     QList<DrGroup*>         m_subgroups;
00161     QHash<QString, DrBase*> m_options;
00162     QList<DrBase*>         m_listoptions; // keep track of order of appearance
00163 };
00164 
00165 /*********************
00166  * Main driver class *
00167  *********************/
00168 
00176 class KDEPRINT_EXPORT DrMain : public DrGroup
00177 {
00178 public:
00179     DrMain();
00180     ~DrMain();
00181 
00182     DriverItem* createTreeView(QTreeWidget *parent);
00183     void addConstraint(DrConstraint *c)  {
00184         m_constraints.append(c);
00185     }
00186     int checkConstraints();
00187     DrPageSize* findPageSize(const QString& name) {
00188         return m_pagesizes.value(name);
00189     }
00190     void addPageSize(DrPageSize *sz);
00191     void removeOptionGlobally(const QString& name);
00192     void removeGroupGlobally(DrGroup *grp);
00193     QMap<QString, DrBase*> flatten();
00194     DrMain* cloneDriver();
00195 
00196 protected:
00197     QList<DrConstraint*>     m_constraints;
00198     QHash<QString, DrPageSize*> m_pagesizes;
00199 };
00200 
00201 /**********************************************************
00202  * Choice group class: a choice that involve a sub-option *
00203  **********************************************************/
00204 
00212 class DrChoiceGroup : public DrGroup
00213 {
00214 public:
00215     DrChoiceGroup();
00216     ~DrChoiceGroup();
00217 
00218     DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00219 };
00220 
00221 /***********************
00222  * String option class *
00223  ***********************/
00224 
00232 class KDEPRINT_EXPORT DrStringOption : public DrBase
00233 {
00234 public:
00235     DrStringOption();
00236     ~DrStringOption();
00237 
00238     virtual QString valueText();
00239     virtual void setValueText(const QString& s);
00240 
00241 protected:
00242     QString m_value;
00243 };
00244 
00245 /**********************************
00246  * Integer numerical option class *
00247  **********************************/
00248 
00256 class KDEPRINT_EXPORT DrIntegerOption : public DrBase
00257 {
00258 public:
00259     DrIntegerOption();
00260     ~DrIntegerOption();
00261 
00262     virtual QString valueText();
00263     virtual void setValueText(const QString& s);
00264     QString fixedVal();
00265 
00266 protected:
00267     int m_value;
00268 };
00269 
00270 /********************************
00271  * Float numerical option class *
00272  ********************************/
00273 
00281 class KDEPRINT_EXPORT DrFloatOption : public DrBase
00282 {
00283 public:
00284     DrFloatOption();
00285     ~DrFloatOption();
00286 
00287     virtual QString valueText();
00288     virtual void setValueText(const QString& s);
00289     QString fixedVal();
00290 
00291 protected:
00292     float m_value;
00293 };
00294 
00295 /***********************
00296  * Single choice class *
00297  ***********************/
00298 
00306 class KDEPRINT_EXPORT DrListOption : public DrBase
00307 {
00308 public:
00309     DrListOption();
00310     ~DrListOption();
00311 
00312     void addChoice(DrBase *ch) {
00313         m_choices.append(ch);
00314     }
00315     QList<DrBase*> choices() {
00316         return m_choices;
00317     }
00318     DrBase* currentChoice() const  {
00319         return m_current;
00320     }
00321     DrBase* findChoice(const QString& txt);
00322     void setChoice(int choicenum);
00323 
00324     virtual QString valueText();
00325     virtual QString prettyText();
00326     virtual void setValueText(const QString& s);
00327     void setOptions(const QMap<QString, QString>& opts);
00328     void getOptions(QMap<QString, QString>& opts, bool incldef = false);
00329     DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
00330     DrBase* clone();
00331 
00332 protected:
00333     QList<DrBase*> m_choices;
00334     DrBase  *m_current;
00335 };
00336 
00344 class KDEPRINT_EXPORT DrBooleanOption : public DrListOption
00345 {
00346     /* just an overloaded class, with different type */
00347 public:
00348     DrBooleanOption() : DrListOption() {
00349         m_type = DrBase::Boolean;
00350     }
00351     ~DrBooleanOption() {}
00352 };
00353 
00354 /********************
00355  * Constraint class *
00356  ********************/
00357 
00365 class DrConstraint
00366 {
00367 public:
00368     DrConstraint(const QString& o1, const QString& o2, const QString& c1 = QString(), const QString& c2 = QString());
00369     DrConstraint(const DrConstraint&);
00370 
00371     bool check(DrMain*);
00372 
00373 protected:
00374     QString  m_opt1, m_opt2;
00375     QString  m_choice1, m_choice2;
00376     DrListOption *m_option1, *m_option2;
00377 };
00378 
00379 /*******************
00380  * Page Size class *
00381  *******************/
00382 
00390 class DrPageSize
00391 {
00392 public:
00393     DrPageSize(const QString& s, float width, float height, float left, float bottom, float right, float top);
00394     DrPageSize(const DrPageSize&);
00395 
00401     float pageWidth() const    {
00402         return m_width;
00403     }
00404     float pageHeight() const   {
00405         return m_height;
00406     }
00407     float leftMargin() const   {
00408         return m_left;
00409     }
00410     float rightMargin() const  {
00411         return m_right;
00412     }
00413     float topMargin() const    {
00414         return m_top;
00415     }
00416     float bottomMargin() const {
00417         return m_bottom;
00418     }
00419     QString pageName() const   {
00420         return m_name;
00421     }
00422 
00423     QSize pageSize() const;
00424     QRect pageRect() const;
00425     QSize margins() const;
00426 
00427 protected:
00428     QString m_name;
00429     float m_width, m_height, m_left, m_bottom, m_right, m_top;
00430 };
00431 
00432 #endif
00433 #endif

KDEPrint

Skip menu "KDEPrint"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  •   KDEPrint
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal