[LyX/master] Fix Qt6 deprecation warning (QMouseEvent::x() ::y())

Juergen Spitzmueller spitz at lyx.org
Sun Mar 21 11:33:12 UTC 2021


commit 15c6d4c6b3feb05052a54aaa027659a44ef8a71a
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sun Mar 21 12:38:05 2021 +0100

    Fix Qt6 deprecation warning (QMouseEvent::x() ::y())
---
 src/frontends/qt/EmptyTable.cpp        |    5 ++++
 src/frontends/qt/GuiCommandBuffer.cpp  |    5 ++++
 src/frontends/qt/GuiSetBorder.cpp      |   22 +++++++++++++++++++
 src/frontends/qt/GuiWorkArea.cpp       |   36 ++++++++++++++++++++++++++++++++
 src/frontends/qt/InsertTableWidget.cpp |    5 ++++
 5 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/src/frontends/qt/EmptyTable.cpp b/src/frontends/qt/EmptyTable.cpp
index 80cbe88..d606515 100644
--- a/src/frontends/qt/EmptyTable.cpp
+++ b/src/frontends/qt/EmptyTable.cpp
@@ -118,8 +118,13 @@ void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
 {
 	int cc = columnCount();
 	int rc = rowCount();
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	int x = ev->position().x();
+	int y = ev->position().y();
+#else
 	int x = ev->x();
 	int y = ev->y();
+#endif
 	int w = cellwidth * cc;
 	int h = cellheight * rc;
 	int wl = cellwidth * (cc - 1);
diff --git a/src/frontends/qt/GuiCommandBuffer.cpp b/src/frontends/qt/GuiCommandBuffer.cpp
index 80e57c0..956821c 100644
--- a/src/frontends/qt/GuiCommandBuffer.cpp
+++ b/src/frontends/qt/GuiCommandBuffer.cpp
@@ -58,8 +58,13 @@ protected:
 	bool event(QEvent * ev) override {
 		if (ev->type() == QEvent::MouseButtonPress) {
 			QMouseEvent * me = static_cast<QMouseEvent *>(ev);
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+			if (me->position().x() < 0 || me->position().y() < 0
+			    || me->position().x() > width() || me->position().y() > height())
+#else
 			if (me->x() < 0 || me->y() < 0
 			    || me->x() > width() || me->y() > height())
+#endif
 				hide();
 			return true;
 		}
diff --git a/src/frontends/qt/GuiSetBorder.cpp b/src/frontends/qt/GuiSetBorder.cpp
index 6866dd2..dfe4948 100644
--- a/src/frontends/qt/GuiSetBorder.cpp
+++ b/src/frontends/qt/GuiSetBorder.cpp
@@ -80,19 +80,32 @@ void GuiSetBorder::init()
 
 void GuiSetBorder::mousePressEvent(QMouseEvent * e)
 {
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	if (e->position().y() > e->position().x()) {
+		if (e->position().y() < height() - e->position().x()) {
+#else
 	if (e->y() > e->x()) {
 		if (e->y() < height() - e->x()) {
+#endif
 			if (left_.enabled) {
 				setLeft(left_.set == LINE_SET ? LINE_UNSET : LINE_SET);
 				// emit signal
 				leftSet();
 			}
 		} else {
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+			if (bottom_trim_left_.enabled && e->position().x() < margin + 4 + 2 * corner_length) {
+#else
 			if (bottom_trim_left_.enabled && e->x() < margin + 4 + 2 * corner_length) {
+#endif
 				setBottomLeftTrim(bottom_trim_left_.set == LINE_SET ? LINE_UNSET : LINE_SET);
 				// emit signal
 				bottomLTSet();
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+			} else if (bottom_trim_right_.enabled && e->position().x() > bwidth - margin - 2 * corner_length - 4) {
+#else
 			} else if (bottom_trim_right_.enabled && e->x() > bwidth - margin - 2 * corner_length - 4) {
+#endif
 					setBottomRightTrim(bottom_trim_right_.set == LINE_SET ? LINE_UNSET : LINE_SET);
 					// emit signal
 					bottomRTSet();
@@ -103,12 +116,21 @@ void GuiSetBorder::mousePressEvent(QMouseEvent * e)
 			}
 		}
 	} else {
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+		if (e->position().y() < height() - e->position().x()) {
+			if (top_trim_left_.enabled && e->position().x() < margin + 4 + 2 * corner_length) {
+#else
 		if (e->y() < height() - e->x()) {
 			if (top_trim_left_.enabled && e->x() < margin + 4 + 2 * corner_length) {
+#endif
 				setTopLeftTrim(top_trim_left_.set == LINE_SET ? LINE_UNSET : LINE_SET);
 				// emit signal
 				topLTSet();
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+			} else if (top_trim_right_.enabled && e->position().x() > bwidth - margin - 2 * corner_length - 4) {
+#else
 			} else if (top_trim_right_.enabled && e->x() > bwidth - margin - 2 * corner_length - 4) {
+#endif
 					setTopRightTrim(top_trim_right_.set == LINE_SET ? LINE_UNSET : LINE_SET);
 					// emit signal
 					topRTSet();
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 4050f8c..bebd122 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -715,7 +715,11 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
 {
 	if (d->dc_event_.active && d->dc_event_ == *e) {
 		d->dc_event_.active = false;
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+		FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->position().x(), e->position().y(),
+#else
 		FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
+#endif
 			q_button_state(e->button()), q_key_state(e->modifiers()));
 		d->dispatch(cmd);
 		e->accept();
@@ -726,7 +730,11 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
 	inputContext()->reset();
 #endif
 
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	FuncRequest const cmd(LFUN_MOUSE_PRESS, e->position().x(), e->position().y(),
+#else
 	FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
+#endif
 			q_button_state(e->button()), q_key_state(e->modifiers()));
 	d->dispatch(cmd);
 
@@ -736,7 +744,11 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
 	// due to the DEPM. We need to do this after the mouse has been
 	// set in dispatch(), because the selection state might change.
 	if (e->button() == Qt::RightButton)
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+		d->context_menu_name_ = d->buffer_view_->contextMenu(e->position().x(), e->position().y());
+#else
 		d->context_menu_name_ = d->buffer_view_->contextMenu(e->x(), e->y());
+#endif
 
 	e->accept();
 }
@@ -747,7 +759,11 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
 	if (d->synthetic_mouse_event_.timeout.running())
 		d->synthetic_mouse_event_.timeout.stop();
 
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->position().x(), e->position().y(),
+#else
 	FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
+#endif
 			q_button_state(e->button()), q_key_state(e->modifiers()));
 #if (QT_VERSION > QT_VERSION_CHECK(5,10,1) && \
 	QT_VERSION < QT_VERSION_CHECK(5,15,1))
@@ -777,21 +793,37 @@ void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
 
 	// we kill the triple click if we move
 	doubleClickTimeout();
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	FuncRequest cmd(LFUN_MOUSE_MOTION, e->position().x(), e->position().y(),
+#else
 	FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
+#endif
 			q_motion_state(e->buttons()), q_key_state(e->modifiers()));
 
 	e->accept();
 
 	// If we're above or below the work area...
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	if ((e->position().y() <= 20 || e->position().y() >= viewport()->height() - 20)
+#else
 	if ((e->y() <= 20 || e->y() >= viewport()->height() - 20)
+#endif
 			&& e->buttons() == mouse_button::button1) {
 		// Make sure only a synthetic event can cause a page scroll,
 		// so they come at a steady rate:
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+		if (e->position().y() <= 20)
+			// _Force_ a scroll up:
+			cmd.set_y(e->position().y() - 21);
+		else
+			cmd.set_y(e->position().y() + 21);
+#else
 		if (e->y() <= 20)
 			// _Force_ a scroll up:
 			cmd.set_y(e->y() - 21);
 		else
 			cmd.set_y(e->y() + 21);
+#endif
 		// Store the event, to be handled when the timeout expires.
 		d->synthetic_mouse_event_.cmd = cmd;
 
@@ -1088,7 +1120,11 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
 	d->dc_event_ = DoubleClick(ev);
 	QTimer::singleShot(QApplication::doubleClickInterval(), this,
 			SLOT(doubleClickTimeout()));
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	FuncRequest cmd(LFUN_MOUSE_DOUBLE, ev->position().x(), ev->position().y(),
+#else
 	FuncRequest cmd(LFUN_MOUSE_DOUBLE, ev->x(), ev->y(),
+#endif
 			q_button_state(ev->button()), q_key_state(ev->modifiers()));
 	d->dispatch(cmd);
 	ev->accept();
diff --git a/src/frontends/qt/InsertTableWidget.cpp b/src/frontends/qt/InsertTableWidget.cpp
index 70f53e2..3746bb1 100644
--- a/src/frontends/qt/InsertTableWidget.cpp
+++ b/src/frontends/qt/InsertTableWidget.cpp
@@ -90,8 +90,13 @@ void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
 
 	int const r0 = right_;
 	int const b0 = bottom_;
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
+	right_ = event->position().x() / colwidth_ + 1;
+	bottom_ = event->position().y() / rowheight_ + 1;
+#else
 	right_ = event->x() / colwidth_ + 1;
 	bottom_ = event->y() / rowheight_ + 1;
+#endif
 
 	if (bottom_ == rows_) {
 		++rows_;


More information about the lyx-cvs mailing list