kexi

widgetfactory.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
00003    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00004    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
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 as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KFORMDESIGNERWIDGETFACTORY_H
00023 #define KFORMDESIGNERWIDGETFACTORY_H
00024 
00025 
00026 #include <qobject.h>
00027 #include <qguardedptr.h>
00028 #include <qpixmap.h>
00029 #include <qpopupmenu.h>
00030 #include <qasciidict.h>
00031 
00032 #include <kexiutils/tristate.h>
00033 
00034 // class QPixmap;
00035 template<class type> class QValueVector;
00036 template<class type> class QPtrList;
00037 template<class type> class QDict;
00038 class QWidget;
00039 class QDomElement;
00040 class QDomDocument;
00041 class QVariant;
00042 class QListView;
00043 class KActionCollection;
00044 class KTextEdit;
00045 class KLineEdit;
00046 
00047 namespace KoProperty {
00048     class Set;
00049 }
00050 
00051 namespace KFormDesigner {
00052 
00053 class WidgetFactory;
00054 class WidgetLibrary;
00055 class Container;
00056 class ResizeHandleSet;
00057 class ObjectTreeItem;
00058 class WidgetPropertySet;
00059 class Form;
00060 
00064 class KFORMEDITOR_EXPORT WidgetInfo
00065 {
00066     public:
00067         typedef QPtrList<WidgetInfo> List;
00068         typedef QAsciiDict<WidgetInfo> Dict;
00069 
00070         WidgetInfo(WidgetFactory *f);
00071 
00072         WidgetInfo(WidgetFactory *f, const char* parentFactoryName, const char* inheritedClassName = 0);
00073 
00074         virtual ~WidgetInfo();
00075 
00077         QString pixmap() const { return m_pixmap; }
00078 
00080         QCString className() const { return m_class; }
00081 
00084         QString namePrefix() const { return m_prefixName; }
00085 
00087         QString name() const { return m_name; }
00088 
00089         QString description() const { return m_desc; }
00090         QString includeFileName() const { return m_include; }
00091         QValueList<QCString> alternateClassNames() const { return m_alternateNames; }
00092         QString savingName() const { return m_saveName; }
00093         WidgetFactory *factory() const { return m_factory; }
00094 
00095         void setPixmap(const QString &p) { m_pixmap = p; }
00096         void setClassName(const QCString &s) { m_class = s; }
00097         void setName(const QString &n) { m_name = n; }
00098         void setNamePrefix(const QString &n) { m_prefixName = n; }
00099         void setDescription(const QString &desc) { m_desc = desc;}
00100 
00103         void setIncludeFileName(const QString &name) { m_include = name;}
00104 
00121         void addAlternateClassName(const QCString& alternateName, bool override = false);
00122 
00127         bool isOverriddenClassName(const QCString& alternateName) const;
00128 
00135         void setSavingName(const QString &saveName) { m_saveName = saveName; }
00136 
00142         void setAutoSyncForProperty(const char *propertyName, tristate flag);
00143 
00146         tristate autoSyncForProperty(const char *propertyName) const;
00147 
00148         QCString parentFactoryName() const { return m_parentFactoryName; }
00149 
00150         WidgetInfo* inheritedClass() const { return m_inheritedClass; }
00151 
00155         void setCustomTypeForProperty(const char *propertyName, int type);
00156 
00160         int customTypeForProperty(const char *propertyName) const;
00161 
00162     protected:
00163         QCString m_parentFactoryName, m_inheritedClassName; 
00164         WidgetInfo* m_inheritedClass;
00165 
00166     private:
00167         QString m_pixmap;
00168         QCString m_class;
00169         QString m_name;
00170         QString m_prefixName;
00171         QString m_desc;
00172         QString m_include;
00173         QValueList<QCString> m_alternateNames;
00174         QAsciiDict<char> *m_overriddenAlternateNames;
00175         QString m_saveName;
00176         QGuardedPtr<WidgetFactory> m_factory;
00177         QAsciiDict<char> *m_propertiesWithDisabledAutoSync;
00178         QMap<QCString,int> *m_customTypesForProperty;
00179 
00180     friend class WidgetLibrary;
00181 };
00182 
00184 
00256 class KFORMEDITOR_EXPORT WidgetFactory : public QObject
00257 {
00258     Q_OBJECT
00259     public:
00261         enum CreateWidgetOptions { 
00262             AnyOrientation = 1, 
00263             HorizontalOrientation = 2,  
00264             VerticalOrientation = 4, 
00265             DesignViewMode = 8, 
00266             DefaultOptions = AnyOrientation | DesignViewMode
00267         };
00268 
00269         WidgetFactory(QObject *parent=0, const char *name=0);
00270         virtual ~WidgetFactory();
00271 
00273         void addClass(WidgetInfo *w);
00274 
00279         void hideClass(const char *classname);
00280 
00284         const WidgetInfo::Dict classes() const { return m_classesByName; }
00285 
00295         virtual QWidget* createWidget(const QCString &classname, QWidget *parent, const char *name,
00296             KFormDesigner::Container *container, 
00297             int options = DefaultOptions) = 0;
00298 
00299         virtual void createCustomActions(KActionCollection* ) {};
00300 
00303         virtual bool createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu,
00304             KFormDesigner::Container *container)=0;
00305 
00311         virtual bool startEditing(const QCString &classname, QWidget *w, Container *container)=0;
00312 
00315         virtual bool previewWidget(const QCString &classname, QWidget *widget, Container *container)=0;
00316 
00317         virtual bool clearWidgetContent(const QCString &classname, QWidget *w);
00318 
00324         virtual bool saveSpecialProperty(const QCString &classname, const QString &name,
00325             const QVariant &value, QWidget *w,
00326             QDomElement &parentNode, QDomDocument &parent);
00327 
00333         virtual bool readSpecialProperty(const QCString &classname, QDomElement &node,
00334             QWidget *w, ObjectTreeItem *item);
00335 
00341         bool isPropertyVisible(const QCString &classname, QWidget *w,
00342             const QCString &property, bool multiple, bool isTopLevel);
00343 
00347         virtual QValueList<QCString> autoSaveProperties(const QCString &classname)=0;
00348 
00351         inline QString propertyDescForName(const QCString &name) { return m_propDesc[name]; };
00352 
00354         inline QString propertyDescForValue(const QCString &name) { return m_propValDesc[name]; };
00355 
00360         virtual void setPropertyOptions( WidgetPropertySet& buf, const WidgetInfo& info, QWidget *w );
00361 
00365         inline QString internalProperty(const QCString& classname, const QCString& property) const {
00366             return m_internalProp[classname+":"+property];
00367         }
00368 
00369     protected:
00370         virtual bool isPropertyVisibleInternal(const QCString &classname, QWidget *w,
00371             const QCString &property, bool isTopLevel);
00372 
00378         void createEditor(const QCString &classname, const QString &text,
00379             QWidget *w, Container *container, QRect geometry,
00380             int align, bool useFrame=false, bool multiLine = false,
00381             BackgroundMode background = Qt::NoBackground);
00382 
00387         void disableFilter(QWidget *w, Container *container);
00388 
00393         bool editList(QWidget *w, QStringList &list);
00394 
00399         bool editRichText(QWidget *w, QString &text);
00400 
00403         void editListView(QListView *listview);
00404 
00406         virtual bool  eventFilter(QObject *obj, QEvent *ev);
00407 
00411         void changeProperty(const char *name, const QVariant &value, Form *form);
00412 
00415         virtual void resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname);
00416 
00417 //      /*! Adds the i18n'ed description of a property, which will be shown in PropertyEditor. */
00418 //      void  addPropertyDescription(Container *container, const char *prop, const QString &desc);
00419 
00420 //      /*! Adds the i18n'ed description of a property value, which will be shown in PropertyEditor. */
00421 //      void  addValueDescription(Container *container, const char *value, const QString &desc);
00422 
00426         bool inheritsFactories();
00427 
00428     public slots:
00429 
00432         void resetEditor();
00433 
00434     protected slots:
00442         virtual bool changeText(const QString &newText);
00443 
00444         void changeTextInternal(const QString& text);
00445 
00446         void slotTextChanged();
00447 
00449         void editorDeleted();
00450         void widgetDestroyed();
00451 
00452     protected:
00453         QString editorText() const;
00454         void setEditorText(const QString& text);
00455         void setEditor(QWidget *widget, QWidget *editor);
00456         QWidget *editor(QWidget *widget) const;
00457         void setWidget(QWidget *widget, Container *container);
00458         QWidget *widget() const;
00459 
00463         void setInternalProperty(const QCString& classname, const QCString& property, const QString& value);
00464 
00465         WidgetLibrary *m_library;
00466         QCString m_editedWidgetClass;
00467 //#ifdef KEXI_KTEXTEDIT
00468 //      QGuardedPtr<KTextEdit>  m_editor;
00469 //#else
00470 //      QGuardedPtr<KLineEdit>  m_editor;
00471 //#endif
00472         QString m_firstText;
00473         QGuardedPtr<ResizeHandleSet> m_handles;
00474         QGuardedPtr<Container> m_container;
00475 //      WidgetInfo::List m_classes;
00476         WidgetInfo::Dict m_classesByName;
00477         QAsciiDict<char>* m_hiddenClasses;
00478 
00480         QMap<QCString, QString> m_propDesc;
00481         QMap<QCString, QString> m_propValDesc;
00483         QMap<QCString, QString> m_internalProp;
00484 
00487         bool m_showAdvancedProperties;
00488 
00489         QGuardedPtr<QWidget> m_widget;
00490         QGuardedPtr<QWidget> m_editor;
00491 
00492     friend class WidgetLibrary;
00493 };
00494 
00496 #define KFORMDESIGNER_WIDGET_FACTORY(factoryClassName, libraryName) \
00497     K_EXPORT_COMPONENT_FACTORY(kformdesigner_ ## libraryName, KGenericFactory<factoryClassName>("kformdesigner_" # libraryName))
00498 
00499 }
00500 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys