/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \page quick-components.html
    \if defined(qtdesignstudio)
    \previouspage studio-app-flows.html
    \else
    \previouspage creator-using-qt-quick-designer.html
    \endif
    \nextpage qtquick-form-editor.html

    \title Creating Components

    A \l{glossary-component}{component} provides a way of defining a new visual item
    that you can re-use in other QML files. A component is like a black box; it
    interacts with the outside world through properties, signals, and slots, and
    is generally defined in its own QML file. You can import components to
    applications.

    The \uicontrol {Library} view lists the available QML types, UI
    components, assets, and QML imports.

    \image qmldesigner-qml-components.png "QML Components"

    The \uicontrol {QML Types} tab displays the QML types grouped by category,
    such as your own QML components, basic types, layouts, positioner types, and
    views.

    \section1 QML Imports

    Sets of UI components with the look and feel of a particular mobile device
    platform have been defined for Qt Quick 1. Since Qt 5.1, ready-made Qt
    Quick Controls, Dialogs, and Layouts are available for creating user
    interfaces using Qt Quick 2. The components and controls are based on
    standard QML types. To view the components and controls in
    \uicontrol {Library}, import the component sets in \uicontrol {QML Imports}.

    The \uicontrol {Qt Quick Application} wizards for a particular platform add
    the import statements automatically. You can remove import statements in
    \uicontrol {QML Imports}.

    \section1 Assets

    \uicontrol {Assets} displays the images and other files that you import to
    the project folder by selecting \uicontrol {Add New Assets}.

    When you drag and drop assets from the tab to \uicontrol Navigator or
    \uicontrol {Form Editor}, QML components with a suitable type are
    automatically created for you. For example, when using graphical
    assets to create components, the components will be of the Image type.

    \section1 Adding Components to Designs

    \image qmldesigner-editing-components.png "Editing QML components in Design mode"

    \list 1
        \li Drag and drop components from \uicontrol Library (1) to
            \uicontrol Navigator (2) or \uicontrol {Form Editor} (3).
        \li Select components in \uicontrol Navigator to edit the
            values of their properties in \uicontrol Properties.
            \image qmldesigner-properties-view.png "Properties view"
            For more information, see \l {Specifying Item Properties}.
        \li To change the appearance and behavior of your components in ways
            that are not supported out of the box, you can define custom
            properties for your components in the \uicontrol Connections view,
            \uicontrol Properties tab.
            \image qmldesigner-dynamicprops.png "Connections view Properties tab"
            For more information, see \l{Specifying Dynamic Properties}.
        \li To enable users to interact with components, connect the components
            to signals in the \uicontrol Connections view. For example, you can
            specify what happens when a component is clicked.
            For more information, see \l{Connecting Objects to Signals}.
            \image qmldesigner-connections.png "Connections view Connections tab"
        \li To dynamically change the behavior of an object when another object
            changes, create bindings between components in the
            \uicontrol Connections view, \uicontrol Bindings tab.
            For more information, see \l{Adding Bindings Between Properties}.
            \image qmldesigner-bindings.png "Connections view Bindings tab"
        \li Add states to apply sets of changes to the property values of one
            or several components in the \uicontrol States view.
            For more information, see \l{Adding States}.
        \li Animate component properties in the \uicontrol Timeline view.
            For more information, see \l{Creating Animations}.
    \endlist

    \section1 Component Types

    The following sections describe the types of components that you can create
    in the Design mode.

    \list
        \li \l Shapes
        \li \l Text
        \li \l Images
        \li \l {User Interaction Methods}
        \li \l {Lists and Other Data Models}
        \if defined(qtdesignstudio)
        \li \l {2D Effects}
        \li \l {Logic Helpers}
        \endif
    \endlist

    \include qtquick-animation-types.qdocinc qtquick animation types

    \include qtquick-mcu-support.qdocinc mcu qtquick components

    \section1 Styling Controls

    Qt Quick Controls provide lightweight QML types for creating performant
    user interfaces for \l{glossary-device}{devices}. The controls can be
    \l {Styling Qt Quick Controls}{styled}. The visual editor reads the
    \c qtquickcontrols2.conf file that specifies the preferred style and some
    style-specific arguments. To change the style, select another style from
    the list on the toolbar. This enables you to check how your UI looks when
    using the available styles.

    \image qtquick-designer-style-list.png "Style menu on the toolbar"

    For an example of defining your own style and using it in the Design mode,
    see \l {Qt Quick Controls 2 - Flat Style}.

    For more information about how to customize a particular control, see
    \l{Customization Reference}.

    \if defined(qtcreator)
    \section1 History of Qt Quick Controls

    In Qt 4, ready-made Qt Quick 1 Components were provided for creating
    UIs with a native look and feel for a particular target platform.
    In Qt 5.1, Qt Quick Controls, Dialogs, and Layouts were added for
    creating classic desktop-style user interfaces using Qt Quick 2.1. The
    Qt Quick Controls Styles could be used to customize Qt Quick Controls.

    Since Qt 5.7, \l {Qt Quick Controls 2} replace Qt Quick Controls 1 and
    Qt Labs Controls. They provide lightweight QML types for creating performant
    user interfaces for \l{glossary-device}{devices}.

    Qt Quick Controls 2 work in conjunction with Qt Quick and Qt Quick Layouts.

    The \QC project wizards create Qt Quick applications that use Qt Quick
    2 types or Qt Quick Controls 2 types.

    Even if you use Qt Quick Controls 2, you can still write cross-platform
    applications, by using different sets of QML files for each platform.

    Some ready-made controls, such as a gauge, dial, status indicator, and
    tumbler, are provided by the \l {Qt Quick Extras} module.
    \endif

    \section1 Creating Components in Design Mode

    You can either use project wizard templates to create custom components and
    controls or \l{Moving Components into Separate Files}{move subcomponents
    into separate files} to make them reusable in other components.

    \section2 Creating Components from Scratch

    To use wizard templates to create custom components:

    \list 1

        \li Select \uicontrol File > \uicontrol {New File or Project} >
            \if defined(qtcreator)
            \uicontrol Qt > \uicontrol {QML File (Qt Quick 2)} >
            \else
            \uicontrol {Qt Quick Files} > \uicontrol {Qt Quick File} >
            \endif
            \uicontrol Choose to create a new .qml file.

            \note Components are listed in the \uicontrol {My QML Components}
            tab in the \uicontrol Library view only if the filename begins with
            a capital letter.

        \li Click \uicontrol Design to open the .qml file in the Design mode.

        \li Drag and drop a QML type from \uicontrol Library to
            \uicontrol Navigator or \uicontrol {Form Editor}.

        \li Edit its properties in \uicontrol Properties.

            \image qmldesigner-custom-component-properties.png

            The available properties depend on the QML type. You can
            \l{Specifying Dynamic Properties}{add properties for
            components} in the \uicontrol Properties tab of the
            \uicontrol {Connection View}.

    \endlist

    The following sections contain more information about how to use
    \uicontrol {Form Editor} to edit 2D content, as well as examples of
    how to create some common components using basic QML types:

    \list

        \li \l{Editing 2D Content}

        \li \l{Creating Buttons}

        \li \l{Creating Scalable Buttons and Borders}

    \endlist

    \if defined(qtdesignstudio)
    \include qtdesignstudio-components.qdocinc creating studio components
    \endif

    \section2 Moving Components into Separate Files

    An alternative way of creating reusable components is to move them into
    separate QML files. Right-click a component in the \uicontrol Navigator
    or \uicontrol {Form Editor} view and select
    \uicontrol {Move Component into Separate File} in the context menu.

    \image qtcreator-move-component-into-separate-file.png

    Give the new component a name and select whether properties are set for
    the new component or for the original one.

    For an example of creating a reusable custom component, see
    \if defined(qtcreator)
    \l{Creating a Mobile Application}.
    \else
    \l{Progress Bar}.
    \endif

    \section1 Moving Within Components

    The QML files that specify components can contain instances of other
    components specified in separate QML files. You can open the QML file
    that specifies a component in different ways from different views:

    \list
        \li In \uicontrol {Form Editor} or \uicontrol Navigator,
            right-click an instance of a component and then select
            \uicontrol {Go into Component} in the context-menu or
            press \key F2.
        \li In \uicontrol Properties, select \uicontrol {Edit Master Component}.
    \endlist

    The component hierarchy is displayed as a bread crumb path, where you can
    click the component names to open the respective files. This enables you
    to easily navigate back to the top level when you are done editing the
    component.

    \image qmldesigner-breadcrumbs.png "Component hierarchy"

    \section1 Merging Files with Templates

    You can merge the current QML file against an existing second QML file and
    using the second QML file in a way similar to using a CSS stylesheet.

    To use this experimental feature, right-click a component in the
    \uicontrol Navigator or \uicontrol {Form Editor} view and select
    \uicontrol {Merge File with Template} in the context menu.

    \image qmldesigner-merge-with-template.png "Merge with Template dialog"

    In the \uicontrol Template field, select the file to use as a template.
*/
