#coding:utf-8
from PyQt4 import QtCore
from PyQt4 import QtGui

from AppFloatTop import AppFloatTop
from AppFloatBottom import AppFloatBottom
from AppActivScrollArea import AppActivScrollArea
from logger.logrecord import LogRecord


class AppFloatLabel(QtGui.QLabel):
    """

    """
    def __init__(self,parent=None,left=0,top=0):
        QtGui.QLabel.__init__(self,parent)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
        self.__parentHeight=parent.geometry().height()
        # print 'scroll pannel'+str(self.__parentHeight)
        self.__width=300
        self.__height=44
        self.__topHeight=34
        self.__bottomHeight=10
        self.setGeometry(left,top,self.__width,self.__height)
        self.setStyleSheet("QLabel{background-color: rgb(9,26,35);}")
        # self.setStyleSheet("QLabel{background:transparent;}")
        self.floatTop=None
        self.activScrollArea=None
        self.floatBottom=None
        # self.setStyleSheet("QLabel{border-image: url(VirtApp/images/ItembottomM.png);background:transparent;}")
        self.hide()
        self.alterSignal=QtCore.pyqtSignal()
        self.connect(self,QtCore.SIGNAL('alterSignal'),parent,QtCore.SIGNAL('alterSignal'))
    @QtCore.pyqtSlot()
    def showActivities(self,activDic={},left=0,top=0):
        self.activDic=activDic
        if self.floatTop != None:
            self.floatTop.close()

        if self.activScrollArea != None:
            self.activScrollArea.close()

        if self.floatBottom != None:
            self.floatBottom.close()

        self.floatTop=AppFloatTop(self,height=self.__topHeight)
        l=self.floatTop.geometry().height()
        self.activScrollArea=AppActivScrollArea(self,self.activDic,l)
        l+=self.activScrollArea.geometry().height()
        self.floatBottom=AppFloatBottom(self,top=l,height=self.__bottomHeight)
        l+=self.floatBottom.geometry().height()
        if left < 0:
            left+=self.__width+43
        if top+l > self.__parentHeight:
            top = self.__parentHeight - l
        self.setGeometry(left,top,self.__width,l)
        #设置圆角
        rect=QtCore.QRectF(0,0,self.geometry().width(),self.geometry().height())
        path=QtGui.QPainterPath()
        path.addRoundRect(rect,10)
        polygon= path.toFillPolygon().toPolygon()
        region=QtGui.QRegion(polygon)
        self.setMask(region)

        self.show()
    # @QtCore.pyqtSlot()
    def hideFloatLabel(self):
        self.hide()

    def closeAll(self):
        """
        关闭所有打开的应用窗口
        :return:
        """
        for k in self.activDic.keys():
            LogRecord.instance().logger.debug("关闭所有窗口")
            self.emit(QtCore.SIGNAL('alterSignal'),k,'close')

