Implement tooltips for visible insets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22298 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-12-25 18:53:38 +00:00
parent 6564f8a52a
commit 7c832d2d84
8 changed files with 70 additions and 3 deletions

View File

@ -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) void BufferView::scrollDocView(int value)
{ {
int const offset = value - d->scrollbarParameters_.position; 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]; TextMetrics & tm = d->text_metrics_[&text];
Inset * inset = tm.checkInsetHit(x, y); Inset * inset = tm.checkInsetHit(x, y);

View File

@ -104,6 +104,8 @@ public:
void updateScrollbar(); void updateScrollbar();
/// return the Scrollbar Parameters. /// return the Scrollbar Parameters.
ScrollbarParameters const & scrollbarParameters() const; ScrollbarParameters const & scrollbarParameters() const;
/// \return Tool tip for the given position.
docstring toolTip(int x, int y) const;
/// Save the current position as bookmark. /// Save the current position as bookmark.
/// if idx == 0, save to temp_bookmark /// if idx == 0, save to temp_bookmark
@ -145,6 +147,7 @@ public:
/// return the pixel height of the document view. /// return the pixel height of the document view.
int workHeight() const; int workHeight() const;
/// translate and insert a character, using the correct keymap. /// translate and insert a character, using the correct keymap.
void translateAndInsert(char_type c, Text * t, Cursor & cur); void translateAndInsert(char_type c, Text * t, Cursor & cur);
@ -266,7 +269,7 @@ private:
Text const & text, //< The Text where we start searching. Text const & text, //< The Text where we start searching.
int x, //< x-coordinate on screen int x, //< x-coordinate on screen
int y //< y-coordinate on screen int y //< y-coordinate on screen
); ) const;
/// ///
int width_; int width_;

View File

@ -479,6 +479,7 @@ void GuiWorkArea::updateScrollbar()
void GuiWorkArea::adjustViewWithScrollBar(int action) void GuiWorkArea::adjustViewWithScrollBar(int action)
{ {
stopBlinkingCursor(); stopBlinkingCursor();
// QToolTip::hideText();
if (action == QAbstractSlider::SliderPageStepAdd) if (action == QAbstractSlider::SliderPageStepAdd)
buffer_view_->scrollDown(viewport()->height()); buffer_view_->scrollDown(viewport()->height());
else if (action == QAbstractSlider::SliderPageStepSub) else if (action == QAbstractSlider::SliderPageStepSub)
@ -490,12 +491,35 @@ void GuiWorkArea::adjustViewWithScrollBar(int action)
buffer_view_->setCursorFromScrollbar(); buffer_view_->setCursorFromScrollbar();
lyx_view_->updateLayoutList(); lyx_view_->updateLayoutList();
} }
/*
lyxerr << "QCursor::pos() = "
<< QCursor::pos().x() << " "
<< QCursor::pos().y() << " "
<<endl;
QToolTip::showText(QCursor::pos(), "toto"), verticalScrollBar());
*/
// Show the cursor immediately after any operation. // Show the cursor immediately after any operation.
startBlinkingCursor(); startBlinkingCursor();
QApplication::syncX(); QApplication::syncX();
} }
bool GuiWorkArea::event(QEvent * e)
{
if (e->type() == QEvent::ToolTip) {
QHelpEvent * helpEvent = static_cast<QHelpEvent *>(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*/) void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
{ {
// Repaint the whole screen. // Repaint the whole screen.

View File

@ -165,6 +165,8 @@ private:
/// Update window titles of all users. /// Update window titles of all users.
void updateWindowTitle(); void updateWindowTitle();
/// ///
bool event(QEvent *);
///
void focusInEvent(QFocusEvent *); void focusInEvent(QFocusEvent *);
/// ///
void focusOutEvent(QFocusEvent *); void focusOutEvent(QFocusEvent *);

View File

@ -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 Dimension const Inset::dimension(BufferView const & bv) const
{ {
return bv.coordCache().getInsets().dim(this); return bv.coordCache().getInsets().dim(this);

View File

@ -284,6 +284,9 @@ public:
/// Is the width forced to some value? /// Is the width forced to some value?
virtual bool hasFixedWidth() const { return false; } 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 // FIXME This should really disappear in favor of
// docstring name() const { return from_ascii(insetName(lyxCode()))); } // docstring name() const { return from_ascii(insetName(lyxCode()))); }

View File

@ -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())); setLayout(bp.getTextClass().insetlayout(name()));
} }

View File

@ -48,6 +48,7 @@ public:
InsetCollapsable * asInsetCollapsable() { return this; } InsetCollapsable * asInsetCollapsable() { return this; }
InsetCollapsable const * asInsetCollapsable() const { 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"); } docstring name() const { return from_ascii("Collapsable"); }
InsetLayout const & getLayout(BufferParams const &) const InsetLayout const & getLayout(BufferParams const &) const
{ return *layout_; } { return *layout_; }