Display position when moving a monitor

This commit is contained in:
Roberto Alsina 2020-02-01 15:55:16 -03:00
parent a73ecbd037
commit 385541e6dd
2 changed files with 16 additions and 11 deletions

16
main.py
View File

@ -105,7 +105,7 @@ class Window(QObject):
self.pos_label = QLabel(self.ui.sceneView)
self.pos_label.setText("FOOOOO")
self.pos_label.move(0, 0)
self.pos_label.move(5, 5)
def scale_mode_changed(self):
mon = self.ui.screenCombo.currentText()
@ -173,7 +173,7 @@ class Window(QObject):
mon = self.ui.screenCombo.currentText()
replicate = self.ui.replicaOf.currentText()
print(f"Making {mon} a replica of {replicate}")
if replicate in ("None", '', None):
if replicate in ("None", "", None):
print("TODO: make things non-replicas")
return
mon = self.xrandr_info[mon]
@ -190,8 +190,8 @@ class Window(QObject):
else:
# Keep the current mode, and change scaling so it
# has the same effective size as the desired mode
mod_x, mod_y = [int(x) for x in mon["current_mode"].split('x')]
target_x, target_y =[replicate[x] for x in ["res_x", "res_y"]]
mod_x, mod_y = [int(x) for x in mon["current_mode"].split("x")]
target_x, target_y = [replicate[x] for x in ["res_x", "res_y"]]
scale_x = 1000 * target_x / mod_x
scale_y = 1000 * target_y / mod_y
breakpoint()
@ -262,6 +262,10 @@ class Window(QObject):
)
self.xrandr_info[mon]["item"].update_visuals(self.xrandr_info[mon])
def show_pos(self, x, y):
self.pos_label.setText(f'{x},{y}')
self.pos_label.resize(self.pos_label.sizeHint())
def monitor_moved(self):
"Update xrandr_info with new monitor positions"
for _, mon in self.xrandr_info.items():
@ -363,7 +367,9 @@ class Window(QObject):
self.ui.modes.blockSignals(False)
def scale_changed(self):
self.ui.horizontalScaleLabel.setText(f"{int(self.ui.horizontalScale.value()/10)}%")
self.ui.horizontalScaleLabel.setText(
f"{int(self.ui.horizontalScale.value()/10)}%"
)
self.ui.verticalScaleLabel.setText(f"{int(self.ui.verticalScale.value()/10)}%")
self.mode_changed() # Not really, but it's the same thing

View File

@ -25,17 +25,13 @@ class MonitorItem(QGraphicsRectItem, QObject):
if data["orientation"] in (0, 2):
self.setRect(0, 0, data["res_x"], data["res_y"])
if data["orientation"] == 0:
self.bottom_edge.setRect(
0, data["res_y"] - 50, data["res_x"], 50
)
self.bottom_edge.setRect(0, data["res_y"] - 50, data["res_x"], 50)
if data["orientation"] == 2:
self.bottom_edge.setRect(0, 0, data["res_x"], 50)
else:
self.setRect(0, 0, data["res_y"], data["res_x"])
if data["orientation"] == 1:
self.bottom_edge.setRect(
data["res_y"] - 50, 0, 50, data["res_x"]
)
self.bottom_edge.setRect(data["res_y"] - 50, 0, 50, data["res_x"])
if data["orientation"] == 3:
self.bottom_edge.setRect(0, 0, 50, data["res_x"])
self.setPos(data["pos_x"], data["pos_y"])
@ -54,6 +50,7 @@ class MonitorItem(QGraphicsRectItem, QObject):
self.z -= 1
def mousePressEvent(self, event):
self.window.pos_label.show()
self.setCursor(Qt.ClosedHandCursor)
self.orig_pos = self.pos()
self.window.ui.screenCombo.setCurrentText(self.name)
@ -61,6 +58,7 @@ class MonitorItem(QGraphicsRectItem, QObject):
def mouseReleaseEvent(self, event):
self.setCursor(Qt.OpenHandCursor)
self.window.monitor_moved()
self.window.pos_label.hide()
def mouseMoveEvent(self, event):
view = event.widget().parent()
@ -69,3 +67,4 @@ class MonitorItem(QGraphicsRectItem, QObject):
self.setPos(
view.mapToScene(view.mapFromScene(self.orig_pos) + current_pos - click_pos)
)
self.window.show_pos(int(self.pos().x()), int(self.pos().y()))