Author: mir3x
Date: Mon Dec 14 03:00:49 2015
New Revision: 30991

URL: http://svn.gna.org/viewcvs/freeciv?rev=30991&view=rev
Log:
Tooltips in city production and research dialog in Qt-client
are now cut if too long, added bolded title to them,
unit properties are shown in table, 
tooltips wont disappear if mouse moved by pixel in city production dialog. 

See patch #6665


Modified:
    branches/S2_5/client/gui-qt/citydlg.cpp
    branches/S2_5/client/gui-qt/citydlg.h
    branches/S2_5/client/gui-qt/optiondlg.cpp
    branches/S2_5/client/gui-qt/optiondlg.h
    branches/S2_5/client/gui-qt/repodlgs.cpp

Modified: branches/S2_5/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/citydlg.cpp?rev=30991&r1=30990&r2=30991&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/citydlg.cpp     (original)
+++ branches/S2_5/client/gui-qt/citydlg.cpp     Mon Dec 14 03:00:49 2015
@@ -58,7 +58,7 @@
                                        * once per client
                                        */
 static city_dialog *city_dlg;
-extern QString split_text(QString text);
+extern QString split_text(QString text, bool cut);
 extern QString cut_helptext(QString text);
 
 /****************************************************************************
@@ -2633,6 +2633,8 @@
     }
     item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
     rect = view->visualRect(index);
+    rect.setX(rect.x() + help_event->globalPos().x());
+    rect.setY(rect.y() + help_event->globalPos().y());
 
     if (!item_tooltip.isEmpty()) {
       QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
@@ -2643,6 +2645,58 @@
   }
   return false;
 }
+
+QString bold(QString text)
+{
+  return QString("<b>" + text + "</b>");
+}
+
+
+/***************************************************************************
+  Returns improvement properties to append in tooltip
+***************************************************************************/
+QString get_tooltip_improvement(impr_type *building)
+{
+  QString def_str;
+
+  def_str = "<p style='white-space:pre'><b>"
+            + QString(improvement_name_translation(building))
+            + "</b>\n";
+  def_str += QString(N_("Cost: %1, Upkeep: %2\n\n"))
+             .arg(impr_build_shield_cost(building))
+             .arg(building->upkeep);
+  return def_str;
+}
+
+/***************************************************************************
+  Returns unit properties to append in tooltip
+***************************************************************************/
+QString get_tooltip_unit(struct unit_type *unit)
+ {
+  QString def_str;
+
+  def_str = "<b>" + QString(utype_name_translation(unit)) + "</b>\n";
+  def_str += "<table><tr><td>" + bold(QString(_("Attack:"))) + " "
+             + QString::number(unit->attack_strength)
+             + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
+             + QString::number(unit->attack_strength)
+             + QString("</td><td>") + bold(QString(_("Move:"))) + " "
+             + QString(move_points_text(unit->move_rate, TRUE))
+             + QString("</td></tr><tr><td>")
+             + bold(QString(_("Cost:"))) + " "
+             + QString::number(utype_build_shield_cost(unit))
+             + QString("</td><td>") + bold(QString(_("Basic Upkeep:")))
+             + " " + QString(helptext_unit_upkeep_str(unit))
+             + QString("</td></tr><tr><td>")
+             + bold(QString(_("Hitpoints:"))) + " "
+             + QString::number(unit->hp)
+             + QString("</td><td>") + bold(QString(_("FirePower:"))) + " "
+             + QString::number(unit->firepower)
+             + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
+             + QString::number((int) sqrt((double) unit->vision_radius_sq))
+             + QString("</td></tr></table><p style='white-space:pre'>");
+  return def_str;
+};
 
 /**************************************************************************
   Returns shortened help for given universal ( stored in qvar )
@@ -2659,24 +2713,12 @@
   target = reinterpret_cast<universal *>(qvar.value<void *>());
   if (target == NULL) {
   } else if (VUT_UTYPE == target->kind) {
-    def_str = QString(N_("Attack: %1, Defense: %2, Move: %3\n"))
-              .arg(target->value.utype->attack_strength)
-              .arg(target->value.utype->defense_strength)
-              .arg(QString(move_points_text(target->value.utype->move_rate, 
TRUE)));
-    def_str += QString(N_("Cost: %1, Basic Upkeep: %2\n"))
-               .arg(utype_build_shield_cost(target->value.utype))
-               .arg(helptext_unit_upkeep_str(target->value.utype));
-    def_str += QString(N_("Hitpoints: %1, FirePower: %2, Vision: %3\n\n"))
-               .arg(target->value.utype->hp)
-               .arg(target->value.utype->firepower)
-               .arg((int)sqrt((double)target->value.utype->vision_radius_sq));
+    def_str = get_tooltip_unit(target->value.utype);
     str = helptext_unit(buffer, sizeof(buffer), client.conn.playing,
                         buf2, target->value.utype);
   } else {
     if (!improvement_has_flag(target->value.building, IF_GOLD)) {
-      def_str = QString(N_("Cost: %1, Upkeep: %2\n\n"))
-                .arg(impr_build_shield_cost(target->value.building))
-                .arg(target->value.building->upkeep);
+      def_str = get_tooltip_improvement(target->value.building);
     }
     str = helptext_building(buffer, sizeof(buffer), client.conn.playing,
                             NULL, target->value.building);
@@ -2684,8 +2726,7 @@
 
   /* Remove all lines from help which has '*' in first 3 chars */
   ret_str = cut_helptext(str);
-
-  ret_str = split_text(ret_str);
+  ret_str = split_text(ret_str, true);
   ret_str = ret_str.trimmed();
   ret_str = def_str + ret_str;
 

