mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 03:03:06 +00:00
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:
parent
6564f8a52a
commit
7c832d2d84
@ -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);
|
||||
|
@ -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_;
|
||||
|
@ -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() << " "
|
||||
<<endl;
|
||||
QToolTip::showText(QCursor::pos(), "toto"), verticalScrollBar());
|
||||
*/
|
||||
// Show the cursor immediately after any operation.
|
||||
startBlinkingCursor();
|
||||
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*/)
|
||||
{
|
||||
// Repaint the whole screen.
|
||||
|
@ -165,6 +165,8 @@ private:
|
||||
/// Update window titles of all users.
|
||||
void updateWindowTitle();
|
||||
///
|
||||
bool event(QEvent *);
|
||||
///
|
||||
void focusInEvent(QFocusEvent *);
|
||||
///
|
||||
void focusOutEvent(QFocusEvent *);
|
||||
|
@ -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);
|
||||
|
@ -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()))); }
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -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_; }
|
||||
|
Loading…
Reference in New Issue
Block a user