-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathffloatwidget.py
214 lines (173 loc) · 6.43 KB
/
ffloatwidget.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from .fmoveablewidget import FMoveableWidget
from .ftitlebar import BaseToolButton, baseHeight
class FTitleBar(QFrame):
settingMenuShowed = Signal()
skinMenuShowed = Signal()
modeed = Signal(bool)
locked = Signal(bool)
pined = Signal(bool)
closed = Signal()
closestyle = '''
QToolButton#close{
background-color: transparent;
color: white;
}
QToolButton#close:hover{
background-color: red;
border: 1px;
}
'''
logostyle = '''
QToolButton#logo{
background-color: transparent;
}
QToolButton#logo:hover{
background-color: transparent;
}
'''
def __init__(self, parent=None):
super(FTitleBar, self).__init__(parent)
self.initData()
self.initUI()
def initData(self):
self.settingDownIcon = QIcon(":/icons/dark/appbar.control.down.png")
self.clothesIcon = QIcon(":/icons/dark/appbar.clothes.shirt.png")
self.lockIcon = QIcon(":/icons/dark/appbar.lock.png")
self.unlockIcon = QIcon(":/icons/dark/appbar.unlock.keyhole.png")
self.pinIcon = QIcon(":/icons/dark/appbar.pin.png")
self.unPinIcon = QIcon(":/icons/dark/appbar.pin.remove.png")
self.closeIcon = QIcon(":/icons/dark/appbar.close.png")
self.max_flag = False
self.lock_flag = False
self.pin_flag = False
def initUI(self):
self.setFixedHeight(baseHeight)
self.lockButton = BaseToolButton()
self.lockButton.setIcon(self.unlockIcon)
self.pinButton = BaseToolButton()
self.pinButton.setIcon(self.unPinIcon)
self.settingDownButton = BaseToolButton()
self.settingDownButton.setIcon(self.settingDownIcon)
self.closeButton = BaseToolButton()
self.closeButton.setObjectName("close")
self.closeButton.setStyleSheet(self.closestyle)
self.closeButton.setIcon(self.closeIcon)
mainLayout = QHBoxLayout()
mainLayout.addStretch()
mainLayout.addWidget(self.settingDownButton)
mainLayout.addWidget(self.pinButton)
mainLayout.addWidget(self.lockButton)
mainLayout.addWidget(self.closeButton)
mainLayout.setContentsMargins(0, 0, 5, 0)
mainLayout.setSpacing(0)
self.setLayout(mainLayout)
self.settingDownButton.clicked.connect(self.settingMenuShowed)
self.lockButton.clicked.connect(self.swithLockIcon)
self.pinButton.clicked.connect(self.swithPinIcon)
self.closeButton.clicked.connect(self.closed)
def swithLockIcon(self):
if self.lock_flag:
self.lockButton.setIcon(self.unlockIcon)
else:
self.lockButton.setIcon(self.lockIcon)
self.lock_flag = not self.lock_flag
self.locked.emit(self.lock_flag)
def swithPinIcon(self):
if self.pin_flag:
self.pinButton.setIcon(self.unPinIcon)
else:
self.pinButton.setIcon(self.pinIcon)
self.pin_flag = not self.pin_flag
self.pined.emit(self.pin_flag)
def isPined(self):
return self.pin_flag
def isLocked(self):
return self.lock_flag
def isMax(self):
return self.max_flag
class FFloatWidget(FMoveableWidget):
default_width = 300
def __init__(self, parent=None):
super(FFloatWidget, self).__init__()
self.parent = parent
self.setWindowFlags(
Qt.WindowType_Mask | Qt.SubWindow | Qt.FramelessWindowHint)
self._initShowAnimation()
self._initHideAnimation()
self._initUI()
self._initConnect()
def _initUI(self):
self.setFixedWidth(self.default_width)
self.titleBar = FTitleBar(self)
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.titleBar)
mainLayout.addStretch()
mainLayout.setSpacing(0)
mainLayout.setContentsMargins(0, 0, 0, 0)
self.setLayout(mainLayout)
self.setGeometry(self.endRect)
def _initConnect(self):
self.titleBar.closed.connect(self.animationHide)
self.titleBar.pined.connect(self.setFlags)
@property
def startRect(self):
mainwindow = self.parent
startRect = QRect(mainwindow.x() + mainwindow.width(),
mainwindow.y() + mainwindow.titleBar().height(),
self.w, mainwindow.height() -
mainwindow.titleBar().height())
return startRect
@property
def endRect(self):
mainwindow = self.parent
endRect = QRect(mainwindow.x() + mainwindow.width(),
mainwindow.y() + mainwindow.titleBar().height(),
self.w, mainwindow.height() -
mainwindow.titleBar().height())
return endRect
@property
def h(self):
return self.height()
@property
def w(self):
return self.width()
def _initShowAnimation(self):
self.showanimation = QPropertyAnimation(self, ('windowOpacity').encode('utf-8'))
self.showanimation.setStartValue(0)
self.showanimation.setEndValue(1)
self.showanimation.setDuration(1000)
self.showanimation.setEasingCurve(QEasingCurve.OutCubic)
def _initHideAnimation(self):
self.hideanimation = QPropertyAnimation(self, ('windowOpacity').encode('utf-8'))
self.hideanimation.setStartValue(1)
self.hideanimation.setEndValue(0)
self.hideanimation.setDuration(1000)
self.hideanimation.setEasingCurve(QEasingCurve.OutCubic)
self.hideanimation.finished.connect(self.hide)
def animationShow(self):
self.show()
self.showanimation.start()
def animationHide(self):
self.hideanimation.start()
def setFlags(self, flag):
if flag:
self.setWindowFlags(
Qt.WindowType_Mask | Qt.SubWindow |
Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
self.show()
else:
self.setWindowFlags(
Qt.WindowType_Mask | Qt.SubWindow | Qt.FramelessWindowHint)
self.show()
def mouseMoveEvent(self, event):
if self.isLocked():
pass
else:
super(FFloatWidget, self).mouseMoveEvent(event)
def isLocked(self):
return self.titleBar.isLocked()