Author: mir3x
Date: Mon Nov 16 19:58:11 2015
New Revision: 30634

URL: http://svn.gna.org/viewcvs/freeciv?rev=30634&view=rev
Log:
Fixed city report columns width in qt-client,
their width is still interactive, but defaults
to contents.
Reported by Jacob Nevins <jtn>.

See bug #24048


Modified:
    trunk/client/gui-qt/cityrep.cpp

Modified: trunk/client/gui-qt/cityrep.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/cityrep.cpp?rev=30634&r1=30633&r2=30634&view=diff
==============================================================================
--- trunk/client/gui-qt/cityrep.cpp     (original)
+++ trunk/client/gui-qt/cityrep.cpp     Mon Nov 16 19:58:11 2015
@@ -151,7 +151,7 @@
   spec = city_report_specs+column;
   fc_snprintf(buf, sizeof(buf), "%*s", NEG_VAL(spec->width),
                 spec->func(i_city, spec->data));
-  return QString(buf);
+  return QString(buf).trimmed();
 }
 
 /***************************************************************************
@@ -219,11 +219,11 @@
 
   if (orientation == Qt::Horizontal && section < NUM_CREPORT_COLS) {
     if (role == Qt::DisplayRole) {
-    spec = city_report_specs + section;
-    fc_snprintf(buf, sizeof(buf), "%*s\n%*s",
-                NEG_VAL(spec->width), spec->title1 ? spec->title1 : "",
-                NEG_VAL(spec->width), spec->title2 ? spec->title2 : "");
-      return QString(buf);
+      spec = city_report_specs + section;
+      fc_snprintf(buf, sizeof(buf), "%*s\n%*s",
+                  NEG_VAL(spec->width), spec->title1 ? spec->title1 : "",
+                  NEG_VAL(spec->width), spec->title2 ? spec->title2 : "");
+      return QString(buf).trimmed();
     }
     if (role == Qt::ToolTipRole) {
       spec = city_report_specs + section;
@@ -357,7 +357,9 @@
   setSelectionBehavior(QAbstractItemView::SelectRows);
   setItemsExpandable(false);
   setAutoScroll(true);
+  setProperty("uniformRowHeights", "true");
   header()->setContextMenuPolicy(Qt::CustomContextMenu);
+  header()->setMinimumSectionSize(10);
   setContextMenuPolicy(Qt::CustomContextMenu);
   hide_columns();
   connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)),
@@ -1068,9 +1070,28 @@
 ***************************************************************************/
 void city_widget::update_model()
 {
+  QStringList sl;
+  QString s, str;
+  int width;
+
   setUpdatesEnabled(false);
   list_model->all_changed();
   restore_selection();
+  for (int j = 0; j < filter_model->columnCount(); j++) {
+    str = list_model->headerData(j, Qt::Horizontal, 
Qt::DisplayRole).toString();
+    if (str.contains('\n')) {
+      sl = str.split('\n');
+      width = 0;
+      foreach (s, sl) {
+        QFont f = QApplication::font();
+        QFontMetrics fm(f);
+        width = qMax(width, fm.width(s));
+      }
+      header()->resizeSection(j, width + 10);
+    } else {
+      header()->resizeSection(j, header()->sectionSizeHint(j));
+    }
+  }
   setUpdatesEnabled(true);
 }
 


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

Reply via email to