// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | info@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// QML component used to display information about the program and suggest a donation
import QtQuick 2.0
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1

Item {

    id: aboutItem
    anchors.fill: parent

    // Rectangle to draw the form border
    Rectangle {
        anchors.fill: parent
        border.width: 1
        border.color: "black"
        color: Qt.rgba(0, 0, 0, 0.6)

        // This is introduced to disable items located on the background
        MouseArea {
            anchors.fill: parent
            onClicked: { }
        }
    }

    // Rectangle to draw the form border
    Rectangle {
        anchors.right: aboutColumnLayout.right
        anchors.top: aboutColumnLayout.top
        anchors.left: aboutColumnLayout.left
        anchors.bottom: aboutColumnLayout.bottom
        anchors.margins: ((Qt.platform.os == 'ios') || (Qt.platform.os == 'android') || (Qt.platform.os == 'winrt') || (Qt.platform.os == 'winphone')) ? contactLabel.height * (-0.85) : -20
        color: "white"
        border.width: 1
        border.color: "black"
        radius: height * 0.025
    }

    // Main items container
    ColumnLayout {
        id: aboutColumnLayout
        anchors.centerIn: parent

        Row {
            id: mainRow

            Image {
                id: imageContainer
                height: redLabel.contentHeight
                fillMode: Image.PreserveAspectFit
                source: "/images/bytran256About.png"
            }

            Label {
                id: redLabel
                Layout.fillHeight: true
                text: "   bytran for mobile devices\n   Ver. 1.0 Beta  -|- Kempsville edition"
                font.bold: false
                color: "red"                
            }
        }

        RowLayout {}

        PlatformLabel {
            id: developersLabel
            text: "Developed by Dzianis Pliutau (Denis Plutov)\nand Kostya Roslyakov"
        }

        PlatformLabel {
            id: contactLabel
            text: "www.bytran.org   |   info@bytran.org"
        }

        Label {
            id: mitLabel
            text: "This open-source software is provided\nunder the terms of the MIT license. Click\nhere to read complete terms."
            color: 'black'

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    var component = Qt.createComponent("License.qml")
                    if (component.status === Component.Ready)
                    {
                        licenseWindow = component.createObject(mainWindow)

                    }
                    licenseWindow.show()
                }

                onReleased: { mitLabel.color = 'black'; }
                onPressed: { mitLabel.color = 'grey'; }
            }
        }        

        PlatformLabel {
            id: descriptionLabel
            text: "Copyright © 2016 Dzianis Pliutau"
        }

        RowLayout {

            // This temporary label was introduced because the donate button does not work under Windows Phone and Windows RT for some reason
            visible: (Qt.platform.os == 'winphone') ? false : true
            enabled: (Qt.platform.os == 'winphone') ? false : true
        }
        RowLayout {

            id: paypalDonateRowLayout
            Layout.alignment: Qt.AlignHCenter

            Rectangle {

                // This temporary label was introduced because the donate button does not work under Windows Phone and Windows RT for some reason
                visible: (Qt.platform.os == 'winphone') ? false : true
                enabled: (Qt.platform.os == 'winphone') ? false : true

                Layout.alignment: Qt.AlignHCenter
                id: donateRectangle
                width: indexText.width * 1.4
                height: indexText.height * 1.8
                border.width: 1
                border.color: 'red'
                color: 'red'
                radius: 50

                MouseArea {
                    anchors.fill: parent
                    onPressed: {
                        donateRectangle.color = 'white';
                        indexText.color = 'red';
                    }
                    onReleased: {
                        donateRectangle.color = 'red';
                        indexText.color = 'white';
                    }
                    onClicked: { aboutDataObj.donateThroughPayPal(); }
                }

                Text {
                    anchors.centerIn: parent
                    id: indexText
                    text: qsTr("Donate with Paypal")
                    font.bold: true
                    horizontalAlignment: Text.AlignRight
                    color: 'white'
                }
            }
        }
    }

    // Button to close the form
    BackRectangle {
        anchors.fill: exitButton
        anchors.margins: 8
    }
    ControlButton {
        anchors.right: aboutItem.right
        anchors.top: aboutItem.top
        id: exitButton
        platformText: qsTr("X")
        opacity: 1.0

        // Enabling the closing of the form when the exit button is pressed
        MouseArea {
            anchors.fill: parent
            onClicked: {
                aboutItem.destroy();
            }
        }
    }    
}
