Add more status icon shapes

This commit is contained in:
Veronica Berglyd Olsen
2024-04-11 11:17:03 +02:00
parent f4decae77f
commit 6cf83bb381
4 changed files with 132 additions and 40 deletions
+19 -7
View File
@@ -269,13 +269,25 @@ class nwLabels:
nwBuildFmt.J_NWD: ".json",
}
STATUS_SHAPES = {
nwStatusShape.SQUARE: QT_TRANSLATE_NOOP("Constant", "Square"),
nwStatusShape.CIRCLE: QT_TRANSLATE_NOOP("Constant", "Circle"),
nwStatusShape.TRIANGLE: QT_TRANSLATE_NOOP("Constant", "Triangle"),
nwStatusShape.DIAMOND: QT_TRANSLATE_NOOP("Constant", "Diamond"),
nwStatusShape.PENTAGON: QT_TRANSLATE_NOOP("Constant", "Pentagon"),
nwStatusShape.STAR: QT_TRANSLATE_NOOP("Constant", "Star"),
nwStatusShape.PACMAN: QT_TRANSLATE_NOOP("Constant", "Pacman"),
nwStatusShape.SQUARE: QT_TRANSLATE_NOOP("Constant", "Square"),
nwStatusShape.CIRCLE_Q: QT_TRANSLATE_NOOP("Constant", "Circle, 1/4"),
nwStatusShape.CIRCLE_H: QT_TRANSLATE_NOOP("Constant", "Circle, Half"),
nwStatusShape.CIRCLE_T: QT_TRANSLATE_NOOP("Constant", "Circle, 3/4"),
nwStatusShape.CIRCLE: QT_TRANSLATE_NOOP("Constant", "Circle, Full"),
nwStatusShape.TRIANGLE: QT_TRANSLATE_NOOP("Constant", "Triangle"),
nwStatusShape.NABLA: QT_TRANSLATE_NOOP("Constant", "Nabla"),
nwStatusShape.DIAMOND: QT_TRANSLATE_NOOP("Constant", "Diamond"),
nwStatusShape.PENTAGON: QT_TRANSLATE_NOOP("Constant", "Pentagon"),
nwStatusShape.STAR: QT_TRANSLATE_NOOP("Constant", "Star"),
nwStatusShape.PACMAN: QT_TRANSLATE_NOOP("Constant", "Pacman"),
nwStatusShape.BARS_1: QT_TRANSLATE_NOOP("Constant", "1 Bar"),
nwStatusShape.BARS_2: QT_TRANSLATE_NOOP("Constant", "2 Bars"),
nwStatusShape.BARS_3: QT_TRANSLATE_NOOP("Constant", "3 Bars"),
nwStatusShape.BARS_4: QT_TRANSLATE_NOOP("Constant", "4 Bars"),
nwStatusShape.BLOCK_1: QT_TRANSLATE_NOOP("Constant", "1 Block"),
nwStatusShape.BLOCK_2: QT_TRANSLATE_NOOP("Constant", "2 Blocks"),
nwStatusShape.BLOCK_3: QT_TRANSLATE_NOOP("Constant", "3 Blocks"),
nwStatusShape.BLOCK_4: QT_TRANSLATE_NOOP("Constant", "4 Blocks"),
}
FILE_FILTERS = {
"*.txt": QT_TRANSLATE_NOOP("Constant", "Text files"),
+63 -19
View File
@@ -244,48 +244,92 @@ class _ShapeCache:
if shape in self._cache:
return self._cache[shape]
def circ(r: float, a: float, x: float, y: float) -> QPointF:
def polar(r: float, a: float, x: float, y: float) -> QPointF:
# Converts polar coordinates to cartesian
# print(round(x+r*sin(pi*a/180), 2), round(y-r*cos(pi*a/180), 2))
return QPointF(round(x+r*sin(pi*a/180), 2), round(y-r*cos(pi*a/180), 2))
return QPointF(x+r*sin(pi*a/180), y-r*cos(pi*a/180))
path = QPainterPath()
if shape == nwStatusShape.SQUARE:
path.addRoundedRect(2.0, 2.0, 44.0, 44.0, 4.0, 4.0)
elif shape == nwStatusShape.CIRCLE_Q:
path.moveTo(24.0, 24.0)
path.arcTo(2.0, 2.0, 44.0, 44.0, 0.0, 90.0)
elif shape == nwStatusShape.CIRCLE_H:
path.moveTo(24.0, 24.0)
path.arcTo(2.0, 2.0, 44.0, 44.0, -90.0, 180.0)
elif shape == nwStatusShape.CIRCLE_T:
path.moveTo(24.0, 24.0)
path.arcTo(2.0, 2.0, 44.0, 44.0, -180.0, 270.0)
elif shape == nwStatusShape.CIRCLE:
path.addEllipse(2.0, 2.0, 44.0, 44.0)
elif shape == nwStatusShape.TRIANGLE:
path.addPolygon(QPolygonF([
circ(23.0, 0.0, 24.0, 26.0),
circ(23.0, 120.0, 24.0, 26.0),
circ(23.0, 240.0, 24.0, 26.0),
polar(23.0, 0.0, 24.0, 26.0),
polar(23.0, 120.0, 24.0, 26.0),
polar(23.0, 240.0, 24.0, 26.0),
]))
elif shape == nwStatusShape.NABLA:
path.addPolygon(QPolygonF([
polar(23.0, 180.0, 24.0, 26.0),
polar(23.0, 300.0, 24.0, 26.0),
polar(23.0, 60.0, 24.0, 26.0),
]))
elif shape == nwStatusShape.DIAMOND:
path.addPolygon(QPolygonF([
circ(22.0, 0.0, 24.0, 24.0),
circ(20.0, 90.0, 24.0, 24.0),
circ(22.0, 180.0, 24.0, 24.0),
circ(20.0, 270.0, 24.0, 24.0),
polar(22.0, 0.0, 24.0, 24.0),
polar(20.0, 90.0, 24.0, 24.0),
polar(22.0, 180.0, 24.0, 24.0),
polar(20.0, 270.0, 24.0, 24.0),
]))
elif shape == nwStatusShape.PENTAGON:
path.addPolygon(QPolygonF([
circ(23.0, 0.0, 24.0, 24.5),
circ(23.0, 72.0, 24.0, 24.5),
circ(23.0, 144.0, 24.0, 24.5),
circ(23.0, 216.0, 24.0, 24.5),
circ(23.0, 288.0, 24.0, 24.5),
polar(23.0, 0.0, 24.0, 24.5),
polar(23.0, 72.0, 24.0, 24.5),
polar(23.0, 144.0, 24.0, 24.5),
polar(23.0, 216.0, 24.0, 24.5),
polar(23.0, 288.0, 24.0, 24.5),
]))
elif shape == nwStatusShape.STAR:
path.addPolygon(QPolygonF([
circ(24.0, 0.0, 24.0, 24.5),
circ(24.0, 144.0, 24.0, 24.5),
circ(24.0, 288.0, 24.0, 24.5),
circ(24.0, 72.0, 24.0, 24.5),
circ(24.0, 216.0, 24.0, 24.5),
polar(24.0, 0.0, 24.0, 24.5), polar(12.0, 36.0, 24.0, 24.5),
polar(24.0, 72.0, 24.0, 24.5), polar(12.0, 108.0, 24.0, 24.5),
polar(24.0, 144.0, 24.0, 24.5), polar(12.0, 180.0, 24.0, 24.5),
polar(24.0, 216.0, 24.0, 24.5), polar(12.0, 252.0, 24.0, 24.5),
polar(24.0, 288.0, 24.0, 24.5), polar(12.0, 314.0, 24.0, 24.5),
]))
path.setFillRule(Qt.FillRule.WindingFill)
elif shape == nwStatusShape.PACMAN:
path.moveTo(24.0, 24.0)
path.arcTo(2.0, 2.0, 44.0, 44.0, 40.0, 280.0)
elif shape == nwStatusShape.BARS_1:
path.addRoundedRect(2.0, 2.0, 8.0, 44.0, 4.0, 4.0)
elif shape == nwStatusShape.BARS_2:
path.addRoundedRect(2.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(14.0, 2.0, 8.0, 44.0, 4.0, 4.0)
elif shape == nwStatusShape.BARS_3:
path.addRoundedRect(2.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(14.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(26.0, 2.0, 8.0, 44.0, 4.0, 4.0)
elif shape == nwStatusShape.BARS_4:
path.addRoundedRect(2.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(14.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(26.0, 2.0, 8.0, 44.0, 4.0, 4.0)
path.addRoundedRect(38.0, 2.0, 8.0, 44.0, 4.0, 4.0)
elif shape == nwStatusShape.BLOCK_1:
path.addRoundedRect(2.0, 2.0, 20.0, 20.0, 4.0, 4.0)
elif shape == nwStatusShape.BLOCK_2:
path.addRoundedRect(2.0, 2.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(24.0, 2.0, 20.0, 20.0, 4.0, 4.0)
elif shape == nwStatusShape.BLOCK_3:
path.addRoundedRect(2.0, 2.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(2.0, 24.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(24.0, 2.0, 20.0, 20.0, 4.0, 4.0)
elif shape == nwStatusShape.BLOCK_4:
path.addRoundedRect(2.0, 2.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(2.0, 24.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(24.0, 2.0, 20.0, 20.0, 4.0, 4.0)
path.addRoundedRect(24.0, 24.0, 20.0, 20.0, 4.0, 4.0)
self._cache[shape] = path
+19 -7
View File
@@ -209,12 +209,24 @@ class nwBuildFmt(Enum):
class nwStatusShape(Enum):
SQUARE = 0
CIRCLE = 1
TRIANGLE = 2
DIAMOND = 3
PENTAGON = 4
STAR = 5
PACMAN = 6
SQUARE = 0
CIRCLE_Q = 1
CIRCLE_H = 2
CIRCLE_T = 3
CIRCLE = 4
TRIANGLE = 5
NABLA = 6
DIAMOND = 7
PENTAGON = 8
STAR = 9
PACMAN = 10
BARS_1 = 11
BARS_2 = 12
BARS_3 = 13
BARS_4 = 14
BLOCK_1 = 15
BLOCK_2 = 16
BLOCK_3 = 17
BLOCK_4 = 18
# END Enum nwStatusShape