From a3f6ce1ac6a37c10e078672215c93bc0d705cab0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 10 Nov 2021 10:49:43 +0100 Subject: [PATCH] MsgDialog: Some code refactoring. Use style for whole Dialog instead of wxWindowID for just one default button --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/MsgDialog.cpp | 36 ++++++++++++-------------------- src/slic3r/GUI/MsgDialog.hpp | 3 +-- src/slic3r/GUI/Plater.cpp | 4 ++-- src/slic3r/GUI/UpdateDialogs.cpp | 23 +++++++------------- 5 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9c16a782e..9e92f1ac9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -865,7 +865,7 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup) "\n\nIf you select yes, PrusaSlicer will copy all profiles and other files from found folder to the current one." "\nIf you select no, you will start with clean installation with configuration wizard.") , m_older_data_dir_path, last_semver.to_string()) - , _L("PrusaSlicer"), wxICON_QUESTION | wxYES_NO); + , _L("PrusaSlicer"), /*wxICON_QUESTION | */wxYES_NO); if (msg.ShowModal() == wxID_YES) { std::string snapshot_id; if (backup) { diff --git a/src/slic3r/GUI/MsgDialog.cpp b/src/slic3r/GUI/MsgDialog.cpp index 2515f0281..1cf522417 100644 --- a/src/slic3r/GUI/MsgDialog.cpp +++ b/src/slic3r/GUI/MsgDialog.cpp @@ -25,7 +25,7 @@ namespace Slic3r { namespace GUI { -MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, wxWindowID button_id, wxBitmap bitmap) +MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style, wxBitmap bitmap) : wxDialog(parent ? parent : dynamic_cast(wxGetApp().mainframe), wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) , boldfont(wxGetApp().normal_font()) , content_sizer(new wxBoxSizer(wxVERTICAL)) @@ -49,12 +49,6 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he rightsizer->Add(content_sizer, 1, wxEXPAND); btn_sizer->AddStretchSpacer(); - if (button_id != wxID_NONE) { - auto *button = new wxButton(this, button_id); - button->SetFocus(); - btn_sizer->Add(button); - } - logo = new wxStaticBitmap(this, wxID_ANY, bitmap.IsOk() ? bitmap : wxNullBitmap); topsizer->Add(logo, 0, wxALL, BORDER); @@ -64,6 +58,8 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he main_sizer->Add(new StaticLine(this), 0, wxEXPAND | wxLEFT | wxRIGHT, HORIZ_SPACING); main_sizer->Add(btn_sizer, 0, wxALL | wxEXPAND, VERT_SPACING); + apply_style(style); + SetSizerAndFit(main_sizer); } @@ -83,9 +79,9 @@ void MsgDialog::apply_style(long style) if (style & wxNO) add_btn(wxID_NO); if (style & wxCANCEL) add_btn(wxID_CANCEL); - logo->SetBitmap(create_scaled_bitmap(style & wxICON_WARNING ? "exclamation" : - style & wxICON_INFORMATION ? "info" : - style & wxICON_QUESTION ? "question" : "PrusaSlicer"/*"_192px_grayscale.png"*/, this, 84)); + logo->SetBitmap( create_scaled_bitmap(style & wxICON_WARNING ? "exclamation" : + style & wxICON_INFORMATION ? "info" : + style & wxICON_QUESTION ? "question" : "PrusaSlicer", this, 64, style & wxICON_ERROR)); } void MsgDialog::finalize() @@ -161,18 +157,17 @@ static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxStrin msg_escaped = std::string("
") + msg_escaped + "
"; html->SetPage("" + wxString::FromUTF8(msg_escaped.data()) + ""); content_sizer->Add(html, 1, wxEXPAND); + wxGetApp().UpdateDarkUI(html); } // ErrorDialog ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg, bool monospaced_font) : MsgDialog(parent, wxString::Format(_(L("%s error")), SLIC3R_APP_NAME), - wxString::Format(_(L("%s has encountered an error")), SLIC3R_APP_NAME), - wxID_NONE) + wxString::Format(_(L("%s has encountered an error")), SLIC3R_APP_NAME), wxOK) , msg(msg) { add_msg_content(this, content_sizer, msg, monospaced_font); - add_btn(wxID_OK, true); // Use a small bitmap with monospaced font, as the error text will not be wrapped. logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, monospaced_font ? 48 : /*1*/84)); @@ -189,10 +184,9 @@ WarningDialog::WarningDialog(wxWindow *parent, const wxString& caption/* = wxEmptyString*/, long style/* = wxOK*/) : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s warning"), SLIC3R_APP_NAME) : caption, - wxString::Format(_L("%s has a warning")+":", SLIC3R_APP_NAME), wxID_NONE) + wxString::Format(_L("%s has a warning")+":", SLIC3R_APP_NAME), style) { add_msg_content(this, content_sizer, message); - apply_style(style); finalize(); } @@ -203,10 +197,9 @@ MessageDialog::MessageDialog(wxWindow* parent, const wxString& message, const wxString& caption/* = wxEmptyString*/, long style/* = wxOK*/) - : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, wxEmptyString, wxID_NONE) + : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, wxEmptyString, style) { add_msg_content(this, content_sizer, message); - apply_style(style); finalize(); } @@ -217,16 +210,16 @@ RichMessageDialog::RichMessageDialog(wxWindow* parent, const wxString& message, const wxString& caption/* = wxEmptyString*/, long style/* = wxOK*/) - : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, wxEmptyString, wxID_NONE) + : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, wxEmptyString, style) { add_msg_content(this, content_sizer, message); m_checkBox = new wxCheckBox(this, wxID_ANY, m_checkBoxText); + wxGetApp().UpdateDarkUI(m_checkBox); m_checkBox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { m_checkBoxValue = m_checkBox->GetValue(); }); btn_sizer->Insert(0, m_checkBox, wxALIGN_CENTER_VERTICAL); - apply_style(style); finalize(); } @@ -245,13 +238,10 @@ int RichMessageDialog::ShowModal() // InfoDialog InfoDialog::InfoDialog(wxWindow* parent, const wxString &title, const wxString& msg) - : MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), title) + : MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), title, wxOK | wxICON_INFORMATION) , msg(msg) { add_msg_content(this, content_sizer, msg); - // Set info bitmap - logo->SetBitmap(create_scaled_bitmap("info", this, 84)); - finalize(); } diff --git a/src/slic3r/GUI/MsgDialog.hpp b/src/slic3r/GUI/MsgDialog.hpp index a4807fd06..e49c29b85 100644 --- a/src/slic3r/GUI/MsgDialog.hpp +++ b/src/slic3r/GUI/MsgDialog.hpp @@ -41,8 +41,7 @@ protected: HORIZ_SPACING = 5, }; - // button_id is an id of a button that can be added by default, use wxID_NONE to disable - MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, wxWindowID button_id = wxID_OK, wxBitmap bitmap = wxNullBitmap); + MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style = wxOK, wxBitmap bitmap = wxNullBitmap); void add_btn(wxWindowID btn_id, bool set_focus = false); void apply_style(long style); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ca4e3e057..a85c4b0a0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2487,7 +2487,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ "The internal unit of PrusaSlicer are millimeters. Do you want to recalculate the dimensions of the object?", "The dimensions of some objects from file %s seem to be defined in meters.\n" "The internal unit of PrusaSlicer are millimeters. Do you want to recalculate the dimensions of these objects?", model.objects.size()), from_path(filename)) + "\n", - _L("The object is too small"), wxICON_WARNING | wxYES | wxNO); + _L("The object is too small"), wxICON_QUESTION | wxYES_NO); dlg.ShowCheckBox(_L("Apply to all the remaining small objects being loaded.")); int answer = dlg.ShowModal(); if (dlg.IsCheckBoxChecked()) @@ -2509,7 +2509,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ "The internal unit of PrusaSlicer are millimeters. Do you want to recalculate the dimensions of the object?", "The dimensions of some objects from file %s seem to be defined in inches.\n" "The internal unit of PrusaSlicer are millimeters. Do you want to recalculate the dimensions of these objects?", model.objects.size()), from_path(filename)) + "\n", - _L("The object is too small"), wxICON_WARNING | wxYES | wxNO); + _L("The object is too small"), wxICON_QUESTION | wxYES_NO); dlg.ShowCheckBox(_L("Apply to all the remaining small objects being loaded.")); int answer = dlg.ShowModal(); if (dlg.IsCheckBoxChecked()) diff --git a/src/slic3r/GUI/UpdateDialogs.cpp b/src/slic3r/GUI/UpdateDialogs.cpp index de132b184..d617ca660 100644 --- a/src/slic3r/GUI/UpdateDialogs.cpp +++ b/src/slic3r/GUI/UpdateDialogs.cpp @@ -156,7 +156,7 @@ MsgUpdateConfig::~MsgUpdateConfig() {} //MsgUpdateForced MsgUpdateForced::MsgUpdateForced(const std::vector& updates) : - MsgDialog(nullptr, wxString::Format(_(L("%s incompatibility")), SLIC3R_APP_NAME), _(L("You must install a configuration update.")) + " ", wxID_NONE) + MsgDialog(nullptr, wxString::Format(_(L("%s incompatibility")), SLIC3R_APP_NAME), _(L("You must install a configuration update.")) + " ", wxICON_ERROR) { auto* text = new wxStaticText(this, wxID_ANY, wxString::Format(_(L( "%s will now start updates. Otherwise it won't be able to start.\n\n" @@ -165,7 +165,6 @@ MsgUpdateForced::MsgUpdateForced(const std::vector& updates) : "Updated configuration bundles:" )), SLIC3R_APP_NAME)); - logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, 192)); text->Wrap(CONTENT_WIDTH * wxGetApp().em_unit()); content_sizer->Add(text); @@ -210,7 +209,7 @@ MsgUpdateForced::MsgUpdateForced(const std::vector& updates) : btn_exit->Bind(wxEVT_BUTTON, exiter); btn_ok->Bind(wxEVT_BUTTON, exiter); - Fit(); + finalize(); } MsgUpdateForced::~MsgUpdateForced() {} @@ -219,10 +218,8 @@ MsgUpdateForced::~MsgUpdateForced() {} MsgDataIncompatible::MsgDataIncompatible(const std::unordered_map &incompats) : MsgDialog(nullptr, wxString::Format(_(L("%s incompatibility")), SLIC3R_APP_NAME), - wxString::Format(_(L("%s configuration is incompatible")), SLIC3R_APP_NAME), wxID_NONE) + wxString::Format(_(L("%s configuration is incompatible")), SLIC3R_APP_NAME), /*wxID_NONE | */wxICON_ERROR) { - logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, 192)); - auto *text = new wxStaticText(this, wxID_ANY, wxString::Format(_(L( "This version of %s is not compatible with currently installed configuration bundles.\n" "This probably happened as a result of running an older %s after using a newer one.\n\n" @@ -265,7 +262,7 @@ MsgDataIncompatible::MsgDataIncompatible(const std::unordered_mapBind(wxEVT_BUTTON, exiter); btn_reconf->Bind(wxEVT_BUTTON, exiter); - Fit(); + finalize(); } MsgDataIncompatible::~MsgDataIncompatible() {} @@ -303,9 +300,7 @@ MsgDataLegacy::MsgDataLegacy() : content_sizer->Add(link); content_sizer->AddSpacer(VERT_SPACING); - wxGetApp().UpdateDlgDarkUI(this); - - Fit(); + finalize(); } MsgDataLegacy::~MsgDataLegacy() {} @@ -314,7 +309,7 @@ MsgDataLegacy::~MsgDataLegacy() {} // MsgNoUpdate MsgNoUpdates::MsgNoUpdates() : - MsgDialog(nullptr, _(L("Configuration updates")), _(L("No updates available"))) + MsgDialog(nullptr, _(L("Configuration updates")), _(L("No updates available")), wxICON_ERROR) { auto* text = new wxStaticText(this, wxID_ANY, wxString::Format( @@ -327,11 +322,7 @@ MsgNoUpdates::MsgNoUpdates() : content_sizer->Add(text); content_sizer->AddSpacer(VERT_SPACING); - logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, 192)); - - wxGetApp().UpdateDlgDarkUI(this); - - Fit(); + finalize(); } MsgNoUpdates::~MsgNoUpdates() {}