/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** 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.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example legend
    \title Legend Example
    \ingroup qtcharts_examples

    \brief This example shows how to detach the legend from the chart and how to attach it back.

    By default, the chart draws the legend inside the same graphics view the chart is contained
    within. In some cases, the user may want to draw the legend somewhere else. To make this
    possible, the legend can be detached from the chart. Detaching means that the legend is no
    longer fixed to an edge of the chart, and the chart no longer controls the legend's layout.
    Instead, the legend geometry is controlled by the user, allowing free control of the location
    and size of the legend. This can be floating atop the content of the chart, or even drawn in a
    different graphics scene. The behavior of the legend can be tested by running this example.

    In this example we show a bar series, allowing bar sets to be added or removed interactively.
    The legend reflects the changes in series as bar sets are added and/or removed. The attachment
    of the legend, its alignment, and its ability to be moved and resized can be controlled using
    methods in \c QLegend.

    When the legend is detached, it can be resized and positioned freely. If the interactive
    feature of the legend is enabled, the legend can be freely dragged and resized by the user.
    If the user drags the legend off of any side of the chart, it will automatically re-attach to
    that side of the chart.


    \image examples_legend_detach.png
    \image examples_legend_detach2.png

    \include examples-run.qdocinc

    \section1 Detaching and Attaching Legends

    Here we turn the legend visible and set its alignment to the bottom of the chart.

    \snippet legend/mainwidget.cpp 1

    This snippet shows how to detach the legend from the chart.

    \snippet legend/mainwidget.cpp 2

    Here we reattach the legend to the chart. The background is turned invisible.

    \snippet legend/mainwidget.cpp 3

    Here we connect to the signal emitted when the legend is detached or attached, turning its
    background on when detached and off when attached. This makes it easier to see how the
    items inside the legend are arranged when it is detached.

    \snippet legend/mainwidget.cpp 4

    This shows how to make the legend interactive to the user using a pointing device such as a
    mouse.

    \snippet legend/mainwidget.cpp 5

    This shows how we set the detached legend dimensions if the legend is not interactive. After
    setting the new values, we call update to show changes on screen.

    \snippet legend/mainwidget.cpp 6
*/
