From bf56af52a115f418f2f34e97c1bddd485ae7e2bf Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 28 Jul 2022 04:19:29 +0300 Subject: [PATCH 50/50] Qt: Rework info_tile::calc_size() - Fix clang analyzer warning about dead assignments - Move variables to inner scopes - No repeated function calls See osdn #45231 Signed-off-by: Marko Lindqvist --- client/gui-qt/mapview.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/client/gui-qt/mapview.cpp b/client/gui-qt/mapview.cpp index 068ea3ccdd..921dab16a4 100644 --- a/client/gui-qt/mapview.cpp +++ b/client/gui-qt/mapview.cpp @@ -1369,9 +1369,6 @@ void info_tile::calc_size() { QFontMetrics fm(info_font); QString str; - int hh = tileset_tile_height(tileset); - int fin_x; - int fin_y; float x, y; int w = 0; @@ -1383,16 +1380,22 @@ void info_tile::calc_size() } setFixedHeight(str_list.count() * (fm.height() + 5)); setFixedWidth(w + 10); + if (tile_to_canvas_pos(&x, &y, itile)) { + int fin_x; + int fin_y; + int wh = height(); + int ww = width(); + int pw = parentWidget()->width(); + fin_x = x; - fin_y = y; - if (y - height() > 0) { - fin_y = y - height(); + if (y - wh > 0) { + fin_y = y - wh; } else { - fin_y = y + hh; + fin_y = y + tileset_tile_height(tileset); } - if (x + width() > parentWidget()->width()) { - fin_x = parentWidget()->width() - width(); + if (x + ww > pw) { + fin_x = pw - ww; } move(fin_x, fin_y); } -- 2.35.1