]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInfo.cpp
Fix bug #9898: inset info cannot show specified icon
[lyx.git] / src / insets / InsetInfo.cpp
index acf073aa107103064ee5fd4e67d8a4e1fb1e1359..2f26c971f864b8293b3d146e59fb038d21775f23 100644 (file)
@@ -10,7 +10,7 @@
 #include <config.h>
 
 #include "InsetInfo.h"
-
+#include "LyX.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
@@ -94,7 +94,6 @@ NameTranslator const & nameTranslator()
 InsetInfo::InsetInfo(Buffer * buf, string const & name) 
        : InsetCollapsable(buf), type_(UNKNOWN_INFO), name_()
 {
-       setAutoBreakRows(true);
        setInfo(name);
        status_ = Collapsed;
 }
@@ -170,12 +169,20 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
 
        case SHORTCUT_INFO:
        case SHORTCUTS_INFO:
-       case MENU_INFO:
-       case ICON_INFO: {
+       case MENU_INFO: {
                FuncRequest func = lyxaction.lookupFunc(name);
                return func.action() != LFUN_UNKNOWN_ACTION;
        }
 
+       case ICON_INFO: {
+               FuncCode const action = lyxaction.lookupFunc(name).action();
+               if (action == LFUN_UNKNOWN_ACTION) {
+                       string dir = "images";
+                       return !imageLibFileSearch(dir, name, "svgz,png").empty();
+               }
+               return true;
+       }
+
        case LYXRC_INFO: {
                ostringstream oss;
                lyxrc.write(oss, true, name);
@@ -419,10 +426,16 @@ void InsetInfo::updateInfo()
                if (!file.exists())
                        break;
                int percent_scale = 100;
-               int imgsize = QImage(toqstr(file.absFileName())).width();
-               if (imgsize > 0) {
-                       int iconsize = Length(1, Length::EM).inPixels(1);
-                       percent_scale = (100 * iconsize + imgsize / 2)/imgsize;
+               if (use_gui) {
+                       // Compute the scale factor for the icon such that its
+                       // width on screen is equal to 1em in pixels.
+                       // The scale factor is rounded to the integer nearest
+                       // to the float value of the ratio 100*iconsize/imgsize.
+                       int imgsize = QImage(toqstr(file.absFileName())).width();
+                       if (imgsize > 0) {
+                               int iconsize = Length(1, Length::EM).inPixels(1);
+                               percent_scale = (100 * iconsize + imgsize / 2)/imgsize;
+                       }
                }
                InsetGraphics * inset = new InsetGraphics(buffer_);
                InsetGraphicsParams igp;