# -*- coding: utf-8 -*-
"""
Copyright (c) 2016 Biuro Urządzania Lasu i Geodezji Leśnej

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.
"""

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QProgressBar
from qgis.core import *
class PasekWiadomosc():
    """Pasek wiadomości"""
    def __init__(self,iface,opis=''):
        
        self.iface=iface
        self.opis=opis
        
    def utworzPasekPostepu(self,opis='',minimum=0,maximum=100):
        """otwarcie paska postępu
        :param opis: opis
        :param minimum: minimalnawartośc
        :param maximum: maksymalna wartośc
        """
        opis=self.opis
        self.progressBar = QProgressBar()
        self.progressBar.setMinimum(minimum)
        self.progressBar.setMaximum(maximum)
        self.progressBar.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        
        self.messageBar = self.iface.messageBar()
        self.progressMessageBarItem = self.messageBar.createMessage(opis)    
        self.progressMessageBarItem.layout().addWidget(self.progressBar)
        self.iface.messageBar().pushWidget(self.progressMessageBarItem,Qgis.Info)
        
        return self.progressBar
    
    def pasekPostepu(self,opis=None,minimum=0,maximum=100):
        """otwarcie paska postępu"""
        if opis is None:
            opis=self.opis
        self.progressBar = QProgressBar()
        self.progressBar.setMinimum(minimum)
        self.progressBar.setMaximum(maximum)
        self.progressBar.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        
        self.messageBar = self.iface.messageBar()
        self.progressMessageBarItem = self.messageBar.createMessage(opis)    
        self.progressMessageBarItem.layout().addWidget(self.progressBar)
        self.iface.messageBar().pushWidget(self.progressMessageBarItem,Qgis.Info)
             
    def setProgressValue(self,value:int):
        """Ustawienie wartości postępu"""
        self.progressBar.setValue(value)
    
    def setText(self,text:str):
        """Ustawia tekst na pasku"""
        self.progressMessageBarItem.setText(text)
        
    def setTitle(self,text:str):
        """Ustawia tytuł na pasku"""
        self.progressMessageBarItem.SetTitle(text)
    
    def clear(self):
        """wyczyśc panel"""        
        self.iface.messageBar().clearWidgets()
        
    def setMaximum(self,maxval):
        """ustaw mak"""
        self.progressBar.setMaximum(maxval)

    def setMinimum(self,minval):
        """ustaw minimum"""
        self.progressBar.setMinimum(minval)
        
    def wiadomoscSukces(self,tytul,wiadomosc):
        """wiadomosc"""
        self.messageBar.pushSuccess(tytul,wiadomosc)
        
    def wiadomoscInfo(self,tytul,wiadomosc,level=0,duration=5):
        """wiadomosc"""
        self.messageBar.pushMessage(tytul,wiadomosc,level=level,duration=duration)
        
        