Author: mir3x
Date: Sun Nov  1 18:24:10 2015
New Revision: 30340

URL: http://svn.gna.org/viewcvs/freeciv?rev=30340&view=rev
Log:
Added splitting of tooltips into max 80 characters in Qt-client. 

See bug #23972


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

Modified: trunk/client/gui-qt/optiondlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/optiondlg.cpp?rev=30340&r1=30339&r2=30340&view=diff
==============================================================================
--- trunk/client/gui-qt/optiondlg.cpp   (original)
+++ trunk/client/gui-qt/optiondlg.cpp   Sun Nov  1 18:24:10 2015
@@ -48,6 +48,39 @@
 /* global value to store pointers to opened config dialogs */
 QMap<const struct option_set *, option_dialog *> dialog_list;
 
+/****************************************************************************
+  Splits long text to 80 characters
+****************************************************************************/
+static QString split_text(QString text)
+{
+  QStringList sl;
+  QString st, str, result;
+  int i;
+
+  sl = text.split("\n");
+  foreach (const QString &s, sl) {
+    st = s;
+    while (st.count() >= 80) {
+      str = st.left(80);
+      i = str.lastIndexOf(' ');
+      if (i == -1) {
+        i = 80;
+      }
+      result = result + str.left(i) + '\n';
+      /* Skip last space - at (i + 1)
+         unless there there was no space */
+      if (i != 80) {
+        st.remove(0, i + 1);
+      } else {
+        st.remove(0, i);
+      }
+    }
+    str = st;
+    result = result + str.left(str.count()) + '\n';
+  }
+  result.remove(result.lastIndexOf('\n'), 1);
+  return result;
+}
 
 /****************************************************************************
   Constructor for options dialog.
@@ -671,7 +704,7 @@
     hbox_layout = new QHBoxLayout();
     hbox_layout->setAlignment(Qt::AlignRight);
     label = new QLabel(description);
-    label->setToolTip(option_help_text(poption));
+    label->setToolTip(split_text(option_help_text(poption)));
     hbox_layout->addWidget(label, 1, Qt::AlignLeft);
     hbox_layout->addStretch();
     hbox_layout->addWidget(widget, 1, Qt::AlignRight);
@@ -682,7 +715,7 @@
   }
 
   widget->setEnabled(option_is_changeable(poption));
-  widget->setToolTip(option_help_text(poption));
+  widget->setToolTip(split_text(option_help_text(poption)));
   option_set_gui_data(poption, widget);
   option_dialog_refresh(poption);
 }


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

Reply via email to