-
Notifications
You must be signed in to change notification settings - Fork 11
/
toolproperties.py
233 lines (165 loc) · 6.2 KB
/
toolproperties.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python
#coding: utf-8
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import Qt
import names as Pixeler
class SizeLabel (QtWidgets.QLabel):
def setValue(self, value):
self.setText(str(value))
class ToolProperties (QtWidgets.QDockWidget):
def __init__(self, title, context, signals, Parent=None):
super(ToolProperties, self).__init__(title, Parent)
self.context = context
self.signals = signals
self.parent = Parent
self.setAllowedAreas(Qt.RightDockWidgetArea)
self.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures)
# Llista de widgets (configuració de cada eina del programa)
self.widgets = self.createWidgets()
self.signals.updateTool.connect(self.updateWidget)
self.updateWidget()
def createWidgets(self):
# Creem una llista amb tots el widgets i la retornem
l = []
l.append(self.createSelectionWidget())
l.append(QtWidgets.QWidget())
l.append(self.createPencilWidget())
l.append(self.createEraserWidget())
l.append(QtWidgets.QWidget())
l.append(QtWidgets.QWidget())
l.append(self.createGradientWidget())
l.append(QtWidgets.QWidget())
return l
def createSelectionWidget(self):
w = QtWidgets.QWidget()
w.setObjectName("ToolProperties")
w.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
vbox = QtWidgets.QVBoxLayout()
transparent = QtWidgets.QCheckBox(self.context.getText("tool_properties_selection", "transparent"), self)
transparent.setChecked(self.context.transparentSelection)
transparent.toggled.connect(self.context.setTransparentSelection)
vbox.setAlignment(QtCore.Qt.AlignTop)
vbox.addWidget(transparent)
w.setLayout(vbox)
return w
def createPencilWidget(self):
w = QtWidgets.QWidget()
w.setObjectName("ToolProperties")
w.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
vbox = QtWidgets.QVBoxLayout()
hbox1 = QtWidgets.QHBoxLayout()
pencilSizeLabel = QtWidgets.QLabel(self.context.getText("tool_properties_pencil", "size"))
slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
slider.setValue(self.context.pencilSize)
self.pencilSize = SizeLabel(str(self.context.pencilSize))
slider.setMaximum(9)
slider.setMinimum(1)
slider.setPageStep(1)
slider.setValue(self.context.pencilSize)
slider.valueChanged.connect(self.context.setPencilSize)
slider.valueChanged.connect(self.pencilSize.setValue)
self.signals.updatePencilSize.connect(slider.setValue)
hbox1.addWidget(pencilSizeLabel)
hbox1.addWidget(slider)
hbox1.addWidget(self.pencilSize)
"""
hbox2 = QtWidgets.QHBoxLayout()
hbox2.addWidget(QtWidgets.QLabel("Alpha:"))
alpha = QtWidgets.QSpinBox()
alpha.setMinimum(0)
alpha.setMaximum(255)
alpha.setValue(255)
alpha.valueChanged.connect(self.setPencilAlpha)
alpha.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
hbox2.addWidget(alpha)
"""
hbox2 = QtWidgets.QHBoxLayout()
eraser = QtWidgets.QCheckBox(self.context.getText("tool_properties_pencil", "eraser"), self)
eraser.setChecked(self.context.secondaryColorEraser)
eraser.toggled.connect(self.toggleSecondaryColorEraser)
hbox2.addWidget(eraser)
vbox.setAlignment(QtCore.Qt.AlignTop)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
w.setLayout(vbox)
return w
def setPencilSize(self, size):
self.pencilSize.setText(str(size))
self.context.pencilSize = size
def setPencilAlpha(self, alpha):
self.context.pencilAlpha = alpha
def toggleSecondaryColorEraser(self):
self.context.secondaryColorEraser = not self.context.secondaryColorEraser
def createEraserWidget(self):
w = QtWidgets.QWidget()
w.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
vbox = QtWidgets.QVBoxLayout()
hbox = QtWidgets.QHBoxLayout()
eraserSizeLabel = QtWidgets.QLabel(self.context.getText("tool_properties_eraser", "size"))
slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
slider.setValue(self.context.eraserSize)
self.eraserSize = SizeLabel(str(self.context.eraserSize))
slider.setMaximum(9)
slider.setMinimum(1)
slider.setPageStep(1)
slider.setValue(self.context.eraserSize)
slider.valueChanged.connect(self.context.setEraserSize)
slider.valueChanged.connect(self.eraserSize.setValue)
self.signals.updateEraserSize.connect(slider.setValue)
hbox.addWidget(eraserSizeLabel)
hbox.addWidget(slider)
hbox.addWidget(self.eraserSize)
vbox.setAlignment(QtCore.Qt.AlignTop)
vbox.addLayout(hbox)
w.setLayout(vbox)
return w
def setEraserSize(self, size):
self.eraserSize.setText(str(size))
self.context.eraserSize = size
def createGradientWidget(self):
self.v = QtWidgets.QVBoxLayout()
v2 = QtWidgets.QVBoxLayout()
self.btn1 = QtWidgets.QRadioButton(self.context.getText("tool_properties_gradient", "horizontal"))
self.btn2 = QtWidgets.QRadioButton(self.context.getText("tool_properties_gradient", "vertical"))
self.btn1.setChecked(True)
self.btn1.clicked.connect( lambda : self.changeDegDir('H') )
self.btn2.clicked.connect( lambda : self.changeDegDir('V') )
h = QtWidgets.QHBoxLayout()
self.label = QtWidgets.QLabel("Transparencia:", self)
self.AlphaSpin = QtWidgets.QSpinBox(self)
self.AlphaSpin.setMinimum(0)
self.AlphaSpin.setMaximum(255)
self.AlphaSpin.setValue(255)
self.AlphaSpin.valueChanged.connect(self.setAlphaValue)
h.addWidget(self.label)
h.addWidget(self.AlphaSpin)
tmp = QtWidgets.QWidget()
tmp.setLayout(h)
self.check = QtWidgets.QCheckBox("Color a Transparente")
self.check.stateChanged.connect(self.changeDegState)
v2.addWidget(self.btn1)
v2.addWidget(self.btn2)
tmp2 = QtWidgets.QWidget()
tmp2.setLayout(v2)
self.v.addWidget(tmp2)
#self.v.addWidget(tmp)
#self.v.addWidget(self.check)
w = QtWidgets.QWidget()
w.setLayout(self.v)
self.v.addStretch()
return w
def changeDegDir(self, state):
if self.btn1.isChecked():
self.context.DegDir = 'H'
elif self.btn2.isChecked():
self.context.DegDir = 'V'
def changeDegState(self):
if self.check.isChecked():
self.context.DegState = 1
else:
self.context.DegState = 2
def setAlphaValue(self):
self.context.DegAlpha = self.AlphaSpin.value()
print(self.context.DegAlpha)
def updateWidget(self):
self.setWidget(self.widgets[self.context.currentTool])