Merge pull request #38 from Nisker/roundkeys

Rounded key corners
main
xyzz 2021-06-26 01:12:18 -04:00 committed by GitHub
commit 68f524aee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,7 @@
KEY_SIZE_RATIO = 2.667 KEY_SIZE_RATIO = 2.667
KEY_SPACING_RATIO = 0.267 KEY_SPACING_RATIO = 0.267
KEY_ROUNDNESS = 9
KEYCODE_BTN_RATIO = 3.333 KEYCODE_BTN_RATIO = 3.333

View File

@ -4,7 +4,7 @@ from PyQt5.QtGui import QPainter, QColor, QPainterPath, QTransform, QBrush, QPol
from PyQt5.QtWidgets import QWidget, QToolTip, QApplication from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
from PyQt5.QtCore import Qt, QSize, QRect, QPointF, pyqtSignal, QEvent, QRectF from PyQt5.QtCore import Qt, QSize, QRect, QPointF, pyqtSignal, QEvent, QRectF
from constants import KEY_SIZE_RATIO, KEY_SPACING_RATIO, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING, KEYBOARD_WIDGET_MASK_HEIGHT from constants import KEY_SIZE_RATIO, KEY_SPACING_RATIO, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING, KEYBOARD_WIDGET_MASK_HEIGHT, KEY_ROUNDNESS
class KeyWidget: class KeyWidget:
@ -90,12 +90,13 @@ class KeyWidget:
def calculate_draw_path(self): def calculate_draw_path(self):
path = QPainterPath() path = QPainterPath()
path.addRect(int(self.x), int(self.y), int(self.w), int(self.h)) corner = int(self.h/KEY_ROUNDNESS) if (self.w > self.h) else int(self.w/KEY_ROUNDNESS)
path.addRoundedRect(int(self.x), int(self.y), int(self.w), int(self.h), corner, corner)
# second part only considered if different from first # second part only considered if different from first
if self.has2: if self.has2:
path2 = QPainterPath() path2 = QPainterPath()
path2.addRect(int(self.x2), int(self.y2), int(self.w2), int(self.h2)) path2.addRoundedRect(int(self.x2), int(self.y2), int(self.w2), int(self.h2), corner, corner)
path = path.united(path2) path = path.united(path2)
return path return path
@ -333,7 +334,9 @@ class KeyboardWidget(QWidget):
qp.setPen(active_pen) qp.setPen(active_pen)
qp.setBrush(active_brush) qp.setBrush(active_brush)
qp.drawRect(key.mask_rect) qp.drawRoundedRect(key.mask_rect,
key.mask_rect.height()/KEY_ROUNDNESS,
key.mask_rect.height()/KEY_ROUNDNESS)
if key.color is not None and not active: if key.color is not None and not active:
qp.setPen(key.color) qp.setPen(key.color)
qp.drawText(key.mask_rect, Qt.AlignCenter, key.mask_text) qp.drawText(key.mask_rect, Qt.AlignCenter, key.mask_text)