From a3d5f27038826bb85fe6f1bed432d41bda69ff1e Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Wed, 25 Mar 2015 21:26:32 +0100 Subject: [PATCH] Remove the iconScaleFactor() method from src/support. I am moving the corresponding code directly to InsetInfo.cpp. Moreover, the size of the image displayed by the info inset is now dynamically set according to the text size. --- src/insets/InsetInfo.cpp | 15 +++++++++++++-- src/support/filetools.cpp | 19 ------------------- src/support/filetools.h | 5 ----- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index e70b519e06..98fe7d7c9b 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -22,6 +22,7 @@ #include "KeyMap.h" #include "LaTeXFeatures.h" #include "LayoutFile.h" +#include "Length.h" #include "LyXAction.h" #include "LyXRC.h" #include "LyXVC.h" @@ -40,10 +41,13 @@ #include "support/filetools.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/qstring_helpers.h" #include "support/Translator.h" #include +#include + using namespace std; using namespace lyx::support; @@ -408,11 +412,18 @@ void InsetInfo::updateInfo() FileName file(to_utf8(icon_name)); 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; + } InsetGraphics * inset = new InsetGraphics(buffer_); InsetGraphicsParams igp; igp.filename = file; - igp.lyxscale = iconScaleFactor(file); - igp.scale = convert(igp.lyxscale); + igp.lyxscale = percent_scale; + igp.scale = string(); + igp.width = Length(1, Length::EM); 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 1f794f2c9c..a05f984554 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -37,7 +37,6 @@ #include "support/qstring_helpers.h" #include -#include #include #include "support/lassert.h" @@ -416,24 +415,6 @@ 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 0180f29d35..b041b366a2 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -115,11 +115,6 @@ 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 -- 2.39.2