commit d00dcc2ca7bf1b9a3043d23b1c5b598ff7e46aad
Author: Enrico Forestieri <[email protected]>
Date:   Fri Mar 13 00:38:05 2015 +0100

    Use the nominal theme's icon size for displaying the icon in an info inset.

diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index d914d94..3d35e29 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -31,6 +31,7 @@
 
 #include "frontends/Application.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/docstring_list.h"
@@ -410,6 +411,8 @@ void InsetInfo::updateInfo()
                InsetGraphics * inset = new InsetGraphics(buffer_);
                InsetGraphicsParams igp;
                igp.filename = file;
+               igp.lyxscale = iconScaleFactor(file);
+               igp.scale = convert<string>(igp.lyxscale);
                inset->setParams(igp);
                clear();
                Font const f(inherit_font, buffer().params().language);
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 134dc17..f5cdb27 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -37,6 +37,7 @@
 #include "support/qstring_helpers.h"
 
 #include <QDir>
+#include <QImage>
 #include <QTemporaryFile>
 
 #include "support/lassert.h"
@@ -407,6 +408,24 @@ FileName const imageLibFileSearch(string & dir, string 
const & name,
 }
 
 
+int iconScaleFactor(FileName const & image)
+{
+       int imgsize = QImage(toqstr(image.absFileName())).height();
+       if (imgsize <= 0)
+               return 100;
+
+       // default icon size
+       int iconsize = 20;
+
+       string dir = "images";
+       FileName const fn = imageLibFileSearch(dir, "iconsize.png");
+       if (!fn.empty())
+               iconsize = QImage(toqstr(fn.absFileName())).height();
+
+       return (100 * iconsize + imgsize / 2)/imgsize;
+}
+
+
 string const commandPrep(string const & command_in)
 {
        static string const token_scriptpath = "$$s/";
diff --git a/src/support/filetools.h b/src/support/filetools.h
index b041b36..0180f29 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -115,6 +115,11 @@ imageLibFileSearch(std::string & dir, std::string const & 
name,
                   std::string const & ext = std::string(),
                   search_mode mode = must_exist);
 
+/** Returns the percentage factor by which an image has to be
+    scaled for matching the (theme dependent) nominal icon size
+  */
+int iconScaleFactor(FileName const & image);
+
 /// How to quote a filename
 enum quote_style {
        /** Quote for the (OS dependant) shell. This is needed for command

Reply via email to