#!/usr/bin/python
#coding=utf8

from PyQt4.QtGui import QDialog,QDesktopWidget, QPainter, QColor
from PyQt4.QtCore import Qt, QString
from ui.ui_changePassword import Ui_Form
from common import common_run

class ChangePasswordQss (QDialog, Ui_Form):

    def __init__(self, parent=None):
        super(ChangePasswordQss, self).__init__(parent)

        self.setupUi(self)
        self.setModal(True)
        self.setWindowFlags( Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint |  Qt.Widget)# 无标题栏 | 置top

        # 使窗口位于屏幕 中央
        screen = QDesktopWidget().screenGeometry()
        self.move((screen.width() - self.width() ) / 2,(screen.height() - self.height()) / 2)
        self.__set_stylesheet()

    def __set_stylesheet(self):

        from os import getenv
        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH')
        self.horizontalLayout_4.setContentsMargins(int(common_run.get_width(15.0)),
                                                   0,
                                                   int(common_run.get_width(15.0)),
                                                   0)
        self.horizontalLayout_5.setContentsMargins(int(common_run.get_width(15.0)),
                                                   0,
                                                   int(common_run.get_width(15.0)),
                                                   0)
        self.horizontalLayout_5.setSpacing(int(common_run.get_width(15.0)))

        self.setMaximumHeight(common_run.get_height(350.0))
        self.setMinimumHeight(common_run.get_height(350.0))
        self.setMaximumWidth(common_run.get_width(560.0))
        self.setMinimumWidth(common_run.get_width(560.0))
        __button_size_height = common_run.get_height(38.0)
        __button_size_with = common_run.get_width(98.0)
        self.btn_cancel.setMinimumHeight(int(__button_size_height))
        self.btn_cancel.setMinimumWidth(int(__button_size_with))
        self.btn_cancel.setMaximumHeight(int(__button_size_height))
        self.btn_cancel.setMaximumWidth(int(__button_size_with))
        self.btn_ok.setMinimumHeight(int(__button_size_height))
        self.btn_ok.setMinimumWidth(int(__button_size_with))
        self.btn_ok.setMaximumHeight(int(__button_size_height))
        self.btn_ok.setMaximumWidth(int(__button_size_with))
        self.btn_close.setMinimumHeight(int(common_run.get_width(29.0)))
        self.btn_close.setMinimumWidth(int(common_run.get_width(21.0)))
        self.btn_close.setMaximumHeight(int(common_run.get_width(29.0)))
        self.btn_close.setMaximumWidth(int(common_run.get_width(21.0)))
        self.label.setMinimumWidth(int(common_run.get_width(80.0)))
        self.label.setMaximumWidth(int(common_run.get_width(80.0)))
        self.label_2.setMinimumWidth(int(common_run.get_width(80.0)))
        self.label_2.setMaximumWidth(int(common_run.get_width(80.0)))
        self.label_3.setMinimumWidth(int(common_run.get_width(80.0)))
        self.label_3.setMaximumWidth(int(common_run.get_width(80.0)))
        self.lineEdit_newPasswd_1.setMinimumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_newPasswd_1.setMaximumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_newPasswd_1.setMinimumHeight(int(common_run.get_height(30.0)))
        self.lineEdit_newPasswd_1.setMaximumHeight(int(common_run.get_height(30.0)))
        self.lineEdit_newPasswd_2.setMinimumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_newPasswd_2.setMaximumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_newPasswd_2.setMinimumHeight(int(common_run.get_height(30.0)))
        self.lineEdit_newPasswd_2.setMaximumHeight(int(common_run.get_height(30.0)))
        self.lineEdit_oldPasswd.setMinimumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_oldPasswd.setMaximumWidth(int(common_run.get_width(300.0)))
        self.lineEdit_oldPasswd.setMinimumHeight(int(common_run.get_height(30.0)))
        self.lineEdit_oldPasswd.setMaximumHeight(int(common_run.get_height(30.0)))
        self.horizontalLayout.setSpacing(int(common_run.get_width(30.0)))
        self.horizontalLayout_2.setSpacing(int(common_run.get_width(30.0)))
        self.horizontalLayout_3.setSpacing(int(common_run.get_width(30.0)))

        self.verticalLayout_2.setContentsMargins(int(common_run.get_width(50.0)),
                                                 0,
                                                 int(common_run.get_width(150.0)),
                                                 0)
        self.verticalLayout_2.setSpacing(int(common_run.get_height(15.0)))

        __font_size = str(int(common_run.get_width(14.0)))
        self.setStyleSheet("QWidget{background-color: rgba(9, 26, 35,0)}"
                           "QLabel{font: 63 "+__font_size+"pt \"ubuntu\" }"
                           "QLineEdit{border:1px groove rgb(200,200,200);}")

        __font_size = str(int((14.0/1440.0)*common_run.SCREEN_WITH))
        self.label_4.setStyleSheet("font: "+__font_size+"pt \"Sans Serif\";")
        self.widget_top.setStyleSheet("QWidget#widget_top{background-color:rgba(255, 255, 255,0)}")
        self.widget_bto.setStyleSheet("QWidget#widget_bto{background-color:rgba(255, 255, 255,0)}")

        self.btn_close.setFocusPolicy(Qt.NoFocus)
        self.btn_close.setStyleSheet(QString("border-image: url(%1/settingWindow/close.png);"
                                             "border: 2px;").arg(self.__borderImagesPath))

        # 确定 按钮样式
        self.btn_ok.setFocusPolicy(Qt.NoFocus)
        self.btn_ok.setStyleSheet(
             QString(
             "QPushButton{font: 63 12pt \"Ubuntu\"; color: rgb(255, 255, 255);}"
             "QPushButton{border-image: url(%1/btn_border.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/btn_hover.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/btn_press.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )
        self.btn_ok.setText(QString.fromUtf8("确定"))
        # 取消 按钮样式
        self.btn_cancel.setFocusPolicy(Qt.NoFocus)
        self.btn_cancel.setStyleSheet(
             QString(
            "QPushButton{font: 63 12pt \"Ubuntu\"; color: rgb(255, 255, 255);}"
            "QPushButton{border-image: url(%1/btn_border.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/btn_hover.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/btn_press.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )
        self.btn_cancel.setText(QString.fromUtf8("取消"))

    def paintEvent(self, event):
        p = QPainter(self)
        p.setBrush(QColor(230,230,230,255))
        p.setPen(Qt.black)
        __r = int((10.0/1440.0)*common_run.SCREEN_WITH)
        p.drawRoundedRect(-1,-1,self.width() +1,self.height() +1,0,0)

    def mousePressEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.currentPos = event.pos()
            self.mousePressed = True

    def mouseReleaseEvent(self, event):
        self.mousePressed = False

    def mouseMoveEvent(self, event):
        if self.mousePressed:
            self.move(self.pos() + event.pos() - self.currentPos)
        # self.default = QString()

if __name__ == "__main__":
    from PyQt4 import QtGui
    from os import environ, getenv

    environ["WIN_UI_IMAGES_PATH"]="../../../images"
    app = QtGui.QApplication([])
    win = ChangePasswordQss()
    win.show()
    app.exec_()
