Commit a66a5f46 authored by Djelloul Bekri's avatar Djelloul Bekri

hud scale param

parent 7970e2e1
......@@ -182,7 +182,8 @@ class MgvHudItem(QtWidgets.QGraphicsItem):
self.graphview.scene.addItem(self)
self.hud = hud
self.data = []
self.w = 50
self.w = 50 * self.graphview.hudScale
self.h = 15 * self.graphview.hudScale
self.active = False
self.i = 0
self.getW()
......@@ -193,24 +194,24 @@ class MgvHudItem(QtWidgets.QGraphicsItem):
def getW(self):
data = self.data if self.active else []
font = QtGui.QFont(myFont, .75 * myFontSize)
font = QtGui.QFont(myFont, .75 * myFontSize * self.graphview.hudScale)
fm = QtGui.QFontMetrics(font)
self.w = max([fm.boundingRect(x).width() for x in (data + [self.hud.getName()])]) + 10
def boundingRect(self):
data = self.data if self.active else []
return QtCore.QRectF(0, -(len(data)+1) * 15, self.w + 15, (len(data)+1) * 15)
return QtCore.QRectF(0, -(len(data)+1) * self.h, self.w + self.h, (len(data)+1) * self.h)
def shape(self):
data = self.data if self.active else []
path = QtGui.QPainterPath()
path.addRect(0, -(len(data)+1) * 15, self.w + 15, (len(data)+1) * 15)
path.addRect(0, -(len(data)+1) * self.h, self.w + self.h, (len(data)+1) * self.h)
return path
def paint(self, painter, option, widget):
pen = QtGui.QPen()
pen.setWidth(1.5)
font = QtGui.QFont(myFont, .75 * myFontSize)
font = QtGui.QFont(myFont, .75 * myFontSize * self.graphview.hudScale)
painter.setFont(font)
t = QtGui.QTextOption()
data = self.data if self.active else []
......@@ -219,17 +220,18 @@ class MgvHudItem(QtWidgets.QGraphicsItem):
pen.setDashOffset(self.i)
pen.setColor(QtGui.QColor('#003300'))
painter.setPen(pen)
painter.drawRoundedRect(0, -(len(data)+1) * 15, self.w, (len(data)+1) * 15, 3, 3)
painter.setBrush(QtGui.QColor("#777777"))
painter.drawRoundedRect(0, -(len(data)+1) * self.h, self.w, (len(data)+1) * self.h, 3, 3)
if len(self.data):
painter.setBrush(QtGui.QColor("#999999"))
painter.drawRoundedRect(0, -(len(data) + 1) * 15, self.w, 15, 3, 3)
painter.drawRoundedRect(0, -(len(data) + 1) * self.h, self.w, self.h, 3, 3)
pen.setColor(QtGui.QColor('#000000'))
painter.setPen(pen)
painter.drawText(QtCore.QRectF(5, -(len(data)+1) * 15, self.w+10, 15), self.hud.getName(), t)
painter.drawText(QtCore.QRectF(5, -(len(data)+1) * self.h, self.w+10, self.h), self.hud.getName(), t)
pen.setColor(QtGui.QColor('#000000'))
for i, x in enumerate(data):
painter.drawText(QtCore.QRectF(5, i * 15 - len(data) * 15, self.w+10, 15), x, t)
painter.drawText(QtCore.QRectF(5, i * self.h - len(data) * self.h, self.w+10, self.h), x, t)
def refreshData(self):
"""Execute hud script."""
......@@ -272,21 +274,22 @@ class MgvUserHud(QtWidgets.QGraphicsItem):
self.setZValue(90)
self.graphview.scene.addItem(self)
self.over = None
self.w = 200
self.w = 200 * self.graphview.hudScale
self.h = 15 * self.graphview.hudScale
def boundingRect(self):
return QtCore.QRectF(0, -len(self.graphview.activeUsers) * 15, self.w + 15,
len(self.graphview.activeUsers) * 15)
return QtCore.QRectF(0, -len(self.graphview.activeUsers) * self.h, self.w + self.h,
len(self.graphview.activeUsers) * self.h)
def shape(self):
path = QtGui.QPainterPath()
path.addRect(0, -len(self.graphview.activeUsers) * 15, self.w + 15, len(self.graphview.activeUsers) * 15)
path.addRect(0, -len(self.graphview.activeUsers) * self.h, self.w + self.h, len(self.graphview.activeUsers) * self.h)
return path
def paint(self, painter, option, widget):
pen = QtGui.QPen()
pen.setWidth(1.5)
font = QtGui.QFont(myFont, .75 * myFontSize)
font = QtGui.QFont(myFont, .75 * myFontSize * self.graphview.hudScale)
painter.setFont(font)
t = QtGui.QTextOption()
......@@ -297,13 +300,13 @@ class MgvUserHud(QtWidgets.QGraphicsItem):
pen.setColor(QtGui.QColor('#FFFF00'))
painter.setPen(pen)
painter.setBrush(user.color)
painter.drawRoundedRect(0, i * 15 + 2.5 - len(self.graphview.activeUsers) * 15, 10, 10, 3, 3)
painter.drawText(QtCore.QRectF(15, i * 15 - len(self.graphview.activeUsers) * 15, 200, 15), username, t)
self.w = painter.fontMetrics().boundingRect(username).width() + 15
painter.drawRoundedRect(0, i * self.h + 2.5 - len(self.graphview.activeUsers) * self.h, self.h*2/3, self.h*2/3, 3, 3)
painter.drawText(QtCore.QRectF(self.h, i * self.h - len(self.graphview.activeUsers) * self.h, self.w, self.h), username, t)
self.w = painter.fontMetrics().boundingRect(username).width() + self.h
def getOver(self, posy):
self.over = None
i = int((posy + len(self.graphview.activeUsers) * 15) / 15)
i = int((posy + len(self.graphview.activeUsers) * self.h) / self.h)
if 0 <= i < len(self.graphview.activeUsers):
self.over = self.graphview.activeUsers[i]
......@@ -478,6 +481,7 @@ class MgvGraphView(QtWidgets.QGraphicsView):
self.setRenderHint(QtGui.QPainter.Antialiasing)
self.globalScale = 10
self.hudScale = 1.5
self.hud = None
self.pos = (20000 * self.globalScale, 20000 * self.globalScale)
self.scale = self.globalScale
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment