From 3cb138699046a3e423b80ec77c22fd7501313d75 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 30 Jan 2023 16:29:15 +0100 Subject: [PATCH] ButtonsDescription files: Some code refactoring ButtonsDescription class is splitted to separated items and put to the namespace GUI_Descriptions --- src/slic3r/GUI/ButtonsDescription.cpp | 14 +++++----- src/slic3r/GUI/ButtonsDescription.hpp | 38 ++++++++++++++------------- src/slic3r/GUI/Preferences.cpp | 4 +-- src/slic3r/GUI/Tab.cpp | 2 +- src/slic3r/GUI/Tab.hpp | 2 +- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/slic3r/GUI/ButtonsDescription.cpp b/src/slic3r/GUI/ButtonsDescription.cpp index 8460a9411..e225c7db7 100644 --- a/src/slic3r/GUI/ButtonsDescription.cpp +++ b/src/slic3r/GUI/ButtonsDescription.cpp @@ -83,8 +83,9 @@ wxBitmapBundle * ModePaletteComboBox::get_bmp(const std::vector &pa return bmp_bndl; } +namespace GUI_Descriptions { -void ButtonsDescription::FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour) +void FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour) { wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(3, 5, 5); sizer->Add(grid_sizer, 0, wxEXPAND); @@ -127,7 +128,7 @@ void ButtonsDescription::FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWi add_color(mod_colour, wxGetApp().get_label_clr_modified(),wxGetApp().get_label_default_clr_modified(), _L("Value was changed and is not equal to the system value or the last saved preset")); } -void ButtonsDescription::FillSizerWithModeColorDescriptions( +void FillSizerWithModeColorDescriptions( wxSizer* sizer, wxWindow* parent, std::vector clr_pickers, std::vector& mode_palette) @@ -195,7 +196,7 @@ void ButtonsDescription::FillSizerWithModeColorDescriptions( } } -ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vector &entries) : +Dialog::Dialog(wxWindow* parent, const std::vector &entries) : wxDialog(parent, wxID_ANY, _(L("Buttons And Text Colors Description")), wxDefaultPosition, wxDefaultSize), m_entries(entries) { @@ -207,7 +208,7 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vectorAdd(grid_sizer, 0, wxEXPAND | wxALL, 20); // Icon description - for (const Entry &entry : m_entries) + for (const ButtonEntry &entry : m_entries) { auto icon = new wxStaticBitmap(this, wxID_ANY, entry.bitmap->bmp()); grid_sizer->Add(icon, -1, wxALIGN_CENTRE_VERTICAL); @@ -219,14 +220,14 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vectorAdd(sizer, 0, wxEXPAND | wxALL, 20); // Mode color markers description mode_palette = wxGetApp().get_mode_palette(); wxSizer* mode_sizer = new wxBoxSizer(wxVERTICAL); - FillSizerWithModeColorDescriptions(mode_sizer, this, { &simple, &advanced, &expert }, mode_palette); + GUI_Descriptions::FillSizerWithModeColorDescriptions(mode_sizer, this, { &simple, &advanced, &expert }, mode_palette); main_sizer->Add(mode_sizer, 0, wxEXPAND | wxALL, 20); auto buttons = CreateStdDialogButtonSizer(wxOK|wxCANCEL); @@ -248,6 +249,7 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vectorSetSizeHints(this); } +} // GUI_Descriptions } // GUI } // Slic3r diff --git a/src/slic3r/GUI/ButtonsDescription.hpp b/src/slic3r/GUI/ButtonsDescription.hpp index d1315d3d0..13aa909ab 100644 --- a/src/slic3r/GUI/ButtonsDescription.hpp +++ b/src/slic3r/GUI/ButtonsDescription.hpp @@ -35,9 +35,20 @@ protected: wxBitmapBundle* get_bmp( const std::vector& palette); }; +namespace GUI_Descriptions { -class ButtonsDescription : public wxDialog +struct ButtonEntry { + ButtonEntry(ScalableBitmap *bitmap, const std::string &symbol, const std::string &explanation) : bitmap(bitmap), symbol(symbol), explanation(explanation) {} + + ScalableBitmap *bitmap; + std::string symbol; + std::string explanation; +}; + +class Dialog : public wxDialog { + std::vector m_entries; + wxColourPickerCtrl* sys_colour{ nullptr }; wxColourPickerCtrl* mod_colour{ nullptr }; @@ -47,26 +58,17 @@ class ButtonsDescription : public wxDialog std::vector mode_palette; public: - struct Entry { - Entry(ScalableBitmap *bitmap, const std::string &symbol, const std::string &explanation) : bitmap(bitmap), symbol(symbol), explanation(explanation) {} - ScalableBitmap *bitmap; - std::string symbol; - std::string explanation; - }; - - ButtonsDescription(wxWindow* parent, const std::vector &entries); - ~ButtonsDescription() {} - - static void FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour); - static void FillSizerWithModeColorDescriptions(wxSizer* sizer, wxWindow* parent, - std::vector clr_pickers, - std::vector& mode_palette); - -private: - std::vector m_entries; + Dialog(wxWindow* parent, const std::vector &entries); + ~Dialog() {} }; +extern void FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour); +extern void FillSizerWithModeColorDescriptions(wxSizer* sizer, wxWindow* parent, + std::vector clr_pickers, + std::vector& mode_palette); +} // GUI_Descriptions + } // GUI } // Slic3r diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 1b2c68bdd..6727b7553 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1041,7 +1041,7 @@ void PreferencesDialog::create_settings_text_color_widget() m_blinkers[opt_key] = new BlinkingBitmap(parent); wxSizer* stb_sizer = new wxStaticBoxSizer(stb, wxVERTICAL); - ButtonsDescription::FillSizerWithTextColorDescriptions(stb_sizer, parent, &m_sys_colour, &m_mod_colour); + GUI_Descriptions::FillSizerWithTextColorDescriptions(stb_sizer, parent, &m_sys_colour, &m_mod_colour); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_blinkers[opt_key], 0, wxRIGHT, 2); @@ -1068,7 +1068,7 @@ void PreferencesDialog::create_settings_mode_color_widget() // Mode color markers description m_mode_palette = wxGetApp().get_mode_palette(); - ButtonsDescription::FillSizerWithModeColorDescriptions(stb_sizer, parent, { &m_mode_simple, &m_mode_advanced, &m_mode_expert }, m_mode_palette); + GUI_Descriptions::FillSizerWithModeColorDescriptions(stb_sizer, parent, { &m_mode_simple, &m_mode_advanced, &m_mode_expert }, m_mode_palette); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_blinkers[opt_key], 0, wxRIGHT, 2); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 43eaa1a22..434d6d1e7 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -194,7 +194,7 @@ void Tab::create_preset_tab() m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); })); m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); })); m_question_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) { - ButtonsDescription dlg(this, m_icon_descriptions); + GUI_Descriptions::Dialog dlg(this, m_icon_descriptions); if (dlg.ShowModal() == wxID_OK) wxGetApp().update_label_colours(); }); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index b131761e6..1a2edfe05 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -254,7 +254,7 @@ protected: std::map m_options_list; int m_opt_status_value = 0; - std::vector m_icon_descriptions = {}; + std::vector m_icon_descriptions = {}; bool m_is_modified_values{ false }; bool m_is_nonsys_values{ true };