1
1
2
+ import os
2
3
from .ec_handler import Handler
3
4
from PySide6 .QtWidgets import (
4
5
QDialog ,
11
12
QSizePolicy ,
12
13
QGraphicsDropShadowEffect
13
14
)
14
- from PySide6 .QtGui import QFont , QIcon
15
- from PySide6 .QtCore import Qt , QTimer
15
+ from PySide6 .QtGui import QFont , QIcon , QPixmap , QPainter , QColor
16
+ from PySide6 .QtCore import Qt , QTimer , Signal , QRect
16
17
17
18
class Keyboard (Handler ):
18
-
19
+ iconClicked = Signal ()
20
+
21
+ class Border (QWidget ):
22
+ iconClicked = Signal ()
23
+
24
+ def __init__ (self ):
25
+ super ().__init__ ()
26
+ self .setFixedHeight (25 )
27
+ self ._drag_active = False
28
+ self ._drag_start_pos = None
29
+
30
+ def paintEvent (self , event ):
31
+ painter = QPainter (self )
32
+ painter .setRenderHint (QPainter .Antialiasing )
33
+ # Draw the close icon
34
+ self .pixmap = QPixmap (f'{ os .path .dirname (os .path .abspath (__file__ ))} /close.png' ).scaled (25 , 25 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
35
+ x = self .width () - self .pixmap .width ()
36
+ y = 0
37
+ painter .drawPixmap (x , y , self .pixmap )
38
+
39
+ # Draw the drag bar in the center
40
+ bar_width = 100
41
+ bar_height = 20
42
+ bar_x = (self .width () - bar_width ) // 2
43
+ bar_y = (self .height () - bar_height ) // 2
44
+ painter .setBrush (QColor ("#bbb" ))
45
+ painter .setPen (Qt .NoPen )
46
+ painter .drawRoundedRect (bar_x , bar_y , bar_width , bar_height , 10 , 10 )
47
+
48
+ def mousePressEvent (self , event ):
49
+ x = self .width () - self .pixmap .width ()
50
+ y = 0
51
+ icon_rect = self .pixmap .rect ().translated (x , y )
52
+ if icon_rect .contains (event .pos ()):
53
+ self .iconClicked .emit ()
54
+ elif self ._bar_rect ().contains (event .pos ()):
55
+ self ._drag_active = True
56
+ self ._drag_start_pos = event .globalPosition ().toPoint ()
57
+ self ._dialog_start_pos = self .window ().pos ()
58
+ else :
59
+ super ().mousePressEvent (event )
60
+
61
+ def mouseMoveEvent (self , event ):
62
+ if self ._drag_active :
63
+ delta = event .globalPosition ().toPoint () - self ._drag_start_pos
64
+ self .window ().move (self ._dialog_start_pos + delta )
65
+ else :
66
+ super ().mouseMoveEvent (event )
67
+
68
+ def mouseReleaseEvent (self , event ):
69
+ self ._drag_active = False
70
+ super ().mouseReleaseEvent (event )
71
+
72
+ def _bar_rect (self ):
73
+ bar_width = 100
74
+ bar_height = 20
75
+ bar_x = (self .width () - bar_width ) // 2
76
+ bar_y = (self .height () - bar_height ) // 2
77
+ return QRect (bar_x , bar_y , bar_width , bar_height )
78
+
19
79
def __init__ (self , program , receiver , parent = None ):
20
80
Handler .__init__ (self , program .compiler )
21
81
@@ -38,6 +98,10 @@ def __init__(self, program, receiver, parent=None):
38
98
39
99
# Add the keyboard
40
100
layout = QVBoxLayout (dialog )
101
+
102
+ border = self .Border ()
103
+ border .iconClicked .connect (dialog .reject )
104
+ layout .addWidget (border )
41
105
layout .addWidget (VirtualKeyboard (42 , receiver , dialog .reject ))
42
106
43
107
# Position at bottom of parent window
0 commit comments