Modified: branches/S2_5/client/gui-qt/citydlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/citydlg.h?rev=30991&r1=30990&r2=30991&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/citydlg.h       (original)
+++ branches/S2_5/client/gui-qt/citydlg.h       Mon Dec 14 03:00:49 2015
@@ -36,6 +36,9 @@
 
 #define NUM_INFO_FIELDS 12
 
+//common
+#include "unittype.h"
+
 // client
 #include "canvas.h"
 
@@ -45,7 +48,9 @@
 #include <QToolTip>
 
 QString get_tooltip(QVariant qvar);
-
+QString get_tooltip_improvement(impr_type *building);
+QString get_tooltip_unit(struct unit_type *unit);
+QString bold(QString text);
 
 class fc_tooltip : public QObject
 {

Modified: branches/S2_5/client/gui-qt/optiondlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/optiondlg.cpp?rev=30991&r1=30990&r2=30991&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/optiondlg.cpp   (original)
+++ branches/S2_5/client/gui-qt/optiondlg.cpp   Mon Dec 14 03:00:49 2015
@@ -51,11 +51,12 @@
 /****************************************************************************
   Splits long text to 80 characters
 ****************************************************************************/
-QString split_text(QString text)
+QString split_text(QString text, bool cut)
 {
   QStringList sl;
   QString st, str, result;
   int i;
+  int j = 0;
 
   sl = text.split("\n");
   foreach (const QString &s, sl) {
@@ -76,7 +77,14 @@
       }
     }
     str = st;
-    result = result + str.left(str.count()) + '\n';
+    if (str.left(str.count()) != "") {
+      result = result + str.left(str.count()) + '\n';
+    }
+    j++;
+    if (j >= 12 && cut) {
+      result = result + _("... read more in help") + "\n";
+      break;
+    }
   }
   result.remove(result.lastIndexOf('\n'), 1);
   return result;
@@ -727,7 +735,7 @@
     hbox_layout = new QHBoxLayout();
     hbox_layout->setAlignment(Qt::AlignRight);
     label = new QLabel(description);
-    label->setToolTip(split_text(option_help_text(poption)));
+    label->setToolTip(split_text(option_help_text(poption), false));
     hbox_layout->addWidget(label, 1, Qt::AlignLeft);
     hbox_layout->addStretch();
     hbox_layout->addWidget(widget, 1, Qt::AlignRight);
@@ -738,7 +746,7 @@
   }
 
   widget->setEnabled(option_is_changeable(poption));
-  widget->setToolTip(split_text(option_help_text(poption)));
+  widget->setToolTip(split_text(option_help_text(poption), false));
   option_set_gui_data(poption, widget);
   option_dialog_refresh(poption);
 }

Modified: branches/S2_5/client/gui-qt/optiondlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/optiondlg.h?rev=30991&r1=30990&r2=30991&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/optiondlg.h     (original)
+++ branches/S2_5/client/gui-qt/optiondlg.h     Mon Dec 14 03:00:49 2015
@@ -31,7 +31,7 @@
 class QWidget;
 class QString;
 
-QString split_text(QString text);
+QString split_text(QString text, bool cut);
 QString cut_helptext(QString text);
 /****************************************************************************
   Dialog for client/server options

Modified: branches/S2_5/client/gui-qt/repodlgs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/repodlgs.cpp?rev=30991&r1=30990&r2=30991&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/repodlgs.cpp    (original)
+++ branches/S2_5/client/gui-qt/repodlgs.cpp    Mon Dec 14 03:00:49 2015
@@ -42,8 +42,11 @@
 
 #include "repodlgs.h"
 
-extern QString split_text(QString text);
+extern QString split_text(QString text, bool cut);
 extern QString cut_helptext(QString text);
+extern QString get_tooltip_improvement(impr_type *building);
+extern QString get_tooltip_unit(struct unit_type *unit);
+
 
 /****************************************************************************
   From reqtree.c used to get tooltips
@@ -270,6 +273,7 @@
   req_tooltip_help *rttp;
   int i;
   QString tt_text;
+  QString def_str;
   char buffer[8192];
   char buf2[1];
 
@@ -281,18 +285,24 @@
         helptext_advance(buffer, sizeof(buffer), client.conn.playing,
                          buf2, rttp->tech_id);
         tt_text = QString(buffer);
+        def_str = "<p style='white-space:pre'><b>"
+                  + QString(advance_name_translation(
+                            advance_by_number(rttp->tech_id))) + "</b>\n";
       } else if (rttp->timpr != nullptr) {
+        def_str = get_tooltip_improvement(rttp->timpr);
         tt_text = helptext_building(buffer, sizeof(buffer),
-                                    client.conn.playing, NULL, rttp->timpr);
+                                     client.conn.playing, NULL, rttp->timpr);
         tt_text = cut_helptext(tt_text);
       } else if (rttp->tunit != nullptr) {
-        tt_text = helptext_unit(buffer, sizeof(buffer), client.conn.playing,
+        def_str = get_tooltip_unit(rttp->tunit);
+        tt_text += helptext_unit(buffer, sizeof(buffer), client.conn.playing,
                                 buf2, rttp->tunit);
         tt_text = cut_helptext(tt_text);
       } else {
         return;
       }
-      tt_text = split_text(tt_text);
+      tt_text = split_text(tt_text, true);
+      tt_text = def_str + tt_text;
       tt_text = tt_text.trimmed();
       if (QToolTip::text() == "") {
         QToolTip::showText(event->globalPos(), tt_text, this, rttp->rect);


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

Reply via email to