# ============================================================================== #
    # about_window.py - AcouSed                                   #
    # Copyright (C) 2024  INRAE                                              #
    #                                                                        #
    # 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 3 of the License, or      #
    # (at your option) any later version.                                    #
    #                                                                        #
    # 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/>. #

    #                                                      by Brahim MOUDJED #
# ============================================================================== #

import sys
from PyQt5.QtGui import QIcon, QPixmap, QFont
from PyQt5.QtWidgets import (QWidget, QLabel, QHBoxLayout, QVBoxLayout, QApplication, QMainWindow, QGridLayout,
                             QDialog, QDialogButtonBox, QPushButton, QTextEdit, QFrame, QLineEdit)
from PyQt5.QtCore import Qt


class AboutWindow(QDialog):

    def __init__(self):

        super().__init__()

        self.logo_path = "./Logo"
        self.logo_AcouSed = QPixmap(self.logo_path + "/" + "Logo_AcouSed_AboutAcouSedWindow.png")
        self.logo_AcouSed.scaled(16, 16, Qt.KeepAspectRatio, Qt.SmoothTransformation)

        self.logo_INRAE = QPixmap(self.logo_path + "/" + "BlocMarque-INRAE-Inter.jpg")

        self.setGeometry(400, 200, 300, 200)

        self.setWindowTitle("About AcouSed")

        self.verticalLayout_Main = QVBoxLayout()
        self.setLayout(self.verticalLayout_Main)

        self.gridLayout = QGridLayout()
        self.verticalLayout_Main.addLayout(self.gridLayout)

        # ----------------------------------------------------------

        self.label_logo_AcouSed = QLabel()
        self.label_logo_AcouSed.setPixmap(self.logo_AcouSed.scaledToHeight(128, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_logo_AcouSed, 0, 0, 3, 1, Qt.AlignCenter)

        self.label_acoused = QLabel()
        self.label_acoused.setText("Acoused 2.0")
        self.label_acoused.setFont(QFont("Ubuntu", 14))
        self.gridLayout.addWidget(self.label_acoused, 0, 1, 1, 1, Qt.AlignCenter)

        self.label_date = QLabel()
        self.label_date.setText("2025.01.01")
        self.label_date.setFont(QFont("Ubuntu", 12))
        self.gridLayout.addWidget(self.label_date, 1, 1, 1, 1, Qt.AlignCenter)

        self.label_logo_INRAE = QLabel()
        self.label_logo_INRAE.setPixmap(self.logo_INRAE.scaledToHeight(42, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_logo_INRAE, 2, 1, 1, 1, Qt.AlignCenter)

        self.label_contact = QLabel()
        self.label_contact.setText("Contact : celine.berni@inrae.fr \n"
                                   "                   jerome.lecoz@inrae.fr")
        self.gridLayout.addWidget(self.label_contact, 3, 1, 1, 1, Qt.AlignLeft)

        # ----------------------------------------------------------

        self.horizontalLine = QFrame()
        self.horizontalLine.setFrameShape(QFrame.HLine)
        self.horizontalLine.setFrameShadow(QFrame.Sunken)

        self.verticalLayout_Main.addWidget(self.horizontalLine)

        # ----------------------------------------------------------

        self.gridLayout_button = QGridLayout()
        self.verticalLayout_Main.addLayout(self.gridLayout_button)

        self.button_Licence = QPushButton()
        self.button_Licence.setText("Licence")
        self.gridLayout_button.addWidget(self.button_Licence, 0, 0, 1, 1)

        self.button_Licence.clicked.connect(self.licence_window)

        self.button_Copyright = QPushButton()
        self.button_Copyright.setText("Copyright")
        self.gridLayout_button.addWidget(self.button_Copyright, 0, 1, 1, 1)

        self.button_Copyright.clicked.connect(self.copyright_window)

        self.button_Support = QPushButton()
        self.button_Support.setText("Support")
        self.gridLayout_button.addWidget(self.button_Support, 0, 2, 1, 1)

        self.button_Support.clicked.connect(self.support_window)

    def licence_window(self):
        lw = Licence()
        lw.exec()

    def copyright_window(self):
        cw = Copyright()
        cw.exec()

    def support_window(self):
        sw = Support()
        sw.exec()


class Licence(QDialog):

    def __init__(self):

        super().__init__()

        self.setWindowTitle("Licence")

        self.setGeometry(500, 300, 450, 300)

        self.verticalLayout = QVBoxLayout()
        self.setLayout(self.verticalLayout)

        self.textEdit = QTextEdit()
        self.verticalLayout.addWidget(self.textEdit)

        self.textEdit.setText("AcouSed \n"
                              "Copyright (C) 2024 - INRAE \n\n"
                              "This program is free software: you can redistribute it and/or modify \n"
                              "it under the terms of the GNU General Public License as published by \n"
                              "the Free Software Foundation, either version 3 of the License, or \n "
                              "(at your option) any later version. \n\n"
                              "This program is distributed in the hope that it will be useful, \n"
                              "but WITHOUT ANY WARRANTY; without even the implied warranty of \n"
                              "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \n"
                              "GNU General Public License for more details. \n\n"
                              "You should have received a copy of the GNU General Public License \n"
                              "along with this program.  If not, see <https://www.gnu.org/licenses/>.")


class Copyright(QDialog):

    def __init__(self):

        super().__init__()

        self.logo_path = "./Logo"
        self.logo_INRAE = QPixmap(self.logo_path + "/" + "BlocMarque-INRAE-Inter.jpg")

        self.setWindowTitle("Copyright")

        self.setGeometry(500, 300, 200, 200)

        self.gridLayout = QGridLayout()
        self.setLayout(self.gridLayout)

        self.textEdit = QTextEdit()
        self.gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)

        self.textEdit.setText("Copyright (c) 2024. INRAE \n"
                              "All Rights Reserved.")

        self.label_INRAE = QLabel()
        self.label_INRAE.setPixmap(self.logo_INRAE.scaledToHeight(64, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_INRAE, 1, 0, 1, 1, Qt.AlignCenter)


class Support(QDialog):

    def __init__(self):

        super().__init__()

        self.logo_path = "./Logo"

        self.logo_OSR = QPixmap(self.logo_path + '/' + "OSR.png")
        self.logo_CNR = QPixmap(self.logo_path + '/' + "CNR.png")
        self.logo_EDF = QPixmap(self.logo_path + '/' + "EDF.png")
        self.logo_Ubertone = QPixmap(self.logo_path + '/' + "Ubertone.jpeg")

        self.setWindowTitle("Support")

        self.setGeometry(500, 300, 300, 300)

        self.gridLayout = QGridLayout()
        self.setLayout(self.gridLayout)

        self.label_support = QLabel()
        self.label_support.setText("The development of AcouSed was supported by OSR6 and CNR Company.")
        self.gridLayout.addWidget(self.label_support, 0, 0, 1, 2, Qt.AlignLeft)

        self.label_OSR = QLabel()
        self.label_OSR.setPixmap(self.logo_OSR.scaledToHeight(96, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_OSR, 1, 0, 1, 1, Qt.AlignCenter)

        self.label_CNR = QLabel()
        self.label_CNR.setPixmap(self.logo_CNR.scaledToHeight(32, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_CNR, 1, 1, 1, 1, Qt.AlignCenter)

        self.label_collaboration = QLabel()
        self.label_collaboration.setText("It was made in collaboration with Ubertone and EDF Companies.")
        self.gridLayout.addWidget(self.label_collaboration, 2, 0, 1, 2, Qt.AlignLeft)

        self.label_Ubertone = QLabel()
        self.label_Ubertone.setPixmap(self.logo_Ubertone.scaledToHeight(48, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_Ubertone, 3, 0, 1, 1, Qt.AlignCenter)

        self.label_EDF = QLabel()
        self.label_EDF.setPixmap(self.logo_EDF.scaledToHeight(48, Qt.SmoothTransformation))
        self.gridLayout.addWidget(self.label_EDF, 3, 1, 1, 1, Qt.AlignCenter)


# if __name__ == "__main__":
#     app = QApplication(sys.argv)
#     w = AboutWindow()
#     w.show()
#     sys.exit(app.exec_())


