Author: mir3x
Date: Sun Nov  1 18:24:04 2015
New Revision: 30339

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

See bug #23972


Modified:
    branches/S2_6/client/gui-qt/optiondlg.cpp

Modified: branches/S2_6/client/gui-qt/optiondlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/optiondlg.cpp?rev=30339&r1=30338&r2=30339&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/optiondlg.cpp   (original)
+++ branches/S2_6/client/gui-qt/optiondlg.cpp   Sun Nov  1 18:24:04 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