#coding:utf-8
from os import getenv

from PyQt4.QtCore import Qt, QString
from PyQt4.QtGui import QDialog, QWidget, QApplication, QPixmap, QPalette, QBrush


class BaseDialog(QWidget):
    def __init__(self,parent = None):
        super(BaseDialog,self).__init__(parent)
        # self.setWindowFlags(Qt.Dialog|Qt.FramelessWindowHint|Qt.WindowStaysOnBottomHint)
        self.setWindowFlags(Qt.Dialog|Qt.FramelessWindowHint)
        self.setWindowModality(Qt.ApplicationModal)

        self.__borderImagesPath = getenv('WIN_UI_IMAGES_PATH')
        jpeg = QPixmap(self.__borderImagesPath + "/winVirturlList/background_down.png").scaled(self.size())  # scaled适应窗口大小
        palette1 = QPalette(self)
        palette1.setBrush(self.backgroundRole(), QBrush(jpeg))
        self.setPalette(palette1)
        self.mousePressed = False


    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()
