# -*- 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.
"""
import os
import Mapa_PU
from PyQt5 import QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import uic, QtWidgets

FORM_CLASS, _ = uic.loadUiType(os.path.join(os.path.dirname(__file__), 'informacja_dialog.ui'))

class InformacjaDialog(QtWidgets.QDialog,FORM_CLASS):
    """informacje o zarządcy"""
   
    def __init__(self,parent=None):
        """Constructor."""
        super(InformacjaDialog, self).__init__(parent)
        # Set up the user interface from Designer.
        # After setupUI you can access any designer object by doing
        # self.<objectname>, and you can use autoconnect slots - see
        # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
        # #widgets-and-dialogs-with-auto-connect
        
        self.setupUi(self)
        self.setGeometry(QRect(QPoint(300,300),QSize(600,200)))
        self.setWindowFlags( QtCore.Qt.WindowTitleHint )  
        self.setWindowIcon(QIcon('%s\\ikony\\Logo_BULiGL.ico' % Mapa_PU.upul_modul.root))
        
    def fillQDialog(self):
        """konfiguracja widoku"""
        #glowny layout:
        self.qgrid_main = QGridLayout(self)
        
        gbox_nadzor  = QGroupBox(u"Podmiot sprawujący nadzór nad lasami", alignment=QtCore.Qt.AlignTop)
        gbox_admin = QGroupBox(u"Organ administrujący, któremu powierzono nadzór nad lasami", alignment=QtCore.Qt.AlignTop)
        
        self.qgrid_main.addWidget(gbox_nadzor,0,0)
        self.qgrid_main.addWidget(gbox_admin,1,0)
        
        #----------------- nadzor ----------------# 
        self.qgrid_nadzor = QGridLayout(gbox_nadzor)
        
        self.qledit_nadzor_nazwa_organizacji = QLineEdit()
        self.qledit_nadzor_nazwa_organizacji.setObjectName("s_orgname")
        qhbox_nadzor_1 = QHBoxLayout()
        qhbox_nadzor_1.addWidget(QLabel("Nazwa organizacji:"))
        qhbox_nadzor_1.addWidget(self.qledit_nadzor_nazwa_organizacji)
        self.qgrid_nadzor.addLayout( qhbox_nadzor_1, 0, 0, 1, 0)
        
        self.qledit_nadzor_kraj = QLineEdit()
        self.qledit_nadzor_kraj.setObjectName("s_country")
        self.qgrid_nadzor.addWidget(QLabel("Kraj:    "),1,0,alignment=QtCore.Qt.AlignLeft)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_kraj,1,1)

        self.qledit_nadzor_kod_pocztowy = QLineEdit()
        self.qledit_nadzor_kod_pocztowy.setObjectName("s_code")
        self.qgrid_nadzor.addWidget(QLabel("Kod pocztowy:"),1,2,alignment=QtCore.Qt.AlignRight)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_kod_pocztowy,1,3)

        self.qledit_nadzor_miasto = QLineEdit()
        self.qledit_nadzor_miasto.setObjectName("s_city")
        self.qgrid_nadzor.addWidget(QLabel("Miasto:"),1,4,alignment=QtCore.Qt.AlignRight)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_miasto,1,5)
        
        self.qledit_nadzor_ulica = QLineEdit()
        self.qledit_nadzor_ulica.setObjectName("s_street")
        qhbox_nadzor_ulica = QHBoxLayout()
        qhbox_nadzor_ulica.addWidget(QLabel("Ulica:    "))
        qhbox_nadzor_ulica.addWidget(self.qledit_nadzor_ulica)
        self.qgrid_nadzor.addLayout(qhbox_nadzor_ulica, 2, 0, 1, 0 )
        
        self.qledit_nadzor_telefon = QLineEdit()
        self.qledit_nadzor_telefon.setObjectName("s_phone")
        self.qgrid_nadzor.addWidget(QLabel("Telefon:"),3,0,alignment=QtCore.Qt.AlignRight)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_telefon,3,1)

        self.qledit_nadzor_fax = QLineEdit()
        self.qledit_nadzor_fax.setObjectName("s_fax")
        self.qgrid_nadzor.addWidget(QLabel("Fax:"),3,2,alignment=QtCore.Qt.AlignRight)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_fax,3,3)        
    
        self.qledit_nadzor_email = QLineEdit()
        self.qledit_nadzor_email.setObjectName("s_email")
        self.qgrid_nadzor.addWidget(QLabel("email:"),3,4,alignment=QtCore.Qt.AlignRight)
        self.qgrid_nadzor.addWidget(self.qledit_nadzor_email,3,5)
        
        
        # ------------------- admin -------------------- #
        self.qgrid_admin = QGridLayout(gbox_admin)
        
        self.qledit_admin_nazwa_organizacji = QLineEdit()
        self.qledit_admin_nazwa_organizacji.setObjectName("ds_orgname")
        qhbox_admin_1 = QHBoxLayout()
        qhbox_admin_1.addWidget(QLabel("Nazwa organizacji:"))
        qhbox_admin_1.addWidget(self.qledit_admin_nazwa_organizacji)
        self.qgrid_admin.addLayout(qhbox_admin_1, 0, 0, 1, 0)
        
        self.qledit_admin_kraj = QLineEdit()
        self.qledit_admin_kraj.setObjectName("ds_country")
        self.qgrid_admin.addWidget(QLabel("Kraj:    "),1,0,alignment=QtCore.Qt.AlignLeft)
        self.qgrid_admin.addWidget(self.qledit_admin_kraj,1,1)

        self.qledit_admin_kod_pocztowy = QLineEdit()
        self.qledit_admin_kod_pocztowy.setObjectName("ds_code")
        self.qgrid_admin.addWidget(QLabel("Kod pocztowy:"),1,2,alignment=QtCore.Qt.AlignRight)
        self.qgrid_admin.addWidget(self.qledit_admin_kod_pocztowy,1,3)

        self.qledit_admin_miasto = QLineEdit()
        self.qledit_admin_miasto.setObjectName("ds_city")
        self.qgrid_admin.addWidget(QLabel("Miasto:"),1,4,alignment=QtCore.Qt.AlignRight)
        self.qgrid_admin.addWidget(self.qledit_admin_miasto,1,5)
        
        self.qledit_admin_ulica = QLineEdit()
        self.qledit_admin_ulica.setObjectName("ds_street")
        qhbox_admin_ulica = QHBoxLayout()
        qhbox_admin_ulica.addWidget(QLabel("Ulica:    "))
        qhbox_admin_ulica.addWidget(self.qledit_admin_ulica)
        self.qgrid_admin.addLayout(qhbox_admin_ulica, 2, 0, 1, 0 )
        
        self.qledit_admin_telefon = QLineEdit()
        self.qledit_admin_telefon.setObjectName("ds_phone")
        self.qgrid_admin.addWidget(QLabel("Telefon:"),3,0,alignment=QtCore.Qt.AlignRight)
        self.qgrid_admin.addWidget(self.qledit_admin_telefon,3,1)

        self.qledit_admin_fax = QLineEdit()
        self.qledit_admin_fax.setObjectName("ds_fax")
        self.qgrid_admin.addWidget(QLabel("Fax:"),3,2,alignment=QtCore.Qt.AlignRight)
        self.qgrid_admin.addWidget(self.qledit_admin_fax,3,3)        
    
        self.qledit_admin_email = QLineEdit()
        self.qledit_admin_email.setObjectName("ds_email")
        self.qgrid_admin.addWidget(QLabel("email:"),3,4,alignment=QtCore.Qt.AlignRight)
        self.qgrid_admin.addWidget(self.qledit_admin_email,3,5)
        
        self.qbox =  QDialogButtonBox()
        #pbutton_ok = self.qbox.addButton(self.qbox.Save)
        self.pbutton_ok = self.qbox.addButton("Zapisz",QDialogButtonBox.AcceptRole)
        #self.pbutton_ok.clicked.connect(self.test)
        self.qbox.accepted.connect(self.commit)
        self.qbox.accepted.connect(self.accept)
        #pbutton_ok.clicked.connect(self.accept)
        #pbutton_ok.clicked.connect(self.informacja.zapiszInformacje)
                        
        self.pbutton_cancel = self.qbox.addButton("Anuluj",QDialogButtonBox.RejectRole)
        self.pbutton_cancel.setDefault(True)        
        self.pbutton_cancel.setAutoDefault(True)
        self.pbutton_cancel.clicked.connect(self.reject)
        
        self.qgrid_main.addWidget(self.qbox, 2, 0, alignment=QtCore.Qt.AlignRight)
        
        # ograniczenie pola tekstowego do 255 znakow #.
        for child in self.findChildren(QLineEdit):
            child.setMaxLength(255)
    def commit(self):
        """
        Akceptacja opisu i wysanie do bazy zmian
        """
        self.informacja.zapiszInformacje()
                