From 7c832d2d84328de9769a5f10a8b208ff0b5d8d94 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 25 Dec 2007 18:53:38 +0000 Subject: [PATCH] Implement tooltips for visible insets. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22298 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 14 +++++++++++++- src/BufferView.h | 5 ++++- src/frontends/qt4/GuiWorkArea.cpp | 24 ++++++++++++++++++++++++ src/frontends/qt4/GuiWorkArea.h | 2 ++ src/insets/Inset.cpp | 6 ++++++ src/insets/Inset.h | 3 +++ src/insets/InsetCollapsable.cpp | 18 +++++++++++++++++- src/insets/InsetCollapsable.h | 1 + 8 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 1eb4d09026..c535cab436 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -479,6 +479,17 @@ ScrollbarParameters const & BufferView::scrollbarParameters() const } +docstring BufferView::toolTip(int x, int y) const +{ + // Get inset under mouse, if there is one. + Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y); + if (!covering_inset) + // No inset, no tooltip... + return docstring(); + return covering_inset->toolTip(*this, x, y); +} + + void BufferView::scrollDocView(int value) { int const offset = value - d->scrollbarParameters_.position; @@ -1268,7 +1279,8 @@ void BufferView::resize(int width, int height) } -Inset const * BufferView::getCoveringInset(Text const & text, int x, int y) +Inset const * BufferView::getCoveringInset(Text const & text, + int x, int y) const { TextMetrics & tm = d->text_metrics_[&text]; Inset * inset = tm.checkInsetHit(x, y); diff --git a/src/BufferView.h b/src/BufferView.h index f518f0026a..104fa805f1 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -104,6 +104,8 @@ public: void updateScrollbar(); /// return the Scrollbar Parameters. ScrollbarParameters const & scrollbarParameters() const; + /// \return Tool tip for the given position. + docstring toolTip(int x, int y) const; /// Save the current position as bookmark. /// if idx == 0, save to temp_bookmark @@ -145,6 +147,7 @@ public: /// return the pixel height of the document view. int workHeight() const; + /// translate and insert a character, using the correct keymap. void translateAndInsert(char_type c, Text * t, Cursor & cur); @@ -266,7 +269,7 @@ private: Text const & text, //< The Text where we start searching. int x, //< x-coordinate on screen int y //< y-coordinate on screen - ); + ) const; /// int width_; diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 3ef881739b..49e227669c 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -479,6 +479,7 @@ void GuiWorkArea::updateScrollbar() void GuiWorkArea::adjustViewWithScrollBar(int action) { stopBlinkingCursor(); +// QToolTip::hideText(); if (action == QAbstractSlider::SliderPageStepAdd) buffer_view_->scrollDown(viewport()->height()); else if (action == QAbstractSlider::SliderPageStepSub) @@ -490,12 +491,35 @@ void GuiWorkArea::adjustViewWithScrollBar(int action) buffer_view_->setCursorFromScrollbar(); lyx_view_->updateLayoutList(); } +/* + lyxerr << "QCursor::pos() = " + << QCursor::pos().x() << " " + << QCursor::pos().y() << " " + <type() == QEvent::ToolTip) { + QHelpEvent * helpEvent = static_cast(e); + QPoint pos = helpEvent->pos(); + if (pos.x() < viewport()->width()) { + QString s = toqstr(buffer_view_->toolTip(pos.x(), pos.y())); + QToolTip::showText(helpEvent->globalPos(), s); + } + else + QToolTip::hideText(); + } + return QAbstractScrollArea::event(e); +} + + void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/) { // Repaint the whole screen. diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index fe014d1dc9..7e254a3448 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -165,6 +165,8 @@ private: /// Update window titles of all users. void updateWindowTitle(); /// + bool event(QEvent *); + /// void focusInEvent(QFocusEvent *); /// void focusOutEvent(QFocusEvent *); diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 4d19fa4b05..7e833e450b 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -125,6 +125,12 @@ docstring Inset::name() const } +docstring Inset::toolTip(BufferView const &, int, int) const +{ + return docstring(); +} + + Dimension const Inset::dimension(BufferView const & bv) const { return bv.coordCache().getInsets().dim(this); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index f3fe83ff0f..a519ec536f 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -284,6 +284,9 @@ public: /// Is the width forced to some value? virtual bool hasFixedWidth() const { return false; } + /// \return Tool tip for this inset. + /// This default implementation returns an empty string. + virtual docstring toolTip(BufferView const & bv, int x, int y) const; // FIXME This should really disappear in favor of // docstring name() const { return from_ascii(insetName(lyxCode()))); } diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index fe747bc9e8..7622fb390d 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -98,7 +98,23 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs) } -void InsetCollapsable::setLayout(BufferParams const & bp) +docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const +{ + Dimension dim = dimensionCollapsed(); + if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des) + return docstring(); + + switch (status_) { + case Open: + return _("Left-click to collapse the inset"); + case Collapsed: + return _("Left-click to open the inset"); + } + return docstring(); +} + + +void InsetCollapsable::setLayout(BufferParams const & bp) { setLayout(bp.getTextClass().insetlayout(name())); } diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 1b6cbc3c45..6c271eceae 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -48,6 +48,7 @@ public: InsetCollapsable * asInsetCollapsable() { return this; } InsetCollapsable const * asInsetCollapsable() const { return this; } + docstring toolTip(BufferView const & bv, int x, int y) const; docstring name() const { return from_ascii("Collapsable"); } InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }