From 21dfb0538458d589c9f15713944bfac7c82bdaf7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 30 Jun 2021 14:19:20 +0200 Subject: [PATCH] InfoDialog: Improvements * Fixed localization * Substitutions are aligned in table --- src/slic3r/GUI/GUI.cpp | 54 +++++++++++++++++++++--------------- src/slic3r/GUI/MsgDialog.cpp | 18 ++++++++++-- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 616d36ba2..9fd7f6af1 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -245,25 +245,32 @@ void warning_catcher(wxWindow* parent, const wxString& message) msg.ShowModal(); } +static wxString bold(const wxString& str) +{ + return wxString::Format("\"%s\"", str); +}; + static void add_config_substitutions(const ConfigSubstitutions& conf_substitutions, wxString& changes) { + changes += ""; for (const ConfigSubstitution& conf_substitution : conf_substitutions) { wxString new_val; - if (!conf_substitution.opt_def) + const ConfigOptionDef* def = conf_substitution.opt_def; + if (!def) continue; - if (conf_substitution.opt_def->type == coEnum) { - const std::vector& labels = conf_substitution.opt_def->enum_labels; - const std::vector& values = conf_substitution.opt_def->enum_values; + if (def->type == coEnum) { + const std::vector& labels = def->enum_labels; + const std::vector& values = def->enum_values; int val = conf_substitution.new_value->getInt(); - bool is_infill = conf_substitution.opt_def->opt_key == "top_fill_pattern" || - conf_substitution.opt_def->opt_key == "bottom_fill_pattern" || - conf_substitution.opt_def->opt_key == "fill_pattern"; + bool is_infill = def->opt_key == "top_fill_pattern" || + def->opt_key == "bottom_fill_pattern" || + def->opt_key == "fill_pattern"; // Each infill doesn't use all list of infill declared in PrintConfig.hpp. // So we should "convert" val to the correct one if (is_infill) { - for (const auto& key_val : *conf_substitution.opt_def->enum_keys_map) + for (const auto& key_val : *def->enum_keys_map) if ((int)key_val.second == val) { auto it = std::find(values.begin(), values.end(), key_val.first); if (it == values.end()) @@ -271,16 +278,20 @@ static void add_config_substitutions(const ConfigSubstitutions& conf_substitutio new_val = from_u8(_utf8(labels[it - values.begin()])); break; } - new_val = _L("Undef"); + if (new_val.IsEmpty()) + new_val = _L("Undef"); } else new_val = from_u8(_utf8(labels[val])); } - else if (conf_substitution.opt_def->type == coBool) + else if (def->type == coBool) new_val = conf_substitution.new_value->getBool() ? "true" : "false"; - changes += "\n" + GUI::format(_L("New unknown value \"%1%\" was changed to defaul value \"%2%\""), conf_substitution.old_value, new_val); + changes += ""; } + changes += "
" + bold(_(def->label)) + ": " + + format_wxstr(_L("new unknown value %1% was changed to default value %2%"), bold(conf_substitution.old_value), bold(new_val)) + + "
"; } void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_substitutions) @@ -288,27 +299,26 @@ void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_su wxString changes; auto preset_type_name = [](Preset::Type type) { - return type == Slic3r::Preset::TYPE_PRINT ? _L("Print") : - type == Slic3r::Preset::TYPE_SLA_PRINT ? _L("SLA Print") : - type == Slic3r::Preset::TYPE_FILAMENT ? _L("Filament") : - type == Slic3r::Preset::TYPE_SLA_MATERIAL ? _L("SLA Material") : - type == Slic3r::Preset::TYPE_PRINTER ? _L("Printer") : ""; + return type == Slic3r::Preset::TYPE_PRINT ? _L("Print settings") : + type == Slic3r::Preset::TYPE_SLA_PRINT ? _L("SLA print settings") : + type == Slic3r::Preset::TYPE_FILAMENT ? _L("Filament") : + type == Slic3r::Preset::TYPE_SLA_MATERIAL ? _L("SLA material") : + type == Slic3r::Preset::TYPE_PRINTER ? _L("Printer") : "" ; }; for (const PresetConfigSubstitutions& substitution : presets_config_substitutions) { - changes += "\n

" + GUI::format(_L(" %1% Preset : %2%"), preset_type_name(substitution.preset_type), substitution.preset_name); + changes += "\n\n" + format_wxstr("%1% : %2%", preset_type_name(substitution.preset_type), bold(substitution.preset_name)); if (!substitution.preset_file.empty()) - changes += GUI::format(" (%1%)", substitution.preset_file); - changes += "

"; + changes += format_wxstr(" (%1%)", substitution.preset_file); add_config_substitutions(substitution.substitutions, changes); } if (!changes.IsEmpty()) changes += "\n\n"; - wxString message = format(_L("Loading profiles found following incompatibilities:%1%" - " To recover these files, incompatible values were changed to default values.\n" - " But data in files won't be changed until you save them in PrusaSlicer."), changes); + wxString message = format_wxstr( _L("Loading profiles found following incompatibilities:%1%" + " To recover these files, incompatible values were changed to default values.\n" + " But data in files won't be changed until you save them in PrusaSlicer."), changes); InfoDialog msg(nullptr, message); msg.ShowModal(); diff --git a/src/slic3r/GUI/MsgDialog.cpp b/src/slic3r/GUI/MsgDialog.cpp index ccbdf2e15..1e05ab8f1 100644 --- a/src/slic3r/GUI/MsgDialog.cpp +++ b/src/slic3r/GUI/MsgDialog.cpp @@ -223,7 +223,6 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg) // Text shown as HTML, so that mouse selection and Ctrl-V to copy will work. wxHtmlWindow* html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO); { - html->SetMinSize(wxSize(40 * wxGetApp().em_unit(), -1)); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont monospace = wxGetApp().code_font(); wxColour text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); @@ -234,6 +233,22 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg) int size[] = { font_size, font_size, font_size, font_size, font_size, font_size, font_size }; html->SetFonts(font.GetFaceName(), monospace.GetFaceName(), size); html->SetBorders(2); + + // calculate html page size from text + int lines = msg.Freq('\n'); + + if (msg.Contains("")) { + int pos = 0; + while (pos < (int)msg.Len() && pos != wxNOT_FOUND) { + pos = msg.find("", pos + 1); + lines+=2; + } + } + int page_height = std::min((font.GetPixelSize().y + 1) * lines, 68 * wxGetApp().em_unit()); + wxSize page_size(68 * wxGetApp().em_unit(), page_height); + + html->SetMinSize(page_size); + std::string msg_escaped = xml_escape(msg.ToUTF8().data(), true); boost::replace_all(msg_escaped, "\r\n", "
"); boost::replace_all(msg_escaped, "\n", "
"); @@ -244,7 +259,6 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg) // Set info bitmap logo->SetBitmap(create_scaled_bitmap("info", this, 84)); - SetMinSize(wxSize(60 * wxGetApp().em_unit(), 30 * wxGetApp().em_unit())); Fit(); }