From 35b31a0064c677bc8f42e856cc1cf423b90f4d78 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 20 Jun 2022 16:43:16 +0300 Subject: [PATCH 44/44] Qt: Use QMouseEvent::pos() instead of ::x() or ::y() See osdn #44875 Signed-off-by: Marko Lindqvist --- client/gui-qt/citydlg.cpp | 8 +++++--- client/gui-qt/dialogs.cpp | 25 ++++++++++++++++--------- client/gui-qt/messagewin.cpp | 35 +++++++++++++++++++++++++---------- client/gui-qt/ratesdlg.cpp | 4 ++-- client/gui-qt/repodlgs.cpp | 3 ++- 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index df90b94360..72731f033c 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -1195,7 +1195,7 @@ void city_label::mousePressEvent(QMouseEvent *event) i = 1 + (num_citizens * 5 / 200); w = w / i; - citnum = event->x() / w; + citnum = event->pos().x() / w; if (!can_client_issue_orders()) { return; @@ -1325,13 +1325,15 @@ QSize city_map::minimumSizeHint() const void city_map::mousePressEvent(QMouseEvent *event) { int canvas_x, canvas_y, city_x, city_y; + QPoint pos; if (!can_client_issue_orders() || event->button() != Qt::LeftButton) { return; } - canvas_x = event->x() / zoom + delta_x; - canvas_y = event->y() / zoom + delta_y; + pos = event->pos(); + canvas_x = pos.x() / zoom + delta_x; + canvas_y = pos.y() / zoom + delta_y; if (canvas_to_city_pos(&city_x, &city_y, city_map_radius_sq_get(mcity), canvas_x, canvas_y)) { diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index 43297c8a28..ea5505afb1 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -390,13 +390,17 @@ void qfc_dialog::mouseMoveEvent(QMouseEvent *event) ***************************************************************************/ void qfc_dialog::mousePressEvent(QMouseEvent *event) { - if (event->pos().y() <= titlebar_height - && event->pos().x() <= width() - close_pix.width()) { + QPoint pos = event->pos(); + int x = pos.x(); + int y = pos.y(); + + if (y <= titlebar_height + && x <= width() - close_pix.width()) { point = event->globalPos() - geometry().topLeft(); moving_now = true; setCursor(Qt::SizeAllCursor); - } else if (event->pos().y() <= titlebar_height - && event->pos().x() > width() - close_pix.width()) { + } else if (y <= titlebar_height + && x > width() - close_pix.width()) { close(); } } @@ -4567,16 +4571,19 @@ void units_select::mouseMoveEvent(QMouseEvent *event) int a, b; int old_h; QFontMetrics fm(info_font); + QPoint pos = event->pos(); + int x = pos.x(); + int y = pos.y(); old_h = highligh_num; highligh_num = -1; - if (event->x() > width() - 11 - || event->y() > height() - fm.height() - 5 - || event->y() < fm.height() + 3 || event->x() < 11) { + if (x > width() - 11 + || y > height() - fm.height() - 5 + || y < fm.height() + 3 || x < 11) { // Do nothing if mouse is on border, just skip next if } else if (row_count > 0) { - a = (event->x() - 10) / item_size.width(); - b = (event->y() - fm.height() - 3) / item_size.height(); + a = (x - 10) / item_size.width(); + b = (y - fm.height() - 3) / item_size.height(); highligh_num = b * 4 + a; } if (old_h != highligh_num) { diff --git a/client/gui-qt/messagewin.cpp b/client/gui-qt/messagewin.cpp index 049f805e03..1e154fbdb6 100644 --- a/client/gui-qt/messagewin.cpp +++ b/client/gui-qt/messagewin.cpp @@ -80,7 +80,6 @@ void info_tab::maximize_chat() chtwdg->scroll_to_bottom(); } - /***********************************************************************//** Checks if info_tab can be moved ***************************************************************************/ @@ -89,22 +88,27 @@ void info_tab::mousePressEvent(QMouseEvent *event) if (gui()->interface_locked) { return; } + if (event->button() == Qt::LeftButton) { + QPoint pos = event->pos(); + int x = pos.x(); + int y = pos.y(); + cursor = event->globalPos() - geometry().topLeft(); - if (event->y() > 0 && event->y() < 25 && event->x() > width() - 25 - && event->x() < width()) { + if (y > 0 && y < 25 && x > width() - 25 && x < width()) { resize_mode = true; resxy = true; return; } - if (event->y() > 0 && event->y() < 5) { + if (y > 0 && y < 5) { resize_mode = true; resy = true; - } else if (event->x() > width() - 5 && event->x() < width()) { + } else if (x > width() - 5 && x < width()) { resize_mode = true; resx = true; } } + event->setAccepted(true); } @@ -141,30 +145,40 @@ void info_tab::mouseReleaseEvent(QMouseEvent* event) ***************************************************************************/ void info_tab::mouseMoveEvent(QMouseEvent *event) { + QPoint pos; + int ex, ey; + if (gui()->interface_locked) { return; } + + pos = event->pos(); + ex = pos.x(); + ey = pos.y(); + if ((event->buttons() & Qt::LeftButton) && resize_mode && resy) { QPoint to_move; int newheight = event->globalY() - cursor.y() - geometry().y(); + resize(width(), this->geometry().height()-newheight); to_move = event->globalPos() - cursor; move(this->x(), to_move.y()); setCursor(Qt::SizeVerCursor); restore_chat(); - } else if (event->x() > width() - 9 && event->y() > 0 && event->y() < 9) { + } else if (ex > width() - 9 && ey > 0 && ey < 9) { setCursor(Qt::SizeBDiagCursor); } else if ((event->buttons() & Qt::LeftButton) && resize_mode && resx) { - resize(event->x(), height()); + resize(ex, height()); setCursor(Qt::SizeHorCursor); - } else if (event->x() > width() - 5 && event->x() < width()) { + } else if (ex > width() - 5 && ex < width()) { setCursor(Qt::SizeHorCursor); - } else if (event->y() > 0 && event->y() < 5) { + } else if (ey > 0 && ey < 5) { setCursor(Qt::SizeVerCursor); } else if (resxy && (event->buttons() & Qt::LeftButton)) { QPoint to_move; int newheight = event->globalY() - cursor.y() - geometry().y(); - resize(event->x(), this->geometry().height()- newheight); + + resize(ex, this->geometry().height()- newheight); to_move = event->globalPos() - cursor; move(this->x(), to_move.y()); setCursor(Qt::SizeBDiagCursor); @@ -172,6 +186,7 @@ void info_tab::mouseMoveEvent(QMouseEvent *event) } else { setCursor(Qt::ArrowCursor); } + event->setAccepted(true); } diff --git a/client/gui-qt/ratesdlg.cpp b/client/gui-qt/ratesdlg.cpp index 90cd168ae8..70bb7543d4 100644 --- a/client/gui-qt/ratesdlg.cpp +++ b/client/gui-qt/ratesdlg.cpp @@ -387,7 +387,7 @@ void fc_double_edge::paintEvent(QPaintEvent *event) void fc_double_edge::mousePressEvent(QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) { - mouse_x = static_cast(event->x()); + mouse_x = static_cast(event->pos().x()); if (mouse_x <= current_max * width() / 10 - 2 * cursor_size) { moved = 1; @@ -414,7 +414,7 @@ void fc_double_edge::mouseMoveEvent(QMouseEvent *event) setCursor(Qt::ArrowCursor); } - x_mouse = static_cast(event->x()); + x_mouse = static_cast(event->pos().x()); x_min = static_cast(current_min) / 10 * ((width() - 1) - 2 * cursor_size) + cursor_size; x_max = static_cast(current_max) / 10 * diff --git a/client/gui-qt/repodlgs.cpp b/client/gui-qt/repodlgs.cpp index e9793b867a..5be7bc3671 100644 --- a/client/gui-qt/repodlgs.cpp +++ b/client/gui-qt/repodlgs.cpp @@ -712,7 +712,8 @@ void research_diagram::reset() ****************************************************************************/ void research_diagram::mousePressEvent(QMouseEvent *event) { - Tech_type_id tech = get_tech_on_reqtree(req, event->x(), event->y()); + QPoint pos = event->pos(); + Tech_type_id tech = get_tech_on_reqtree(req, pos.x(), pos.y()); req_tooltip_help *rttp; int i; -- 2.35.1