widgetfactory.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4 Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KFORMDESIGNERWIDGETFACTORY_H
23#define KFORMDESIGNERWIDGETFACTORY_H
24
25
26#include <tqobject.h>
27#include <tqguardedptr.h>
28#include <tqpixmap.h>
29#include <tqpopupmenu.h>
30#include <tqasciidict.h>
31
32#include <kexiutils/tristate.h>
33
34// class TQPixmap;
35template<class type> class TQValueVector;
36template<class type> class TQPtrList;
37template<class type> class TQDict;
38class TQWidget;
39class TQDomElement;
40class TQDomDocument;
41class TQVariant;
42class TQListView;
43class TDEActionCollection;
44class KTextEdit;
45class KLineEdit;
46class KXMLGUIClient;
47
48namespace KoProperty {
49 class Set;
50}
51
52namespace KFormDesigner {
53
54class WidgetFactory;
55class WidgetLibrary;
56class Container;
57class ResizeHandleSet;
58class ObjectTreeItem;
59class WidgetPropertySet;
60class Form;
61
65class KFORMEDITOR_EXPORT WidgetInfo
66{
67 public:
68 typedef TQPtrList<WidgetInfo> List;
69 typedef TQAsciiDict<WidgetInfo> Dict;
70
72
73 WidgetInfo(WidgetFactory *f, const char* parentFactoryName, const char* inheritedClassName = 0);
74
75 virtual ~WidgetInfo();
76
78 TQString pixmap() const { return m_pixmap; }
79
81 TQCString className() const { return m_class; }
82
85 TQString namePrefix() const { return m_prefixName; }
86
88 TQString name() const { return m_name; }
89
90 TQString description() const { return m_desc; }
91 TQString includeFileName() const { return m_include; }
92 TQValueList<TQCString> alternateClassNames() const { return m_alternateNames; }
93 TQString savingName() const { return m_saveName; }
94 WidgetFactory *factory() const { return m_factory; }
95
96 void setPixmap(const TQString &p) { m_pixmap = p; }
97 void setClassName(const TQCString &s) { m_class = s; }
98 void setName(const TQString &n) { m_name = n; }
99 void setNamePrefix(const TQString &n) { m_prefixName = n; }
100 void setDescription(const TQString &desc) { m_desc = desc;}
101
104 void setIncludeFileName(const TQString &name) { m_include = name;}
105
122 void addAlternateClassName(const TQCString& alternateName, bool override = false);
123
128 bool isOverriddenClassName(const TQCString& alternateName) const;
129
136 void setSavingName(const TQString &saveName) { m_saveName = saveName; }
137
143 void setAutoSyncForProperty(const char *propertyName, tristate flag);
144
147 tristate autoSyncForProperty(const char *propertyName) const;
148
149 TQCString parentFactoryName() const { return m_parentFactoryName; }
150
151 WidgetInfo* inheritedClass() const { return m_inheritedClass; }
152
156 void setCustomTypeForProperty(const char *propertyName, int type);
157
161 int customTypeForProperty(const char *propertyName) const;
162
163 protected:
164 TQCString m_parentFactoryName, m_inheritedClassName;
165 WidgetInfo* m_inheritedClass;
166
167 private:
168 TQString m_pixmap;
169 TQCString m_class;
170 TQString m_name;
171 TQString m_prefixName;
172 TQString m_desc;
173 TQString m_include;
174 TQValueList<TQCString> m_alternateNames;
175 TQAsciiDict<char> *m_overriddenAlternateNames;
176 TQString m_saveName;
177 TQGuardedPtr<WidgetFactory> m_factory;
178 TQAsciiDict<char> *m_propertiesWithDisabledAutoSync;
179 TQMap<TQCString,int> *m_customTypesForProperty;
180
181 friend class WidgetLibrary;
182};
183
185
257class KFORMEDITOR_EXPORT WidgetFactory : public TQObject
258{
259 TQ_OBJECT
260
261 public:
264 AnyOrientation = 1,
265 HorizontalOrientation = 2,
266 VerticalOrientation = 4,
267 DesignViewMode = 8,
268 DefaultOptions = AnyOrientation | DesignViewMode
269 };
270
271 WidgetFactory(TQObject *parent=0, const char *name=0);
272 virtual ~WidgetFactory();
273
275 void addClass(WidgetInfo *w);
276
281 void hideClass(const char *classname);
282
286 const WidgetInfo::Dict classes() const { return m_classesByName; }
287
297 virtual TQWidget* createWidget(const TQCString &classname, TQWidget *parent, const char *name,
298 KFormDesigner::Container *container,
299 int options = DefaultOptions) = 0;
300
303 virtual void createCustomActions(TDEActionCollection *col) { Q_UNUSED(col); };
304
307 virtual bool createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu,
308 KFormDesigner::Container *container)=0;
309
315 virtual bool startEditing(const TQCString &classname, TQWidget *w, Container *container)=0;
316
319 virtual bool previewWidget(const TQCString &classname, TQWidget *widget, Container *container)=0;
320
321 virtual bool clearWidgetContent(const TQCString &classname, TQWidget *w);
322
328 virtual bool saveSpecialProperty(const TQCString &classname, const TQString &name,
329 const TQVariant &value, TQWidget *w,
330 TQDomElement &parentNode, TQDomDocument &parent);
331
337 virtual bool readSpecialProperty(const TQCString &classname, TQDomElement &node,
338 TQWidget *w, ObjectTreeItem *item);
339
345 bool isPropertyVisible(const TQCString &classname, TQWidget *w,
346 const TQCString &property, bool multiple, bool isTopLevel);
347
351 virtual TQValueList<TQCString> autoSaveProperties(const TQCString &classname)=0;
352
355 inline TQString propertyDescForName(const TQCString &name) { return m_propDesc[name]; };
356
358 inline TQString propertyDescForValue(const TQCString &name) { return m_propValDesc[name]; };
359
364 virtual void setPropertyOptions( WidgetPropertySet& buf, const WidgetInfo& info, TQWidget *w );
365
369 inline TQString internalProperty(const TQCString& classname, const TQCString& property) const {
370 return m_internalProp[classname+":"+property];
371 }
372
373 protected:
377 virtual bool isPropertyVisibleInternal(const TQCString &classname, TQWidget *w,
378 const TQCString &property, bool isTopLevel);
379
382 virtual bool propertySetShouldBeReloadedAfterPropertyChange(const TQCString& classname, TQWidget *w,
383 const TQCString& property);
384
389 void createEditor(const TQCString &classname, const TQString &text,
390 TQWidget *w, Container *container, TQRect geometry,
391 int align, bool useFrame=false, bool multiLine = false,
392 BackgroundMode background = TQt::NoBackground);
393
398 void disableFilter(TQWidget *w, Container *container);
399
404 bool editList(TQWidget *w, TQStringList &list);
405
410 bool editRichText(TQWidget *w, TQString &text);
411
414 void editListView(TQListView *listview);
415
417 virtual bool eventFilter(TQObject *obj, TQEvent *ev);
418
422 void changeProperty(const char *name, const TQVariant &value, Form *form);
423
426 virtual void resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname);
427
428// /*! Adds the i18n'ed description of a property, which will be shown in PropertyEditor. */
429// void addPropertyDescription(Container *container, const char *prop, const TQString &desc);
430
431// /*! Adds the i18n'ed description of a property value, which will be shown in PropertyEditor. */
432// void addValueDescription(Container *container, const char *value, const TQString &desc);
433
437 bool inheritsFactories();
438
439 public slots:
440
443 void resetEditor();
444
445 protected slots:
453 virtual bool changeText(const TQString &newText);
454
455 void changeTextInternal(const TQString& text);
456
457 void slotTextChanged();
458
460 void editorDeleted();
461 void widgetDestroyed();
462
463 protected:
464 TQString editorText() const;
465 void setEditorText(const TQString& text);
466 void setEditor(TQWidget *widget, TQWidget *editor);
467 TQWidget *editor(TQWidget *widget) const;
468 void setWidget(TQWidget *widget, Container *container);
469 TQWidget *widget() const;
470
474 void setInternalProperty(const TQCString& classname, const TQCString& property, const TQString& value);
475
476 WidgetLibrary *m_library;
477 TQCString m_editedWidgetClass;
478//#ifdef KEXI_KTEXTEDIT
479// TQGuardedPtr<KTextEdit> m_editor;
480//#else
481// TQGuardedPtr<KLineEdit> m_editor;
482//#endif
483 TQString m_firstText;
484 TQGuardedPtr<ResizeHandleSet> m_handles;
485 TQGuardedPtr<Container> m_container;
486// WidgetInfo::List m_classes;
487 WidgetInfo::Dict m_classesByName;
488 TQAsciiDict<char>* m_hiddenClasses;
489
491 TQMap<TQCString, TQString> m_propDesc;
492 TQMap<TQCString, TQString> m_propValDesc;
494 TQMap<TQCString, TQString> m_internalProp;
495
499
505
506 KXMLGUIClient *m_guiClient;
507
508 TQGuardedPtr<TQWidget> m_widget;
509 TQGuardedPtr<TQWidget> m_editor;
510
511 friend class WidgetLibrary;
512};
513
515#define KFORMDESIGNER_WIDGET_FACTORY(factoryClassName, libraryName) \
516 K_EXPORT_COMPONENT_FACTORY(kformdesigner_ ## libraryName, KGenericFactory<factoryClassName>("kformdesigner_" # libraryName))
517
518}
519#endif
This class makes a container out of any TQWidget.
Definition container.h:74
A simple class representing a form.
Definition form.h:136
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
The base class for all widget Factories.
TQMap< TQCString, TQString > m_propDesc
i18n stuff
virtual bool startEditing(const TQCString &classname, TQWidget *w, Container *container)=0
TQString propertyDescForValue(const TQCString &name)
TQMap< TQCString, TQString > m_internalProp
internal properties
virtual void createCustomActions(TDEActionCollection *col)
TQString internalProperty(const TQCString &classname, const TQCString &property) const
CreateWidgetOptions
Options used in createWidget()
virtual TQValueList< TQCString > autoSaveProperties(const TQCString &classname)=0
virtual bool createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu, KFormDesigner::Container *container)=0
TQString propertyDescForName(const TQCString &name)
const WidgetInfo::Dict classes() const
virtual TQWidget * createWidget(const TQCString &classname, TQWidget *parent, const char *name, KFormDesigner::Container *container, int options=DefaultOptions)=0
Creates a widget (and if needed a KFormDesigner::Container)
virtual bool previewWidget(const TQCString &classname, TQWidget *widget, Container *container)=0
This class holds properties of widget classes provided by a factory.
void setSavingName(const TQString &saveName)
TQString namePrefix() const
TQString pixmap() const
void setIncludeFileName(const TQString &name)
TQCString m_inheritedClassName
Used for inheriting widgets between factories.
TQCString className() const
This class searches for factories and provides TDEActions for widget creation.
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100