#coding:utf-8

from PyQt4.QtCore import Qt, SIGNAL, QRect, QPoint,QSize
from PyQt4.QtGui import  QPainter, QBrush, QColor, QPushButton, QPen, QLinearGradient, QFontMetrics,QIcon
from model.setting.base.basedialog import BaseDialog
class InfoHintDialog(BaseDialog):
        
    def __init__(self, hintInfo, parent = None):
        super(InfoHintDialog,self).__init__(parent)
        self.setWindowTitle(u'提示信息')
        self.setWindowFlags(Qt.Dialog|Qt.FramelessWindowHint)
        self.setWindowModality(Qt.ApplicationModal)
        self.setFixedSize(350, 200)
        #self.setStyleSheet("QPushButton{background:url(images/button.png);font-size: 12pt;}")
                           
        self.setStyleSheet("QPushButton{color:black; font: 10pt; border:1px;background:url(images/button.png);}")
        
        self.okBtn = QPushButton(u'确  定', self)
        self.okBtn.setFixedSize(75,27)
        
        self.okBtn.setFlat(True)
        self.setTitle(u'提示信息')
        
        self.hintInfo = hintInfo
        
        self.okBtn.move((self.width() - self.okBtn.width())/2, self.height() - self.okBtn.height() - 10)
        
        self.connect(self.okBtn, SIGNAL("clicked()"),self.slotOk)
        
    def slotOk(self):
        self.accept()
        
    def setTitle(self, title):
        self.title = title
        
    def setHintInfo(self, hintInfo):
        self.hintInfo = hintInfo
        self.update()
        
    def paintEvent(self,event):
        titleHeight = 30
        bottomHeight = 2
        
        #画标题背景
        painter = QPainter(self)
        painter.save()
        linearGradient = QLinearGradient(0, 0,0,titleHeight)
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.1, QColor(6,88,200))
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        contenRect = QRect(0, 0, self.width(), titleHeight)
        painter.fillRect(contenRect, QBrush(linearGradient))
        painter.restore()
        
        #画标题内容
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        font = painter.font()
        font.setPointSize(12)
        painter.setFont(font)
        painter.drawText(QPoint(10,20), self.title)
        painter.restore()
        
        #画中间白色背景
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        brush = QBrush(QColor(242,242,242))
        painter.setBrush(brush)
        contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight)
#         painter.fillRect(contenRect, brush)
        painter.drawRect(contenRect)
        painter.restore()
        
        #画提示信息内容
        painter.save()
        painter.setPen(QPen(QColor(1, 1, 1),1))
        font = painter.font()
        font.setPointSize(10)
        painter.setFont(font)
        fm = QFontMetrics(font)
        infoWidth = fm.width(self.hintInfo)
        painter.drawText(QPoint((self.width() - infoWidth - 10)/2, self.height()/2), self.hintInfo)
        painter.restore()
        
        #画底层背景
        painter.save()
        brush = QBrush(QColor(219,234,255))
        painter.setBrush(brush)
        contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight)
        painter.fillRect(contenRect, brush)
        painter.restore()
        
        
        
        
        