#coding:utf-8
from PyQt4.QtGui import QWidget,QDialog,QMovie,QLabel,QColor,QFontMetrics,QApplication,QHBoxLayout,QFont,QPushButton,QPainter,QPixmap,QVBoxLayout,QPainter,QBrush,QPen,QLinearGradient
from PyQt4.QtCore import Qt,SIGNAL,QRect,QPoint

class WaitingWidget(QWidget):
    def __init__(self,parent=None):
        super(WaitingWidget,self).__init__(parent)
        
        self.setFixedSize(350,200)
        self.setWindowFlags(Qt.FramelessWindowHint|Qt.Dialog)
        self.setWindowModality(Qt.ApplicationModal)
        self.setWindowTitle(u"请稍候")
        self.title = u"请稍候..."
        
        self.tip = ""
#         moveToCenter.moveWidgetToScreenCenter()
        
    
        
    def setTip(self,text):
        self.tip = text
        
    def paintEvent(self,event):
        titleHeight = 30
        bottomHeight = 30
        #画标题背景
        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.tip)
        painter.drawText(QPoint((self.width() - infoWidth - 10)/2, self.height()/2), self.tip)
        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()
        
        #self.title.move(QPoint(5,5))

"""
app = QApplication(sys.argv)
ex = WaitingWidget()
ex.setTip("text")
ex.show()
app.exec_()
"""
