diff --git a/src/Changes.cpp b/src/Changes.cpp index 7741753899..b2fec78d40 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -503,14 +503,16 @@ void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer) const Toc::iterator it = change_list.item(0, author); if (it == change_list.end()) { change_list.push_back(TocItem(dit, 0, author)); - change_list.push_back(TocItem(dit, 1, str)); + change_list.push_back(TocItem(dit, 1, str, + support::wrapParas(str, 4))); continue; } for (++it; it != change_list.end(); ++it) { if (it->depth() == 0 && it->str() != author) break; } - change_list.insert(it, TocItem(dit, 1, str)); + change_list.insert(it, TocItem(dit, 1, str, + support::wrapParas(str, 4))); } } diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 2ba097cab8..ed80366f77 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -44,8 +44,8 @@ namespace lyx { // /////////////////////////////////////////////////////////////////////////// -TocItem::TocItem(DocIterator const & dit, int d, docstring const & s) - : dit_(dit), depth_(d), str_(s) +TocItem::TocItem(DocIterator const & dit, int d, docstring const & s, + docstring const & t) : dit_(dit), depth_(d), str_(s), tooltip_(t) { } @@ -68,6 +68,12 @@ docstring const & TocItem::str() const } +docstring const & TocItem::tooltip() const +{ + return tooltip_; +} + + docstring const TocItem::asString() const { return docstring(4 * depth_, ' ') + str_; diff --git a/src/TocBackend.h b/src/TocBackend.h index d1d0d1ad0a..40d2dbafe1 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -42,7 +42,8 @@ public: /// TocItem(DocIterator const & dit, int depth, - docstring const & s + docstring const & s, + docstring const & t = docstring() ); /// ~TocItem() {} @@ -53,6 +54,8 @@ public: /// docstring const & str() const; /// + docstring const & tooltip() const; + /// docstring const asString() const; /// DocIterator const & dit() const; @@ -69,6 +72,9 @@ protected: /// Full item string docstring str_; + + /// The tooltip string + docstring tooltip_; }; diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 870b9242da..86cf124396 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -148,6 +148,7 @@ void TocModel::updateItem(DocIterator const & dit) QModelIndex index = modelIndex(dit); TocItem const & toc_item = tocItem(index); model_->setData(index, toqstr(toc_item.str()), Qt::DisplayRole); + model_->setData(index, toqstr(toc_item.tooltip()), Qt::ToolTipRole); } @@ -177,6 +178,7 @@ void TocModel::reset(Toc const & toc) QModelIndex top_level_item = model_->index(current_row, 0); model_->setData(top_level_item, toqstr(item.str()), Qt::DisplayRole); model_->setData(top_level_item, index, Qt::UserRole); + model_->setData(top_level_item, toqstr(item.tooltip()), Qt::ToolTipRole); LYXERR(Debug::GUI, "Toc: at depth " << item.depth() << ", added item " << item.str()); @@ -218,6 +220,7 @@ void TocModel::populate(unsigned int & index, QModelIndex const & parent) child_item = model_->index(current_row, 0, parent); model_->setData(child_item, toqstr(item.str()), Qt::DisplayRole); model_->setData(child_item, index, Qt::UserRole); + model_->setData(child_item, toqstr(item.tooltip()), Qt::ToolTipRole); populate(index, child_item); if (index >= end) break; diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 76cb30720e..b43fda3d2e 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -286,7 +286,7 @@ void InsetBranch::addToToc(DocIterator const & cpit) Toc & toc = buffer().tocBackend().toc("branch"); docstring const str = params_.branch + ": " + text().getPar(0).asString(); - toc.push_back(TocItem(pit, 0, str)); + toc.push_back(TocItem(pit, 0, str, toolTipText())); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit); } diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index bd29cd3d67..f6d94c26be 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -128,11 +128,7 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv)) return docstring(); - OutputParams rp(&buffer().params().encoding()); - odocstringstream ods; - InsetText::plaintext(ods, rp); - docstring const content_tip = ods.str(); - return support::wrapParas(content_tip, 4); + return toolTipText(); } diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index 79167d1ded..fd8038f4ee 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -67,7 +67,7 @@ void InsetFoot::addToToc(DocIterator const & cpit) Toc & toc = buffer().tocBackend().toc("footnote"); docstring str; str = custom_label_ + ": " + text().getPar(0).asString(); - toc.push_back(TocItem(pit, 0, str)); + toc.push_back(TocItem(pit, 0, str, toolTipText())); // Proceed with the rest of the inset. InsetFootlike::addToToc(cpit); } diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index 86b93bd4b7..377693f17b 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -59,7 +59,7 @@ void InsetMarginal::addToToc(DocIterator const & cpit) Toc & toc = buffer().tocBackend().toc("marginalnote"); docstring str; str = text().getPar(0).asString(); - toc.push_back(TocItem(pit, 0, str)); + toc.push_back(TocItem(pit, 0, str, toolTipText())); // Proceed with the rest of the inset. InsetFootlike::addToToc(cpit); } diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 189c290791..6af19a3bc9 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -224,7 +224,7 @@ void InsetNote::addToToc(DocIterator const & cpit) docstring str; str = notetranslator_loc().find(params_.type) + from_ascii(": ") + text().getPar(0).asString(); - toc.push_back(TocItem(pit, 0, str)); + toc.push_back(TocItem(pit, 0, str, toolTipText())); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit); } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 157ab71181..8ef6116908 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -721,7 +721,8 @@ void InsetText::addToToc(DocIterator const & cdit) // insert this into the table of contents if (tocstring.empty()) tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS); - toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring)); + toc.push_back(TocItem(dit, toclevel - min_toclevel, + tocstring, tocstring)); } // And now the list of changes. @@ -818,6 +819,18 @@ docstring InsetText::contextMenu(BufferView const &, int, int) const } +docstring InsetText::toolTipText() const +{ + OutputParams rp(&buffer().params().encoding()); + odocstringstream ods; + // do not remove InsetText::, otherwise there + // will be no tooltip text for InsetNotes + InsetText::plaintext(ods, rp); + docstring const content_tip = ods.str(); + return support::wrapParas(content_tip, 4); +} + + InsetCaption const * InsetText::getCaptionInset() const { ParagraphList::const_iterator pit = paragraphs().begin(); diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index a4c83f0b91..5743be2f51 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -190,6 +190,8 @@ public: bool insertCompletion(Cursor & cur, docstring const & s, bool finished); /// void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const; + /// returns the text to be used as tooltip + docstring toolTipText() const; /// virtual docstring contextMenu(BufferView const & bv, int x, int y) const;