File indexing completed on 2024-05-12 16:39:48

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
0003    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
0004    Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org>
0005    Copyright (C) 2014 Michał Poteralski <michalpoteralskikde@gmail.com>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KFORMDESIGNERFORM_H
0024 #define KFORMDESIGNERFORM_H
0025 
0026 #include "kformdesigner_export.h"
0027 #include "widgetlibrary.h"
0028 #include <kexi_global.h>
0029 
0030 #include <QMetaProperty>
0031 #include <QAction>
0032 
0033 class QWidget;
0034 class KActionCollection;
0035 
0036 class PixmapCollection;
0037 
0038 class KProperty;
0039 class KPropertySet;
0040 class KUndo2Command;
0041 
0042 namespace KFormDesigner
0043 {
0044 
0045 class Command;
0046 class PropertyCommandGroup;
0047 #ifdef KFD_SIGSLOTS
0048 class ConnectionBuffer;
0049 #endif
0050 class Container;
0051 class ObjectTree;
0052 class ObjectTreeItem;
0053 typedef QList<ObjectTreeItem*> ObjectTreeList;
0054 class FormPrivate;
0055 class FormWidget;
0056 class ResizeHandleSet;
0057 
0058 /*!
0059   This class represents one form and holds the corresponding ObjectTree and Containers.
0060   It takes care of widget selection and pasting widgets.
0061  **/
0062 //! A simple class representing a form
0063 class KFORMDESIGNER_EXPORT Form : public QObject
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068     enum WidgetAlignment {
0069         AlignToGrid,
0070         AlignToLeft,
0071         AlignToRight,
0072         AlignToTop,
0073         AlignToBottom
0074     };
0075 
0076     //! Form's mode: design or data.
0077     enum Mode {
0078         DataMode,
0079         DesignMode
0080     };
0081 
0082     //! States like widget inserting. Used only in design mode.
0083     enum State {
0084         WidgetSelecting, //!< widget selecting
0085         WidgetInserting //!< widget inserting
0086 #ifdef KFD_SIGSLOTS
0087         , Connecting       //!< signal/slot connecting
0088 #endif
0089     };
0090 
0091     /*! Features used while creating Form objects. */
0092     enum Feature {
0093         NoFeatures = 0,
0094         EnableEvents = 1,
0095         EnableFileActions = 2
0096 #ifdef KFD_SIGSLOTS
0097         , EnableConnections = 4
0098 #endif
0099     };
0100     Q_DECLARE_FLAGS(Features, Feature)
0101 
0102     //! Types of layout
0103     enum LayoutType {
0104         NoLayout = 0,
0105         HBox,
0106         VBox,
0107         Grid,
0108         HFlow,
0109         VFlow,
0110         /* special types */
0111         HSplitter,
0112         VSplitter
0113     };
0114 
0115     /*! Creates Form object. */
0116     Form(WidgetLibrary* library, Mode mode, KActionCollection &col, ActionGroup& group);
0117 
0118     /*! Creates Form object as a child of other form. */
0119     explicit Form(Form *parent);
0120 
0121     ~Form();
0122 
0123     //! \return A pointer to the WidgetLibrary supporting this form.
0124     WidgetLibrary* library() const;
0125 
0126     KPropertySet* propertySet();
0127 
0128     void setFeatures(Features features);
0129 
0130     Features features() const;
0131 
0132     /*!
0133      Creates a toplevel widget out of another widget.
0134      \a container will become the Form toplevel widget,
0135      will be associated to an ObjectTree and so on.
0136      \code QWidget *toplevel = new QWidget(this);
0137      form->createToplevel(toplevel); \endcode
0138      */
0139     void createToplevel(QWidget *container, FormWidget *formWidget = 0,
0140                         const QByteArray &classname = "QWidget");
0141 
0142     /*! \return the toplevel Container or 0 if the form is in data mode or createToplevel()
0143        has not been called yet. */
0144     Container* toplevelContainer() const;
0145 
0146     //! \return the FormWidget that holds this Form
0147     FormWidget* formWidget() const;
0148 
0149     //! \return a pointer to this form's ObjectTree.
0150     ObjectTree* objectTree() const;
0151 
0152     //! \return the form's toplevel widget, or 0 if not in design mode.
0153     QWidget* widget() const;
0154 
0155     /*! \return A pointer to the currently active Container, ie the parent Container for a simple widget,
0156         and the widget's Container if it is itself a container.
0157      */
0158     Container* activeContainer();
0159 
0160     /*! \return A pointer to the parent Container of the currently selected widget.
0161      It is the same as activeContainer() for a simple widget, but unlike this function
0162       it will also return the parent Container if the widget itself is a Container.
0163      */
0164     Container* parentContainer(QWidget *w = 0) const;
0165 
0166     /*! \return The Container which is a parent of all widgets in \a wlist.
0167      Used by activeContainer(), and to find where
0168      to paste widgets when multiple widgets are selected. */
0169     ObjectTreeItem* commonParentContainer(const QWidgetList &wlist);
0170 
0171     //! \return the list of currently selected widgets in this form
0172     QWidgetList* selectedWidgets() const;
0173 
0174     /*! \return currently selected widget in this form,
0175      or 0 if there is no widget selected or more than one widget selected.
0176      \see selectedWidgets() */
0177     QWidget* selectedWidget() const;
0178 
0179     //! \return true if form widget itself is selected.
0180     /*! Used to check whether it is possible to execute copy/cut/delete actions. */
0181     bool isFormWidgetSelected() const;
0182 
0183     /*! Emits the action signals. */
0184     void emitActionSignals();
0185 
0186     /*! Emits the action signals for the undo/redo related signals. */
0187     void emitUndoActionSignals();
0188 
0189     /*! Emits again all signal related to selection (ie Form::selectionChanged()).
0190       Called eg when the user has the focus again. */
0191     void emitSelectionSignals();
0192 
0193     /*! Sets the Form interactivity mode. Form is not interactive when
0194     pasting widgets, or loading a Form.
0195      */
0196     void setInteractiveMode(bool interactive);
0197 
0198     /*! \return true if the Form is being updated by the user, ie the created
0199     widget were drawn on the Form.
0200         \return false if the Form is being updated by the program, ie the widget
0201          are created by FormIO, and so composed widgets
0202         should not be populated automatically (such as QTabWidget).
0203      */
0204     bool interactiveMode() const;
0205 
0206     /*! Sets form's mode to @a mode.
0207      In data mode, information related to design mode (object tree and the containers..) is removed. */
0208     void setMode(Mode mode);
0209 
0210     //! @return The actual mode of the Form.
0211     Mode mode() const;
0212 
0213     //! @return true if the form modification flag is set.
0214     bool isModified() const;
0215 
0216     //! Sets modification flag. Always emits modified() signal.
0217     void setModified(bool set);
0218 
0219     //! \return the default margin for all the layout inside this Form.
0220     int defaultMargin() const;
0221 
0222     //! \return the default spacing for all the layout inside this Form.
0223     int defaultSpacing() const;
0224 
0225     /*! This function is used by ObjectTree to emit childAdded() signal (as it is not a QObject). */
0226     void emitChildAdded(ObjectTreeItem *item);
0227 
0228     /*! This function is used by ObjectTree to emit childRemoved() signal (as it is not a QObject). */
0229     void emitChildRemoved(ObjectTreeItem *item);
0230 
0231     /*! \return The filename of the UI file this Form was saved to,
0232     or empty string if the Form hasn't be saved yet. */
0233 //! @todo move this field out of this class
0234     QString fileName() const;
0235 
0236     //! Sets the filename of this Form to \a filename.
0237 //! @todo move this field out of this class
0238     void setFileName(const QString &file);
0239 
0240     /*! Clears form's undo/redo stack. */
0241     void clearUndoStack();
0242 
0243     /*! Sets undo/redo stack in a clean state, used when the document is saved. */
0244     void setUndoStackClean();
0245 
0246 #ifdef KFD_SIGSLOTS
0247     ConnectionBuffer* connectionBuffer() const;
0248 #endif
0249 
0250     PixmapCollection* pixmapCollection() const;
0251 
0252     void setPixmapsStoredInline(bool set);
0253 
0254     bool pixmapsStoredInline() const;
0255 
0256     //! Options for addCommand() method.
0257     enum AddCommandOption {
0258         DontExecuteCommand = 0, //!< command is not executed in addCommand()
0259         ExecuteCommand = 1      //!< command is executed in addCommand()
0260     };
0261 
0262     /*! Adds a command @a command in the form's undo/redo stack and returns true.
0263      If @a command is merged with the existing command and deleted, false is returned. */
0264     bool addCommand(Command *command, AddCommandOption option = ExecuteCommand);
0265 
0266     //! Creates a new PropertyCommand object and adds it to the undo/redo stack.
0267     /*! Takes care about the case when the same property of the same object is changed
0268      one-after-one. In this case only value of the present command on stack is changed.  */
0269     void addPropertyCommand(const QByteArray &wname, const QVariant &oldValue,
0270                             const QVariant &value, const QByteArray &propertyName,
0271                             AddCommandOption addOption, int idOfPropertyCommand = 0);
0272 
0273     void addPropertyCommand(const QHash<QByteArray, QVariant> &oldValues,
0274                             const QVariant &value, const QByteArray &propertyName,
0275                             AddCommandOption addOption, int idOfPropertyCommand = 0);
0276 
0277     //! Adds @a commandGroup to the undo/redo stack.
0278     /*! Assuming the @a commandGroup contains PropertyCommand objects, the method takes care
0279      about the case when the same properties of the same list of objects is changed
0280      one-after-one. In this case only values of the command in the present command group
0281      on the stack are changed and @a commandGroup is deleted.*/
0282     void addPropertyCommandGroup(PropertyCommandGroup *commandGroup,
0283                                  AddCommandOption addOption, int idOfPropertyCommand = 0);
0284 
0285     /*! \return tabstops list. It contains all the widgets that can have focus
0286      (i.e. no labels, etc.) in the order of the tabs.*/
0287     ObjectTreeList* tabStops();
0288 
0289     /*! Called (e.g. by KexiDBForm) when certain widgets can have updated focusPolicy properties
0290      these having no TabFocus flags set are removed from tabStops() list. */
0291     void updateTabStopsOrder();
0292 
0293     /*! Adds the widget at the end of tabstops list. Called on widget creation. */
0294     void addWidgetToTabStops(ObjectTreeItem *it);
0295 
0296     /*! \return True if the Form automatically handles tab stops. */
0297     bool autoTabStops() const;
0298 
0299     /*! If \a autoTab is true (the default), then the Form will automatically handle tab stops,
0300        and the "Edit Tab Order" dialog will be disabled.
0301        The tab widget will be set from the top-left to the bottom-right corner.\n
0302         If \a autoTab is false, it's up to the user to change tab stops.*/
0303     void setAutoTabStops(bool autoTab);
0304 
0305     /*! Tells the Form to reassign the tab stops because the widget layout has changed
0306      (called for example before saving or displaying the tab order dialog).
0307      Automatically sorts widget from the top-left to bottom-right corner.
0308      Widget can be grouped with containers. In particular, for tab widgets,
0309      child widgets should ordered by parent tab's order. */
0310     void autoAssignTabStops();
0311 
0312     //! Specifies target of context menu. Used in createContextMenu().
0313     enum ContextMenuTarget
0314     {
0315         FormContextMenuTarget, //!< Context menu should be displayed on the form
0316                                //!< with offset specified by menuPos argument.
0317         WidgetTreeContextMenuTarget //!< Context menu should be displayed on the widget tree
0318                                     //!< area with offset specified by menuPos argument.
0319     };
0320 
0321     /*! This function creates and displays the context menu corresponding to the widget \a w.
0322         The menu item are disabled if necessary, and
0323         the widget specific part is added (menu from the factory and buddy selection). */
0324     void createContextMenu(QWidget *w, Container *container, const QPoint& menuPos, ContextMenuTarget target);
0325 
0326     //! @return true if snapping to grid is enabled. The defalt value is false.
0327     bool isSnapToGridEnabled() const;
0328 
0329     //! Sets state of snapping to grid to @a enabled.
0330     void setSnapToGridEnabled(bool enabled);
0331 
0332     //! @return size of grid. Positive values make sense here. The defalt value is 0.
0333     //! @todo make gridSize configurable at global level
0334     int gridSize() const;
0335 
0336     //! Sets size of grid to @a gridSize.
0337     void setGridSize(int gridSize);
0338 
0339 #ifdef KEXI_DEBUG_GUI
0340     //! For debugging purposes
0341     QString m_recentlyLoadedUICode;
0342 #endif
0343 
0344     ResizeHandleSet* resizeHandlesForWidget(QWidget* w);
0345 
0346     /*! A set of value/key pairs provided to be stored as attributes in
0347      <kfd:customHeader/> XML element (saved as a first child of \<UI> element). */
0348     QHash<QByteArray, QString>* headerProperties();
0349 
0350     //! \return format version number for this form.
0351     //! For new forms it is equal to KFormDesigner::version().
0352     QString formatVersion() const;
0353     void setFormatVersion(const QString &ver);
0354 
0355     //! \return original format version number for this form (as loaded from .ui XML string)
0356     //! For new forms it is equal to KFormDesigner::version().
0357     QString originalFormatVersion() const;
0358     void setOriginalFormatVersion(const QString &ver);
0359 
0360 #ifdef KFD_SIGSLOTS
0361     /*! Related to signal/slots connections.
0362      Resets recently selected signal/slot connection (when the user clicks
0363      outside of signals/slots menu). We stay in "connection creation" mode,
0364      but user can only start a new connection. */
0365     void resetSelectedConnection();
0366 #endif
0367 
0368     //! @return state ofthe Form, i.e. the current operation like inserting a widget or selecting.
0369     State state() const;
0370 
0371     //! selection flags used in methods like selectWidget()
0372     enum WidgetSelectionFlag {
0373         AddToPreviousSelection = 0,   //!< add to the previous selection, for clarity,
0374                                       //!< do not use with ReplacePreviousSelection
0375         ReplacePreviousSelection = 1, //!< replace the actually selected widget(s)
0376         MoreWillBeSelected = 0,       //!< indicates that more selections will be added
0377                                       //!< do not use with LastSelection
0378                                       //!< so the property editor can be updated (used without ReplacePreviousSelection)
0379         LastSelection = 2,            //!< indicates that this selection is the last one
0380                                       //!< so the property editor can be updated (used without ReplacePreviousSelection)
0381         Raise = 0,                    //!< raise the widget(s) on selection
0382                                       //!< do not use with DontRaise
0383         DontRaise = 4,                //!< do not raise the widget(s) on selection
0384         DefaultWidgetSelectionFlags = ReplacePreviousSelection | LastSelection | Raise
0385     };
0386     Q_DECLARE_FLAGS(WidgetSelectionFlags, WidgetSelectionFlag)
0387 
0388     /*! \return The name of the class being inserted, corresponding
0389      to the menu item or the toolbar button clicked. */
0390     QByteArray selectedClass() const;
0391 
0392     /*! @return widgets list for names @a names. Form widget, if present is omitted. */
0393     QList<QWidget*> widgetsForNames(const QList<QByteArray>& names) const;
0394 
0395     //! @return action from related action collection
0396     QAction* action(const QString& name);
0397 
0398     void createPropertyCommandsInDesignMode(QWidget* widget,
0399                                             const QHash<QByteArray, QVariant> &propValues,
0400                                             Command *parentCommand, bool addToActiveForm = true);
0401 
0402     //! @return class name of currently edited widget's
0403     QByteArray editedWidgetClass() const;
0404 
0405     //! @return true if we're within redo(). Useful to check if command is being executed
0406     //! in response of a redo or it is caused by some other event.
0407     bool isRedoing() const;
0408 
0409 public Q_SLOTS:
0410     /*! Called when the user presses a widget item of the toolbox.
0411       The form enters into "widget inserting" state.
0412       Prepares all form's widgets for creation of a new widget
0413       (i.e. temporarily changes their cursor). */
0414     void enterWidgetInsertingState(const QByteArray &classname);
0415 
0416     //! Called when the user presses 'Pointer' icon. Switches to Default mode.
0417     void enterWidgetSelectingState();
0418 
0419     /*! Aborts the current widget inserting operation (i.e. unsets the cursor ...). */
0420     void abortWidgetInserting();
0421 
0422 #ifdef KFD_SIGSLOTS
0423      //! Enters the Connection creation state.
0424      void enterConnectingState();
0425 
0426     //! Leave the Connection creation mode.
0427     void abortCreatingConnection();
0428 #endif
0429 
0430     /*! Called when the name of a widget was changed in the Property Editor.
0431      Renames the ObjectTreeItem associated to this widget.
0432      */
0433     void changeName(const QByteArray &oldname, const QByteArray &newname);
0434 
0435     /*! Sets @a selected to be the selected widget of this Form.
0436      The form widget is always selected alone. */
0437     void selectWidget(QWidget *selected, WidgetSelectionFlags flags = DefaultWidgetSelectionFlags);
0438 
0439     /*! Sets all widgets @a widgets to be the selected for this Form.
0440      Form widget, if present is omitted. */
0441     void selectWidgets(const QList<QWidget*>& widgets, WidgetSelectionFlags flags);
0442 
0443     /*! Sets all widgets with @a names to be the selected for this Form.
0444      Form widget, if present is omitted. */
0445     void selectWidgets(const QList<QByteArray>& names, WidgetSelectionFlags flags);
0446 
0447     /*! Removes selection for widget \a w.
0448      The widget is removed from the Container's list
0449      and its resize handle is removed as well. */
0450     void deselectWidget(QWidget *w);
0451 
0452     /*! Sets the form widget selected. Deselects any previously selected widgets. */
0453     void selectFormWidget();
0454 
0455     /*! Clears the current selection. */
0456     void clearSelection();
0457 
0458     /*! Sets the point where the subsequently pasted widget should be moved to. */
0459     void setInsertionPoint(const QPoint &p);
0460 
0461     void undo();
0462     void redo();
0463 
0464     /*! Changes undoing state of the list. Used by Undo command to
0465      prevent recursion. */
0466     void setUndoing(bool isUndoing);
0467 
0468     bool isUndoing() const;
0469 
0470     /*! @return number of commands on the undo stack. */
0471     int commandsCount() const;
0472 
0473     /*! @return command with index @a index on the undo stack. */
0474     const KUndo2Command* command(int index) const;
0475 
0476     bool isTopLevelWidget(QWidget *w) const;
0477 
0478     /*! Deletes the selected widget in active Form and all of its children. */
0479     void deleteWidget();
0480 
0481     /*! Copies the slected widget and all its children of the active Form using an XML representation. */
0482     void copyWidget();
0483 
0484     /*! Cuts (ie Copies and deletes) the selected widget and all its children of
0485      the active Form using an XML representation. */
0486     void cutWidget();
0487 
0488     /*! Pastes the XML representation of the copied or cut widget. The widget is
0489       pasted when the user clicks the Form to
0490       indicate the new position of the widget, or at the position of the contextual menu if there is one. */
0491     void pasteWidget();
0492 
0493     /*! Selects all toplevel widgets in trhe current form. */
0494     void selectAll();
0495 
0496     /*! Clears the contents of the selected widget(s) (eg for a line edit or a listview). */
0497     void clearWidgetContent();
0498 
0499     /*! Displays a dialog where the user can modify the tab order of the active Form,
0500      by drag-n-drop or using up/down buttons. */
0501     void editTabOrder();
0502 
0503     /*! Adjusts the size of the selected widget, ie resize it to its size hint. */
0504     void adjustWidgetSize();
0505 
0506     /*! Creates a dialog to edit the activeForm() PixmapCollection. */
0507     void editFormPixmapCollection();
0508 
0509     /*! Creates a dialog to edit the Connection of activeForm(). */
0510     void editConnections();
0511 
0512     void alignWidgetsToLeft();
0513 
0514     void alignWidgetsToRight();
0515 
0516     void alignWidgetsToTop();
0517 
0518     void alignWidgetsToBottom();
0519 
0520     void alignWidgetsToGrid();
0521 
0522     void adjustSizeToGrid();
0523 
0524     //! Resize all selected widgets to the width of the narrowest widget.
0525     void adjustWidthToSmall();
0526 
0527     //! Resize all selected widgets to the width of the widest widget.
0528     void adjustWidthToBig();
0529 
0530     //! Resize all selected widgets to the height of the shortest widget.
0531     void adjustHeightToSmall();
0532 
0533     //! Resize all selected widgets to the height of the tallest widget.
0534     void adjustHeightToBig();
0535 
0536     void bringWidgetToFront();
0537 
0538     void sendWidgetToBack();
0539 
0540     /*! Executes font dialog and changes it for currently selected widget(s). */
0541     void changeFont();
0542 
0543     //! Sets slotPropertyChangedEnabled() enabled or disabled.
0544     void setSlotPropertyChangedEnabled(bool set);
0545 
0546     /*! @internal. This slot is called when the editor has lost focus or the user pressed Enter.
0547     It destroys the editor or installs again the event filter on the widget. */
0548     void resetInlineEditor();
0549 
0550     /*! This function provides a simple editing mode: it just disables event filtering
0551      for the widget, and it install it again when
0552      the widget loose focus or Enter is pressed.
0553     */
0554     void disableFilter(QWidget *w, Container *container);
0555 
0556 protected Q_SLOTS:
0557     /*! This slot is called when the toplevel widget of this Form is deleted
0558     (ie the window closed) so that the Form gets deleted at the same time.
0559      */
0560     void formDeleted();
0561 
0562     void emitUndoEnabled();
0563     void emitRedoEnabled();
0564 
0565     /*! This slot is called when form is restored, ie when the user has undone
0566       all actions. The form modified flag is updated, and
0567     \ref modified() is called. */
0568     void slotFormRestored();
0569 
0570     /*!  This function is called every time a property is modifed.  It also takes
0571      care of saving set and enum properties. */
0572     void slotPropertyChanged(KPropertySet& set, KProperty& property);
0573 
0574     /*! This slot is called when a property is reset using the "reload" button in PropertyEditor. */
0575     void slotPropertyReset(KPropertySet& set, KProperty& property);
0576 
0577     /*! Default implementation changes "text" property.
0578     You have to reimplement this function for editing inside the Form to work if your widget's
0579     property you want to change isn't named "text".
0580     This slot is called when the line edit text changes, and you have to make
0581     it really change the good property of the widget using changeProperty() (text, or title, etc.).
0582     */
0583     void changeInlineTextInternal(const QString& text);
0584 
0585     void slotInlineTextChanged();
0586 
0587     /*! This slot is called when the editor is destroyed.*/
0588     void inlineEditorDeleted();
0589 
0590     void widgetDestroyed();
0591 
0592 Q_SIGNALS:
0593     /*! This signal is emitted by selectWidget() when user selects a new widget,
0594      to update both the Property Editor and the Object Tree View.
0595      \a w is the newly selected widget.
0596       */
0597     void selectionChanged(QWidget *w, KFormDesigner::Form::WidgetSelectionFlags flags);
0598 
0599     /*! This signal is emitted when a new widget is created, to update ObjectTreeView.
0600      \a it is the ObjectTreeItem representing this new widget.
0601      */
0602     void childAdded(KFormDesigner::ObjectTreeItem *it);
0603 
0604     /*! This signal is emitted when a widget is deleted, to update ObjectTreeView.
0605      \a it is the ObjectTreeItem representing this deleted widget.
0606      */
0607     void childRemoved(KFormDesigner::ObjectTreeItem *it);
0608 
0609     //! This signal emitted when Form is about to be destroyed
0610     void destroying();
0611 
0612     /*! This signal is emitted when the property set has been switched. */
0613     void propertySetSwitched();
0614 
0615     /*! This signal is emitted when any change is made to the 'modified' flag of the form. */
0616     void modified(bool m);
0617 
0618     /*! Signal emitted when a normal widget is selected inside of the form
0619      (not the form's widget). If \a multiple is true, then more than one widget is selected.
0620      Use this to update actions state. */
0621     void widgetSelected(bool multiple);
0622 
0623     /*! Signal emitted when the form widget is selected inside of the form.
0624      Use this to update actions state. */
0625     void formWidgetSelected();
0626 
0627     /*! Signal emitted when no form (or a preview form) is selected.
0628      Use this to update actions state. */
0629     void noFormSelected();
0630 
0631 #ifdef KFD_SIGSLOTS
0632     /*! Signal emitted when the Connection creation by drag-and-drop ends.
0633      \a connection is the created Connection. You should copy it,
0634       because it is deleted just after the signal is emitted. */
0635     void connectionCreated(KFormDesigner::Form *form, KFormDesigner::Connection &connection);
0636 
0637     /*! Signal emitted when the Connection creation by drag-and-drop is aborted by user. */
0638     void connectionAborted(KFormDesigner::Form *form);
0639 #endif
0640 
0641     /*! Emitted when the name of the widget is modified.
0642      @a oldname is the name of the widget before the
0643      change, @a newname is the name after renaming. */
0644     void widgetNameChanged(const QByteArray &oldname, const QByteArray &newname);
0645 
0646 protected:
0647     void emitSelectionChanged(QWidget *w, WidgetSelectionFlags flags);
0648 
0649     void updatePropertiesForSelection(QWidget *w, WidgetSelectionFlags flags);
0650 
0651 #ifdef KFD_SIGSLOTS
0652     //! Sets connection buffer to @a b, which will be owned by the form.
0653     //! The previous buffer will be deleted, if there is any.
0654     void setConnectionBuffer(ConnectionBuffer *b);
0655 #endif
0656 
0657     void setFormWidget(FormWidget* w);
0658 
0659     void emitFormWidgetSelected();
0660 
0661     void emitWidgetSelected(bool multiple);
0662 
0663     //! @internal
0664     void emitNoFormSelected();
0665 
0666     void enableFormActions();
0667 
0668     void disableWidgetActions();
0669 
0670     /*! Checks if the name entered by user is valid, ie that it is
0671      a valid identifier, and that there is no name conflict.  */
0672     bool isNameValid(const QString &name) const;
0673 
0674     void addWidget(QWidget *w);
0675 
0676     /*! Clears the current property set and fills it with properties related to the widget @a w.
0677      Also updates the newly created properties with previously set values. */
0678     void createPropertiesForWidget(QWidget *w);
0679 
0680     /*! Changes \a property old value and changed state, using the value
0681     stored in \a tree. Optional \a meta can be specified if you need to handle enum values. */
0682     void updatePropertyValue(ObjectTreeItem *tree, const char *property,
0683                              const QMetaProperty &meta = QMetaProperty());
0684 
0685     /*! Function called by all other alignWidgets*() function. */
0686     void alignWidgets(WidgetAlignment alignment);
0687 
0688     /*! This function is used to filter the properties to be shown
0689        (ie not show "caption" if the widget isn't toplevel).
0690        \return true if the property should be shown. False otherwise.*/
0691     bool isPropertyVisible(const QByteArray &property, bool isTopLevel,
0692                            const QByteArray &classname = QByteArray()) const;
0693 
0694     // Following methods are used to create special types of properties, different
0695     // from Q_PROPERTY
0696 
0697     /*! Creates the properties related to alignment (ie hAlign, vAlign) for
0698      the QWidget \a widget. \a subwidget is the same as \a widget if the widget itself handles
0699      the property and it's a child widget if the child handles the property.
0700      For example, the second case is true for KexiDBAutoField.
0701      \a meta  is the QMetaProperty for "alignment" property" of subwidget.  */
0702     void createAlignProperty(const QMetaProperty &meta, QWidget *widget, QWidget *subwidget);
0703 
0704     /*! Saves the properties related to alignment (ie hAlign, vAlign)
0705      and modifies the "alignment" property of  the widget.*/
0706     void saveAlignProperty(const QString &property);
0707 
0708     KActionCollection  *actionCollection() const;
0709 
0710     //! @todo rm when the 2 libs are merged
0711     KFormDesigner::ActionGroup* widgetActionGroup() const;
0712 
0713     /*! Called when a property has been changed.
0714       @a w is the widget concerned, @a property
0715       is the name of the modified property, and @a value is the new value of this property. */
0716     void handleWidgetPropertyChanged(QWidget *w, const QByteArray &name, const QVariant &value);
0717 
0718     /*! This function creates a QLineEdit to input some text and edit a widget's contents. */
0719     void createInlineEditor(const KFormDesigner::WidgetFactory::InlineEditorCreationArguments& args);
0720 
0721     QString inlineEditorText() const;
0722 
0723     void setInlineEditorText(const QString& text);
0724 
0725     /*! This function destroys the editor when it loses focus or Enter is pressed. */
0726     virtual bool eventFilter(QObject *obj, QEvent *ev) override;
0727 
0728 private:
0729     void selectWidgetInternal(QWidget *w, WidgetSelectionFlags flags);
0730 
0731     FormPrivate * const d;
0732 
0733     friend class FormWidget;
0734     friend class WidgetLibrary;
0735 #ifdef KFD_SIGSLOTS
0736     friend class ConnectionDialog;
0737 #endif
0738 };
0739 
0740 Q_DECLARE_OPERATORS_FOR_FLAGS(Form::Features)
0741 Q_DECLARE_OPERATORS_FOR_FLAGS(Form::WidgetSelectionFlags)
0742 
0743 }
0744 
0745 #endif