]> git.lyx.org Git - lyx.git/commitdiff
Use the nominal theme's icon size for displaying the icon in an info inset.
authorEnrico Forestieri <forenr@lyx.org>
Thu, 12 Mar 2015 23:38:05 +0000 (00:38 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 12 Mar 2015 23:38:05 +0000 (00:38 +0100)
src/insets/InsetInfo.cpp
src/support/filetools.cpp
src/support/filetools.h

index d914d949389c4bf95e32f22f4fa1f1bae3f8725e..3d35e293e04d37dc1ff7f784fef520d89d2e12c9 100644 (file)
@@ -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);
index 134dc1756101ac2d8ad27aeecbfc36db33e244d0..f5cdb277515714ba5c1a3a8791e8afe5461c4146 100644 (file)
@@ -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/";
index b041b366a2ca3ea1d08ce501be5b6e4d100df9ea..0180f29d35af02559065627644c1950cb7fd74c0 100644 (file)
@@ -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