kexi
KFormDesigner::WidgetFactory Class Reference
#include <widgetfactory.h>
Inheritance diagram for KFormDesigner::WidgetFactory:

Detailed Description
The base class for all widget Factories.
This is the class you need to inherit to create a new Factory. There are few virtuals you need to implement, and some other functions to implement if you want more features.
Widget Creation
To be able to create widgets, you need to implement the create() function, an classes(), which should return all the widgets supported by this factory.
GUI Integration
The following functions allow you to customize even more the look-n-feel of your widgets inside KFormDesigner. You can use createMenuActions() to add custom items in widget's context menu. The previewWidget() is called when the Form gets in Preview mode, and you have a last opportunity to remove all editing-related stuff (see eg Spring class).
You can also choose which properties to show in the Property Editor. By default, most all properties are shown (see implementation for details), but you can hide some reimplementing isPropertyVisibleInternal() (don't forget to call superclass' method) To add new properties, just define new Q_PROPERTY in widget class definition.
Inline editing
KFormDesigner allow you to edit the widget's contents inside Form, without using a dialog. You can of course customize the behaviour of your widgets, using startEditing(). There are some editing modes already implemented in WidgetFactroy, but you can create your own if you want:
- Editing using a line edit (createEditor()): a line edit is created on top of widget, where the user inputs text. As the text changes, changeText() is called (where you should set your widget's text and resize widget to fit the text if needed) and resizeEditor() to update editor's position when widget is moved/resized.
- Editing by disabling event filter: if you call disableFilter(), the event filter on the object is temporarily disabled, so the widget behaves as usual. This can be used for more complex widgets, such as spinbox, date/time edit, etc.
- Other modes: there are 3 other modes, to edit a string list: editList() (for combo box, listbox), to edit rich text: editRichText() (for labels, etc.) and to edit a listview: editListView().
You can also control how your widget are saved/loaded. You can choose which properties to save (see autoSaveProperties()), and save/load custom properties, ie properties that are not Q_PROPERTY but you want to save in the UI file. This is used eg to save combo box or listview contents (see saveSpecialProperty() and readSpecialProperty()).
Special internal properties
Use void setInternalProperty(const QCString& classname, const QCString& property, const QString& value); to set values of special internal properties. Currently these properties are used for customizing popup menu items used for orientation selection. Customization for class ClassName should look like: void setInternalProperty("ClassName", "orientationSelectionPopup", "myicon");
Available internal properties: "orientationSelectionPopup" - set it to "1" if you want a given class to offer orientation selection, so orientation selection popup will be displayed when needed. "orientationSelectionPopup:horizontalIcon" - sets a name of icon for "Horizontal" item for objects of class 'ClassName'. Set this property only for classes supporting orientations. "orientationSelectionPopup:verticalIcon" - the same for "Vertical" item. Set this property only for classes supporting orientations. "orientationSelectionPopup:horizontalText" - sets a i18n'd text for "Horizontal" item for objects of class 'ClassName', e.g. i18n("Insert Horizontal Line"). Set this property only for classes supporting orientations. "orientationSelectionPopup:verticalText" - the same for "Vertical" item, e.g. i18n("Insert Vertical Line"). Set this property only for classes supporting orientations. "dontStartEditingOnInserting" - if not empty, WidgetFactory::startEditing() will not be executed upon widget inseting by a user. "forceShowAdvancedProperty:{propertyname}" - set it to "1" for "{propertyname}" advanced property if you want to force it to be visible even if WidgetLibrary::setAdvancedPropertiesVisible(false) has been called. For example, setting "forceShowAdvancedProperty:pixmap" to "1" unhides "pixmap" property for a given class.
See StdWidgetFactory::StdWidgetFactory() for properies like "Line:orientationSelectionPopup:horizontalIcon".
See the standard factories in formeditor/factories for an example of factories, and how to deal with complex widgets (eg tabwidget).
Definition at line 256 of file widgetfactory.h.
Public Types | |
AnyOrientation = 1 | |
HorizontalOrientation = 2 | |
VerticalOrientation = 4 | |
DesignViewMode = 8 | |
DefaultOptions = AnyOrientation | DesignViewMode | |
enum | CreateWidgetOptions { AnyOrientation = 1, HorizontalOrientation = 2, VerticalOrientation = 4, DesignViewMode = 8, DefaultOptions = AnyOrientation | DesignViewMode } |
Public Slots | |
void | resetEditor () |
Public Member Functions | |
WidgetFactory (QObject *parent=0, const char *name=0) | |
virtual | ~WidgetFactory () |
void | addClass (WidgetInfo *w) |
void | hideClass (const char *classname) |
const WidgetInfo::Dict | classes () const |
virtual QWidget * | createWidget (const QCString &classname, QWidget *parent, const char *name, KFormDesigner::Container *container, int options=DefaultOptions)=0 |
virtual void | createCustomActions (KActionCollection *) |
virtual bool | createMenuActions (const QCString &classname, QWidget *w, QPopupMenu *menu, KFormDesigner::Container *container)=0 |
virtual bool | startEditing (const QCString &classname, QWidget *w, Container *container)=0 |
virtual bool | previewWidget (const QCString &classname, QWidget *widget, Container *container)=0 |
virtual bool | clearWidgetContent (const QCString &classname, QWidget *w) |
virtual bool | saveSpecialProperty (const QCString &classname, const QString &name, const QVariant &value, QWidget *w, QDomElement &parentNode, QDomDocument &parent) |
virtual bool | readSpecialProperty (const QCString &classname, QDomElement &node, QWidget *w, ObjectTreeItem *item) |
bool | isPropertyVisible (const QCString &classname, QWidget *w, const QCString &property, bool multiple, bool isTopLevel) |
virtual QValueList< QCString > | autoSaveProperties (const QCString &classname)=0 |
QString | propertyDescForName (const QCString &name) |
QString | propertyDescForValue (const QCString &name) |
virtual void | setPropertyOptions (WidgetPropertySet &buf, const WidgetInfo &info, QWidget *w) |
QString | internalProperty (const QCString &classname, const QCString &property) const |
Protected Slots | |
virtual bool | changeText (const QString &newText) |
void | changeTextInternal (const QString &text) |
void | slotTextChanged () |
void | editorDeleted () |
void | widgetDestroyed () |
Protected Member Functions | |
virtual bool | isPropertyVisibleInternal (const QCString &classname, QWidget *w, const QCString &property, bool isTopLevel) |
void | createEditor (const QCString &classname, const QString &text, QWidget *w, Container *container, QRect geometry, int align, bool useFrame=false, bool multiLine=false, BackgroundMode background=Qt::NoBackground) |
void | disableFilter (QWidget *w, Container *container) |
bool | editList (QWidget *w, QStringList &list) |
bool | editRichText (QWidget *w, QString &text) |
void | editListView (QListView *listview) |
virtual bool | eventFilter (QObject *obj, QEvent *ev) |
void | changeProperty (const char *name, const QVariant &value, Form *form) |
virtual void | resizeEditor (QWidget *editor, QWidget *widget, const QCString &classname) |
bool | inheritsFactories () |
QString | editorText () const |
void | setEditorText (const QString &text) |
void | setEditor (QWidget *widget, QWidget *editor) |
QWidget * | editor (QWidget *widget) const |
void | setWidget (QWidget *widget, Container *container) |
QWidget * | widget () const |
void | setInternalProperty (const QCString &classname, const QCString &property, const QString &value) |
Protected Attributes | |
WidgetLibrary * | m_library |
QCString | m_editedWidgetClass |
QString | m_firstText |
QGuardedPtr< ResizeHandleSet > | m_handles |
QGuardedPtr< Container > | m_container |
WidgetInfo::Dict | m_classesByName |
QAsciiDict< char > * | m_hiddenClasses |
QMap< QCString, QString > | m_propDesc |
QMap< QCString, QString > | m_propValDesc |
QMap< QCString, QString > | m_internalProp |
bool | m_showAdvancedProperties |
QGuardedPtr< QWidget > | m_widget |
QGuardedPtr< QWidget > | m_editor |
Friends | |
class | WidgetLibrary |
Member Enumeration Documentation
Options used in createWidget().
- Enumerator:
Definition at line 261 of file widgetfactory.h.
Member Function Documentation
void WidgetFactory::addClass | ( | WidgetInfo * | w | ) |
Adds a new class described by w.
Definition at line 160 of file widgetfactory.cpp.
virtual QValueList<QCString> KFormDesigner::WidgetFactory::autoSaveProperties | ( | const QCString & | classname | ) | [pure virtual] |
You need to return here a list of the properties that should automatically be saved for a widget belonging to classname, and your custom properties (eg "text" for label or button, "contents" for combobox...).
Implemented in ContainerFactory, StdWidgetFactory, KexiDBFactory, and KexiReportFactory.
void WidgetFactory::changeProperty | ( | const char * | name, | |
const QVariant & | value, | |||
Form * | form | |||
) | [protected] |
This function is used to modify a property of a widget (eg after editing it). Please use it instead of w->setProperty() to allow sync inside PropertyEditor.
Definition at line 502 of file widgetfactory.cpp.
bool WidgetFactory::changeText | ( | const QString & | newText | ) | [protected, virtual, slot] |
Default implementation changes "text" property. You have to reimplement this function for editing inside the Form to work if your widget's property you want to change isn't named "text". This slot is called when the line edit text changes, and you have to make it really change the good property of the widget using changeProperty() (text, or title, etc.).
Reimplemented in ContainerFactory, StdWidgetFactory, and KexiDBFactory.
Definition at line 609 of file widgetfactory.cpp.
const WidgetInfo::Dict KFormDesigner::WidgetFactory::classes | ( | ) | const [inline] |
- Returns:
- all classes which are provided by this factory
Definition at line 284 of file widgetfactory.h.
void WidgetFactory::createEditor | ( | const QCString & | classname, | |
const QString & | text, | |||
QWidget * | w, | |||
Container * | container, | |||
QRect | geometry, | |||
int | align, | |||
bool | useFrame = false , |
|||
bool | multiLine = false , |
|||
BackgroundMode | background = Qt::NoBackground | |||
) | [protected] |
This function creates a KLineEdit to input some text and edit a widget's contents. This can be used in startEditing(). text is the text to display by default in the line edit, w is the edited widget, geometry is the geometry the new line edit should have, and align is Qt::AlignmentFlags of the new line edit.
Definition at line 181 of file widgetfactory.cpp.
virtual bool KFormDesigner::WidgetFactory::createMenuActions | ( | const QCString & | classname, | |
QWidget * | w, | |||
QPopupMenu * | menu, | |||
KFormDesigner::Container * | container | |||
) | [pure virtual] |
This function can be used to add custom items in widget w context menu menu.
Implemented in ContainerFactory, StdWidgetFactory, KexiDBFactory, and KexiReportFactory.
virtual QWidget* KFormDesigner::WidgetFactory::createWidget | ( | const QCString & | classname, | |
QWidget * | parent, | |||
const char * | name, | |||
KFormDesigner::Container * | container, | |||
int | options = DefaultOptions | |||
) | [pure virtual] |
Creates a widget (and if needed a KFormDesigner::Container).
- Returns:
- the created widget
- Parameters:
-
classname the classname of the widget, which should get created parent the parent for the created widget name the name of the created widget container the toplevel Container (if a container should get created) options options for the created widget: orientation and view mode (see CreateWidgetOptions)
Implemented in ContainerFactory, StdWidgetFactory, KexiDBFactory, and KexiReportFactory.
void WidgetFactory::disableFilter | ( | QWidget * | w, | |
Container * | container | |||
) | [protected] |
This function provides a simple editing mode : it justs disable event filtering for the widget, and it install it again when the widget loose focus or Enter is pressed.
Definition at line 275 of file widgetfactory.cpp.
bool WidgetFactory::editList | ( | QWidget * | w, | |
QStringList & | list | |||
) | [protected] |
This function creates a little dialog (a KEditListBox) to modify the contents of a list (of strings). It can be used to modify the contents of a combo box for instance. The modified list is copied into list when the user presses "Ok".
Definition at line 309 of file widgetfactory.cpp.
void WidgetFactory::editListView | ( | QListView * | listview | ) | [protected] |
This function creates a dialog to modify the contents of a ListView. You can modify both columns and list items. The listview is automatically updated if the user presses "Ok".
Definition at line 340 of file widgetfactory.cpp.
void WidgetFactory::editorDeleted | ( | ) | [protected, slot] |
This slot is called when the editor is destroyed.
Definition at line 488 of file widgetfactory.cpp.
bool WidgetFactory::editRichText | ( | QWidget * | w, | |
QString & | text | |||
) | [protected] |
This function creates a little editor to modify rich text. It supports alignment, subscript and superscript and all basic formatting properties. If the user presses "Ok", the edited text is put in text. If he presses "Cancel", nothing happens.
Definition at line 328 of file widgetfactory.cpp.
bool WidgetFactory::eventFilter | ( | QObject * | obj, | |
QEvent * | ev | |||
) | [protected, virtual] |
This function destroys the editor when it loses focus or Enter is pressed.
Definition at line 347 of file widgetfactory.cpp.
void WidgetFactory::hideClass | ( | const char * | classname | ) |
This method allows to force a class classname to hidden. It is useful if you do not want a class to be available (e.g. because it is not implemented well yet for our purposes). All widget libraries are affected by this setting.
Definition at line 173 of file widgetfactory.cpp.
bool WidgetFactory::inheritsFactories | ( | ) | [protected] |
- Returns:
- true if at least one class defined by this factory inherits a class from other factory. Used in WidgetLibrary::loadFactories() to load factories in proper order.
Definition at line 627 of file widgetfactory.cpp.
QString KFormDesigner::WidgetFactory::internalProperty | ( | const QCString & | classname, | |
const QCString & | property | |||
) | const [inline] |
- Returns:
- internal property property for a class classname. Internal properties are not stored within objects, but can be just provided to describe classes' details.
Definition at line 365 of file widgetfactory.h.
bool WidgetFactory::isPropertyVisible | ( | const QCString & | classname, | |
QWidget * | w, | |||
const QCString & | property, | |||
bool | multiple, | |||
bool | isTopLevel | |||
) |
This function is used to know whether the property for the widget w should be shown or not in the PropertyEditor. If multiple is true, then multiple widgets of the same class are selected, and you should only show properties shared by widgets (eg font, color). By default, all properties are shown if multiple == true, and none if multiple == false.
Definition at line 538 of file widgetfactory.cpp.
virtual bool KFormDesigner::WidgetFactory::previewWidget | ( | const QCString & | classname, | |
QWidget * | widget, | |||
Container * | container | |||
) | [pure virtual] |
This function is called just before the Form is previewed. It allows widgets to make changes before switching (ie for a Spring, hiding the cross)
Implemented in ContainerFactory, StdWidgetFactory, KexiDBFactory, and KexiReportFactory.
QString KFormDesigner::WidgetFactory::propertyDescForName | ( | const QCString & | name | ) | [inline] |
- Returns:
- The i18n'ed name of the property whose name is name, that will be displayed in PropertyEditor.
Definition at line 351 of file widgetfactory.h.
QString KFormDesigner::WidgetFactory::propertyDescForValue | ( | const QCString & | name | ) | [inline] |
- Returns:
- The i18n'ed name of the property's value whose name is name.
Definition at line 354 of file widgetfactory.h.
bool WidgetFactory::readSpecialProperty | ( | const QCString & | classname, | |
QDomElement & | node, | |||
QWidget * | w, | |||
ObjectTreeItem * | item | |||
) | [virtual] |
This function is called when FormIO finds a property or an unknown element in a .ui file. You can this way load a special property, for example the contents of a listbox.
- See also:
- saveSpecialProperty()
Reimplemented in ContainerFactory, and StdWidgetFactory.
Definition at line 616 of file widgetfactory.cpp.
void WidgetFactory::resizeEditor | ( | QWidget * | editor, | |
QWidget * | widget, | |||
const QCString & | classname | |||
) | [protected, virtual] |
This function is called when the widget is resized, and the editor size needs to be updated.
Reimplemented in ContainerFactory, StdWidgetFactory, and KexiDBFactory.
Definition at line 577 of file widgetfactory.cpp.
bool WidgetFactory::saveSpecialProperty | ( | const QCString & | classname, | |
const QString & | name, | |||
const QVariant & | value, | |||
QWidget * | w, | |||
QDomElement & | parentNode, | |||
QDomDocument & | parent | |||
) | [virtual] |
This function is called when FormIO finds a property, at save time, that it cannot handle (ie not a normal property). This way you can save special properties, for example the contents of a listbox.
- See also:
- readSpecialProperty()
Reimplemented in ContainerFactory, and StdWidgetFactory.
Definition at line 622 of file widgetfactory.cpp.
void WidgetFactory::setInternalProperty | ( | const QCString & | classname, | |
const QCString & | property, | |||
const QString & | value | |||
) | [protected] |
Assigns value for internal property property for a class classname. Internal properties are not stored within objects, but can be provided to describe classes' details.
Definition at line 698 of file widgetfactory.cpp.
void WidgetFactory::setPropertyOptions | ( | WidgetPropertySet & | buf, | |
const WidgetInfo & | info, | |||
QWidget * | w | |||
) | [virtual] |
This method is called after WidgetPropertySet was filled with properties of a widget w, of class defined by info. Default implementation does nothing. Implement this if you need to set options for properties within the set buf.
Reimplemented in StdWidgetFactory.
Definition at line 704 of file widgetfactory.cpp.
virtual bool KFormDesigner::WidgetFactory::startEditing | ( | const QCString & | classname, | |
QWidget * | w, | |||
Container * | container | |||
) | [pure virtual] |
Creates (if necessary) an editor to edit the contents of the widget directly in the Form (eg creates a line edit to change the text of a label). classname is the class the widget belongs to, w is the widget to edit and container is the parent container of this widget (to access Form etc.).
Implemented in ContainerFactory, StdWidgetFactory, KexiDBFactory, and KexiReportFactory.
Member Data Documentation
QMap<QCString, QString> KFormDesigner::WidgetFactory::m_internalProp [protected] |
QMap<QCString, QString> KFormDesigner::WidgetFactory::m_propDesc [protected] |
bool KFormDesigner::WidgetFactory::m_showAdvancedProperties [protected] |
flag useful to decide whether to hide some properties. It's value is inherited from WidgetLibrary.
Definition at line 487 of file widgetfactory.h.
The documentation for this class was generated from the following files: