#coding:utf-8
'''
Created on Oct 14, 2014

@author: root
'''

from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.QtGui import QVBoxLayout, QLabel, QGridLayout, QLineEdit, QPushButton, QHBoxLayout

from base.infohintdialog import InfoHintDialog


class EditDialog(InfoHintDialog):
    def __init__(self, hintInfo="", parent = None):
        InfoHintDialog.__init__(self, hintInfo, parent)
        self.setWindowTitle(u'编辑域名')
        self.setFixedSize(450,350)
        self.setStyleSheet("QWidget{font-size : 10pt;}"
                           "QLineEdit{border:1px groove rgb(170,214,252);}"
                           "QLineEdit{height:25;}"
                           "QComboBox{border: 1px groove rgb(170,214,252);}"
                           "QComboBox{height:25;}"
                           "QComboBox::drop-down{border-bottom-right-radius: 3px;}"
                           "QComboBox::drop-down{subcontrol-origin: padding;}"
                           "QComboBox::drop-down{subcontrol-position: top right;}"
                           "QComboBox::drop-down{width: 20px;}"
                           "QComboBox::drop-down{border-left-width: 1px;}"
                           "QComboBox::drop-down{border-left-color: rgb(170,214,252);}"
                           "QComboBox::drop-down{border-left-style: solid;}"
                           "QComboBox::drop-down{border-top-right-radius: 3px;}"
                           "QComboBox::down-arrow {image:url(../images/s2_r8_c10.gif);}"
                           "QPushButton{background:url(../images/button.png);border:2px;}")
        self.setTitle(u'编辑域名')
       
        self.setWindowFlags(Qt.Dialog|Qt.FramelessWindowHint)
        self.setWindowModality(Qt.ApplicationModal)
        self.labelName = QLabel(u"域名:")
        #self.labelName.setAlignment()
        self.lineEditName = QLineEdit()
        self.lineEditName.setFixedWidth(200)
        self.labelIp = QLabel(u"IP地址：")

        self.lineEditIp = QLineEdit(self)
        self.oip = self.lineEditIp.text()
        self.lineEditIp.setFixedWidth(200)
        
        self.saveBtn = QPushButton(u'保存')
        self.saveBtn.setFixedSize(75,27)
        self.saveBtn.setFlat(True)
        self.cancelBtn = QPushButton(u'取消')
        self.cancelBtn.setFixedSize(75,27)
        self.cancelBtn.setFlat(True)
        
        miniLayout = QGridLayout()
        miniLayout.setSpacing(20)
        miniLayout.addWidget(self.labelName,0,0)
        miniLayout.addWidget(self.lineEditName,0,1)
        miniLayout.addWidget(self.labelIp,2,0)
        miniLayout.addWidget(self.lineEditIp,2,1)
        
        btnLayout = QHBoxLayout()
        btnLayout.addWidget(self.saveBtn)
        btnLayout.addSpacing(50)
        btnLayout.addWidget(self.cancelBtn)
        
        vLayout = QVBoxLayout()
        vLayout.addSpacing(90)
        vLayout.addLayout(miniLayout)
        vLayout.addSpacing(60)
        vLayout.addLayout(btnLayout)
        
        self.mainlayout = QHBoxLayout(self)
        self.mainlayout.addSpacing(70)
        self.mainlayout.addLayout(vLayout)
        self.mainlayout.addSpacing(70)
        
       
        
        self.okBtn.hide()
        
        self.connect(self.saveBtn, SIGNAL("clicked()"),self.slotSave)
        self.connect(self.cancelBtn, SIGNAL("clicked()"),self.slotCancel)
    def setHostInfo(self,info):
        self.lineEditIp.setText(info["hostip"])
        self.lineEditName.setText(info["hostdes"])
        
    def slotSave(self):
        name = self.lineEditName.text().trimmed()
        ip = self.lineEditIp.text().trimmed()
     
        self.emit(SIGNAL("edithostover"),name,ip)
       
    def slotCancel(self):
        self.close()
        