]> git.lyx.org Git - features.git/commitdiff
Button face-lift: use mouse hover-buttons.
authorBo Peng <bpeng@lyx.org>
Mon, 4 Dec 2006 04:31:18 +0000 (04:31 +0000)
committerBo Peng <bpeng@lyx.org>
Mon, 4 Dec 2006 04:31:18 +0000 (04:31 +0000)
* src/insets/insetbase.h: add setMouseHover function
* src/insets/insetcommand.h/C: handle setMouseHover
* src/insets/insetcollapsable.h/C: handle setMouseHover
* src/LColor.h/C: redefine some colors
* src/insets/render_base.h: add state_
* src/insets/render_button.C: draw differently according to state_
* src/frontends/Painter.h/C: hover-stype button
* src/frontends/qt4/GuiWorkArea.C: enable mouse tracking
* src/BufferView.C: track mouse_motion without button events

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16162 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/BufferView.C
src/LColor.C
src/LColor.h
src/frontends/Painter.C
src/frontends/Painter.h
src/frontends/qt4/GuiWorkArea.C
src/insets/insetbase.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/render_base.h
src/insets/render_button.C

index fa53dd8cccbae35584a68443ffc1064698abce1b..7337937031ab53cb0f44427f3fa1a4eb23766df8 100644 (file)
@@ -1055,6 +1055,25 @@ std::pair<bool, bool> BufferView::workAreaDispatch(FuncRequest const & cmd0)
        //lyxerr << BOOST_CURRENT_FUNCTION
        //       << " * created temp cursor:" << cur << endl;
 
+       // NOTE: eidtXY returns the top level inset of nested insets. If you happen
+       // to move from a text (inset=0) to a text inside an inset (e.g. an opened
+       // footnote inset, again inset=0), that inset will not be redrawn.
+       static InsetBase * last_inset = NULL;
+       if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
+               bool need_update = false;
+               
+               if (inset != last_inset) {
+                       if (last_inset)
+                               need_update |= last_inset->setMouseHover(false);
+                       if (inset)
+                               need_update |= inset->setMouseHover(true);
+                       last_inset = inset;
+               }
+               // This event (moving without mouse click) is not passed further.
+               // This should be changed if it is further utilized.
+               return make_pair(need_update, need_update);
+       }
+
        // Put anchor at the same position.
        cur.resetAnchor();
 
