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

from PyQt4.QtGui import QDialog,QDesktopWidget,QPainter,QColor
from PyQt4.QtCore import Qt,QString
from os import getenv
from common import common_run


from ui.ui_messageDialog import Ui_messageDialog

class MessageDialogQss (QDialog, Ui_messageDialog):

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

        self.setWindowFlags(Qt.CustomizeWindowHint | Qt.FramelessWindowHint| Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground,True) # 窗体透明

        # 确定 按钮样式
        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH')
        __button_size_height = common_run.SCREEN_HEIGHT * 31.5 / 900.0
        __button_size_with = common_run.SCREEN_WITH * 81.0 / 1440.0
        self.btn_ok.setMinimumHeight(int(__button_size_height))
        self.btn_ok.setMinimumWidth(int(__button_size_with))
        self.btn_ok.setText(u'确定')
        self.btn_ok.setFocusPolicy(Qt.NoFocus)
        self.btn_ok.setStyleSheet(
             QString("QPushButton{color: rgb(255,255,255);border-image: url(%1/settingWindow/btn_backgound1.png);border: 2px;}"
            "QPushButton:hover{border-image:url(%1/settingWindow/btn_backgound2.png);border: 2px;}"
            "QPushButton:pressed{border-image: url(%1/settingWindow/btn_backgound3.png);border: 2px;}").arg(str(self.__borderImagesPath))
        )

    def keyPressEvent(self,event):
        if (event.key() == Qt.Key_Enter) or (event.key() == Qt.Key_Return):
            self.btn_ok.click()

    def paintEvent(self, event):
        p = QPainter(self)
        p.setBrush(QColor(230,230,230,255))
        # p.drawRoundedRect(0,0,self.width() -1,self.height() -1,10,10)
        p.drawRect(-1,-1,self.width()+1,self.height()+1)

if __name__ == "__main__":
    from PyQt4 import QtGui
    from os import environ
    environ["WIN_UI_IMAGES_PATH"]="../../../images"
    app = QtGui.QApplication([])
    win = MessageDialogQss()
    win.show()
    app.exec_()
