Преглед на файлове

UI: Fix Qt 6 position deprecations

gxalpha преди 3 години
родител
ревизия
05c6a408e3
променени са 7 файла, в които са добавени 53 реда и са изтрити 21 реда
  1. 2 1
      UI/media-slider.cpp
  2. 1 1
      UI/menu-button.cpp
  3. 8 0
      UI/scene-tree.cpp
  4. 8 1
      UI/source-tree.cpp
  5. 5 3
      UI/window-basic-interaction.cpp
  6. 25 13
      UI/window-basic-preview.cpp
  7. 4 2
      UI/window-projector.cpp

+ 2 - 1
UI/media-slider.cpp

@@ -22,7 +22,8 @@ MediaSlider::MediaSlider(QWidget *parent) : SliderIgnoreScroll(parent)
 
 void MediaSlider::mouseMoveEvent(QMouseEvent *event)
 {
-	int val = minimum() + ((maximum() - minimum()) * event->x()) / width();
+	int val = minimum() +
+		  ((maximum() - minimum()) * event->pos().x()) / width();
 
 	if (val > maximum())
 		val = maximum();

+ 1 - 1
UI/menu-button.cpp

@@ -24,7 +24,7 @@ void MenuButton::keyPressEvent(QKeyEvent *event)
 void MenuButton::mousePressEvent(QMouseEvent *event)
 {
 	if (menu()) {
-		if (width() - event->x() <= 30)
+		if (width() - event->pos().x() <= 30)
 			showMenu();
 		else
 			setDown(true);

+ 8 - 0
UI/scene-tree.cpp

@@ -124,7 +124,11 @@ void SceneTree::dropEvent(QDropEvent *event)
 
 		float wid = contentsRect().width() - scrollWid - 1;
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+		QPoint point = event->position().toPoint();
+#else
 		QPoint point = event->pos();
+#endif
 
 		int x = (float)point.x() / wid * ceil(wid / maxWidth);
 		int y = point.y() / itemHeight;
@@ -157,7 +161,11 @@ void SceneTree::RepositionGrid(QDragMoveEvent *event)
 	float wid = contentsRect().width() - scrollWid - 1;
 
 	if (event) {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+		QPoint point = event->position().toPoint();
+#else
 		QPoint point = event->pos();
+#endif
 
 		int x = (float)point.x() / wid * ceil(wid / maxWidth);
 		int y = point.y() / itemHeight;

+ 8 - 1
UI/source-tree.cpp

@@ -1186,7 +1186,14 @@ void SourceTree::dropEvent(QDropEvent *event)
 	QModelIndexList indices = selectedIndexes();
 
 	DropIndicatorPosition indicator = dropIndicatorPosition();
-	int row = indexAt(event->pos()).row();
+	int row = indexAt(
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+			  event->position().toPoint()
+#else
+			  event->pos()
+#endif
+				  )
+			  .row();
 	bool emptyDrop = row == -1;
 
 	if (emptyDrop) {

+ 5 - 3
UI/window-basic-interaction.cpp

@@ -319,8 +319,9 @@ bool OBSBasicInteraction::HandleMouseClickEvent(QMouseEvent *event)
 	//if (event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))
 	//	clickCount = 2;
 
-	bool insideSource = GetSourceRelativeXY(event->x(), event->y(),
-						mouseEvent.x, mouseEvent.y);
+	QPoint pos = event->pos();
+	bool insideSource = GetSourceRelativeXY(pos.x(), pos.y(), mouseEvent.x,
+						mouseEvent.y);
 
 	if (mouseUp || insideSource)
 		obs_source_send_mouse_click(source, &mouseEvent, button,
@@ -337,7 +338,8 @@ bool OBSBasicInteraction::HandleMouseMoveEvent(QMouseEvent *event)
 
 	if (!mouseLeave) {
 		mouseEvent.modifiers = TranslateQtMouseEventModifiers(event);
-		mouseLeave = !GetSourceRelativeXY(event->x(), event->y(),
+		QPoint pos = event->pos();
+		mouseLeave = !GetSourceRelativeXY(pos.x(), pos.y(),
 						  mouseEvent.x, mouseEvent.y);
 	}
 

+ 25 - 13
UI/window-basic-preview.cpp

@@ -39,10 +39,10 @@ vec2 OBSBasicPreview::GetMouseEventPos(QMouseEvent *event)
 	OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
 	float pixelRatio = main->devicePixelRatioF();
 	float scale = pixelRatio / main->previewScale;
+	QPoint qtPos = event->pos();
 	vec2 pos;
-	vec2_set(&pos,
-		 (float(event->x()) - main->previewX / pixelRatio) * scale,
-		 (float(event->y()) - main->previewY / pixelRatio) * scale);
+	vec2_set(&pos, (qtPos.x() - main->previewX / pixelRatio) * scale,
+		 (qtPos.y() - main->previewY / pixelRatio) * scale);
 
 	return pos;
 }
@@ -499,11 +499,17 @@ void OBSBasicPreview::wheelEvent(QWheelEvent *event)
 
 void OBSBasicPreview::mousePressEvent(QMouseEvent *event)
 {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+	QPointF pos = event->position();
+#else
+	QPointF pos = event->localPos();
+#endif
+
 	if (scrollMode && IsFixedScaling() &&
 	    event->button() == Qt::LeftButton) {
 		setCursor(Qt::ClosedHandCursor);
-		scrollingFrom.x = event->x();
-		scrollingFrom.y = event->y();
+		scrollingFrom.x = pos.x();
+		scrollingFrom.y = pos.x();
 		return;
 	}
 
@@ -519,8 +525,8 @@ void OBSBasicPreview::mousePressEvent(QMouseEvent *event)
 
 	OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
 	float pixelRatio = main->devicePixelRatioF();
-	float x = float(event->x()) - main->previewX / pixelRatio;
-	float y = float(event->y()) - main->previewY / pixelRatio;
+	float x = pos.x() - main->previewX / pixelRatio;
+	float y = pos.y() - main->previewY / pixelRatio;
 	Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
 	bool altDown = (modifiers & Qt::AltModifier);
 	bool shiftDown = (modifiers & Qt::ShiftModifier);
@@ -1459,11 +1465,17 @@ void OBSBasicPreview::mouseMoveEvent(QMouseEvent *event)
 {
 	changed = true;
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+	QPointF qtPos = event->position();
+#else
+	QPointF qtPos = event->localPos();
+#endif
+
 	if (scrollMode && event->buttons() == Qt::LeftButton) {
-		scrollingOffset.x += event->x() - scrollingFrom.x;
-		scrollingOffset.y += event->y() - scrollingFrom.y;
-		scrollingFrom.x = event->x();
-		scrollingFrom.y = event->y();
+		scrollingOffset.x += qtPos.x() - scrollingFrom.x;
+		scrollingOffset.y += qtPos.y() - scrollingFrom.y;
+		scrollingFrom.x = qtPos.x();
+		scrollingFrom.y = qtPos.y();
 		emit DisplayResized();
 		return;
 	}
@@ -1537,8 +1549,8 @@ void OBSBasicPreview::mouseMoveEvent(QMouseEvent *event)
 			OBSBasic *main = reinterpret_cast<OBSBasic *>(
 				App()->GetMainWindow());
 			float scale = main->devicePixelRatioF();
-			float x = float(event->x()) - main->previewX / scale;
-			float y = float(event->y()) - main->previewY / scale;
+			float x = qtPos.x() - main->previewX / scale;
+			float y = qtPos.y() - main->previewY / scale;
 			vec2_set(&startPos, x, y);
 			updateCursor = true;
 		}

+ 4 - 2
UI/window-projector.cpp

@@ -232,8 +232,9 @@ void OBSProjector::mouseDoubleClickEvent(QMouseEvent *event)
 		return;
 
 	if (event->button() == Qt::LeftButton) {
+		QPoint pos = event->pos();
 		OBSSource src =
-			multiview->GetSourceByPosition(event->x(), event->y());
+			multiview->GetSourceByPosition(pos.x(), pos.y());
 		if (!src)
 			return;
 
@@ -283,8 +284,9 @@ void OBSProjector::mousePressEvent(QMouseEvent *event)
 		return;
 
 	if (event->button() == Qt::LeftButton) {
+		QPoint pos = event->pos();
 		OBSSource src =
-			multiview->GetSourceByPosition(event->x(), event->y());
+			multiview->GetSourceByPosition(pos.x(), pos.y());
 		if (!src)
 			return;