commit 4089ff1ec36292a37866c81d844e9ebd6dffd850
Author: Guillaume Munch <[email protected]>
Date: Sat Jun 11 12:57:18 2016 +0100
Beautify ToolTips in work area
* 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 | 4 ++--
src/frontends/qt4/GuiWorkArea.cpp | 2 +-
src/insets/Inset.h | 4 +++-
src/insets/InsetBibtex.cpp | 31 +++++++++++--------------------
src/insets/InsetCitation.cpp | 15 ++++++++-------
src/insets/InsetText.cpp | 14 ++++++--------
src/insets/InsetText.h | 9 +++++----
7 files changed, 36 insertions(+), 43 deletions(-)
diff --git a/src/frontends/qt4/GuiDocument.cpp
b/src/frontends/qt4/GuiDocument.cpp
index 139bdb4..af42fd8 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -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),
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index b273183..dad7de4 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -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();
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index c450505..bb6323a 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -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
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index ca7cdba..e3202ec 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -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");
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 4bf6333..2b9033f 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -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;
}
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index d34c8d2..7d28020 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -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;
}
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index b42dce3..3718e1d 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -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;