#coding=utf-8
from PyQt4.QtCore import Qt,QString,SIGNAL
from PyQt4.Qt import QPalette,QColor, QDialog
from view.setting.settingview import Ui_Form

import controller.setting.centerset
import controller.setting.domainsettings
import controller.setting.personalizedsetting
import controller.setting.usbset
import controller.setting.wirednetwork
import controller.setting.wirelessnetwork
from common.logrecord import LogRecord
from common.globalfun import moveWidgetToScreenCenter
 
class Setting(QDialog,Ui_Form):
    def __init__(self):
        super(Setting,self).__init__()
        #--------------界面初始化-top
        LogRecord.instance().recordLog(u"初始化设置函数")
        self.setupUi(self)
        flags = Qt.FramelessWindowHint;
        self.setWindowFlags(flags);
        self.frame.setStyleSheet(QString("QWidget#frame{border-image: url(../images/setop.png);}"))
        self.frame.setAttribute(Qt.WA_TransparentForMouseEvents)
#         self.pushButtonQuit.setFlat(True)
        
        _centerSetC = controller.setting.centerset.CenterSet()
        _domainSettingsC = controller.setting.domainsettings.DomainSettings()
        _personalizedSettingC = controller.setting.personalizedsetting.PersonalizedSetting()
        _usbSetC = controller.setting.usbset.UsbSetT()
        _wiredNetworkC = controller.setting.wirednetwork.WiredNetwork()
        _wirelessNetworkC = controller.setting.wirelessnetwork.WirelessNetWork()
        self.tabWidget.addTab(_centerSetC, QString.fromUtf8("中心设置"))
        self.tabWidget.addTab(_wiredNetworkC, QString.fromUtf8("有线网络"))
        self.tabWidget.addTab(_wirelessNetworkC, QString.fromUtf8("无线网络"))
        self.tabWidget.addTab(_personalizedSettingC, QString.fromUtf8("个性化设置"))
        self.tabWidget.addTab(_domainSettingsC, QString.fromUtf8("域名设置"))
        self.tabWidget.addTab(_usbSetC, QString.fromUtf8("USB透传"))
        
        self.connect(_wiredNetworkC, SIGNAL("updateCenterSetNetCard"),_centerSetC.refreshComboNet)
        self.connect(_centerSetC, SIGNAL("updateCenter_Date"),self.updateCenterDate)
        self.connect(_personalizedSettingC, SIGNAL("setscreenover"),self.resetScreen)
        
        self.mousePressed = False
        self.setAutoFillBackground(True)
        palettle=QPalette()
        palettle.setColor(QPalette.Background,QColor(150,150,150))
        self.setPalette(palettle)
        self.setStyleSheet(QString("QWidget#Form{background-color:rgba(130, 130, 130,130);}"))
        self.connect(self.pushButtonQuit, SIGNAL("clicked()"),self.closeSelf)
        moveWidgetToScreenCenter(self)
        _centerSetC.pushButtonAdd.setFocus()
        self.setStyleSheet(QString("QComboBox{border:1px groove rgb(170,214,252);height:25;}"))
        
    def closeSelf(self):
        self.close()
        
    def resetScreen(self):
        print "发送中心更新信号"
        self.emit(SIGNAL("setscreenover"))
        
    def updateCenterDate(self):
        print "发送更新中心信号"
        self.emit(SIGNAL("updateCenterDateS"))

    def mouseMoveEvent(self,event):
        if self.mousePressed:
            self.move(self.pos() + event.pos() - self.currentPos)   
        self.default = QString()
    def mousePressEvent(self,event):
        if event.buttons() == Qt.LeftButton:
            self.currentPos = event.pos()
            self.mousePressed = True
    def mouseReleaseEvent(self,event):
        if event.buttons() == Qt.LeftButton:
            self.mousePressed = False
        #--------------界面初始化-end
        
        
        
        