]> git.lyx.org Git - features.git/commitdiff
Implement tooltips for visible insets.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 25 Dec 2007 18:53:38 +0000 (18:53 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 25 Dec 2007 18:53:38 +0000 (18:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22298 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h
src/insets/Inset.cpp
src/insets/Inset.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h

index 1eb4d09026b94459ebdfdc69c88f61f63ee6b205..c535cab436ea461f5e6e2cb922d848778a17561f 100644 (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)
 {
        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);
index f518f0026ad99f4660288c281a3122b4a1238aa3..104fa805f15fac6d6adafb6bf1e9c41af2f76665 100644 (file)
@@ -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_;
index 3ef881739ba732ff1b66a2895e62e1d3e8da64bd..49e227669c23fedf67e0e5e71ade7f2508c30bb5 100644 (file)
@@ -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.
index fe014d1dc945a4f1ace99f033c5d314b409a6c55..7e254a3448baaaa50c24f0070b2fb75eb2e689f2 100644 (file)
@@ -165,6 +165,8 @@ private:
        /// Update window titles of all users.
        void updateWindowTitle();
        ///
+       bool event(QEvent *);
+       ///
        void focusInEvent(QFocusEvent *);
        ///
        void focusOutEvent(QFocusEvent *);
index 4d19fa4b05e6b8c3f5b75ac676f5e5a7836ae8dd..7e833e450b65bd9a362674b4fd20f04877c315d4 100644 (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
 {
        return bv.coordCache().getInsets().dim(this);
index f3fe83ff0f255e3ac1ab1205240c8dd0df65909a..a519ec536f5dbab560a5aff778631c9dcfc5815b 100644 (file)
@@ -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()))); }
index fe747bc9e8b840db7e264d4d4a53d3e0edc0372d..7622fb390d860c7c6f40c2f29e3bcb819fcbe7df 100644 (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()));
 }
index 1b6cbc3c45edf1ea30dba459d737ba19781795ef..6c271eceaed3a2c7a3b3927bb535dd2ef94f7b0c 100644 (file)
@@ -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_; }