프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / TextInfo.py @ f145d925

이력 | 보기 | 이력해설 | 다운로드 (2.28 KB)

1 8744138e humkyung
# coding: utf-8
2 4d4b604e humkyung
from PyQt5.QtCore import *
3
4 8744138e humkyung
5
class TextInfo:
6 d86f328a 김정우
    def __init__(self, text, x, y, w, h, angle):
7 f5002159 esham21
        self._text = TextInfo.text_filter(text)
8 4d4b604e humkyung
        self.text_area = QRect(x, y, w, h)
9
        """
10 dd360120 김정우
        self.x = x
11
        self.y = y
12
        self.w = w
13
        self.h = h
14 4d4b604e humkyung
        """
15 d86f328a 김정우
        self.angle = angle
16 dd360120 김정우
17 d6518150 humkyung
    @property
18 8b804ab7 esham21
    def area(self):
19 8744138e humkyung
        """ return area of area """
20 4d4b604e humkyung
        return self.text_area.width() * self.text_area.height()
21 8b804ab7 esham21
22
    def contains(self, pt):
23
        if len(pt) == 2:
24 4d4b604e humkyung
            """
25 8b804ab7 esham21
            if pt[0] < self.x: return False
26
            if pt[0] > self.x + self.w: return False
27
            if pt[1] < self.y: return False
28
            if pt[1] > self.y + self.h: return False
29 4d4b604e humkyung
            """
30
            return self.text_area.contains(pt[0], pt[1])
31 8b804ab7 esham21
        elif len(pt) == 4:
32 4d4b604e humkyung
            """
33 8b804ab7 esham21
            minx = pt[0]
34
            miny = pt[1]
35
            maxx = pt[2]
36
            maxy = pt[3]
37

38
            if minx < self.x: return False
39
            if maxx > self.x + self.w: return False
40
            if miny < self.y: return False
41
            if maxy > self.y + self.h: return False
42 4d4b604e humkyung
            """
43
            return self.text_area.contains(QRect(pt[0], pt[1], pt[2] - pt[0], pt[3] - pt[1]))
44 8b804ab7 esham21
45 4d4b604e humkyung
        return False
46 8b804ab7 esham21
47
    @property
48 d6518150 humkyung
    def center(self):
49 8744138e humkyung
        """ return center of text """
50 4d4b604e humkyung
        return self.text_area.center().x(), self.text_area.center().y()
51 d6518150 humkyung
52 dd360120 김정우
    def setText(self, text):
53 d2c68320 humkyung
        self._text = text
54 dd360120 김정우
55
    def getText(self):
56 d2c68320 humkyung
        return self._text
57 dd360120 김정우
58
    def setX(self, x):
59 4d4b604e humkyung
        self.text_area.moveLeft(x)
60 dd360120 김정우
61
    def getX(self):
62 4d4b604e humkyung
        return int(self.text_area.x())
63 dd360120 김정우
64
    def setY(self, y):
65 4d4b604e humkyung
        self.text_area.moveTop(y)
66 dd360120 김정우
67
    def getY(self):
68 4d4b604e humkyung
        return int(self.text_area.y())
69 dd360120 김정우
70
    def setW(self, w):
71 4d4b604e humkyung
        self.text_area.setWidth(w)
72 dd360120 김정우
73
    def getW(self):
74 4d4b604e humkyung
        return int(self.text_area.width())
75 dd360120 김정우
76
    def setH(self, h):
77 4d4b604e humkyung
        self.text_area.setHeight(h)
78 dd360120 김정우
79
    def getH(self):
80 4d4b604e humkyung
        return int(self.text_area.height())
81 d86f328a 김정우
82
    def setAngle(self, angle):
83
        self.angle = angle
84
85
    def getAngle(self):
86 8744138e humkyung
        return self.angle
87 3c2b570d esham21
    
88 f5002159 esham21
    staticmethod
89
    def text_filter(text):
90 3c2b570d esham21
        """ fix input text """
91 dee3eade esham21
        text = text.replace('', '-').replace('--', '-').replace('', '"').replace(r'%%C', 'Ø').replace(r'%%%', '%')
92 3c2b570d esham21
        return text
클립보드 이미지 추가 (최대 크기: 500 MB)