mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-14 07:02:22 +00:00
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
|
from PySide2.QtCore import Qt
|
||
|
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsTextItem
|
||
|
|
||
|
|
||
|
class MonitorItem(QGraphicsRectItem):
|
||
|
def __init__(self, *a, **kw):
|
||
|
super().__init__(*a, **kw)
|
||
|
self.setAcceptedMouseButtons(Qt.LeftButton)
|
||
|
self.label = QGraphicsTextItem(kw["name"], self)
|
||
|
label_scale = min(
|
||
|
self.rect().width() / self.label.boundingRect().width(),
|
||
|
self.rect().height() / self.label.boundingRect().height(),
|
||
|
)
|
||
|
self.label.setScale(label_scale)
|
||
|
|
||
|
def mousePressEvent(self, event):
|
||
|
self.setCursor(Qt.ClosedHandCursor)
|
||
|
self.orig_pos = self.pos()
|
||
|
|
||
|
def mouseReleaseEvent(self, event):
|
||
|
self.setCursor(Qt.OpenHandCursor)
|
||
|
|
||
|
def mouseMoveEvent(self, event):
|
||
|
view = event.widget().parent()
|
||
|
click_pos = event.buttonDownScreenPos(Qt.LeftButton)
|
||
|
current_pos = event.screenPos()
|
||
|
self.setPos(
|
||
|
view.mapToScene(view.mapFromScene(self.orig_pos) + current_pos - click_pos)
|
||
|
)
|