]> git.lyx.org Git - lyx.git/commitdiff
Embedding: display a pin at the top left corner of embedded figures
authorBo Peng <bpeng@lyx.org>
Tue, 8 Jan 2008 16:22:05 +0000 (16:22 +0000)
committerBo Peng <bpeng@lyx.org>
Tue, 8 Jan 2008 16:22:05 +0000 (16:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22439 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/scons_manifest.py
lib/Makefile.am
lib/images/pin.png [new file with mode: 0644]
src/graphics/GraphicsParams.cpp
src/graphics/GraphicsParams.h
src/insets/InsetGraphics.cpp
src/insets/InsetGraphicsParams.cpp
src/insets/RenderGraphic.cpp
src/insets/RenderGraphic.h

index 5b4743c791042966a216ec168d168245d5e4241d..4abc860d7f1bdd476790bb5e2118a58605cc14ed 100644 (file)
@@ -1428,6 +1428,7 @@ lib_images_files = Split('''
     note-next.png
     paste.png
     promote.png
+    pin.png
     psnfss1.png
     psnfss2.png
     psnfss3.png
index ac476b2708e76f031cceff7775c5b8b3365a53de..262aee34d9bc24cbac76d908680c74d34c6de82c 100644 (file)
@@ -335,6 +335,7 @@ dist_images_DATA = \
        images/note-insert.png \
        images/note-next.png \
        images/paste.png \
+       images/pin.png \
        images/promote.png \
        images/psnfss1.png \
        images/psnfss2.png \
diff --git a/lib/images/pin.png b/lib/images/pin.png
new file mode 100644 (file)
index 0000000..c1f9a75
Binary files /dev/null and b/lib/images/pin.png differ
index a88d6dc5c0c3b5b5bbc660611418e38658daa3e4..e5c9b3d24f75fb4302737ff6307076159b552b5e 100644 (file)
@@ -24,7 +24,8 @@ namespace graphics {
 Params::Params()
        : display(ColorDisplay),
          scale(100),
-         angle(0)
+         angle(0),
+         icon("")
 {}
 
 
@@ -34,7 +35,8 @@ bool operator==(Params const & a, Params const & b)
                a.display == b.display &&
                a.bb == b.bb &&
                a.scale == b.scale &&
-               a.angle == b.angle);
+               a.angle == b.angle &&
+               a.icon == b.icon);
 }
 
 
index a7b7c8ffa424cac72e383b2b8a2edc20f54f4786..d086a2585765856d57d87219c4ad7d2834b14df1 100644 (file)
@@ -72,6 +72,12 @@ public:
         */
        /// Rotation angle.
        double angle;
+
+       /** The icon to be displayed to the top-left corner of an image.
+        *  It is mutable because an icon reflects a temporary state of
+        *  the image, and is variable.
+        */
+       mutable std::string icon;
 };
 
 bool operator==(Params const &, Params const &);
index 36ad1b7f40d6a89529e08f5efe4e06d208172a61..687014677b7ddf0691723012f0072ceb17538fec 100644 (file)
@@ -173,7 +173,7 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
                if (!p.filename.empty()) {
                        try {
-                               updateEmbeddedFile(buffer, p.filename);
+                               p.filename.enable(buffer.embeddedFiles().enabled(), &buffer);
                        } catch (ExceptionMessage const & message) {
                                Alert::error(message.title_, message.details_);
                                // do not set parameter if an error happens
index 5df541bf7d38027a948a0f581a639dba65935e3b..a0dba1a5d166307b12c78f68f1becd65bce3450e 100644 (file)
@@ -274,6 +274,7 @@ graphics::Params InsetGraphicsParams::as_grfxParams() const
 {
        graphics::Params pars;
        pars.filename = filename.availableFile();
+       pars.icon = filename.embedded() ? "pin.png" : "";
        pars.scale = lyxscale;
        pars.angle = convert<double>(rotateAngle);
 
index 05ce78a93814935e442846d8b379d9a651988665..3520290a973bff05ae6a1c44fa2e355fbd114187 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "insets/Inset.h"
 
+#include "support/FileName.h"
+#include "support/filetools.h"
 #include "support/gettext.h"
 #include "LyX.h"
 #include "LyXRC.h"
@@ -36,13 +38,16 @@ namespace lyx {
 RenderGraphic::RenderGraphic(Inset const * inset)
 {
        loader_.connect(boost::bind(&Inset::updateFrontend, inset));
+       icon_.connect(boost::bind(&Inset::updateFrontend, inset));
 }
 
 
 RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset)
-       : RenderBase(other), loader_(other.loader_), params_(other.params_)
+       : RenderBase(other), loader_(other.loader_), icon_(other.icon_),
+               params_(other.params_)
 {
        loader_.connect(boost::bind(&Inset::updateFrontend, inset));
+       icon_.connect(boost::bind(&Inset::updateFrontend, inset));
 }
 
 
@@ -58,6 +63,15 @@ void RenderGraphic::update(graphics::Params const & params)
 
        if (!params_.filename.empty())
                loader_.reset(params_.filename, params_);
+       // If icon is set to empty, icon_ will not be reset to empty
+       // but will not be displayed. This is to avoid repeated loading
+       // of the same icon when figure status changes.
+       if (!params_.icon.empty()) {
+               support::FileName const icon = support::libFileSearch("images/",
+                       params_.icon, "png");
+               if (!icon.empty()) // using an empty bounding box
+                       icon_.reset(icon, graphics::Params());
+       }
 }
 
 
@@ -172,6 +186,10 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
                        loader_.startLoading();
                if (!loader_.monitoring())
                        loader_.startMonitoring();
+               if (icon_.status() == graphics::WaitingToLoad)
+                       icon_.startLoading();
+               if (!icon_.monitoring())
+                       icon_.startMonitoring();
        }
 
        // This will draw the graphics. If the graphics has not been
@@ -211,6 +229,9 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
                                     y - 4, msg, msgFont);
                }
        }
+       if (!params_.icon.empty() && readyToDisplay(icon_))
+               pi.pain.image(x + Inset::TEXT_TO_INSET_OFFSET, y - dim_.asc, 
+                       10, 10, *icon_.image());
 }
 
 
index 5edb7ce9400cac49cf38c3efc6c2cd87ddfb8ecb..938322fad0abf5497d3c0964c7f11a6779d284db 100644 (file)
@@ -45,6 +45,7 @@ private:
 
        /// The stored data.
        graphics::Loader loader_;
+       graphics::Loader icon_;
        graphics::Params params_;
 };