Merge pull request #37 from Nisker/scaling

Scalable KeyboardWidget
main
xyzz 2021-06-26 01:13:19 -04:00 committed by GitHub
commit bc438fb130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -357,9 +357,9 @@ class KeyboardWidget(QWidget):
""" Returns key, hit_masked_part """
for key in self.widgets:
if key.masked and key.mask_polygon.containsPoint(pos, Qt.OddEvenFill):
if key.masked and key.mask_polygon.containsPoint(pos/self.scale, Qt.OddEvenFill):
return key, True
if key.polygon.containsPoint(pos, Qt.OddEvenFill):
if key.polygon.containsPoint(pos/self.scale, Qt.OddEvenFill):
return key, False
return None, False
@ -414,3 +414,6 @@ class KeyboardWidget(QWidget):
def set_scale(self, scale):
self.scale = scale
def get_scale(self):
return self.scale

View File

@ -24,12 +24,14 @@ class KeymapEditor(BasicEditor):
self.layout_editor = layout_editor
self.layout_layers = QHBoxLayout()
self.layout_size = QVBoxLayout()
layer_label = QLabel(tr("KeymapEditor", "Layer"))
layout_labels_container = QHBoxLayout()
layout_labels_container.addWidget(layer_label)
layout_labels_container.addLayout(self.layout_layers)
layout_labels_container.addStretch()
layout_labels_container.addLayout(self.layout_size)
# contains the actual keyboard
self.container = KeyboardWidget(layout_editor)
@ -83,6 +85,20 @@ class KeymapEditor(BasicEditor):
btn.clicked.connect(lambda state, idx=x: self.switch_layer(idx))
self.layout_layers.addWidget(btn)
self.layer_buttons.append(btn)
for x in range(0,2):
btn = SquareButton("-") if x else SquareButton("+")
btn.setFocusPolicy(Qt.NoFocus)
btn.setCheckable(False)
btn.clicked.connect(lambda state, idx=x: self.adjust_size(idx))
self.layout_size.addWidget(btn)
self.layer_buttons.append(btn)
def adjust_size(self, minus):
if minus:
self.container.set_scale(self.container.get_scale() - 0.1)
else:
self.container.set_scale(self.container.get_scale() + 0.1)
self.refresh_layer_display()
def rebuild(self, device):
super().rebuild(device)