// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The bytran logo is distributed under the Creative Commons 3.0 Attribution License: https://creativecommons.org/licenses/by/3.0/us/
//
// 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 the license to the user
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Window 2.2

Item {

    id: aboutItem
    anchors.fill: parent

    // Used to rotate the menu
    onHeightChanged: {

        // Resizing controls
        if (Screen.primaryOrientation === Qt.PortraitOrientation)
        {
            aboutColumnLayout.height = aboutItem.height - exitButton.height - 1.70 * coreObj.defaultLabelHeight - exitButton.padding
            aboutColumnLayout.anchors.top = exitButton.bottom
        }
        else
        {
            aboutColumnLayout.height = aboutItem.height - 1.90 * coreObj.defaultLabelHeight
            aboutColumnLayout.anchors.top = aboutItem.top
        }

        // Updating the scroll (maybe there is a better way to update but did this for now)
        descriptionFlickable.contentY = descriptionFlickable.contentY - 1
        descriptionFlickable.contentY = descriptionFlickable.contentY + 1
    }

    // Rectangle to shade the background
    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 in the background
        MouseArea {
            anchors.fill: parent
            onClicked: { }
        }
    }

    // Rectangle to draw the form border
    Rectangle {
        anchors.fill: aboutColumnLayout
        anchors.margins: coreObj.defaultLabelHeight * (-0.6)
        anchors.topMargin: coreObj.defaultLabelHeight * (-1.05)
        color: "white"
        border.width: 1
        border.color: 'black'
        radius: coreObj.defaultLabelHeight * 0.5
    }

    CustomLabel {
        id: widthLabel
        Layout.fillHeight: true
        text: "   bytran for mobile devices\n   Version 1.2  -|-  Kempsville edition "
        font.bold: false
        font.pointSize: coreObj.defaultFontPointSize
        visible: false
        color: "red"
    }

    // QML component is used to display the license
    ColumnLayout {
        id: aboutColumnLayout
        anchors.top: exitButton.bottom
        anchors.topMargin: coreObj.defaultLabelHeight * 1.2
        anchors.horizontalCenter: aboutItem.horizontalCenter

        Row {
            id: mainRow
            anchors.top: aboutColumnLayout.top
            Image {
                id: imageContainer
                anchors.verticalCenter: parent.verticalCenter
                height: redLabel.contentHeight * 0.9
                fillMode: Image.PreserveAspectFit
                source: "/images/bytran256About.png"
            }
            CustomLabel {
                id: redLabel
                Layout.fillHeight: true
                text: "  bytran -|- spectral calculations for portable \n  devices using the HITRAN database "
                font.bold: false
                font.pointSize: coreObj.defaultFontPointSize
                color: "red"
            }
        }

        ColumnLayout {
            id: descriptionColumnLayout
            anchors.top: mainRow.bottom
            anchors.left: aboutColumnLayout.left
            anchors.right: aboutColumnLayout.right
            anchors.bottom: paypalDonateRowLayout.top
            anchors.topMargin: coreObj.defaultLabelHeight * 0.25

            Flickable {
                id: descriptionFlickable
                anchors.fill: parent
                ScrollBar.vertical: ScrollBar { }

                // https://blog.shantanu.io/2015/02/15/creating-working-hyperlinks-in-qtquick-text/
                TextArea.flickable: CustomTextArea {
                    id: mitLicenseTextArea
                    implicitHeight: aboutColumnLayout.height - mainRow.height - paypalDonateRowLayout.height
                    implicitWidth: mainRow.width
                    padding: coreObj.defaultLabelHeight * 0.2
                    readOnly: true
                    wrapMode: Text.WordWrap
                    onLinkActivated: Qt.openUrlExternally(link)
                    color: 'black'
                    textFormat: TextEdit.RichText
                    text:
"bytran Version 1.2, released May 2, 2018.<br><br> \
\
This open-source software is provided under the terms of the MIT license. First made available under the Android operating system.  Version 1.0 Alpha for Android released on May 16, 2016.<br><br> \
\
The MIT license (MIT) <br> \
Copyright (c) 2016 Dzianis Pliutau<br>\
<html><a style='color: black; text-decoration: none;' href = 'http://www.bytran.org'>www.bytran.org</a> </html>    |    contact@bytran.org<br><br>\
\
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:<br><br>\
\
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<br><br>\
\
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.<br><br> \
\
End of software license. Additional information:<br><br>
\
This software was made possible through the support from the Russian Orthodox Church including St. Joseph of Optina Russian Orthodox Church outside of Russia, 810 Kempsville Rd, Virginia Beach, VA 23464, <html><a style='color: red; text-decoration: none;' href = 'http://www.stjosephofoptina.org'>link</a></html>.<br><br>\
\
The usage of bytran may be cited as follows: D. Pliutau, K. Roslyakov, \"Bytran -|- spectral calculations for portable devices using the HITRAN database\", Earth Sci. Inform., Volume 10, Issue 3, Pages 395-404, (2017), <html><a style='color: red; text-decoration: none;' href = 'http://doi.org/10.1007/s12145-017-0288-4'>link</a></html>. A view only version of this publication is available through Readcube at <html><a style='color: red; text-decoration: none;' href = 'http://rdcu.be/piDB'>http://rdcu.be/piDB</a></html>.<br><br>\
\
This application was developed with Qt (<html><a style='color: red; text-decoration: none;' href = 'https://www.qt.io/'>link</a></html>) and uses dynamically linked Qt modules distributed under LGPLv3 license.<br><br> \
\
Parts of the calculation algorithm are based on the Python code from the HITRAN Application Programming Interface (HAPI) \
and the theoretical information posted at HITRAN.org (<html><a style='color: red; text-decoration: none;' href = 'http://hitran.org'>link</a></html>). \
  HAPI reference: R.V. Kochanov, I.E. Gordon, L.S. Rothman, P. Wcisło, C. Hill, J.S. Wilzewski, \"HITRAN Application Programming \
Interface (HAPI): A comprehensive approach to working with spectroscopic data\", JQSRT, Volume 177, Pages 15–30, (2016), \
<html><a style='color: red; text-decoration: none;' href = 'http://dx.doi.org/10.1016/j.jqsrt.2016.03.005'>link</a></html>.<br><br> \
\
The Voigt calculation routine uses the algorithm described in: Abrarov, S., and Quine, B. \
\"A rational approximation for efficient computation of the Voigt function in quantitative spectroscopy\". \
Journal of Mathematics Research, 7(2), p 163, (2015), <html><a style='color: red; text-decoration: none;' href = 'http://dx.doi.org/10.5539/jmr.v7n2'>link</a></html>.<br><br> \
\
Appendices 1.1, 4, and 9 of the HITRAN-PC 4.0 manual were consulted for line intensity and radiance calculations (\
<html><a style='color: red; text-decoration: none;' href = 'http://www.cas.usf.edu/lidarlab/hitran_pc_demo.html'>link</a></html>). HITRAN-PC reference: Killinger D.K., Wilcox W.E., \
Pliutau D., \"HITRAN-PC: 25 years of academic development and commercialization of laser atmospheric transmission software for \
environmental remote sensing\", Technology & Innovation, Vol. 14, No. 3-4, pp. 303-327, (2012), \
<html><a style='color: red; text-decoration: none;' href = 'http://dx.doi.org/10.3727/194982412X13500042169054'>link</a></html>.<br><br> \
\
Conversion between the relative humidity and water vapor concentration (ppmv) uses formulas according to a Wikipedia <a style='color: red; text-decoration: none;' href='https://en.wikipedia.org/wiki/Arden_Buck_equation'>article</a> and the referenced links including Arden L. Buck \"New equations for computing vapor pressure and enhancement factor\", J. Appl. Meteorology, Vol. 20, pp. 1527-1532, (1981), <a style='color: red; text-decoration: none;' href = 'http://dx.doi.org/10.1175/1520-0450(1981)020<1527:NEFCVP>2.0.CO;2'>link</a>. <br> <br> \
\
Image and data sharing (Android and iOS) are based on the code Copyrighted (c) 2014 to Nicolas Froment \
(<html><a style='color: red; text-decoration: none;' href = 'http://blog.lasconic.com/share-on-ios-and-android-using-qml/'>link</a></html>) \
and other sources.<br><br>\
\
The bytran logo is distributed under the Creative Commons 3.0 Attribution License, \
<html><a style='color: red; text-decoration: none;' href = 'https://creativecommons.org/licenses/by/3.0/'>link</a></html>."
                }
            }
        }

        // https://forum.qt.io/topic/23124/solved-how-to-draw-a-transparent-hole-inside-a-qquickview-qquickwindow-based-on-a-custom-qquickitem/10
        ColumnLayout {
            id: paypalDonateRowLayout
            anchors.bottom: aboutColumnLayout.bottom
            anchors.horizontalCenter: aboutColumnLayout.horizontalCenter
            spacing: 0
            Rectangle {
                Layout.alignment: Qt.AlignHCenter
                implicitHeight: buttonText.height * 0.25
                border.color: 'transparent'
                color: 'transparent'
            }
            Rectangle {
                id: donateRectangle
                Layout.alignment: Qt.AlignHCenter
                width: buttonText.width * 1.4
                height: buttonText.height * 1.8
                border.width: 1
                border.color: 'red'
                color: 'red'
                radius: 50
                MouseArea {
                    anchors.fill: parent
                    onPressed: {
                        donateRectangle.color = 'white';
                        buttonText.color = 'red';
                    }
                    onReleased: {
                        donateRectangle.color = 'red';
                        buttonText.color = 'white';
                    }
                    onClicked: { aboutQml.donate(); }
                }

                CustomText {
                    id: buttonText
                    anchors.centerIn: parent
                    text: qsTr("Visit website")
                    font.bold: true
                    horizontalAlignment: Text.AlignRight
                    color: 'white'
                    font.pointSize: coreObj.defaultFontPointSize
                }
            }
        }
    }

    // Exit button
    CustomButton {
        id: exitButton
        anchors.top: aboutItem.top
        anchors.right: aboutItem.right
        anchors.margins: coreObj.defaultLabelHeight * 0.1
        implicitWidth: 1.5 * exitButton.height
        text: qsTr("X")
        onClicked: aboutItem.destroy()
    }
}
