]> git.lyx.org Git - features.git/commitdiff
Beautify ToolTips in work area
authorGuillaume Munch <gm@lyx.org>
Sat, 11 Jun 2016 11:57:18 +0000 (12:57 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 3 Jul 2016 15:28:46 +0000 (17:28 +0200)
* Justification and nicer line breaks.

* Much nicer tooltip for lists of bibliographical references.

* Removed unnecessary iterated copies of the string buffer in
  InsetText::ToolTipText() which looked bad. This function used to be costly
  (cf64064), maybe it is quicker now.

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/insets/Inset.h
src/insets/InsetBibtex.cpp
src/insets/InsetCitation.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h

index 139bdb436671bcebb87f7655003fe8ea7005dee3..af42fd8be10c8a889b45502efa75f858fd924495 100644 (file)
@@ -1278,10 +1278,10 @@ GuiDocument::GuiDocument(GuiView & lv)
                QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
                if (!available) {
                        docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
-                       tooltip += '\n' + toqstr(wrap(bformat(_("Class not found by LyX. "
+                       tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
                                                           "Please check if you have the matching %1$s class "
                                                           "and all required packages (%2$s) installed."),
-                                                        output_type, from_utf8(tc.prerequisites(", ")))));
+                                                        output_type, from_utf8(tc.prerequisites(", "))));
                }
                latexModule->classCO->addItemSort(toqstr(tc.name()),
                                                  toqstr(guiname),
index b27318388ee9a2af18973e56e97262f7045af4c3..dad7de4b6e6d6d9600c42b07845cc0a6aacb3428 100644 (file)
@@ -701,7 +701,7 @@ bool GuiWorkArea::event(QEvent * e)
                        QPoint pos = helpEvent->pos();
                        if (pos.x() < viewport()->width()) {
                                QString s = toqstr(d->buffer_view_->toolTip(pos.x(), pos.y()));
-                               QToolTip::showText(helpEvent->globalPos(), s);
+                               QToolTip::showText(helpEvent->globalPos(), formatToolTip(s,35));
                        }
                        else
                                QToolTip::hideText();
index c450505ed2bdb7343dd09fe50a1167db979b89bc..bb6323a45447a999fc0e2a0b43ffd829cb4df1e0 100644 (file)
@@ -412,7 +412,9 @@ public:
        virtual bool producesOutput() const { return true; }
 
        /// \return Tool tip for this inset.
-       /// This default implementation returns an empty string.
+       /// This default implementation returns an empty string. This can be
+       /// either plain text or Qt html, and formatToolTip will be called
+       /// on it before display in both cases.
        virtual docstring toolTip(BufferView const & bv, int x, int y) const;
        
        /// \return Context menu identifier. This function determines
index ca7cdbaa239f1614292992c6f91f0edccd496b8e..e3202ec5d35285d8eff70b2934f2c1c14bcf7940 100644 (file)
@@ -173,21 +173,16 @@ docstring InsetBibtex::screenLabel() const
 
 docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
 {
-       docstring item = from_ascii("* ");
-       docstring tip = _("Databases:") + "\n";
+       docstring tip = _("Databases:");
        vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
 
-       if (bibfilelist.empty()) {
-               tip += item;
-               tip += _("none");
-       } else {
-               vector<docstring>::const_iterator it = bibfilelist.begin();
-               vector<docstring>::const_iterator en = bibfilelist.end();
-               for (; it != en; ++it) {
-                       tip += item;
-                       tip += *it + "\n";
-               }
-       }
+       tip += "<ul>";
+       if (bibfilelist.empty())
+               tip += "<li>" + _("none") + "</li>";
+       else
+               for (docstring const & bibfile : bibfilelist)
+                       tip += "<li>" + bibfile + "</li>";
+       tip += "</ul>";
 
        // Style-Options
        bool toc = false;
@@ -199,14 +194,10 @@ docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/)
                        style = split(style, bibtotoc, char_type(','));
        }
 
-       tip += _("Style File:") +"\n";
-       tip += item;
-       if (!style.empty())
-               tip += style;
-       else
-               tip += _("none");
+       tip += _("Style File:");
+       tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
 
-       tip += "\n" + _("Lists:") + " ";
+       tip += _("Lists:") + " ";
        docstring btprint = getParam("btprint");
                if (btprint == "btPrintAll")
                        tip += _("all references");
index 4bf6333f2791bd4dd56d2b7a1d0efd8a9e64440d..2b9033f42dfc64c362ed5864c00480b1fc0734f0 100644 (file)
@@ -165,17 +165,18 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
                return _("No citations selected!");
 
        vector<docstring> keys = getVectorFromString(key);
-       vector<docstring>::const_iterator it = keys.begin();
-       vector<docstring>::const_iterator en = keys.end();
+       if (keys.size() == 1)
+               return  bi.getInfo(keys[0], buffer(), true);
+
        docstring tip;
-       for (; it != en; ++it) {
-               docstring const key_info = bi.getInfo(*it, buffer());
+       tip += "<ol>";
+       for (docstring const & key : keys) {
+               docstring const key_info = bi.getInfo(key, buffer(), true);
                if (key_info.empty())
                        continue;
-               if (!tip.empty())
-                       tip += "\n";
-               tip += wrap(key_info, -4);
+               tip += "<li>" + key_info + "</li>";
        }
+       tip += "</ol>";
        return tip;
 }
 
index d34c8d26d46d186c0df6bf163b10de99a12f7473..7d28020669caff829576a2919f71254dea8013bd 100644 (file)
@@ -965,10 +965,8 @@ string InsetText::contextMenuName() const
 }
 
 
-docstring InsetText::toolTipText(docstring prefix,
-               size_t numlines, size_t len) const
+docstring InsetText::toolTipText(docstring prefix, size_t const len) const
 {
-       size_t const max_length = numlines * len;
        OutputParams rp(&buffer().params().encoding());
        rp.for_tooltip = true;
        odocstringstream oss;
@@ -978,17 +976,17 @@ docstring InsetText::toolTipText(docstring prefix,
        ParagraphList::const_iterator end = paragraphs().end();
        ParagraphList::const_iterator it = beg;
        bool ref_printed = false;
-       docstring str;
 
        for (; it != end; ++it) {
                if (it != beg)
                        oss << '\n';
-               writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
-               str = oss.str();
-               if (str.length() >= max_length)
+               writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, len);
+               if (oss.tellp() >= 0 && size_t(oss.tellp()) > len)
                        break;
        }
-       return support::wrapParas(str, 4, len, numlines);
+       docstring str = oss.str();
+       support::truncateWithEllipsis(str, len);
+       return str;
 }
 
 
index b42dce39ef76c8200a3b8579eaf903e39105b896..3718e1d1d3e948815c29dd2b415a8f04ef705686 100644 (file)
@@ -201,13 +201,14 @@ public:
        /// returns the text to be used as tooltip
        /// \param prefix: a string that will preced the tooltip,
        /// e.g., "Index: ".
-       /// \param numlines: the number of lines in the tooltip
-       /// \param len: length of those lines
+       /// \param len: length of the resulting string
        /// NOTE This routine is kind of slow. It's fine to use it within the 
        /// GUI, but definitely do not try to use it in updateBuffer or anything
-       /// of that sort.
+       /// of that sort. (Note: unnecessary internal copies have been removed
+       /// since the previous note. The efficiency would have to be assessed
+       /// again by profiling.)
        docstring toolTipText(docstring prefix = empty_docstring(),
-                       size_t numlines = 5, size_t len = 80) const;
+                             size_t len = 400) const;
 
        ///
        std::string contextMenu(BufferView const &, int, int) const;