-
Notifications
You must be signed in to change notification settings - Fork 0
/
paneltoprightcorner.py
138 lines (114 loc) · 4.59 KB
/
paneltoprightcorner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from PyQt5.QtCore import Qt, QRect, QSize, QPoint, pyqtSignal, QEvent
from PyQt5.QtGui import QPainter, QPalette, QPen
from PyQt5.QtWidgets import QWidget
__author__ = 'npatro'
class MOUSE_HOVER():
HOVER_NONE = 0
HOVER_VSPLIT = 1
HOVER_HSPLIT = 2
HOVER_FLOAT = 3
HOVER_CLOSE = 4
class PanelTopRightCorner(QWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
self.vSplitRect = QRect()
self.hSplitRect = QRect()
self.floatRect = QRect()
self.closeRect = QRect()
self.closeClicked = pyqtSignal()
self.floatClicked = pyqtSignal()
self.splitClicked = pyqtSignal()
self.mouseHoverState = MOUSE_HOVER.HOVER_NONE
self.mouseClickPos = QPoint()
self.setMouseTracking(True)
self.setAttribute(Qt.WA_Hover)
self.installEventFilter(self)
def minimumSizeHint(self):
w = 4
w += self.vSplitRect.width() + 6
w += self.hSplitRect.width() + 6
w += self.floatRect.width() + 6
w += self.closeRect.width() + 6
s = QSize(w, 22)
return s
def sizeHint(self):
return self.minimumSizeHint()
def mouseMoveEvent(self, event):
p = event.pos()
r = QRect()
if self.vSplitRect.contains(p):
self.mouseHoverState = MOUSE_HOVER.HOVER_VSPLIT
elif self.hSplitRect.contains(p):
self.mouseHoverState = MOUSE_HOVER.HOVER_HSPLIT
elif self.closeRect.contains(p):
self.mouseHoverState = MOUSE_HOVER.HOVER_CLOSE
elif self.floatRect.contains(p):
self.mouseHoverState = MOUSE_HOVER.HOVER_FLOAT
else:
self.mouseHoverState = MOUSE_HOVER.HOVER_NONE
self.repaint(r.adjusted(-1, -1, 1, 1))
def mousePressEvent(self, event):
self.mouseClickPos = event.pos()
if self.closeRect.contains(self.mouseClickPos):
self.closeClicked.emit()
elif self.floatRect.contains(self.mouseClickPos):
self.floatClicked.emit()
elif self.vSplitRect.contains(self.mouseClickPos):
self.splitClicked.emit(Qt.Vertical)
elif self.hSplitRect.contains(self.mouseClickPos):
self.splitClicked.emit(Qt.Horizontal)
self.mouseHoverState = MOUSE_HOVER.HOVER_NONE
def paintEvent(self, event):
painter = QPainter(self)
palette = self.palette()
midColor = palette.mid().color()
highlight = palette.highlight().color()
# background
painter.fillRect(self.rect(), midColor.lighter())
# float rect
color = highlight if self.mouseHoverState == MOUSE_HOVER.HOVER_FLOAT else midColor
painter.setPen(color)
painter.setBrush(palette.light())
painter.drawRect(self.floatRect)
painter.setBrush(highlight if color == highlight else midColor)
painter.drawRect(self.floatRect.adjusted(4, 2, -2, -4))
# hsplit rect
color = highlight if self.mouseHoverState == MOUSE_HOVER.HOVER_HSPLIT else midColor
painter.setPen(color)
painter.setBrush(palette.light())
painter.drawRect(self.hSplitRect)
painter.setBrush(highlight if color == highlight else midColor)
painter.drawRect(self.hSplitRect.adjusted(2, 2, -6, -2))
# float rect
color = highlight if self.mouseHoverState == MOUSE_HOVER.HOVER_VSPLIT else midColor
painter.setPen(color)
painter.setBrush(palette.light())
painter.drawRect(self.vSplitRect)
painter.setBrush(highlight if color == highlight else midColor)
painter.drawRect(self.vSplitRect.adjusted(2, 2, -2, -6))
# float rect
color = highlight if self.mouseHoverState == MOUSE_HOVER.HOVER_CLOSE else midColor
painter.setPen(color)
painter.setBrush(palette.light())
painter.drawRect(self.closeRect)
painter.translate(self.closeRect.topLeft())
painter.setPen(QPen(color, 1.5))
painter.drawLine(QPoint(4, 4), QPoint(9, 9))
painter.drawLine(QPoint(4, 9), QPoint(9, 4))
painter.resetTransform()
def resizeEvent(self, event):
w = self.width()
self.hSplitRect = QRect(w-72, 4, 12, 12)
self.vSplitRect = QRect(w-54, 4, 12, 12)
self.floatRect = QRect(w-36, 4, 12, 12)
self.closeRect = QRect(w-18, 4, 12, 12)
def eventFilter(self, obj, event):
if event.type() == QEvent.HoverLeave:
self.mouseHoverState = MOUSE_HOVER.HOVER_NONE
self.repaint(self.rect())
return True
return False
def main():
pass
if __name__ == '__main__':
main()