/**
 * Copyright 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.5
import QtQuick.Window 2.5
import QtQuick.Particles 2.0

Item {
    id: root
    anchors.fill: parent

    property real xPos: 0.5
    property real yPos: 0.5

    property real devicePixelRatio: Window.window != null && Window.window.screen != null ? Window.window.screen.devicePixelRatio : 1.0

    ParticleSystem {
        id: particles
        width: parent.width/20
        height: width

        x: root.width * root.xPos - width/2
        y: root.height * root.yPos - height/2

        ImageParticle {
            groups: ["center"]
            anchors.fill: parent
            source: "qrc:///particleresources/glowdot.png"
            colorVariation: 0.1
            color: "#FF9999FF"
        }
        ImageParticle {
            groups: ["edge"]
            anchors.fill: parent
            source: "qrc:///particleresources/glowdot.png"
            colorVariation: 0.1
            color: "#000099FF"
        }

        Emitter {
            anchors.fill: parent
            group: "center"
            emitRate: 900
            lifeSpan: 200
            size: 20 * devicePixelRatio
            sizeVariation: 2
            endSize: 0
            //! [0]
            shape: EllipseShape {fill: false}
            velocity: TargetDirection {
                targetX: particles.width/2
                targetY: particles.height/2
                proportionalMagnitude: true
                magnitude: 0.5
            }
            //! [0]
        }

        Emitter {
            anchors.fill: parent
            group: "edge"
            startTime: 200
            emitRate: 2000
            lifeSpan: 20
            size: 28 * devicePixelRatio
            sizeVariation: 2 * devicePixelRatio
            endSize: 16 * devicePixelRatio
            shape: EllipseShape {fill: false}
            velocity: TargetDirection {
                targetX: particles.width/2
                targetY: particles.height/2
                proportionalMagnitude: true
                magnitude: 0.1
                magnitudeVariation: 0.1
            }
            acceleration: TargetDirection {
                targetX: particles.width
                targetY: particles.height
                targetVariation: 200
                proportionalMagnitude: true
                magnitude: 0.1
                magnitudeVariation: 0.1
            }
        }
    }
}