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-2006 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 class KXMLGUIClient;
00047 
00048 namespace KoProperty {
00049     class Set;
00050 }
00051 
00052 namespace KFormDesigner {
00053 
00054 class WidgetFactory;
00055 class WidgetLibrary;
00056 class Container;
00057 class ResizeHandleSet;
00058 class ObjectTreeItem;
00059 class WidgetPropertySet;
00060 class Form;
00061 
00065 class KFORMEDITOR_EXPORT WidgetInfo
00066 {
00067     public:
00068         typedef QPtrList<WidgetInfo> List;
00069         typedef QAsciiDict<WidgetInfo> Dict;
00070 
00071         WidgetInfo(WidgetFactory *f);
00072 
00073         WidgetInfo(WidgetFactory *f, const char* parentFactoryName, const char* inheritedClassName = 0);
00074 
00075         virtual ~WidgetInfo();
00076 
00078         QString pixmap() const { return m_pixmap; }
00079 
00081         QCString className() const { return m_class; }
00082 
00085         QString namePrefix() const { return m_prefixName; }
00086 
00088         QString name() const { return m_name; }
00089 
00090         QString description() const { return m_desc; }
00091         QString includeFileName() const { return m_include; }
00092         QValueList<QCString> alternateClassNames() const { return m_alternateNames; }
00093         QString savingName() const { return m_saveName; }
00094         WidgetFactory *factory() const { return m_factory; }
00095 
00096         void setPixmap(const QString &p) { m_pixmap = p; }
00097         void setClassName(const QCString &s) { m_class = s; }
00098         void setName(const QString &n) { m_name = n; }
00099         void setNamePrefix(const QString &n) { m_prefixName = n; }
00100         void setDescription(const QString &desc) { m_desc = desc;}
00101 
00104         void setIncludeFileName(const QString &name) { m_include = name;}
00105 
00122         void addAlternateClassName(const QCString& alternateName, bool override = false);
00123 
00128         bool isOverriddenClassName(const QCString& alternateName) const;
00129 
00136         void setSavingName(const QString &saveName) { m_saveName = saveName; }
00137 
00143         void setAutoSyncForProperty(const char *propertyName, tristate flag);
00144 
00147         tristate autoSyncForProperty(const char *propertyName) const;
00148 
00149         QCString parentFactoryName() const { return m_parentFactoryName; }
00150 
00151         WidgetInfo* inheritedClass() const { return m_inheritedClass; }
00152 
00156         void setCustomTypeForProperty(const char *propertyName, int type);
00157 
00161         int customTypeForProperty(const char *propertyName) const;
00162 
00163     protected:
00164         QCString m_parentFactoryName, m_inheritedClassName; 
00165         WidgetInfo* m_inheritedClass;
00166 
00167     private:
00168         QString m_pixmap;
00169         QCString m_class;
00170         QString m_name;
00171         QString m_prefixName;
00172         QString m_desc;
00173         QString m_include;
00174         QValueList<QCString> m_alternateNames;
00175         QAsciiDict<char> *m_overriddenAlternateNames;
00176         QString m_saveName;
00177         QGuardedPtr<WidgetFactory> m_factory;
00178         QAsciiDict<char> *m_propertiesWithDisabledAutoSync;
00179         QMap<QCString,int> *m_customTypesForProperty;
00180 
00181     friend class WidgetLibrary;
00182 };
00183 
00185 
00257 class KFORMEDITOR_EXPORT WidgetFactory : public QObject
00258 {
00259     Q_OBJECT
00260     public:
00262         enum CreateWidgetOptions { 
00263             AnyOrientation = 1, 
00264             HorizontalOrientation = 2,  
00265             VerticalOrientation = 4, 
00266             DesignViewMode = 8, 
00267             DefaultOptions = AnyOrientation | DesignViewMode
00268         };
00269 
00270         WidgetFactory(QObject *parent=0, const char *name=0);
00271         virtual ~WidgetFactory();
00272 
00274         void addClass(WidgetInfo *w);
00275 
00280         void hideClass(const char *classname);
00281 
00285         const WidgetInfo::Dict classes() const { return m_classesByName; }
00286 
00296         virtual QWidget* createWidget(const QCString &classname, QWidget *parent, const char *name,
00297             KFormDesigner::Container *container, 
00298             int options = DefaultOptions) = 0;
00299 
00302         virtual void createCustomActions(KActionCollection *col) { Q_UNUSED(col); };
00303 
00306         virtual bool createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu,
00307             KFormDesigner::Container *container)=0;
00308 
00314         virtual bool startEditing(const QCString &classname, QWidget *w, Container *container)=0;
00315 
00318         virtual bool previewWidget(const QCString &classname, QWidget *widget, Container *container)=0;
00319 
00320         virtual bool clearWidgetContent(const QCString &classname, QWidget *w);
00321 
00327         virtual bool saveSpecialProperty(const QCString &classname, const QString &name,
00328             const QVariant &value, QWidget *w,
00329             QDomElement &parentNode, QDomDocument &parent);
00330 
00336         virtual bool readSpecialProperty(const QCString &classname, QDomElement &node,
00337             QWidget *w, ObjectTreeItem *item);
00338 
00344         bool isPropertyVisible(const QCString &classname, QWidget *w,
00345             const QCString &property, bool multiple, bool isTopLevel);
00346 
00350         virtual QValueList<QCString> autoSaveProperties(const QCString &classname)=0;
00351 
00354         inline QString propertyDescForName(const QCString &name) { return m_propDesc[name]; };
00355 
00357         inline QString propertyDescForValue(const QCString &name) { return m_propValDesc[name]; };
00358 
00363         virtual void setPropertyOptions( WidgetPropertySet& buf, const WidgetInfo& info, QWidget *w );
00364 
00368         inline QString internalProperty(const QCString& classname, const QCString& property) const {
00369             return m_internalProp[classname+":"+property];
00370         }
00371 
00372     protected:
00376         virtual bool isPropertyVisibleInternal(const QCString &classname, QWidget *w,
00377             const QCString &property, bool isTopLevel);
00378 
00381         virtual bool propertySetShouldBeReloadedAfterPropertyChange(const QCString& classname, QWidget *w, 
00382             const QCString& property);
00383 
00388         void createEditor(const QCString &classname, const QString &text,
00389             QWidget *w, Container *container, QRect geometry,
00390             int align, bool useFrame=false, bool multiLine = false,
00391             BackgroundMode background = Qt::NoBackground);
00392 
00397         void disableFilter(QWidget *w, Container *container);
00398 
00403         bool editList(QWidget *w, QStringList &list);
00404 
00409         bool editRichText(QWidget *w, QString &text);
00410 
00413         void editListView(QListView *listview);
00414 
00416         virtual bool  eventFilter(QObject *obj, QEvent *ev);
00417 
00421         void changeProperty(const char *name, const QVariant &value, Form *form);
00422 
00425         virtual void resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname);
00426 
00427 //      /*! Adds the i18n'ed description of a property, which will be shown in PropertyEditor. */
00428 //      void  addPropertyDescription(Container *container, const char *prop, const QString &desc);
00429 
00430 //      /*! Adds the i18n'ed description of a property value, which will be shown in PropertyEditor. */
00431 //      void  addValueDescription(Container *container, const char *value, const QString &desc);
00432 
00436         bool inheritsFactories();
00437 
00438     public slots:
00439 
00442         void resetEditor();
00443 
00444     protected slots:
00452         virtual bool changeText(const QString &newText);
00453 
00454         void changeTextInternal(const QString& text);
00455 
00456         void slotTextChanged();
00457 
00459         void editorDeleted();
00460         void widgetDestroyed();
00461 
00462     protected:
00463         QString editorText() const;
00464         void setEditorText(const QString& text);
00465         void setEditor(QWidget *widget, QWidget *editor);
00466         QWidget *editor(QWidget *widget) const;
00467         void setWidget(QWidget *widget, Container *container);
00468         QWidget *widget() const;
00469 
00473         void setInternalProperty(const QCString& classname, const QCString& property, const QString& value);
00474 
00475         WidgetLibrary *m_library;
00476         QCString m_editedWidgetClass;
00477 //#ifdef KEXI_KTEXTEDIT
00478 //      QGuardedPtr<KTextEdit>  m_editor;
00479 //#else
00480 //      QGuardedPtr<KLineEdit>  m_editor;
00481 //#endif
00482         QString m_firstText;
00483         QGuardedPtr<ResizeHandleSet> m_handles;
00484         QGuardedPtr<Container> m_container;
00485 //      WidgetInfo::List m_classes;
00486         WidgetInfo::Dict m_classesByName;
00487         QAsciiDict<char>* m_hiddenClasses;
00488 
00490         QMap<QCString, QString> m_propDesc;
00491         QMap<QCString, QString> m_propValDesc;
00493         QMap<QCString, QString> m_internalProp;
00494 
00497         bool m_showAdvancedProperties;
00498 
00503         QString m_xmlGUIFileName;
00504 
00505         KXMLGUIClient *m_guiClient;
00506 
00507         QGuardedPtr<QWidget> m_widget;
00508         QGuardedPtr<QWidget> m_editor;
00509 
00510     friend class WidgetLibrary;
00511 };
00512 
00514 #define KFORMDESIGNER_WIDGET_FACTORY(factoryClassName, libraryName) \
00515     K_EXPORT_COMPONENT_FACTORY(kformdesigner_ ## libraryName, KGenericFactory<factoryClassName>("kformdesigner_" # libraryName))
00516 
00517 }
00518 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys