from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import (QBrush, QColor, QImage, QPalette, QPixmap, QMovie)
from qgis.PyQt.QtWidgets import (QApplication, QDialog, QFrame, QHBoxLayout, QLabel, QTextEdit)
from qgis.core import QgsApplication

from rdigc.objmaker import funnyPushButton
from rdigc.utils import (getThemeIcon, setObjSizes, windowIcon)
     

class ui_About(QDialog):
    def __init__(self, parent):
        QDialog.__init__(self)
        self.parent = parent
        self.setupUi()
    
    def setupUi(self):
        self.setObjectName("ui_About")
        self.maxWidth, self.maxheight = 530, 440
        setObjSizes(self, self.maxWidth, self.maxheight)
        self.resize(self.maxWidth, self.maxheight) 
        windowIcon(self, "about_off.png")
        
        self.textEdit = QTextEdit(self)

        palette = QPalette()
        brush = QBrush(QColor(0,0,0,0))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Active, QPalette.Base,brush)
        brush = QBrush(QColor(0,0,0,0))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Inactive, QPalette.Base,brush)

        brush = QBrush(QColor(255,255,255))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Disabled, QPalette.Base,brush)
        self.textEdit.setPalette(palette)
        self.textEdit.setAutoFillBackground(True)
        self.textEdit.setFrameShape(QFrame.NoFrame)
        self.textEdit.setFrameShadow(QFrame.Plain)
        self.textEdit.setReadOnly(True)
        self.textEdit.setObjectName("textEdit")
        self.textEdit.setTextInteractionFlags(Qt.TextBrowserInteraction)
        self.textEdit.setGeometry(60, 295, 400, 120)
        self.textEdit.setAlignment(Qt.AlignCenter)

        self.labelImage = QLabel(self)
        myImgPath = getThemeIcon("rdiabout.png")
        carIcon = QImage(myImgPath)
        self.labelImage.setPixmap(QPixmap.fromImage(carIcon))
        self.labelImage.setGeometry(60, 10, 400, 300)

        self.labelAnimation = QLabel(self)
        self.movie = QMovie(getThemeIcon("animation.gif")) 
        self.labelAnimation.setMovie(self.movie)
        self.labelAnimation.setLayout(QHBoxLayout())
        self.labelAnimation.layout().addWidget(QLabel(''))
        self.labelAnimation.setVisible(True)
        self.labelAnimation.setGeometry(205, 100, 120, 120)
        self.movie.start()
        self.labelAnimation.repaint()

        self.closeButton = funnyPushButton(self)
        self.closeButton.initPushButton(128, 128, self.width()-140,  self.height()-140, "closeButton", "", "Fermer", True, getThemeIcon("closeabout.png"), 128, 128, True, False)
        
        self.translateUi()
        self.closeButton.clicked.connect(self.reject)
        
    def unload(self) : self.movie.stop()

    def translateUi(self):
        self.setWindowTitle("%s - A propos ..." % self.parent.namePlugin)
        self.textEdit.setHtml("<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
        "p, li { white-space: pre-wrap; }\n"
        "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:8pt; font-weight:400; font-style:normal;\">\n"
        "<center><p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n"
        "<p style=\"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
        "<b>DDT de Corse-du-Sud, SMEP / UAT<br>M. MASSE Christophe</b>"
        "<br>version : %s <br><i>date de révision: %s</i><br>API Hubeau v2<br>API Open Meteo v1</p></center></body></html>" % (self.parent.version, self.parent.dateVersion) )