index ba6f4289ae81222988b3cb31843a8394e54685b0..62b55f2e6c625eca837d2076833e3383afeab374 100644 (file)
@@ -107,7 +107,7 @@ LColor::LColor()
        { selection, N_("selection"), "selection", "LightBlue", "selection" },
        { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
        { preview, N_("previewed snippet"), "preview", "black", "preview" },
-       { note, N_("note"), "note", "yellow", "note" },
+       { note, N_("note"), "note", "blue", "note" },
        { notebg, N_("note background"), "notebg", "yellow", "notebg" },
        { comment, N_("comment"), "comment", "magenta", "comment" },
        { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
@@ -145,11 +145,9 @@ LColor::LColor()
             "LightSteelBlue", "tabularonoffline" },
        { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
        { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
-       { top, N_("top of button"), "top", "grey90", "top" },
-       { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
-       { left, N_("left of button"), "left", "grey90", "left" },
-       { right, N_("right of button"), "right", "grey60", "right" },
-       { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
+       { buttonframe, N_("frame of button"), "buttonframe", "#A9ABB5", "buttonframe" },
+       { buttonbg, N_("button background"), "buttonbg", "linen", "buttonbg" },
+       { buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
        { inherit, N_("inherit"), "inherit", "black", "inherit" },
        { ignore, N_("ignore"), "ignore", "black", "ignore" },
        { ignore, 0, 0, 0, 0 }
index c6bf6cebf7c47a754bd67411c3643b61157cd712..95a4cf7cd4b5f239144bb02a1ff427e535ac4ae6 100644 (file)
@@ -166,16 +166,12 @@ public:
                pagebreak,
 
                // FIXME: why are the next four separate ??
-               /// Color used for top of boxes
-               top,
-               /// Color used for bottom of boxes
-               bottom,
-               /// Color used for left side of boxes
-               left,
-               /// Color used for right side of boxes
-               right,
+               /// Color used for button frame
+               buttonframe,
                /// Color used for bottom background
                buttonbg,
+               /// Color used for buttom under focus
+               buttonhoverbg,
 
                // Logical attributes
 
index 25f8edf2beb6ee5905c6b615a4b5efb89d8c8309..3f330ea30da1004c863a55346789ca5ab9e304a2 100644 (file)
@@ -26,27 +26,22 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-void Painter::button(int x, int y, int w, int h)
+void Painter::button(int x, int y, int w, int h, bool mouseHover)
 {
-       fillRectangle(x, y, w, h, LColor::buttonbg);
+       if (mouseHover)
+               fillRectangle(x, y, w, h, LColor::buttonhoverbg);
+       else
+               fillRectangle(x, y, w, h, LColor::buttonbg);
        buttonFrame(x, y, w, h);
 }
 
 
 void Painter::buttonFrame(int x, int y, int w, int h)
 {
-       //  Width of a side of the button
-       int const d = 2;
-
-       fillRectangle(x, y, w, d, LColor::top);
-       fillRectangle(x, y + h - d, w, d, LColor::bottom);
-
-       for (int i = 0 ; i < d ; ++i) {
-               line(x + i, y + i,
-                    x + i, y + h - 1 - i, LColor::left);
-               line(x + w - 1 - i, y + i + 1,
-                    x + w - 1 - i, y + h - 1 - i, LColor::right);
-       }
+       line(x, y, x, y + h - 1, LColor::buttonframe);
+       line(x - 1 + w, y, x - 1 + w, y + h - 1, LColor::buttonframe);
+       line(x, y - 1, x - 1 + w, y - 1, LColor::buttonframe);
+       line(x, y + h - 1, x - 1 + w, y + h - 1, LColor::buttonframe);
 }
 
 
@@ -74,7 +69,8 @@ void Painter::rectText(int x, int y,
 }
 
 
-void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & font)
+void Painter::buttonText(int x, int y, docstring const & str, 
+       LyXFont const & font, bool mouseHover)
 {
        int width;
        int ascent;
@@ -83,8 +79,11 @@ void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & fo
        FontMetrics const & fm = theFontMetrics(font);
        fm.buttonText(str, width, ascent, descent);
 
-       button(x, y - ascent, width, descent + ascent);
-       text(x + 4, y, str, font);
+       button(x, y - ascent, width, descent + ascent, mouseHover);
+       if (mouseHover)
+               text(x + 4, y, str, font);
+       else
+               text(x + 3, y - 1, str, font);
 }
 
 
index 309dae3f15c269afc4d8510468ba32f11d736ff3..40f624b420f73edda88fa512b0b1e6ec22f24a5b 100644 (file)
@@ -118,7 +118,7 @@ public:
 
        /// draw a filled rectangle with the shape of a 3D button
        virtual void button(int x, int y,
-               int w, int h);
+               int w, int h, bool mouseHover);
 
        /// draw an image from the image cache
        virtual void image(int x, int y,
@@ -162,8 +162,8 @@ public:
                LColor_color frame);
 
        /// draw a string and enclose it inside a button frame
-       void buttonText(int x,
-               int baseline, docstring const & s, LyXFont const & font);
+       void buttonText(int x, int baseline, docstring const & s,
+               LyXFont const & font, bool mouseHover);
 
 protected:
        /// check the font, and if set, draw an underline
index d0d7aeb83330a4a04098f14e349c18fa1c87b139..eb743e0a344714daa1b34d51b262681f958479c5 100644 (file)
@@ -166,6 +166,7 @@ GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
        setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setAcceptDrops(true);
+       setMouseTracking(true);
        setMinimumSize(100, 70);
 
        viewport()->setAutoFillBackground(false);
index f0aa1d4903a3d7d6a1846c665044fb5b84577352..f414af2d26eeb0fb7cbfd005e6d4a42e50d68381 100644 (file)
@@ -180,6 +180,9 @@ public:
        /// is called when the cursor leaves this inset
        //  returns true if cursor is now invalid.
        virtual bool notifyCursorLeaves(LCursor &) { return false; }
+       /// is called when the mouse enter or leave this inset
+       /// return true if this inset needs repaint
+       virtual bool setMouseHover(bool mouse_hover) { return false; }
 
        /// request "external features"
        virtual void validate(LaTeXFeatures &) const {}
index a2502a0dae8e87450b8a51f162e06c06ce8c1afa..e90fd05f51eab5c6b3b378e9965ab331d5665fae 100644 (file)
@@ -53,7 +53,7 @@ InsetCollapsable::CollapseStatus InsetCollapsable::status() const
 InsetCollapsable::InsetCollapsable
                (BufferParams const & bp, CollapseStatus status)
        : InsetText(bp), label(from_ascii("Label")), status_(status),
-         openinlined_(false), autoOpen_(false)
+         openinlined_(false), autoOpen_(false), mouse_hover_(false)
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
@@ -168,6 +168,13 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
+bool InsetCollapsable::setMouseHover(bool mouse_hover)
+{
+       mouse_hover_ = mouse_hover;
+       return true;
+}
+
+
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
        const int xx = x + TEXT_TO_INSET_OFFSET;
@@ -181,7 +188,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                button_dim.y1 = top;
                button_dim.y2 = top + dimc.height();
 
-               pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_);
+               pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_, mouse_hover_);
 
                if (status() == Open) {
                        int textx, texty;
@@ -281,7 +288,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
 InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
 {
        //lyxerr << "InsetCollapsable: edit xy" << endl;
-       if (status() == Collapsed)
+       if (status() == Collapsed || button_dim.contains(x, y))
                return this;
        cur.push(*this);
        return InsetText::editXY(cur, x, y);
index 82bae54483cd59eae7932a2cd4e3cdc8efafd63b..5680dcb3a897b616b9c9a7a526ae15c168b101e4 100644 (file)
@@ -80,6 +80,8 @@ public:
        bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
        ///
        void setStatus(LCursor & cur, CollapseStatus st);
+       ///
+       bool setMouseHover(bool mouse_hover);
 
 protected:
        ///
@@ -117,6 +119,8 @@ private:
        mutable bool autoOpen_;
        ///
        mutable Dimension textdim_;
+       /// changes color when mouse enters/leaves this inset
+       bool mouse_hover_;
 };
 
 // A helper function that pushes the cursor out of the inset.
index 3a7d50aa02dddaf275f5c6d26b5c0f4a43b7f62b..6d5248844b923d5650941ffb563ea74feb0313ae 100644 (file)
@@ -35,6 +35,7 @@ InsetCommand::InsetCommand(InsetCommandParams const & p,
                           string const & mailer_name)
        : p_(p),
          mailer_name_(mailer_name),
+         mouse_hover_(false),
          updateButtonLabel_(true)
 {}
 
@@ -60,9 +61,17 @@ bool InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
+bool InsetCommand::setMouseHover(bool mouse_hover)
+{
+       mouse_hover_ = mouse_hover;
+       return true;
+}
+
+
 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
 {
        setPosCache(pi, x, y);
+       button_.setRenderState(mouse_hover_);
        button_.draw(pi, x, y);
 }
 
index c268f07e551223f11fc75378088c63e0893612d0..404874c698b82e3752aaf24263d479812bf6ae02 100644 (file)
@@ -91,6 +91,8 @@ public:
        std::string const getSecOptions() const { return p_.getSecOptions(); }
        ///
        RenderButton & button() const { return button_; }
+       ///
+       bool setMouseHover(bool mouse_hover);
 
 protected:
        ///
@@ -128,6 +130,8 @@ private:
        ///
        InsetCommandParams p_;
        std::string mailer_name_;
+       /// changes color when mouse enters/leaves this inset
+       bool mouse_hover_;
        mutable bool updateButtonLabel_;
        mutable RenderButton button_;
 };
index 6a5dc57d3e733503fa6f83e8696f078e13dd029a..4aea45469824baed9111d9234950b178da082edf 100644 (file)
@@ -39,6 +39,10 @@ public:
        virtual bool metrics(MetricsInfo & mi, Dimension & dim) const = 0;
        /// draw inset and update (xo, yo)-cache
        virtual void draw(PainterInfo & pi, int x, int y) const = 0;
+       /// render state, exact meaning of state is render-specific
+       void setRenderState(int state) { state_ = state; }
+       /// get render state
+       int renderState() const { return state_; } 
 
        /// equivalent to dynamic_cast
        virtual RenderButton * asButton() { return 0; }
@@ -51,6 +55,8 @@ protected:
        RenderBase(RenderBase const &) {}
        RenderBase & operator=(RenderBase const &) { return *this; }
 
+       /// render state. currently, render_button uses this to store mouse_hover_
+       int state_;
        /// Cached
        mutable Dimension dim_;
 };
index 87172ddbc69e40f9ea29693b62a3fc06eb66308c..a20b378a90b40bfde461000483d1cd8b59705233 100644 (file)
@@ -71,7 +71,7 @@ void RenderButton::draw(PainterInfo & pi, int x, int y) const
        font.decSize();
 
        if (editable_) {
-               pi.pain.buttonText(x + 2, y, text_, font);
+               pi.pain.buttonText(x + 2, y, text_, font, renderState());
        } else {
                pi.pain.rectText(x + 2, y, text_, font,
                                 LColor::commandbg, LColor::commandframe);