/*!
    \example designer/customwidgetplugin
    \title Custom Widget Plugin Example

    The Custom Widget example shows how to create a custom widget plugin for \QD.

    \image customwidgetplugin-example.png

    In this example, the custom widget used is based on the
    \l{widgets/analogclock}{Analog Clock example}, and does not provide any custom
    signals or slots.

    \section1 Preparation

    To provide a custom widget that can be used with \QD, we need to supply a
    self-contained implementation and provide a plugin interface. In this
    example, we reuse the \l{widgets/analogclock}{Analog Clock example} for
    convenience.

    Since custom widgets plugins rely on components supplied with \QD, the
    project file that we use needs to contain information about \QD's
    library components:

    \quotefromfile designer/customwidgetplugin/customwidgetplugin.pro
    \skipto TEMPLATE
    \printline TEMPLATE
    \quotefromfile designer/customwidgetplugin/customwidgetplugin.pro
    \skipto CONFIG
    \printline CONFIG

    The \c TEMPLATE variable's value makes \c qmake create the custom
    widget as a library. Later, we will ensure that the widget will be
    recognized as a plugin by Qt by using the Q_EXPORT_PLUGIN2() macro
    to export the relevant widget information.

    The \c CONFIG variable contains two values, \c designer and \c
    plugin:

    \list

    \o \c designer: Since custom widgets plugins rely on components
    supplied with \QD, this value ensures that our plugin links
    against \QD's library (\c libQtDesigner.so).

    \o \c plugin: We also need to ensure that \c qmake considers the
    custom widget a plugin library.

    \endlist

    When Qt is configured to build in both debug and release modes,
    \QD will be built in release mode. When this occurs, it is
    necessary to ensure that plugins are also built in release
    mode. For that reason we add the \c debug_and_release value to the
    \c CONFIG variable. Otherwise, if a plugin is built in a mode that
    is incompatible with \QD, it won't be loaded and
    installed.

    The header and source files for the widget are declared in the usual way,
    and we provide an implementation of the plugin interface so that \QD can
    use the custom widget:

    \skipto HEADERS
    \printuntil customwidgetplugin.cpp

    It is also important to ensure that the plugin is installed in a
    location that is searched by \QD. We do this by specifying a
    target path for the project and adding it to the list of items to
    install:

    \code
        target.path = $$[QT_INSTALL_PLUGINS]/designer
        INSTALLS += target
    \endcode

    The custom widget is created as a library, and will be installed
    alongside the other \QD plugins when the project is installed
    (using \c{make install} or an equivalent installation procedure).
    Later, we will ensure that it is recognized as a plugin by \QD by
    using the Q_EXPORT_PLUGIN2() macro to export the relevant widget
    information.

    Note that if you want the plugins to appear in a Visual Studio
    integration, the plugins must be built in release mode and their
    libraries must be copied into the plugin directory in the install
    path of the integration (for an example, see \c {C:/program
    files/trolltech as/visual studio integration/plugins}).

    For more information about plugins, see the \l {How to
    Create Qt Plugins} documentation.

    \section1 AnalogClock Class Definition and Implementation

    The \c AnalogClock class is defined and implemented in exactly the same
    way as described in the \l{widgets/analogclock}{Analog Clock example}.
    Since the class is self-contained, and does not require any external
    configuration, it can be used without modification as a custom widget in
    \QD.

    \section1 AnalogClockPlugin Class Definition

    The \c AnalogClock class is exposed to \QD through the \c
    AnalogClockPlugin class. This class inherits from both QObject and
    the QDesignerCustomWidgetInterface class, and implements an
    interface defined by QDesignerCustomWidgetInterface:

    \quotefromfile designer/customwidgetplugin/customwidgetplugin.h
    \skipto class AnalogClockPlugin
    \printuntil /^\};/

    The functions provide information about the widget that \QD can use in
    the \l{Getting Started with Qt Designer#WidgetBox}{widget box}.
    The \c initialized private member variable is used to record whether
    the plugin has been initialized by \QD.

    Note that the only part of the class definition that is specific to
    this particular custom widget is the class name.

    \section1 AnalogClockPlugin Implementation

    The class constructor simply calls the QObject base class constructor
    and sets the \c initialized variable to \c false.

    \quotefromfile designer/customwidgetplugin/customwidgetplugin.cpp
    \skipto AnalogClockPlugin::AnalogClockPlugin
    \printuntil /^\}/

    \QD will initialize the plugin when it is required by calling the
    \c initialize() function:

    \skipto AnalogClockPlugin::initialize(
    \printuntil /^\}/

    In this example, the \c initialized private variable is tested, and only
    set to \c true if the plugin is not already initialized. Although, this
    plugin does not require any special code to be executed when it is
    initialized, we could include such code after the test for initialization.

    The \c isInitialized() function lets \QD know whether the plugin is
    ready for use:

    \skipto AnalogClockPlugin::isInitialized(
    \printuntil /^\}/

    Instances of the custom widget are supplied by the \c createWidget()
    function. The implementation for the analog clock is straightforward:

    \skipto AnalogClockPlugin::createWidget(
    \printuntil /^\}/

    In this case, the custom widget only requires a \c parent to be specified.
    If other arguments need to be supplied to the widget, they can be
    introduced here.

    The following functions provide information for \QD to use to represent
    the widget in the widget box.
    The \c name() function returns the name of class that provides the
    custom widget:

    \skipto AnalogClockPlugin::name(
    \printuntil /^\}/

    The \c group() function is used to describe the type of widget that the
    custom widget belongs to:

    \skipto AnalogClockPlugin::group(
    \printuntil /^\}/

    The widget plugin will be placed in a section identified by its
    group name in \QD's widget box. The icon used to represent the
    widget in the widget box is returned by the \c icon() function:

    \skipto AnalogClockPlugin::icon(
    \printuntil /^\}/

    In this case, we return a null icon to indicate that we have no icon
    that can be used to represent the widget.

    A tool tip and "What's This?" help can be supplied for the custom widget's
    entry in the widget box. The \c toolTip() function should return a short
    message describing the widget:

    \skipto AnalogClockPlugin::toolTip(
    \printuntil /^\}/

    The \c whatsThis() function can return a longer description:

    \skipto AnalogClockPlugin::whatsThis(
    \printuntil /^\}/

    The \c isContainer() function tells \QD whether the widget is supposed to
    be used as a container for other widgets. If not, \QD will not allow the
    user to place widgets inside it.

    \skipto AnalogClockPlugin::isContainer(
    \printuntil /^\}/

    Most widgets in Qt can contain child widgets, but it only makes sense
    to use dedicated container widgets for this purpose in \QD. By returning
    \c false, we indicate that the custom widget cannot hold other widgets;
    if we returned true, \QD would allow other widgets to be placed inside
    the analog clock and a layout to be defined.

    The \c domXml() function provides a way to include default settings for
    the widget in the standard XML format used by \QD. In this case, we only
    specify the widget's geometry:

    \skipto AnalogClockPlugin::domXml(
    \printuntil /^\}/

    If the widget provides a reasonable size hint, it is not necessary to
    define it here. In addition, returning an empty string instead of a
    \c{<widget>} element will tell \QD not to install the widget in the
    widget box.

    To make the analog clock widget usable by applications, we implement
    the \c includeFile() function to return the name of the header file
    containing the custom widget class definition:

    \skipto AnalogClockPlugin::includeFile(
    \printuntil /^\}/

    Finally, we use the Q_EXPORT_PLUGIN2() macro to export the \c
    AnalogClockPlugin class for use with \QD:

    \skipto Q_EXPORT_PLUGIN2
    \printuntil Q_EXPORT_PLUGIN2

    This macro ensures that \QD can access and construct the custom widget.
    Without this macro, there is no way for \QD to use the widget.
*/
