Author: mir3x
Date: Fri Dec  2 09:32:27 2016
New Revision: 34672

URL: http://svn.gna.org/viewcvs/freeciv?rev=34672&view=rev
Log:
Qt client - widgets position and size is stored using floats instead ints

See patch #8038


Modified:
    trunk/client/gui-qt/fc_client.cpp
    trunk/client/gui-qt/fc_client.h
    trunk/client/gui-qt/hudwidget.cpp
    trunk/client/gui-qt/messagewin.cpp

Modified: trunk/client/gui-qt/fc_client.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.cpp?rev=34672&r1=34671&r2=34672&view=diff
==============================================================================
--- trunk/client/gui-qt/fc_client.cpp   (original)
+++ trunk/client/gui-qt/fc_client.cpp   Fri Dec  2 09:32:27 2016
@@ -579,35 +579,35 @@
   if (s.contains("Fonts-set") == false) {
     configure_fonts();
   }
-  if (s.contains("Chat-x-size")) {
-    qt_settings.chat_width = s.value("Chat-x-size").toInt();
-  } else {
-    qt_settings.chat_width = 2000;
-  }
-  if (s.contains("Chat-y-size")) {
-    qt_settings.chat_height = s.value("Chat-y-size").toInt();
-  } else {
-    qt_settings.chat_height = 4000;
-  }
-  if (s.contains("Chat-x-pos")) {
-    qt_settings.chat_x_pos = s.value("Chat-x-pos").toInt();
-  } else {
-    qt_settings.chat_x_pos = 0;
-  }
-  if (s.contains("Chat-y-pos")) {
-    qt_settings.chat_y_pos = s.value("Chat-y-pos").toInt();
-  } else {
-    qt_settings.chat_y_pos = 10000;
-  }
-  if (s.contains("unit_x")) {
-    qt_settings.unit_info_pos_x = s.value("unit_x").toInt();
-  } else {
-    qt_settings.unit_info_pos_x = 330;
-  }
-  if (s.contains("unit_y")) {
-    qt_settings.unit_info_pos_y = s.value("unit_y").toInt();
-  } else {
-    qt_settings.unit_info_pos_y = 880;
+  if (s.contains("Chat-fx-size")) {
+    qt_settings.chat_fwidth = s.value("Chat-fx-size").toFloat();
+  } else {
+    qt_settings.chat_fwidth = 0.2;
+  }
+  if (s.contains("Chat-fy-size")) {
+    qt_settings.chat_fheight = s.value("Chat-fy-size").toFloat();
+  } else {
+    qt_settings.chat_fheight = 0.4;
+  }
+  if (s.contains("Chat-fx-pos")) {
+    qt_settings.chat_fx_pos = s.value("Chat-fx-pos").toFloat();
+  } else {
+    qt_settings.chat_fx_pos = 0.0;
+  }
+  if (s.contains("Chat-fy-pos")) {
+    qt_settings.chat_fy_pos = s.value("Chat-fy-pos").toFloat();
+  } else {
+    qt_settings.chat_fy_pos = 0.6;
+  }
+  if (s.contains("unit_fx")) {
+    qt_settings.unit_info_pos_fx = s.value("unit_fx").toFloat();
+  } else {
+    qt_settings.unit_info_pos_fx = 0.33;
+  }
+  if (s.contains("unit_fy")) {
+    qt_settings.unit_info_pos_fy = s.value("unit_fy").toFloat();
+  } else {
+    qt_settings.unit_info_pos_fy = 0.88;
   }
   if (s.contains("minimap_x")) {
     qt_settings.minimap_x = s.value("minimap_x").toFloat();
@@ -665,8 +665,29 @@
   qt_settings.player_repo_sort_col = -1;
   qt_settings.city_repo_sort_col = -1;
 
-  if (qt_settings.chat_x_pos < 0) {
-    qt_settings.chat_x_pos = 0;
+  if (qt_settings.chat_fx_pos < 0 || qt_settings.chat_fx_pos >= 1) {
+    qt_settings.chat_fx_pos = 0.0;
+  }
+  if (qt_settings.chat_fy_pos >= 1 || qt_settings.chat_fy_pos < 0) {
+    qt_settings.chat_fy_pos = 0.6;
+  }
+  if (qt_settings.chat_fwidth < 0.05 || qt_settings.chat_fwidth > 0.9) {
+    qt_settings.chat_fwidth = 0.2;
+  }
+  if (qt_settings.chat_fheight < 0.05 || qt_settings.chat_fheight > 0.9) {
+    qt_settings.chat_fheight = 0.33;
+  }
+  if (qt_settings.battlelog_x < 0.0) {
+    qt_settings.battlelog_x = 0.33;
+  }
+  if (qt_settings.battlelog_y < 0.0) {
+    qt_settings.battlelog_y = 0.0;
+  }
+  if (qt_settings.minimap_x < 0 || qt_settings.minimap_x > 1) {
+    qt_settings.chat_fx_pos = 0.84;
+  }
+  if (qt_settings.minimap_y < 0 || qt_settings.minimap_y > 1) {
+    qt_settings.chat_fx_pos = 0.79;
   }
 }
 
@@ -678,16 +699,16 @@
   QSettings s(QSettings::IniFormat, QSettings::UserScope,
               "freeciv-qt-client");
   s.setValue("Fonts-set", true);
-  s.setValue("Chat-x-size", qt_settings.chat_width);
-  s.setValue("Chat-y-size", qt_settings.chat_height);
-  s.setValue("Chat-x-pos", qt_settings.chat_x_pos);
-  s.setValue("Chat-y-pos", qt_settings.chat_y_pos);
+  s.setValue("Chat-fx-size", qt_settings.chat_fwidth);
+  s.setValue("Chat-fy-size", qt_settings.chat_fheight);
+  s.setValue("Chat-fx-pos", qt_settings.chat_fx_pos);
+  s.setValue("Chat-fy-pos", qt_settings.chat_fy_pos);
   s.setValue("City-dialog", qt_settings.city_geometry);
   s.setValue("splitter1", qt_settings.city_splitter1);
   s.setValue("splitter2", qt_settings.city_splitter2);
   s.setValue("splitter3", qt_settings.city_splitter3);
-  s.setValue("unit_x", qt_settings.unit_info_pos_x);
-  s.setValue("unit_y", qt_settings.unit_info_pos_y);
+  s.setValue("unit_fx", qt_settings.unit_info_pos_fx);
+  s.setValue("unit_fy", qt_settings.unit_info_pos_fy);
   s.setValue("minimap_x", qt_settings.minimap_x);
   s.setValue("minimap_y", qt_settings.minimap_y);
   s.setValue("minimap_width", qt_settings.minimap_width);
@@ -955,28 +976,27 @@
   if (C_S_RUNNING <= client_state()) {
     gui()->sidebar_wdg->resize_me(size.width(), size.height());
     map_canvas_resized(size.width(), size.height());
-    size.setWidth(event->size().width() - gui()->sidebar_wdg->width());
-    gui()->infotab->resize((size.width()
-                             * gui()->qt_settings.chat_width) / 10000,
-                             (size.height()
-                             * gui()->qt_settings.chat_height) / 10000);
-    gui()->infotab->move((size.width() * gui()->qt_settings.chat_x_pos)
-                         /10000,
-                         (size.height() * gui()->qt_settings.chat_y_pos)
-                         /10000 - gui()->infotab->height());
+    gui()->infotab->resize(qRound((size.width()
+                             * gui()->qt_settings.chat_fwidth)),
+                             qRound((size.height()
+                             * gui()->qt_settings.chat_fheight)));
+    gui()->infotab->move(qRound((size.width()
+                                 * gui()->qt_settings.chat_fx_pos)),
+                         qRound((size.height()
+                                 * gui()->qt_settings.chat_fy_pos)));
     gui()->infotab->restore_chat();
-    gui()->minimapview_wdg->move(gui()->qt_settings.minimap_x
-                                 * mapview.width,
-                                 gui()->qt_settings.minimap_y
-                                 * mapview.height);
-    gui()->minimapview_wdg->resize(gui()->qt_settings.minimap_width
-                                   * mapview.width,
-                                   gui()->qt_settings.minimap_height
-                                   * mapview.height);
-    gui()->battlelog_wdg->move(gui()->qt_settings.battlelog_x
-                               * mapview.width,
-                               gui()->qt_settings.battlelog_y
-                               * mapview.height);
+    gui()->minimapview_wdg->move(qRound(gui()->qt_settings.minimap_x
+                                 * mapview.width),
+                                 qRound(gui()->qt_settings.minimap_y
+                                 * mapview.height));
+    gui()->minimapview_wdg->resize(qRound(gui()->qt_settings.minimap_width
+                                   * mapview.width),
+                                   qRound(gui()->qt_settings.minimap_height
+                                   * mapview.height));
+    gui()->battlelog_wdg->move(qRound(gui()->qt_settings.battlelog_x
+                               * mapview.width),
+                               qRound(gui()->qt_settings.battlelog_y
+                               * mapview.height));
     gui()->x_vote->move(width() / 2 - gui()->x_vote->width() / 2, 0);
     gui()->update_sidebar_tooltips();
     side_disable_endturn(get_turn_done_button_state());

Modified: trunk/client/gui-qt/fc_client.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.h?rev=34672&r1=34671&r2=34672&view=diff
==============================================================================
--- trunk/client/gui-qt/fc_client.h     (original)
+++ trunk/client/gui-qt/fc_client.h     Fri Dec  2 09:32:27 2016
@@ -121,10 +121,10 @@
 ****************************************************************************/
 struct fc_settings
 {
-  int chat_width;
-  int chat_height;
-  int chat_x_pos;
-  int chat_y_pos;
+  float chat_fwidth;
+  float chat_fheight;
+  float chat_fx_pos;
+  float chat_fy_pos;
   int player_repo_sort_col;
   bool show_new_turn_text;
   bool show_battle_log;
@@ -135,8 +135,8 @@
   QByteArray city_splitter1;
   QByteArray city_splitter2;
   QByteArray city_splitter3;
-  int unit_info_pos_x;
-  int unit_info_pos_y;
+  float unit_info_pos_fx;
+  float unit_info_pos_fy;
   float minimap_x;
   float minimap_y;
   float minimap_width;

Modified: trunk/client/gui-qt/hudwidget.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/hudwidget.cpp?rev=34672&r1=34671&r2=34672&view=diff
==============================================================================
--- trunk/client/gui-qt/hudwidget.cpp   (original)
+++ trunk/client/gui-qt/hudwidget.cpp   Fri Dec  2 09:32:27 2016
@@ -550,18 +550,10 @@
 ****************************************************************************/
 void hud_units::moveEvent(QMoveEvent *event)
 {
-  if (event->pos().x() != 0) {
-    gui()->qt_settings.unit_info_pos_x = 1 + (event->pos().x() * 1000)
-                                          / gui()->mapview_wdg->width();
-  } else {
-    gui()->qt_settings.unit_info_pos_x = 0;
-  }
-  if (event->pos().y() != 0) {
-    gui()->qt_settings.unit_info_pos_y = 1 + (event->pos().y() * 1000)
-                                          / gui()->mapview_wdg->height();
-  } else {
-    gui()->qt_settings.unit_info_pos_y = 0;
-  }
+  gui()->qt_settings.unit_info_pos_fx = static_cast<float>(event->pos().x())
+                                        / gui()->mapview_wdg->width();
+  gui()->qt_settings.unit_info_pos_fy = static_cast<float>(event->pos().y())
+                                        / gui()->mapview_wdg->height();
 }
 
 
@@ -600,10 +592,11 @@
   font.setBold(true);
   setFixedHeight(parentWidget()->height() / 12);
   text_label.setFixedHeight((height() * 2) / 10);
-  move((gui()->mapview_wdg->width()
-        * gui()->qt_settings.unit_info_pos_x) / 1000,
-        (gui()->mapview_wdg->height()
-        * gui()->qt_settings.unit_info_pos_y) / 1000);
+
+  move(qRound(gui()->mapview_wdg->width()
+        * gui()->qt_settings.unit_info_pos_fx),
+       qRound((gui()->mapview_wdg->height()
+        * gui()->qt_settings.unit_info_pos_fy)));
   unit_icons->setFixedHeight((height() * 8) / 10);
 
   setUpdatesEnabled(false);
@@ -1884,7 +1877,7 @@
 void hud_battle_log::moveEvent(QMoveEvent *event)
 {
   QPoint p;
-  p = event->pos();
+  p = pos();
   gui()->qt_settings.battlelog_x = static_cast<float>(p.x()) / mapview.width;
   gui()->qt_settings.battlelog_y = static_cast<float>(p.y())
                                    / mapview.height;

Modified: trunk/client/gui-qt/messagewin.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/messagewin.cpp?rev=34672&r1=34671&r2=34672&view=diff
==============================================================================
--- trunk/client/gui-qt/messagewin.cpp  (original)
+++ trunk/client/gui-qt/messagewin.cpp  Fri Dec  2 09:32:27 2016
@@ -110,6 +110,7 @@
 ***************************************************************************/
 void info_tab::mouseReleaseEvent(QMouseEvent* event)
 {
+  QPoint p;
   if (gui()->interface_locked) {
     return;
   }
@@ -119,15 +120,16 @@
     resy = false;
     resxy = false;
     setCursor(Qt::ArrowCursor);
-    gui()->qt_settings.chat_width = (width() * 10000)
-                                    / gui()->mapview_wdg->width();
-    gui()->qt_settings.chat_height = (height() * 10000)
+  }
+  p = pos();
+  gui()->qt_settings.chat_fwidth = static_cast<float>(width())
+                                   / gui()->mapview_wdg->width();
+  gui()->qt_settings.chat_fheight = static_cast<float>(height())
                                     / gui()->mapview_wdg->height();
-  }
-  gui()->qt_settings.chat_x_pos = 1 + (pos().x() * 10000)
-                                     / gui()->mapview_wdg->width();
-  gui()->qt_settings.chat_y_pos = 1 + ((pos().y() + height()) * 10000)
-                                     / gui()->mapview_wdg->height();
+  gui()->qt_settings.chat_fx_pos = static_cast<float>(p.x())
+                                   / gui()->mapview_wdg->width();
+  gui()->qt_settings.chat_fy_pos = static_cast<float>(p.y())
+                                   / gui()->mapview_wdg->height();
 }
 
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to